Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(label): clear invalid labels #5310

Merged
merged 1 commit into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions __tests__/plots/interaction/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ export { unemploymentChoropleth } from './unemployment-choropleth';
export { weatherLineLegendMark } from './weather-line-legend-mark';
export { countriesAnnotationSliderFilter } from './countries-annotation-slider-filter';
export { unemploymentAreaLegendFilterPages } from './unemployment-area-legend-filter-pages';
export { mockAreaSliderFilterLabel } from './mock-area-slider-filter-label';
52 changes: 52 additions & 0 deletions __tests__/plots/interaction/mock-area-slider-filter-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { CustomEvent } from '@antv/g';
import { G2Spec } from '../../../src';
import { SLIDER_CLASS_NAME } from '../../../src/interaction/sliderFilter';

export function mockAreaSliderFilterLabel(): G2Spec {
return {
type: 'area',
padding: 'auto',
data: [
{ year: '1991', value: 15468 },
{ year: '1992', value: 16100 },
{ year: '1993', value: 15900 },
{ year: '1994', value: 17409 },
{ year: '1995', value: 17000 },
{ year: '1996', value: 31056 },
{ year: '1997', value: 31982 },
{ year: '1998', value: 32040 },
{ year: '1999', value: 33233 },
],
encode: {
x: 'year',
y: 'value',
},
labels: [{ text: 'value' }],
slider: { x: true },
style: { fillOpacity: 0.4 },
};
}

export function dispatchValueChange(slider, values = [0.25, 0.75]) {
slider.update({ values });
slider.dispatchEvent(
new CustomEvent('valuechange', {
detail: {
value: [0.25, 0.75],
},
}),
);
}

mockAreaSliderFilterLabel.steps = ({ canvas }) => {
const { document } = canvas;
const sliders = document.getElementsByClassName(SLIDER_CLASS_NAME);
const [s1] = sliders;
return [
{
changeState: () => {
dispatchValueChange(s1);
},
},
];
};
10 changes: 8 additions & 2 deletions src/shape/label/position/default.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,18 @@ function inferInnerCircularStyle(
};
}

// Set to null will not be set with default value as below.
// const { x = 0 } = options;
function maybeUndefined(d) {
return d === undefined ? null : d;
}

export function inferIdentityStyle(position, points, value, coordinate) {
const { bounds } = value;
const [p] = bounds;
return {
x: p[0],
y: p[1],
x: maybeUndefined(p[0]),
y: maybeUndefined(p[1]),
};
}

Expand Down
9 changes: 7 additions & 2 deletions src/shape/text/advance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,13 @@ export const Advance = createElement((g) => {
coordCenter,
...rest
} = g.attributes as TextShapeStyleProps;
// Position is invalid, do not render the UI.
if ([x, y, x0, y0].some((v) => !isNumber(v))) return;

// Position is invalid, do not render the UI,
// or clear previous elements.
if ([x, y, x0, y0].some((v) => !isNumber(v))) {
g.children.forEach((d) => d.remove());
return;
}

const { padding, ...backgroundStyle } = subObject(rest, 'background');
const { points = [], ...connectorStyle } = subObject(rest, 'connector');
Expand Down
Loading