diff --git a/public/app/plugins/panel/geomap/dims/scale.test.ts b/public/app/plugins/panel/geomap/dims/scale.test.ts index 7325a5c2ce2..096171babee 100644 --- a/public/app/plugins/panel/geomap/dims/scale.test.ts +++ b/public/app/plugins/panel/geomap/dims/scale.test.ts @@ -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]); + }); }); diff --git a/public/app/plugins/panel/geomap/dims/scale.ts b/public/app/plugins/panel/geomap/dims/scale.ts index a91545184e5..410afbd5299 100644 --- a/public/app/plugins/panel/geomap/dims/scale.ts +++ b/public/app/plugins/panel/geomap/dims/scale.ts @@ -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,