mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Dashboards: Fix issue with percentage difference formatting (#93389)
* Dashboards: Fix issue with percentage difference formatting --------- Co-authored-by: Ihor Yeromin <yeryomin.igor@gmail.com>
This commit is contained in:
parent
0a01b60305
commit
6c8f24adc9
@ -55,13 +55,14 @@ describe('Stats Calculators', () => {
|
|||||||
it('should calculate basic stats', () => {
|
it('should calculate basic stats', () => {
|
||||||
const stats = reduceField({
|
const stats = reduceField({
|
||||||
field: basicTable.fields[0],
|
field: basicTable.fields[0],
|
||||||
reducers: [ReducerID.first, ReducerID.last, ReducerID.mean, ReducerID.count],
|
reducers: [ReducerID.first, ReducerID.last, ReducerID.mean, ReducerID.count, ReducerID.diffperc],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(stats.first).toEqual(10);
|
expect(stats.first).toEqual(10);
|
||||||
expect(stats.last).toEqual(20);
|
expect(stats.last).toEqual(20);
|
||||||
expect(stats.mean).toEqual(15);
|
expect(stats.mean).toEqual(15);
|
||||||
expect(stats.count).toEqual(2);
|
expect(stats.count).toEqual(2);
|
||||||
|
expect(stats.diffperc).toEqual(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should handle undefined field data without crashing', () => {
|
it('should handle undefined field data without crashing', () => {
|
||||||
|
@ -582,7 +582,7 @@ export function doStandardCalcs(field: Field, ignoreNulls: boolean, nullAsZero:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isNumber(calcs.firstNotNull) && isNumber(calcs.diff)) {
|
if (isNumber(calcs.firstNotNull) && isNumber(calcs.diff)) {
|
||||||
calcs.diffperc = calcs.diff / calcs.firstNotNull;
|
calcs.diffperc = (calcs.diff / calcs.firstNotNull) * 100;
|
||||||
}
|
}
|
||||||
return calcs;
|
return calcs;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ describe('BigValue', () => {
|
|||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(screen.getByText('50%')).toBeInTheDocument();
|
expect(screen.getByText('0.5%')).toBeInTheDocument();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should render without percent change', () => {
|
it('should render without percent change', () => {
|
||||||
|
@ -27,6 +27,7 @@ export const PercentChange = ({ percentChange, styles }: Props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// percentChange is expected to be a value between 0-100
|
||||||
export const percentChangeString = (percentChange: number) => {
|
export const percentChangeString = (percentChange: number) => {
|
||||||
return percentChange.toLocaleString(undefined, { style: 'percent', maximumSignificantDigits: 3 });
|
return (percentChange / 100).toLocaleString(undefined, { style: 'percent', maximumSignificantDigits: 3 });
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user