From 66ea0f0b123ce09bfbc3e301f6951b22a758f3eb Mon Sep 17 00:00:00 2001 From: liwenbo Date: Wed, 6 Dec 2023 21:25:02 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(dual-axes):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=8F=8C=E8=BD=B4=E5=9B=BE=E7=BC=A9=E7=95=A5=E8=BD=B4=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/plots/dual-axes/util/render-sider.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/plots/dual-axes/util/render-sider.ts b/src/plots/dual-axes/util/render-sider.ts index d8f89b1a65..be75e84e56 100644 --- a/src/plots/dual-axes/util/render-sider.ts +++ b/src/plots/dual-axes/util/render-sider.ts @@ -21,8 +21,8 @@ export const doSliderFilter = (view: View, sliderValue: [number, number]) => { const values = valuesOfKey(data, xScale.field); const xValues = isHorizontal ? values : values.reverse(); const xTickCount = size(xValues); - const minIndex = Math.floor(min * (xTickCount - 1)); - const maxIndex = Math.floor(max * (xTickCount - 1)); + const minIndex = Math.round(min * (xTickCount - 1)); + const maxIndex = Math.round(max * (xTickCount - 1)); // 增加 x 轴的过滤器 view.filter(xScale.field, (value: any) => { From 1ab71a664dbb0d8ee91f0785e5b61c0a4425eddb Mon Sep 17 00:00:00 2001 From: liwenbo Date: Wed, 6 Dec 2023 22:10:26 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix(dual-axes):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=8F=8C=E8=BD=B4=E5=9B=BE=E7=BC=A9=E7=95=A5=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?start=E6=88=96end=E4=B8=A2=E5=A4=B1=E5=8F=B3=E4=BE=A7view?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __tests__/bugs/bug-dual-axes-silder-spec.ts | 71 +++++++++++++++++++++ src/plots/dual-axes/adaptor.ts | 4 +- 2 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 __tests__/bugs/bug-dual-axes-silder-spec.ts diff --git a/__tests__/bugs/bug-dual-axes-silder-spec.ts b/__tests__/bugs/bug-dual-axes-silder-spec.ts new file mode 100644 index 0000000000..6f58d52087 --- /dev/null +++ b/__tests__/bugs/bug-dual-axes-silder-spec.ts @@ -0,0 +1,71 @@ +import { DualAxes } from '../../src'; +import { createDiv } from '../utils/dom'; + +describe('dual-axes slider', () => { + const data = [ + { time: '2019-03', value: 350, count: 800 }, + { time: '2019-04', value: 900, count: 600 }, + { time: '2019-05', value: 300, count: 400 }, + { time: '2019-06', value: 450, count: 380 }, + { time: '2019-07', value: 470, count: 220 }, + ]; + + it('slider left view should have data', () => { + const dualAxes = new DualAxes(createDiv(), { + data: [data, data], + xField: 'time', + yField: ['value', 'count'], + slider: { + end: 1, + }, + geometryOptions: [ + { + geometry: 'column', + }, + { + geometry: 'line', + lineStyle: { + lineWidth: 2, + }, + }, + ], + }); + + dualAxes.render(); + const filterData = dualAxes.chart.views[1].getData(); + expect(filterData.length).toBeGreaterThan(0); + expect(filterData).toEqual(data); + + dualAxes.destroy(); + }); + + it('dual axes should have same data', () => { + const dualAxes = new DualAxes(createDiv(), { + data: [data, data], + xField: 'time', + yField: ['value', 'count'], + slider: { + end: 0.9, + }, + geometryOptions: [ + { + geometry: 'column', + }, + { + geometry: 'line', + lineStyle: { + lineWidth: 2, + }, + }, + ], + }); + + dualAxes.render(); + + const columnFilterData = dualAxes.chart.views[0].getData(); + const lineFilterData = dualAxes.chart.views[1].getData(); + expect(columnFilterData).toEqual(lineFilterData); + + dualAxes.destroy(); + }); +}); diff --git a/src/plots/dual-axes/adaptor.ts b/src/plots/dual-axes/adaptor.ts index 151eaec6b3..ca9035f059 100644 --- a/src/plots/dual-axes/adaptor.ts +++ b/src/plots/dual-axes/adaptor.ts @@ -473,8 +473,8 @@ export function slider(params: Params): Params chart.once('afterpaint', () => { // 初始化数据,配置默认值时需要同步 if (!isBoolean(slider)) { - const { start, end } = slider; - if (start || end) { + const { start = 0, end = 1 } = slider; + if (start !== 0 || end !== 1) { doSliderFilter(rightView, [start, end]); } }