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(dual-axes): 修复双轴图缩略轴问题 #3714

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
71 changes: 71 additions & 0 deletions __tests__/bugs/bug-dual-axes-silder-spec.ts
Original file line number Diff line number Diff line change
@@ -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();
});
});
4 changes: 2 additions & 2 deletions src/plots/dual-axes/adaptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,8 @@ export function slider(params: Params<DualAxesOptions>): Params<DualAxesOptions>
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]);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/plots/dual-axes/util/render-sider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Loading