Skip to content

Commit e8a9f28

Browse files
authored
allow to the define colours for specific values via mappings (#57)
* allow to the define colours for specific values via mappings
1 parent b509a89 commit e8a9f28

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Changelog
22

3+
## v1.4.2
4+
- allow to the define colours for specific values via mappings
5+
36
## v1.4.1
47
- fix icon visualisation in pop-up and improve pop-up format
58
- support label for legends

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "orchestracities-map-panel",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "",
55
"scripts": {
66
"build": "grafana-toolkit plugin:build",

src/dimensions/color.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { DataFrame, Field, getFieldColorModeForField, getScaleCalculator, GrafanaTheme2 } from '@grafana/data';
2+
import { ScaleCalculator } from '@grafana/data/field/scale';
23
import { ColorDimensionConfig, DimensionSupplier } from './types';
34
import { findField, getLastNotNullFieldValue } from './utils';
45

@@ -42,9 +43,24 @@ export function getColorDimensionForField(
4243
return {
4344
get: (i) => {
4445
const val = field.values.get(i);
45-
return scale(val).color;
46+
return computeColor(scale, field.config?.mappings, val, theme);
4647
},
4748
field,
4849
value: () => scale(getLastNotNullFieldValue(field)).color,
4950
};
5051
}
52+
53+
function computeColor(scale: ScaleCalculator, mapping: any, value: any, theme: GrafanaTheme2) {
54+
let color = scale(value).color;
55+
mapping.forEach((map: any) => {
56+
if (map.type === 'value') {
57+
Object.keys(map.options).forEach((key) => {
58+
if (key === value && map.options[key].color) {
59+
let colorName = map.options[key].color ?? 'grey';
60+
color = theme.visualization.getColorByName(colorName);
61+
}
62+
});
63+
}
64+
});
65+
return color;
66+
}

0 commit comments

Comments
 (0)