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 slider filter #3761

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
53 changes: 53 additions & 0 deletions __tests__/bugs/issue-3749-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { DualAxes } from '../../src';
import { createDiv } from '../utils/dom';

describe('#3749', () => {
it('dual-axes', async () => {
const data = [
{ time: '10:10', call: 4, waiting: 2, people: 2 },
{ time: '10:15', call: 2, waiting: 6, people: 3 },
{ time: '10:20', call: 13, waiting: 2, people: 5 },
{ time: '10:25', call: 9, waiting: 9, people: 1 },
{ time: '10:30', call: 5, waiting: 2, people: 3 },
{ time: '10:31', call: 6, waiting: 3, people: 4 },
// { time: '10:32', call: 5, waiting: 3, people: 4 },
// { time: '10:33', call: 5, waiting: 3, people: 4 },
// { time: '10:34', call: 5, waiting: 3, people: 4 },
// { time: '10:35', call: 5, waiting: 3, people: 4 },
// { time: '10:36', call: 5, waiting: 3, people: 4 },
// { time: '10:37', call: 5, waiting: 3, people: 4 },
// { time: '10:38', call: 5, waiting: 3, people: 4 },
// { time: '10:39', call: 5, waiting: 3, people: 4 },
// { time: '10:40', call: 5, waiting: 3, people: 4 },
// { time: '10:41', call: 5, waiting: 3, people: 4 },
// { time: '10:42', call: 5, waiting: 3, people: 4 },
// { time: '10:43', call: 5, waiting: 3, people: 4 },
// { time: '10:44', call: 5, waiting: 3, people: 4 },
];

const dualAxes = new DualAxes(createDiv(), {
data: [data, data],
xField: 'time',
yField: ['waiting', 'people'],
slider: {
start: 0,
end: 1,
},
tooltip: false,
geometryOptions: [
{
geometry: 'column',
},
{
geometry: 'line',
lineStyle: {
lineWidth: 2,
},
},
],
});

dualAxes.render();
console.log('dualAxes: ', dualAxes);
});
});
14 changes: 14 additions & 0 deletions src/plots/dual-axes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,18 @@ export class DualAxes extends Plot<DualAxesOptions> {
protected getSchemaAdaptor(): Adaptor<DualAxesOptions> {
return adaptor;
}

/**
* 覆写父类的方法
*/
protected triggerResize() {
if (!this.chart.destroyed) {
// 首先自适应容器的宽高
this.chart.forceFit(); // g2 内部执行 changeSize,changeSize 中执行 render(true)
this.chart.clear();
this.execAdaptor(); // 核心:宽高更新之后计算padding
// 渲染
this.chart.render(true);
}
}
}
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