Skip to content

Commit

Permalink
fix(#2212): fix when slider option has no start or end
Browse files Browse the repository at this point in the history
  • Loading branch information
hustcc authored and simaQ committed Mar 27, 2020
1 parent d3c06b9 commit 36a3b5d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/chart/controller/slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export default class Slider extends Controller<Option> {
}
// changeData 的时候同样需要更新
// 设置初始的 text
const min = this.slider.component.get('start');
const max = this.slider.component.get('end');
const min = this.slider.component.get('start') || 0;
const max = this.slider.component.get('end') || 1;

this.updateMinMaxText(min, max);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/chart/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ export class View extends Base {
// 对于内置的 option,避免覆盖。
// name 在原型上,说明可能是内置 API,存在 option 被覆盖的风险,不处理
if (View.prototype[name]) {
throw new Error(`Can't built in variable name "${name}", please change another one.`);
throw new Error(`Can't use built in variable name "${name}", please change another one.`);
}

// 存入到 option 中
Expand Down
36 changes: 36 additions & 0 deletions tests/bugs/2212-spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { Chart } from '../../src';
import { createDiv } from '../util/dom';
import { COMPONENT_TYPE } from '../../src/constant';

describe('#2212', () => {
const chart = new Chart({
container: createDiv(),
height: 360,
autoFit: true,
});

const data = [
{ Dev_Time: '2020-03-23 01:01:01', Vel_X: 10 },
{ Dev_Time: '2020-03-23 01:02:02', Vel_X: 12 },
{ Dev_Time: '2020-03-23 01:03:03', Vel_X: 8 },
{ Dev_Time: '2020-03-23 01:04:04', Vel_X: 10 },
];

chart.scale('Dev_Time', {
type: 'cat',
});

chart.data(data);
chart.interval().position('Dev_Time*Vel_X');

it('slider no start end', () => {
chart.option('slider', {
});

chart.render();
const slider = chart.getComponents().filter(co => co.type === COMPONENT_TYPE.OTHER)[0].component;

expect(slider.get('start')).toBe(0);
expect(slider.get('end')).toBe(1);
});
});

0 comments on commit 36a3b5d

Please sign in to comment.