@opendata-ai/openchart-engine 6.28.2 → 6.28.4

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 CHANGED
@@ -11280,6 +11280,15 @@ function formatValueForSearch(value2, column) {
11280
11280
 
11281
11281
  // src/tables/heatmap.ts
11282
11282
  import { adaptColorForDarkMode as adaptColorForDarkMode2 } from "@opendata-ai/openchart-core";
11283
+ function relativeLuminance(hex2) {
11284
+ const m = /^#?([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})$/i.exec(hex2);
11285
+ if (!m) return 0;
11286
+ const [r, g, b] = [m[1], m[2], m[3]].map((c) => {
11287
+ const v = Number.parseInt(c, 16) / 255;
11288
+ return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
11289
+ });
11290
+ return 0.2126 * r + 0.7152 * g + 0.0722 * b;
11291
+ }
11283
11292
  function interpolatorFromStops(stops) {
11284
11293
  if (stops.length === 0) return () => "#ffffff";
11285
11294
  if (stops.length === 1) return () => stops[0];
@@ -11332,7 +11341,19 @@ function computeHeatmapColors(data, column, theme, darkMode) {
11332
11341
  if (darkMode) {
11333
11342
  const lightBg = "#ffffff";
11334
11343
  const darkBg = theme.colors.background;
11344
+ const originalStops = stops;
11335
11345
  stops = stops.map((c) => adaptColorForDarkMode2(c, lightBg, darkBg));
11346
+ if (originalStops.length >= 2) {
11347
+ const origDirection = Math.sign(
11348
+ relativeLuminance(originalStops[originalStops.length - 1]) - relativeLuminance(originalStops[0])
11349
+ );
11350
+ const adaptedDirection = Math.sign(
11351
+ relativeLuminance(stops[stops.length - 1]) - relativeLuminance(stops[0])
11352
+ );
11353
+ if (origDirection !== 0 && adaptedDirection !== 0 && origDirection !== adaptedDirection) {
11354
+ stops = stops.slice().reverse();
11355
+ }
11356
+ }
11336
11357
  }
11337
11358
  const interpolator = interpolatorFromStops(stops);
11338
11359
  const scale = sequential(interpolator).domain(domain).clamp(true);
@@ -11956,6 +11977,7 @@ function compileTileMap(spec, options) {
11956
11977
  keyboardNavigable: tiles.length > 0
11957
11978
  };
11958
11979
  const resolvedAnimation = resolveAnimation(tilemapSpec.animation);
11980
+ const contentHeight = tileGridOffsetY + tilePositions.gridHeight + legendGap2 + legendTotalHeight + chrome.bottomHeight + padding;
11959
11981
  return {
11960
11982
  area: fullArea,
11961
11983
  chrome,
@@ -11965,7 +11987,7 @@ function compileTileMap(spec, options) {
11965
11987
  a11y,
11966
11988
  theme,
11967
11989
  width: options.width,
11968
- height: options.height,
11990
+ height: contentHeight,
11969
11991
  animation: resolvedAnimation,
11970
11992
  watermark,
11971
11993
  measureText: options.measureText ?? ((text, fontSize) => ({ width: estimateTextWidth15(text, fontSize), height: fontSize }))