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 show error when missing data #5175

Merged
merged 1 commit into from
Jun 8, 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.
31 changes: 31 additions & 0 deletions __tests__/plots/static/aapl-line-missing-label.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { G2Spec } from '../../../src';

export function aaplLineMissingLabel(): G2Spec {
return {
type: 'line',
data: [
{ time: '10:10', call: 4, waiting: 2, people: 2 },
{ time: '10:15', call: 2, waiting: 6, people: 3 },
{ time: '10:20', call: 13, waiting: 2 },
{ time: '10:25', call: 9, waiting: 9, people: 1 },
{ time: '10:30', call: 5, waiting: 2, people: 3 },
{ time: '10:35', call: 8, waiting: 2, people: 1 },
{ time: '10:40', call: 13, waiting: 1, people: 2 },
],
encode: {
x: 'time',
y: 'people',
},
labels: [
{
text: 'people',
dy: -20,
connector: true,
connectorStroke: 'red',
connectorLineWidth: 2,
},
],
};
}

aaplLineMissingLabel.maxError = 100;
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export { unemploymentLineMultiSeries } from './unemployment-line-multi-series';
export { receiptsLineSlope } from './receipts-line-slope';
export { stocksLineAggregateLabel } from './stocks-line-aggregate-label';
export { aaplLineMissing } from './aapl-line-missing';
export { aaplLineMissingLabel } from './aapl-line-missing-label';
export { aaplLineMissingConnect } from './aapl-line-missing-connect';
export { aaplLineMissingStyled } from './aapl-line-missing-styled';
export { paragraphTextVis } from './paragraph-text-vis';
Expand Down
18 changes: 8 additions & 10 deletions src/runtime/plot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1031,16 +1031,14 @@ function getLabels(
];
}
const selector = normalizeLabelSelector(label);
const F = SI.filter((_, i) => points[i].every(defined)).map(
(index: number, i: number) => ({
...label,
key: `${seriesKey[i]}-${labelIndex}`,
bounds: [points[i]],
index,
points,
dependentElement: element,
}),
);
const F = SI.map((index: number, i: number) => ({
...label,
key: `${seriesKey[i]}-${labelIndex}`,
bounds: [points[i]],
index,
points,
dependentElement: element,
}));
return selector ? selector(F) : F;
}

Expand Down
6 changes: 5 additions & 1 deletion src/shape/text/advance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
RectStyleProps,
PathStyleProps,
} from '@antv/g';
import { isNumber } from '@antv/util';
import { Marker } from '@antv/gui';
import { line } from 'd3-shape';
import { WithPrefix } from '../../runtime';
Expand Down Expand Up @@ -103,7 +104,7 @@ function inferConnectorPath(
}

const P: any = [[x0 - x1, y0 - y1]].concat(
controlPoints.length ? controlPoints : [0, 0],
controlPoints.length ? controlPoints : [[0, 0]],
);

const p0 = [coordCenter[0] - x1, coordCenter[1] - y1] as Vector2;
Expand Down Expand Up @@ -142,6 +143,9 @@ 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;

hustcc marked this conversation as resolved.
Show resolved Hide resolved
const { padding, ...backgroundStyle } = subObject(rest, 'background');
const { points = [], ...connectorStyle } = subObject(rest, 'connector');
const endPoints: Vector2[] = [
Expand Down