-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show bucket size for Time Series Visual Builder on X-Axis (#11639)
* Adding seconds to the timeseries tooltip * Adding x-axis label to show the bucket size
- Loading branch information
1 parent
ee6fa6b
commit 98de700
Showing
8 changed files
with
72 additions
and
4 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
src/core_plugins/metrics/public/components/lib/__tests__/get_axis_label_string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { expect } from 'chai'; | ||
import { getAxisLabelString } from '../get_axis_label_string'; | ||
|
||
describe('getAxisLabelString(interval)', () => { | ||
it('should return a valid label for 10 seconds', () => { | ||
expect(getAxisLabelString(10000)).to.equal('per 10 seconds'); | ||
}); | ||
it('should return a valid label for 2 minutes', () => { | ||
expect(getAxisLabelString(120000)).to.equal('per 2 minutes'); | ||
}); | ||
it('should return a valid label for 2 hour', () => { | ||
expect(getAxisLabelString(7200000)).to.equal('per 2 hours'); | ||
}); | ||
}); | ||
|
||
|
25 changes: 25 additions & 0 deletions
25
src/core_plugins/metrics/public/components/lib/get_axis_label_string.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { relativeOptions } from '../../../../../ui/public/timepicker/relative_options'; | ||
import _ from 'lodash'; | ||
import moment from 'moment'; | ||
const unitLookup = { | ||
s: 'seconds', | ||
m: 'minutes', | ||
h: 'hours', | ||
d: 'days', | ||
w: 'weeks', | ||
M: 'months', | ||
y: 'years' | ||
}; | ||
export function getAxisLabelString(interval) { | ||
const units = _.pluck(_.clone(relativeOptions).reverse(), 'value') | ||
.filter(s => /^[smhdwMy]$/.test(s)); | ||
const duration = moment.duration(interval, 'ms'); | ||
for (let i = 0; i < units.length; i++) { | ||
const as = duration.as(units[i]); | ||
if (Math.abs(as) > 1) { | ||
const unitValue = Math.round(Math.abs(as)); | ||
const unitString = unitLookup[units[i]]; | ||
return `per ${unitValue} ${unitString}`; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,4 @@ | |
color: rgba(255,255,255,0.8); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters