mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Decimals: Big Improvements to auto decimals and fixes to auto decimals bug found in 7.4-beta1 (#30519)
* Decimals: Nukes scaledDecimals from the earth it was an abomination * Moved move tests * Fixed test * Updated tests * Updated test
This commit is contained in:
@@ -599,7 +599,7 @@ describe('logSeriesToLogsModel', () => {
|
||||
hasUniqueLabels: false,
|
||||
meta: [
|
||||
{ label: 'Limit', value: '1000 (0 returned)', kind: 1 },
|
||||
{ label: 'Total bytes processed', value: '97 kB', kind: 1 },
|
||||
{ label: 'Total bytes processed', value: '97.0 kB', kind: 1 },
|
||||
],
|
||||
rows: [],
|
||||
};
|
||||
|
||||
@@ -4,7 +4,6 @@ import { DecimalCount, TimeZone } from '@grafana/data';
|
||||
interface ValueFormatTest {
|
||||
id: string;
|
||||
decimals?: DecimalCount;
|
||||
scaledDecimals?: DecimalCount;
|
||||
timeZone?: TimeZone;
|
||||
value: number;
|
||||
result: string;
|
||||
@@ -22,8 +21,8 @@ const formatTests: ValueFormatTest[] = [
|
||||
{ id: 'ms', decimals: 2, value: 1250, result: '1.25 s' },
|
||||
{ id: 'ms', decimals: 1, value: 10000086.123, result: '2.8 hour' },
|
||||
{ id: 'ms', decimals: 0, value: 1200, result: '1 s' },
|
||||
{ id: 'short', decimals: 0, scaledDecimals: -1, value: 98765, result: '98.77 K' },
|
||||
{ id: 'short', decimals: 0, scaledDecimals: 0, value: 9876543, result: '9.876543 Mil' },
|
||||
{ id: 'short', decimals: 0, value: 98765, result: '99 K' },
|
||||
{ id: 'short', decimals: 0, value: 9876543, result: '10 Mil' },
|
||||
{ id: 'kbytes', decimals: 3, value: 10000000, result: '9.537 GiB' },
|
||||
{ id: 'deckbytes', decimals: 3, value: 10000000, result: '10.000 GB' },
|
||||
{ id: 'megwatt', decimals: 3, value: 1000, result: '1.000 GW' },
|
||||
@@ -45,7 +44,7 @@ describe('Chcek KBN value formats', () => {
|
||||
for (const test of formatTests) {
|
||||
describe(`value format: ${test.id}`, () => {
|
||||
it(`should translate ${test.value} as ${test.result}`, () => {
|
||||
const result = kbn.valueFormats[test.id](test.value, test.decimals, test.scaledDecimals);
|
||||
const result = kbn.valueFormats[test.id](test.value, test.decimals);
|
||||
expect(result).toBe(test.result);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -743,7 +743,7 @@ class GraphElement {
|
||||
};
|
||||
|
||||
// Use 'short' format for histogram values
|
||||
this.configureAxisMode(options.xaxis, 'short');
|
||||
this.configureAxisMode(options.xaxis, 'short', null);
|
||||
}
|
||||
|
||||
addXTableAxis(options: any) {
|
||||
@@ -794,13 +794,15 @@ class GraphElement {
|
||||
this.applyLogScale(options.yaxes[1], data);
|
||||
this.configureAxisMode(
|
||||
options.yaxes[1],
|
||||
this.panel.percentage && this.panel.stack ? 'percent' : this.panel.yaxes[1].format
|
||||
this.panel.percentage && this.panel.stack ? 'percent' : this.panel.yaxes[1].format,
|
||||
this.panel.yaxes[1].decimals
|
||||
);
|
||||
}
|
||||
this.applyLogScale(options.yaxes[0], data);
|
||||
this.configureAxisMode(
|
||||
options.yaxes[0],
|
||||
this.panel.percentage && this.panel.stack ? 'percent' : this.panel.yaxes[0].format
|
||||
this.panel.percentage && this.panel.stack ? 'percent' : this.panel.yaxes[0].format,
|
||||
this.panel.yaxes[0].decimals
|
||||
);
|
||||
}
|
||||
|
||||
@@ -915,14 +917,19 @@ class GraphElement {
|
||||
return ticks;
|
||||
}
|
||||
|
||||
configureAxisMode(axis: { tickFormatter: (val: any, axis: any) => string }, format: string) {
|
||||
configureAxisMode(
|
||||
axis: { tickFormatter: (val: any, axis: any) => string },
|
||||
format: string,
|
||||
decimals?: number | null
|
||||
) {
|
||||
axis.tickFormatter = (val, axis) => {
|
||||
const formatter = getValueFormat(format);
|
||||
|
||||
if (!formatter) {
|
||||
throw new Error(`Unit '${format}' is not supported`);
|
||||
}
|
||||
return formattedValueToString(formatter(val, axis.tickDecimals, axis.scaledDecimals));
|
||||
|
||||
return formattedValueToString(formatter(val, decimals));
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
5
public/vendor/flot/jquery.flot.js
vendored
5
public/vendor/flot/jquery.flot.js
vendored
@@ -1783,11 +1783,6 @@ Licensed under the MIT license.
|
||||
axis.tickDecimals = Math.max(0, maxDec != null ? maxDec : dec);
|
||||
axis.tickSize = opts.tickSize || size;
|
||||
|
||||
// grafana addition
|
||||
if (opts.tickDecimals === null || opts.tickDecimals === undefined) {
|
||||
axis.scaledDecimals = axis.tickDecimals + dec;
|
||||
}
|
||||
|
||||
// Time mode was moved to a plug-in in 0.8, and since so many people use it
|
||||
// we'll add an especially friendly reminder to make sure they included it.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user