@opendata-ai/openchart-engine 7.7.0 → 7.8.0

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opendata-ai/openchart-engine",
3
- "version": "7.7.0",
3
+ "version": "7.8.0",
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": "7.7.0",
51
+ "@opendata-ai/openchart-core": "7.8.0",
52
52
  "d3-array": "^3.2.0",
53
53
  "d3-format": "^3.1.2",
54
54
  "d3-interpolate": "^3.0.0",
package/src/compile.ts CHANGED
@@ -967,7 +967,7 @@ function compileFaceted(
967
967
 
968
968
  // Compute scales for this panel's area
969
969
  const panelScales = computeScales(panelSpecWithDomains, gridPanel.area, panelData);
970
- applyColorScaleRange(panelScales, panelSpecWithDomains.encoding, theme);
970
+ applyColorScaleRange(panelScales, panelSpecWithDomains.encoding, theme, renderSpec.highlight);
971
971
  panelScales.defaultColor =
972
972
  chartSpec.markDef.fill ?? chartSpec.markDef.stroke ?? theme.colors.categorical[0];
973
973
 
@@ -38,6 +38,7 @@ import {
38
38
  computeChrome,
39
39
  estimateTextWidth,
40
40
  formatNumber,
41
+ pickLabelColor,
41
42
  resolveTheme,
42
43
  SEQUENTIAL_PALETTES,
43
44
  } from '@opendata-ai/openchart-core';
@@ -226,6 +227,7 @@ function compileQuantitative(
226
227
  formattedValue,
227
228
  hasData,
228
229
  theme,
230
+ isDarkMode: !!isDarkMode,
229
231
  }),
230
232
  );
231
233
  }
@@ -397,6 +399,7 @@ function compileCategorical(
397
399
  formattedValue,
398
400
  hasData,
399
401
  theme,
402
+ isDarkMode: !!isDarkMode,
400
403
  category: hasData ? category : undefined,
401
404
  }),
402
405
  );
@@ -488,6 +491,7 @@ interface TileMarkOptions {
488
491
  formattedValue: string;
489
492
  hasData: boolean;
490
493
  theme: ResolvedTheme;
494
+ isDarkMode: boolean;
491
495
  category?: string | null;
492
496
  }
493
497
 
@@ -505,16 +509,20 @@ function buildTileMark(opts: TileMarkOptions): TileMapTileMark {
505
509
  formattedValue,
506
510
  hasData,
507
511
  theme,
512
+ isDarkMode,
508
513
  category,
509
514
  } = opts;
510
515
  const tileCenterX = gridOffsetX + pos.x + tileSize / 2;
511
516
  const tileTopY = gridOffsetY + pos.y;
512
517
 
518
+ const textColor = hasData ? pickLabelColor(fill, isDarkMode) : '#ffffff';
519
+ const isLightText = textColor === '#ffffff';
520
+
513
521
  const labelStyle: TextStyle = {
514
522
  fontFamily: theme.fonts.family,
515
523
  fontSize: tileSize > 24 ? 10 : 7,
516
524
  fontWeight: 700,
517
- fill: '#ffffff',
525
+ fill: textColor,
518
526
  lineHeight: 1.2,
519
527
  };
520
528
 
@@ -522,7 +530,7 @@ function buildTileMark(opts: TileMarkOptions): TileMapTileMark {
522
530
  fontFamily: theme.fonts.family,
523
531
  fontSize: tileSize > 24 ? 10 : 7,
524
532
  fontWeight: 300,
525
- fill: 'rgba(255,255,255,0.6)',
533
+ fill: isLightText ? 'rgba(255,255,255,0.6)' : 'rgba(0,0,0,0.45)',
526
534
  lineHeight: 1.2,
527
535
  };
528
536