From b21224269a8e35f7bf09377fa1e3d5d801073af1 Mon Sep 17 00:00:00 2001 From: taoliujun <290762903@qq.com> Date: Tue, 5 Dec 2023 14:20:37 +0800 Subject: [PATCH] fix: area and line shares the same curve generator(#5877) * docs: update description of mark shape options * fix: let area and line use the same curve smoothing strategy * test: update tests for modification of the area curve strategy * test: add tests for modification of the area curve strategy --------- Co-authored-by: taoliujun --- .../snapshots/animation/control/interval0.svg | 62 +- .../snapshots/animation/control/interval1.svg | 62 +- .../snapshots/animation/control/interval2.svg | 59 +- .../snapshots/animation/control/interval3.svg | 59 +- .../os-area-stack-enter/interval0-0.svg | 56 +- .../os-area-stack-enter/interval0-1.svg | 56 +- .../os-area-stack-enter/interval0-2.svg | 56 +- .../animation/stocks-keyframe/interval2-0.svg | 14 +- .../animation/stocks-keyframe/interval2-1.svg | 14 +- .../animation/stocks-keyframe/interval3-0.svg | 14 +- .../animation/stocks-keyframe/interval3-1.svg | 14 +- .../static/aaplAreaLineSmoothSample.svg | 1067 +++++++++++++++++ .../static/forecastRangeAreaLine.svg | 4 +- .../static/aapl-area-line-smooth-sample.ts | 49 + __tests__/plots/static/index.ts | 1 + site/docs/spec/mark/area.zh.md | 12 +- site/docs/spec/mark/line.zh.md | 6 +- src/shape/area/smooth.ts | 22 +- src/shape/line/smooth.ts | 8 +- 19 files changed, 1365 insertions(+), 270 deletions(-) create mode 100644 __tests__/integration/snapshots/static/aaplAreaLineSmoothSample.svg create mode 100644 __tests__/plots/static/aapl-area-line-smooth-sample.ts diff --git a/__tests__/integration/snapshots/animation/control/interval0.svg b/__tests__/integration/snapshots/animation/control/interval0.svg index 22abac6ced..8372120a34 100644 --- a/__tests__/integration/snapshots/animation/control/interval0.svg +++ b/__tests__/integration/snapshots/animation/control/interval0.svg @@ -9,31 +9,25 @@ - - + + - - + + - - + + - + - + @@ -1898,7 +1895,7 @@ - - + + - + - + - + @@ -1886,7 +1883,7 @@ @@ -1928,7 +1925,7 @@ @@ -1949,7 +1946,7 @@ @@ -1970,7 +1967,7 @@ diff --git a/__tests__/integration/snapshots/animation/os-area-stack-enter/interval0-0.svg b/__tests__/integration/snapshots/animation/os-area-stack-enter/interval0-0.svg index 6093e3639c..cbfa6ae59f 100644 --- a/__tests__/integration/snapshots/animation/os-area-stack-enter/interval0-0.svg +++ b/__tests__/integration/snapshots/animation/os-area-stack-enter/interval0-0.svg @@ -9,20 +9,20 @@ - - + + - + - + - + - - + + - + - + - + @@ -915,7 +915,7 @@ - - + + - + - + - + @@ -915,7 +915,7 @@ @@ -957,7 +957,7 @@ @@ -978,7 +978,7 @@ @@ -999,7 +999,7 @@ diff --git a/__tests__/integration/snapshots/animation/stocks-keyframe/interval2-0.svg b/__tests__/integration/snapshots/animation/stocks-keyframe/interval2-0.svg index 1b6a8f39d3..b7192a0cb4 100644 --- a/__tests__/integration/snapshots/animation/stocks-keyframe/interval2-0.svg +++ b/__tests__/integration/snapshots/animation/stocks-keyframe/interval2-0.svg @@ -3505,7 +3505,7 @@ - + - + - + - + - + - + - + - + - + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2008 + + + + + + + 2009 + + + + + + + 2010 + + + + + + + 2011 + + + + + + + 2012 + + + + + + + + + date + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 0 + + + + + + + 100 + + + + + + + 200 + + + + + + + 300 + + + + + + + 400 + + + + + + + 500 + + + + + + + 600 + + + + + + + + + close + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/__tests__/integration/snapshots/static/forecastRangeAreaLine.svg b/__tests__/integration/snapshots/static/forecastRangeAreaLine.svg index aa4550966e..048fc0fdef 100644 --- a/__tests__/integration/snapshots/static/forecastRangeAreaLine.svg +++ b/__tests__/integration/snapshots/static/forecastRangeAreaLine.svg @@ -735,11 +735,11 @@ transform="matrix(1,0,0,1,0,0)" class="main-layer" > - + ; export const Smooth: SC = (options, context) => { - const { alpha = 0.5, ...rest } = options; + const { ...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, ...rest }, context)(...params); }; }; diff --git a/src/shape/line/smooth.ts b/src/shape/line/smooth.ts index 142cae9418..bac431a477 100644 --- a/src/shape/line/smooth.ts +++ b/src/shape/line/smooth.ts @@ -7,12 +7,10 @@ import { isPolar, isTranspose } from '../../utils/coordinate'; import { ShapeComponent as SC } from '../../runtime'; import { Curve } from './curve'; -export type SmoothOptions = { - alpha?: number; -}; +export type SmoothOptions = Record; export const Smooth: SC = (options, context) => { - const { alpha = 0.5, ...rest } = options; + const { ...rest } = options; const { coordinate } = context; return (...params) => { const curve = isPolar(coordinate) @@ -20,7 +18,7 @@ export const Smooth: SC = (options, context) => { : isTranspose(coordinate) ? curveMonotoneY : curveMonotoneX; - return Curve({ curve: curve, ...rest }, context)(...params); + return Curve({ curve, ...rest }, context)(...params); }; };