Skip to content

Commit 5074199

Browse files
Line Visualization improper scaling can result in gaps #79663 (#80135) (#80291)
Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
1 parent 07e5e8a commit 5074199

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ describe('TimeBuckets', () => {
6969
test('setInterval/getInterval - intreval is a string', () => {
7070
const timeBuckets = new TimeBuckets(timeBucketConfig);
7171
timeBuckets.setInterval('20m');
72+
7273
const interval = timeBuckets.getInterval();
7374

7475
expect(interval.description).toEqual('20 minutes');
@@ -77,6 +78,23 @@ describe('TimeBuckets', () => {
7778
expect(interval.expression).toEqual('20m');
7879
});
7980

81+
test('getInterval - should scale interval', () => {
82+
const timeBuckets = new TimeBuckets(timeBucketConfig);
83+
const bounds = {
84+
min: moment('2020-03-25'),
85+
max: moment('2020-03-31'),
86+
};
87+
timeBuckets.setBounds(bounds);
88+
timeBuckets.setInterval('1m');
89+
90+
const interval = timeBuckets.getInterval();
91+
92+
expect(interval.description).toEqual('day');
93+
expect(interval.esValue).toEqual(1);
94+
expect(interval.esUnit).toEqual('d');
95+
expect(interval.expression).toEqual('1d');
96+
});
97+
8098
test('setInterval/getInterval - intreval is a string and bounds is defined', () => {
8199
const timeBuckets = new TimeBuckets(timeBucketConfig);
82100
const bounds = {

src/plugins/data/common/search/aggs/buckets/lib/time_buckets/time_buckets.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -263,18 +263,16 @@ export class TimeBuckets {
263263
}
264264

265265
const maxLength: number = this._timeBucketConfig['histogram:maxBars'];
266-
const approxLen = Number(duration) / Number(interval);
266+
const minInterval = calcAutoIntervalLessThan(maxLength, Number(duration));
267267

268268
let scaled;
269269

270-
if (approxLen > maxLength) {
271-
scaled = calcAutoIntervalLessThan(maxLength, Number(duration));
270+
if (interval < minInterval) {
271+
scaled = minInterval;
272272
} else {
273273
return interval;
274274
}
275275

276-
if (+scaled === +interval) return interval;
277-
278276
interval = decorateInterval(interval);
279277
return Object.assign(scaled, {
280278
preScaled: interval,

0 commit comments

Comments
 (0)