Skip to content

Commit

Permalink
fix(line): use curveMonotone (#5751)
Browse files Browse the repository at this point in the history
  • Loading branch information
pearmini committed Nov 7, 2023
1 parent db505fe commit 2bedfba
Show file tree
Hide file tree
Showing 24 changed files with 62 additions and 4 deletions.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/static/browserImageTrending.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/static/forecastRangeAreaLine.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/static/weatherLineAreaDualAxis.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/static/weatherLineMultiAxes.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified __tests__/integration/snapshots/static/weatherLineMultiSlider.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions __tests__/plots/static/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,3 +297,6 @@ export { intervalPointBulletDatas } from './interval-point-bullet-datas';
export { mockIntervalLine } from './mock-interval-line';
export { alphabetIntervalSizedPadding } from './alphabet-interval-sized-padding';
export { alphabetIntervalRotatePadding } from './alphabet-interval-rotate-padding';
export { mockLineZeroX } from './mock-line-zero-x';
export { mockLineZeroY } from './mock-line-zero-y';
export { mockLineCloseX } from './mock-line-close-x';
14 changes: 14 additions & 0 deletions __tests__/plots/static/mock-line-close-x.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { G2Spec } from '../../../src';

export function mockLineCloseX(): G2Spec {
return {
type: 'line',
data: [
{ x: 0, y: 0 },
{ x: 0.02, y: 0.8 },
{ x: 1, y: 1 },
],
encode: { x: 'x', y: 'y' },
style: { shape: 'smooth' },
};
}
16 changes: 16 additions & 0 deletions __tests__/plots/static/mock-line-zero-x.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { G2Spec } from '../../../src';

export function mockLineZeroX(): G2Spec {
return {
type: 'line',
data: [
{ date: '2-1', close: 1 },
{ date: '2-2', close: 10 },
{ date: '2-3', close: 0 },
{ date: '2-4', close: 0 },
{ date: '2-5', close: 12 },
],
encode: { x: 'date', y: 'close' },
style: { shape: 'smooth' },
};
}
17 changes: 17 additions & 0 deletions __tests__/plots/static/mock-line-zero-y.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { G2Spec } from '../../../src';

export function mockLineZeroY(): G2Spec {
return {
type: 'line',
coordinate: { transform: [{ type: 'transpose' }] },
data: [
{ date: '2-1', close: 1 },
{ date: '2-2', close: 10 },
{ date: '2-3', close: 0 },
{ date: '2-4', close: 0 },
{ date: '2-5', close: 12 },
],
encode: { x: 'date', y: 'close' },
style: { shape: 'smooth' },
};
}
16 changes: 12 additions & 4 deletions src/shape/line/smooth.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import { curveCatmullRom, curveCatmullRomClosed } from 'd3-shape';
import { isPolar } from '../../utils/coordinate';
import {
curveMonotoneX,
curveMonotoneY,
curveCatmullRomClosed,
} from 'd3-shape';
import { isPolar, isTranspose } from '../../utils/coordinate';
import { ShapeComponent as SC } from '../../runtime';
import { Curve } from './curve';

Expand All @@ -11,8 +15,12 @@ export const Smooth: SC<SmoothOptions> = (options, context) => {
const { alpha = 0.5, ...rest } = options;
const { coordinate } = context;
return (...params) => {
const curve = isPolar(coordinate) ? curveCatmullRomClosed : curveCatmullRom;
return Curve({ curve: curve.alpha(alpha), ...rest }, context)(...params);
const curve = isPolar(coordinate)
? curveCatmullRomClosed
: isTranspose(coordinate)
? curveMonotoneY
: curveMonotoneX;
return Curve({ curve: curve, ...rest }, context)(...params);
};
};

Expand Down

0 comments on commit 2bedfba

Please sign in to comment.