@opendata-ai/openchart-engine 6.15.1 → 6.16.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/dist/index.js CHANGED
@@ -596,7 +596,7 @@ function evaluateFieldPredicate(datum, pred) {
596
596
  return pred.valid ? isValid : !isValid;
597
597
  }
598
598
  if (pred.equal !== void 0) {
599
- return value2 === pred.equal;
599
+ return value2 == pred.equal;
600
600
  }
601
601
  const numValue = Number(value2);
602
602
  if (pred.lt !== void 0) {
@@ -616,7 +616,7 @@ function evaluateFieldPredicate(datum, pred) {
616
616
  return numValue >= min4 && numValue <= max4;
617
617
  }
618
618
  if (pred.oneOf !== void 0) {
619
- return pred.oneOf.includes(value2);
619
+ return pred.oneOf.some((v) => v == value2);
620
620
  }
621
621
  return true;
622
622
  }
@@ -8123,7 +8123,7 @@ function computeDimensions(spec, options, legendLayout, theme, strategy, waterma
8123
8123
  }
8124
8124
  }
8125
8125
  if (maxLabelWidth > 0) {
8126
- margins.right = Math.max(margins.right, padding + maxLabelWidth + 16);
8126
+ margins.right = Math.max(margins.right, padding + maxLabelWidth + 8);
8127
8127
  }
8128
8128
  }
8129
8129
  }
@@ -8499,14 +8499,18 @@ function buildPointScale(channel, data, rangeStart, rangeEnd) {
8499
8499
  function buildOrdinalColorScale(channel, data, palette) {
8500
8500
  const explicitDomain = channel.scale?.domain;
8501
8501
  const values = explicitDomain ? explicitDomain.map(String) : applyCategoricalSort(uniqueStrings(fieldValues(data, channel.field)), channel.sort);
8502
- const scale = ordinal().domain(values).range(palette);
8502
+ const explicitRange = channel.scale?.range;
8503
+ const colors = explicitRange ?? palette;
8504
+ const scale = ordinal().domain(values).range(colors);
8503
8505
  return { scale, type: "ordinal", channel };
8504
8506
  }
8505
8507
  function buildSequentialColorScale(channel, data, palette) {
8506
8508
  const values = parseNumbers(fieldValues(data, channel.field));
8507
8509
  const domainMin = min2(values) ?? 0;
8508
8510
  const domainMax = max2(values) ?? 1;
8509
- const scale = linear2().domain([domainMin, domainMax]).range([palette[0], palette[palette.length - 1]]).clamp(true);
8511
+ const explicitRange = channel.scale?.range;
8512
+ const colors = explicitRange ?? palette;
8513
+ const scale = linear2().domain([domainMin, domainMax]).range([colors[0], colors[colors.length - 1]]).clamp(true);
8510
8514
  return { scale, type: "sequential", channel };
8511
8515
  }
8512
8516
  function buildPositionalScale(channel, data, rangeStart, rangeEnd, chartType, axis) {
@@ -8730,14 +8734,23 @@ function extractColorEntries(spec, theme) {
8730
8734
  if ("condition" in colorEnc) return [];
8731
8735
  if (colorEnc.type === "quantitative") return [];
8732
8736
  const uniqueValues = [...new Set(spec.data.map((d) => String(d[colorEnc.field])))];
8733
- const palette = theme.colors.categorical;
8737
+ const explicitDomain = colorEnc.scale?.domain;
8738
+ const explicitRange = colorEnc.scale?.range;
8739
+ const palette = explicitRange ?? theme.colors.categorical;
8734
8740
  const shape = swatchShapeForType(spec.markType);
8735
- return uniqueValues.map((value2, i) => ({
8736
- label: value2,
8737
- color: palette[i % palette.length],
8738
- shape,
8739
- active: true
8740
- }));
8741
+ return uniqueValues.map((value2, i) => {
8742
+ let colorIndex = i;
8743
+ if (explicitDomain && explicitRange) {
8744
+ const domainIdx = explicitDomain.indexOf(value2);
8745
+ if (domainIdx >= 0) colorIndex = domainIdx;
8746
+ }
8747
+ return {
8748
+ label: value2,
8749
+ color: palette[colorIndex % palette.length],
8750
+ shape,
8751
+ active: true
8752
+ };
8753
+ });
8741
8754
  }
8742
8755
  function entriesThatFit(entries, maxWidth, maxRows, labelStyle) {
8743
8756
  let row = 1;
@@ -9915,8 +9928,13 @@ function computeCategoryColors(data, column, theme, darkMode) {
9915
9928
  if (raw == null) continue;
9916
9929
  const key = String(raw);
9917
9930
  let bg;
9918
- if (explicitMap[key]) {
9931
+ let isExplicit = false;
9932
+ if (explicitMap[key] != null) {
9933
+ if (explicitMap[key] === "transparent" || explicitMap[key] === "none") {
9934
+ continue;
9935
+ }
9919
9936
  bg = explicitMap[key];
9937
+ isExplicit = true;
9920
9938
  } else if (autoAssigned.has(key)) {
9921
9939
  bg = autoAssigned.get(key);
9922
9940
  } else {
@@ -9924,7 +9942,7 @@ function computeCategoryColors(data, column, theme, darkMode) {
9924
9942
  nextPaletteIndex++;
9925
9943
  autoAssigned.set(key, bg);
9926
9944
  }
9927
- if (darkMode) {
9945
+ if (darkMode && !isExplicit) {
9928
9946
  bg = adaptColorForDarkMode(bg, lightBg, darkBg);
9929
9947
  }
9930
9948
  const textColor = accessibleTextColor(bg);
@@ -11139,16 +11157,21 @@ function compileChart(spec, options) {
11139
11157
  const renderSpec = renderData !== chartSpec.data ? { ...chartSpec, data: renderData } : chartSpec;
11140
11158
  const scales = computeScales(renderSpec, chartArea, renderSpec.data);
11141
11159
  if (scales.color) {
11160
+ const hasExplicitRange = !!(renderSpec.encoding.color && "field" in renderSpec.encoding.color && renderSpec.encoding.color.scale?.range?.length);
11142
11161
  if (scales.color.type === "sequential") {
11143
- const seqStops = Object.values(theme.colors.sequential)[0] ?? theme.colors.categorical;
11144
- scales.color.scale.range([
11145
- seqStops[0],
11146
- seqStops[seqStops.length - 1]
11147
- ]);
11162
+ if (!hasExplicitRange) {
11163
+ const seqStops = Object.values(theme.colors.sequential)[0] ?? theme.colors.categorical;
11164
+ scales.color.scale.range([
11165
+ seqStops[0],
11166
+ seqStops[seqStops.length - 1]
11167
+ ]);
11168
+ }
11148
11169
  } else {
11149
- scales.color.scale.range(
11150
- theme.colors.categorical
11151
- );
11170
+ if (!hasExplicitRange) {
11171
+ scales.color.scale.range(
11172
+ theme.colors.categorical
11173
+ );
11174
+ }
11152
11175
  }
11153
11176
  }
11154
11177
  scales.defaultColor = chartSpec.markDef.fill ?? theme.colors.categorical[0];