diff --git a/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-0.png b/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-0.png index 8246ef6111..12b9a75fc1 100644 Binary files a/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-0.png and b/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-0.png differ diff --git a/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-1.png b/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-1.png index 0ad22b715f..9e65472480 100644 Binary files a/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-1.png and b/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-1.png differ diff --git a/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-2.png b/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-2.png index dcf18f5457..c3e8e0d8d5 100644 Binary files a/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-2.png and b/__tests__/integration/snapshots/animation/doughnut-purchases-line-path-in/interval0-2.png differ diff --git a/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step0.png b/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step0.png index 1fc83becb7..9af4d332a1 100644 Binary files a/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step0.png and b/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step0.png differ diff --git a/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step1.png b/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step1.png index cb060014f5..81c387cf0e 100644 Binary files a/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step1.png and b/__tests__/integration/snapshots/interaction/weather-line-legend-mark/step1.png differ diff --git a/__tests__/integration/snapshots/static/browserImageTrending.png b/__tests__/integration/snapshots/static/browserImageTrending.png index 8110f10773..db56a35d0b 100644 Binary files a/__tests__/integration/snapshots/static/browserImageTrending.png and b/__tests__/integration/snapshots/static/browserImageTrending.png differ diff --git a/__tests__/integration/snapshots/static/forecastRangeAreaLine.png b/__tests__/integration/snapshots/static/forecastRangeAreaLine.png index 7ddde50c2a..57aab08a5b 100644 Binary files a/__tests__/integration/snapshots/static/forecastRangeAreaLine.png and b/__tests__/integration/snapshots/static/forecastRangeAreaLine.png differ diff --git a/__tests__/integration/snapshots/static/gammaRandomLineSortXQuantitative.png b/__tests__/integration/snapshots/static/gammaRandomLineSortXQuantitative.png index 79feb3b484..b47c415024 100644 Binary files a/__tests__/integration/snapshots/static/gammaRandomLineSortXQuantitative.png and b/__tests__/integration/snapshots/static/gammaRandomLineSortXQuantitative.png differ diff --git a/__tests__/integration/snapshots/static/mockLineCloseX.png b/__tests__/integration/snapshots/static/mockLineCloseX.png new file mode 100644 index 0000000000..72cba0b49f Binary files /dev/null and b/__tests__/integration/snapshots/static/mockLineCloseX.png differ diff --git a/__tests__/integration/snapshots/static/mockLineZeroX.png b/__tests__/integration/snapshots/static/mockLineZeroX.png new file mode 100644 index 0000000000..fdf5e6aabc Binary files /dev/null and b/__tests__/integration/snapshots/static/mockLineZeroX.png differ diff --git a/__tests__/integration/snapshots/static/mockLineZeroY.png b/__tests__/integration/snapshots/static/mockLineZeroY.png new file mode 100644 index 0000000000..db05122c05 Binary files /dev/null and b/__tests__/integration/snapshots/static/mockLineZeroY.png differ diff --git a/__tests__/integration/snapshots/static/stocksLineSeriesGradient.png b/__tests__/integration/snapshots/static/stocksLineSeriesGradient.png index 9dae0744e6..a16ab4dddf 100644 Binary files a/__tests__/integration/snapshots/static/stocksLineSeriesGradient.png and b/__tests__/integration/snapshots/static/stocksLineSeriesGradient.png differ diff --git a/__tests__/integration/snapshots/static/weatherLineAreaDualAxis.png b/__tests__/integration/snapshots/static/weatherLineAreaDualAxis.png index 425bf87f2d..32e3b7b14a 100644 Binary files a/__tests__/integration/snapshots/static/weatherLineAreaDualAxis.png and b/__tests__/integration/snapshots/static/weatherLineAreaDualAxis.png differ diff --git a/__tests__/integration/snapshots/static/weatherLineMultiAxes.png b/__tests__/integration/snapshots/static/weatherLineMultiAxes.png index 1b29f3c1c5..f79e98f2ae 100644 Binary files a/__tests__/integration/snapshots/static/weatherLineMultiAxes.png and b/__tests__/integration/snapshots/static/weatherLineMultiAxes.png differ diff --git a/__tests__/integration/snapshots/static/weatherLineMultiAxesAutoPadding.png b/__tests__/integration/snapshots/static/weatherLineMultiAxesAutoPadding.png index b743c6d0cf..04c9d732ec 100644 Binary files a/__tests__/integration/snapshots/static/weatherLineMultiAxesAutoPadding.png and b/__tests__/integration/snapshots/static/weatherLineMultiAxesAutoPadding.png differ diff --git a/__tests__/integration/snapshots/static/weatherLineMultiAxesLegend.png b/__tests__/integration/snapshots/static/weatherLineMultiAxesLegend.png index cb060014f5..81c387cf0e 100644 Binary files a/__tests__/integration/snapshots/static/weatherLineMultiAxesLegend.png and b/__tests__/integration/snapshots/static/weatherLineMultiAxesLegend.png differ diff --git a/__tests__/integration/snapshots/static/weatherLineMultiScrollbar.png b/__tests__/integration/snapshots/static/weatherLineMultiScrollbar.png index a78fec956d..220aa27f37 100644 Binary files a/__tests__/integration/snapshots/static/weatherLineMultiScrollbar.png and b/__tests__/integration/snapshots/static/weatherLineMultiScrollbar.png differ diff --git a/__tests__/integration/snapshots/static/weatherLineMultiSlider.png b/__tests__/integration/snapshots/static/weatherLineMultiSlider.png index b3297cd380..16dd42e4d8 100644 Binary files a/__tests__/integration/snapshots/static/weatherLineMultiSlider.png and b/__tests__/integration/snapshots/static/weatherLineMultiSlider.png differ diff --git a/__tests__/integration/snapshots/static/weatherLineViewLabelTransform.png b/__tests__/integration/snapshots/static/weatherLineViewLabelTransform.png index f45c43c0a2..ffc8665af2 100644 Binary files a/__tests__/integration/snapshots/static/weatherLineViewLabelTransform.png and b/__tests__/integration/snapshots/static/weatherLineViewLabelTransform.png differ diff --git a/__tests__/plots/static/index.ts b/__tests__/plots/static/index.ts index ab2985742b..17b06db9f1 100644 --- a/__tests__/plots/static/index.ts +++ b/__tests__/plots/static/index.ts @@ -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'; diff --git a/__tests__/plots/static/mock-line-close-x.ts b/__tests__/plots/static/mock-line-close-x.ts new file mode 100644 index 0000000000..6e8090b371 --- /dev/null +++ b/__tests__/plots/static/mock-line-close-x.ts @@ -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' }, + }; +} diff --git a/__tests__/plots/static/mock-line-zero-x.ts b/__tests__/plots/static/mock-line-zero-x.ts new file mode 100644 index 0000000000..0a051c62c3 --- /dev/null +++ b/__tests__/plots/static/mock-line-zero-x.ts @@ -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' }, + }; +} diff --git a/__tests__/plots/static/mock-line-zero-y.ts b/__tests__/plots/static/mock-line-zero-y.ts new file mode 100644 index 0000000000..7b7bebd953 --- /dev/null +++ b/__tests__/plots/static/mock-line-zero-y.ts @@ -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' }, + }; +} diff --git a/src/shape/line/smooth.ts b/src/shape/line/smooth.ts index 7ccbf37664..142cae9418 100644 --- a/src/shape/line/smooth.ts +++ b/src/shape/line/smooth.ts @@ -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'; @@ -11,8 +15,12 @@ export const Smooth: SC = (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); }; };