mirror of
https://github.com/grafana/grafana.git
synced 2025-02-11 08:05:43 -06:00
Geomap: fix scale calculations (#37375)
This commit is contained in:
parent
bee185b637
commit
d269d901fc
@ -1,4 +1,5 @@
|
||||
import { validateScaleConfig } from './scale';
|
||||
import { ArrayVector, DataFrame, FieldType } from '@grafana/data';
|
||||
import { getScaledDimension, validateScaleConfig } from './scale';
|
||||
|
||||
describe('scale dimensions', () => {
|
||||
it('should validate empty input', () => {
|
||||
@ -35,4 +36,33 @@ describe('scale dimensions', () => {
|
||||
}
|
||||
`);
|
||||
});
|
||||
|
||||
it('should support negative min values', () => {
|
||||
const values = [-20, -10, -5, 0, 5, 10, 20];
|
||||
const frame: DataFrame = {
|
||||
name: 'a',
|
||||
length: values.length,
|
||||
fields: [
|
||||
{ name: 'time', type: FieldType.number, values: new ArrayVector(values), config: {} },
|
||||
{
|
||||
name: 'hello',
|
||||
type: FieldType.number,
|
||||
values: new ArrayVector(values),
|
||||
config: {
|
||||
min: -10,
|
||||
max: 10,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
const supplier = getScaledDimension(frame, {
|
||||
min: -1,
|
||||
max: 1,
|
||||
field: 'hello',
|
||||
fixed: 0,
|
||||
});
|
||||
const scaled = frame.fields[0].values.toArray().map((k, i) => supplier.get(i));
|
||||
expect(scaled).toEqual([-1, -1, -0.5, 0, 0.5, 1, 1]);
|
||||
});
|
||||
});
|
||||
|
@ -34,6 +34,11 @@ export function getScaledDimension(frame: DataFrame, config: ScaleDimensionConfi
|
||||
if (value !== -Infinity) {
|
||||
percent = (value - info.min!) / info.delta;
|
||||
}
|
||||
if (percent > 1) {
|
||||
percent = 1;
|
||||
} else if (percent < 0) {
|
||||
percent = 0;
|
||||
}
|
||||
return config.min + percent * delta;
|
||||
},
|
||||
field,
|
||||
|
Loading…
Reference in New Issue
Block a user