Browse Source

BI-65178 fix: 最大最小值相差量级大可能导致端点值异常

master
windy 5 years ago
parent
commit
7161a07914
  1. 45
      src/widget/intervalslider/__test__/intervalslider.test.js
  2. 7
      src/widget/intervalslider/intervalslider.js

45
src/widget/intervalslider/__test__/intervalslider.test.js

@ -61,4 +61,49 @@ describe("intervalSlider", function () {
intervalSliderLabel.destroy();
});
/**
* test_author_windy
*/
it("测试拖拽", function () {
var intervalSliderLabel = BI.Test.createWidget({
type: "bi.interval_slider",
width: 300,
unit: "px",
cls: "layout-bg-white"
});
intervalSliderLabel.setMinAndMax({
min: 0,
max: 120
});
intervalSliderLabel.setValue({
min: 10,
max: 120
});
intervalSliderLabel.reset();
intervalSliderLabel.populate();
expect(intervalSliderLabel.getValue()).eql({
min: "",
max: ""
});
intervalSliderLabel.destroy();
});
/**
* test_author_windy
*/
it("BI-65178", function () {
var intervalSliderLabel = BI.Test.createWidget({
type: "bi.interval_slider",
width: 300,
unit: "px",
cls: "layout-bg-white"
});
intervalSliderLabel.setMinAndMax({
min: -2,
max: 237939882
});
expect(intervalSliderLabel._getValueByPercent(0)).to.equal(-2);
expect(intervalSliderLabel._getValueByPercent(100)).to.equal(237939882);
intervalSliderLabel.destroy();
});
});

7
src/widget/intervalslider/intervalslider.js

@ -397,7 +397,14 @@ BI.IntervalSlider = BI.inherit(BI.Single, {
},
// 其中取max-min后保留4为有效数字后的值的小数位数为最终value的精度
// 端点处的值有可能因为min,max相差量级很大(precision很大)而丢失精度,此时直接返回端点值即可
_getValueByPercent: function (percent) {// return (((max-min)*percent)/100+min)
if (percent === 0) {
return this.min;
}
if (percent === 100) {
return this.max;
}
var sub = this.calculation.accurateSubtraction(this.max, this.min);
var mul = this.calculation.accurateMultiplication(sub, percent);
var div = this.calculation.accurateDivisionTenExponent(mul, 2);

Loading…
Cancel
Save