Skip to content

Commit 49e0f88

Browse files
Chart: fix auto breaks calculation when there are duplicated and high-precision values (T1256385) (#29108)
1 parent 63d0101 commit 49e0f88

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

packages/devextreme/js/viz/axes/xy_axes.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ function generateAutoBreaks({ logarithmBase, type, maxAutoBreakCount }, series,
204204

205205
let minDiff = RANGE_RATIO * visibleRange;
206206

207-
const ranges = generateRangesOnPoints(sortedAllPoints, edgePoints, getRange).sort((a, b) => b.length - a.length);
207+
const ranges = generateRangesOnPoints(sortedAllPoints, edgePoints, getRange)
208+
.filter(({ length }) => !!length)
209+
.sort((a, b) => b.length - a.length);
208210
const epsilon = _math.min.apply(null, ranges.map(r => r.length)) / 1000;
209211
const _maxAutoBreakCount = isDefined(maxAutoBreakCount) ? _math.min(maxAutoBreakCount, ranges.length) : ranges.length;
210212

packages/devextreme/testing/tests/DevExpress.viz.core/xyAxes.tests.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4150,6 +4150,26 @@ QUnit.test('Option maxCountOfBreaks is undefined', function(assert) {
41504150
]);
41514151
});
41524152

4153+
QUnit.test('Breaks generated correctly for float values, maxCountOfBreaks is default (T1256385)', function(assert) {
4154+
const min = 0;
4155+
const max = 426.2648;
4156+
this.series = [
4157+
this.stubSeries([[max, 55.6356, 6.1606, 0.6016, min, min, min], []]),
4158+
];
4159+
this.axis.setGroupSeries(this.series);
4160+
4161+
this.options.maxAutoBreakCount = 4;
4162+
this.updateOptions({ autoBreaksEnabled: true });
4163+
this.axis.setBusinessRange({ min, max });
4164+
4165+
this.axis.createTicks(this.canvas);
4166+
4167+
const breaks = this.tickGeneratorSpy.lastCall.args[7];
4168+
const spacing = breaks.reduce((prev, item) => prev + (item.to - item.from), 0);
4169+
4170+
assert.notEqual(spacing, max - min, 'Generated breaks length sum does not equal to business range');
4171+
});
4172+
41534173
QUnit.test('Logarithmic axis', function(assert) {
41544174
this.series = [
41554175
this.stubSeries([[0.1, 1, 10, 100, 1000, 10000000], []])

0 commit comments

Comments
 (0)