Skip to content

Commit

Permalink
Line Visualization improper scaling can result in gaps #79663 (#80135) (
Browse files Browse the repository at this point in the history
#80291)

Co-authored-by: Kibana Machine <[email protected]>

Co-authored-by: Kibana Machine <[email protected]>
  • Loading branch information
alexwizp and kibanamachine authored Oct 13, 2020
1 parent 07e5e8a commit 5074199
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ describe('TimeBuckets', () => {
test('setInterval/getInterval - intreval is a string', () => {
const timeBuckets = new TimeBuckets(timeBucketConfig);
timeBuckets.setInterval('20m');

const interval = timeBuckets.getInterval();

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

test('getInterval - should scale interval', () => {
const timeBuckets = new TimeBuckets(timeBucketConfig);
const bounds = {
min: moment('2020-03-25'),
max: moment('2020-03-31'),
};
timeBuckets.setBounds(bounds);
timeBuckets.setInterval('1m');

const interval = timeBuckets.getInterval();

expect(interval.description).toEqual('day');
expect(interval.esValue).toEqual(1);
expect(interval.esUnit).toEqual('d');
expect(interval.expression).toEqual('1d');
});

test('setInterval/getInterval - intreval is a string and bounds is defined', () => {
const timeBuckets = new TimeBuckets(timeBucketConfig);
const bounds = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,16 @@ export class TimeBuckets {
}

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

let scaled;

if (approxLen > maxLength) {
scaled = calcAutoIntervalLessThan(maxLength, Number(duration));
if (interval < minInterval) {
scaled = minInterval;
} else {
return interval;
}

if (+scaled === +interval) return interval;

interval = decorateInterval(interval);
return Object.assign(scaled, {
preScaled: interval,
Expand Down

0 comments on commit 5074199

Please sign in to comment.