@opendata-ai/openchart-engine 6.28.5 → 6.28.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/tables/__tests__/heatmap.test.ts +4 -27
- package/src/tables/heatmap.ts +6 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opendata-ai/openchart-engine",
|
|
3
|
-
"version": "6.28.
|
|
3
|
+
"version": "6.28.6",
|
|
4
4
|
"description": "Headless compiler for openchart: spec validation, data compilation, scales, and layout",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Riley Hilliard",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"typecheck": "tsc --noEmit"
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
|
-
"@opendata-ai/openchart-core": "6.28.
|
|
51
|
+
"@opendata-ai/openchart-core": "6.28.6",
|
|
52
52
|
"d3-array": "^3.2.0",
|
|
53
53
|
"d3-format": "^3.1.2",
|
|
54
54
|
"d3-interpolate": "^3.0.0",
|
|
@@ -112,7 +112,7 @@ describe('computeHeatmapColors', () => {
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
|
|
115
|
-
it('
|
|
115
|
+
it('custom palette arrays are not adapted in dark mode', () => {
|
|
116
116
|
const col: ColumnConfig = {
|
|
117
117
|
key: 'value',
|
|
118
118
|
heatmap: { palette: ['#fca5a5', '#c44e52'], domain: [0, 100] },
|
|
@@ -127,32 +127,9 @@ describe('computeHeatmapColors', () => {
|
|
|
127
127
|
const darkLowBg = darkColors.get(0)!.backgroundColor!;
|
|
128
128
|
const darkHighBg = darkColors.get(4)!.backgroundColor!;
|
|
129
129
|
|
|
130
|
-
|
|
131
|
-
expect(darkLowBg).
|
|
132
|
-
|
|
133
|
-
function parseLum(color: string): number {
|
|
134
|
-
const rgbMatch = /rgb\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/.exec(color);
|
|
135
|
-
if (rgbMatch) {
|
|
136
|
-
const [r, g, b] = [rgbMatch[1], rgbMatch[2], rgbMatch[3]].map((c) => {
|
|
137
|
-
const v = Number(c) / 255;
|
|
138
|
-
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
139
|
-
});
|
|
140
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
141
|
-
}
|
|
142
|
-
const hexMatch = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(color);
|
|
143
|
-
if (!hexMatch) return 0;
|
|
144
|
-
const [r, g, b] = [hexMatch[1], hexMatch[2], hexMatch[3]].map((c) => {
|
|
145
|
-
const v = Number.parseInt(c, 16) / 255;
|
|
146
|
-
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
|
|
147
|
-
});
|
|
148
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// Light mode: high values get darker/more saturated bg (lower luminance = more prominent)
|
|
152
|
-
expect(parseLum(lightLowBg)).toBeGreaterThan(parseLum(lightHighBg));
|
|
153
|
-
|
|
154
|
-
// Dark mode: high values get brighter bg (higher luminance = more prominent on dark bg)
|
|
155
|
-
expect(parseLum(darkHighBg)).toBeGreaterThan(parseLum(darkLowBg));
|
|
130
|
+
// Custom palettes produce the same colors in both modes
|
|
131
|
+
expect(darkLowBg).toBe(lightLowBg);
|
|
132
|
+
expect(darkHighBg).toBe(lightHighBg);
|
|
156
133
|
});
|
|
157
134
|
|
|
158
135
|
it('supports array of color stops as palette', () => {
|
package/src/tables/heatmap.ts
CHANGED
|
@@ -95,9 +95,13 @@ export function computeHeatmapColors(
|
|
|
95
95
|
domain = [min, max];
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
// Resolve palette and build scale
|
|
98
|
+
// Resolve palette and build scale.
|
|
99
|
+
// Only adapt theme-derived palettes for dark mode. Custom color arrays
|
|
100
|
+
// are used as-is since the author chose them for a reason, and
|
|
101
|
+
// adaptColorForDarkMode inverts the perceived intensity ordering
|
|
102
|
+
// (light pink -> dark red becomes dark red -> pink on dark backgrounds).
|
|
99
103
|
let stops = resolvePalette(config.palette, theme);
|
|
100
|
-
if (darkMode) {
|
|
104
|
+
if (darkMode && !Array.isArray(config.palette)) {
|
|
101
105
|
const lightBg = '#ffffff';
|
|
102
106
|
const darkBg = theme.colors.background;
|
|
103
107
|
stops = stops.map((c) => adaptColorForDarkMode(c, lightBg, darkBg));
|