Skip to content

Commit

Permalink
fix(axis): autoHide should not set crossSize (#5032)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini authored May 16, 2023
1 parent 6481b00 commit 86052fc
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ export function aaplLineSliderFilterTranspose(): G2Spec {

aaplLineSliderFilterTranspose.maxError = 500;

aaplLineSliderFilterTranspose.skip = true;

aaplLineSliderFilterTranspose.steps = ({ canvas }) => {
const { document } = canvas;
const sliders = document.getElementsByClassName(SLIDER_CLASS_NAME);
Expand Down
21 changes: 21 additions & 0 deletions __tests__/plots/static/aapl-line-axis-y-hide.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { G2Spec } from '../../../src';

export function aaplLineAxisYHide(): G2Spec {
return {
type: 'line',
height: 200,
paddingLeft: 80,
data: {
type: 'fetch',
value: 'data/aapl.csv',
},
encode: {
x: 'date',
y: 'close',
},
axis: {
x: false,
y: { labelFormatter: (d) => `${d}000`, transform: [{ type: 'hide' }] },
},
};
}
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,4 @@ export { alphabetIntervalLabelRotate } from './alphabet-interval-label-rotate';
export { aaplLineBasicTranspose } from './aapl-line-basic-transpose';
export { alphabetIntervalSortXDomain } from './alphabet-interval-sort-x-domain';
export { basicIntervalZeroDomainMin } from './basic-interval-zero-domain-min';
export { aaplLineAxisYHide } from './aapl-line-axis-y-hide';
17 changes: 11 additions & 6 deletions src/component/axis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Coordinate } from '@antv/coord';
import type { DisplayObject } from '@antv/g';
import { Axis as AxisComponent } from '@antv/gui';
import { Linear as LinearScale } from '@antv/scale';
import { deepMix } from '@antv/util';
import { deepMix, has } from '@antv/util';
import { extent } from 'd3-array';
import { format } from 'd3-format';
import {
Expand Down Expand Up @@ -199,22 +199,22 @@ function inferLabelOverlap(transform = [], style: Record<string, any>) {

const finalTransforms = [];

const addToTransfroms = (overlap, state) => {
const addToTransforms = (overlap, state) => {
if (state) {
finalTransforms.push(overlap);
}
};

addToTransfroms(
addToTransforms(
{
type: 'rotate',
optionalAngles: [0, 15, 30, 45, 60, 90],
},
labelAutoRotate,
);
addToTransfroms({ type: 'ellipsis', minLength: 20 }, labelAutoEllipsis);
addToTransfroms({ type: 'hide' }, labelAutoHide);
addToTransfroms(
addToTransforms({ type: 'ellipsis', minLength: 20 }, labelAutoEllipsis);
addToTransforms({ type: 'hide' }, labelAutoHide);
addToTransforms(
{ type: 'wrap', wordWrapWidth: 100, maxLines: 3, recoveryWhenFail: true },
labelAutoWrap,
);
Expand Down Expand Up @@ -530,6 +530,11 @@ const LinearAxisComponent: GCC<AxisOptions> = (options) => {
...overrideStyle,
...important,
};

// For hide overlap, do not set crossSize.
const hasHide = finalAxisStyle.labelOverlap.find((d) => d.type === 'hide');
if (hasHide) finalAxisStyle.crossSize = false;

return new AxisComponent({
className: 'axis',
style: adaptor(finalAxisStyle),
Expand Down

0 comments on commit 86052fc

Please sign in to comment.