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(line): support missing trail #5227

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

export function aaplLineMissingDataTrial(): G2Spec {
return {
type: 'line',
data: {
type: 'fetch',
value: 'data/aapl.csv',
transform: [
{ type: 'slice', end: 100 },
{
type: 'map',
callback: (d) => ({
...d,
close1: d.date.getDate() <= 14 ? NaN : d.close,
}),
},
],
},
encode: {
x: 'date',
y: 'close1',
size: 'close',
},
style: { shape: 'trail' },
};
}

aaplLineMissingDataTrial.maxError = 125;
1 change: 1 addition & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,4 @@ export { mockLegendColorSize } from './mock-legend-color-size';
export { weatherLineMultiAxesLegend } from './weather-line-multi-axes-legend';
export { population2015IntervalDonutTextAnnotationInset } from './population2015-interval-donut-text-annotation-inset';
export { stocksLineSeriesGradient } from './stocks-line-series-gradient';
export { aaplLineMissingDataTrial } from './aapl-line-missing-data-trial';
31 changes: 31 additions & 0 deletions site/examples/general/line/demo/line-var-size-missing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { Chart } from '@antv/g2';

const chart = new Chart({
container: 'container',
theme: 'classic',
autoFit: true,
});

chart
.line()
.data({
type: 'fetch',
value:
'https://gw.alipayobjects.com/os/bmw-prod/551d80c6-a6be-4f3c-a82a-abd739e12977.csv',
transform: [
{ type: 'slice', end: 100 },
{
type: 'map',
callback: (d) => ({
...d,
close1: d.date.getDate() <= 5 ? NaN : d.close,
}),
},
],
})
.encode('x', (d) => new Date(d.date))
.encode('y', 'close1')
.encode('size', 'close')
.style('shape', 'trail');

chart.render();
8 changes: 8 additions & 0 deletions site/examples/general/line/demo/meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*pWrERLZIMyQAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "line-var-size-missing.ts",
"title": {
"zh": "缺失变宽折线图",
"en": "Missing Var Size Line Chart"
},
"screenshot": "https://mdn.alipayobjects.com/huamei_qa8qxu/afts/img/A*haZaQaG0tBgAAAAAAAAAAAAADmJ7AQ/original"
},
{
"filename": "line-var-size-facet.ts",
"title": {
Expand Down
4 changes: 3 additions & 1 deletion src/shape/line/trail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ShapeComponent as SC } from '../../runtime';
import { select } from '../../utils/selection';
import { applyStyle } from '../utils';
import { angle, sub, add, Vector2 } from '../../utils/vector';
import { defined } from '../../utils/helper';
import { Curve } from './curve';

/**
Expand Down Expand Up @@ -44,6 +45,7 @@ function stroke(path, p0, p1, s0, s1) {

export type TrailOptions = Record<string, any>;

// @todo Support connect and connectStyle.
export const Trail: SC<TrailOptions> = (options, context) => {
const { document } = context;
return (P, value, defaults) => {
Expand All @@ -55,7 +57,7 @@ export const Trail: SC<TrailOptions> = (options, context) => {
const p1 = P[i + 1];
const s0 = seriesSize[i];
const s1 = seriesSize[i + 1];
stroke(path, p0, p1, s0, s1);
if ([...p0, ...p1].every(defined)) stroke(path, p0, p1, s0, s1);
}
return select(document.createElement('path', {}))
.call(applyStyle, rest)
Expand Down