@opendata-ai/openchart-engine 7.0.3 → 7.0.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
@@ -1243,7 +1243,6 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy) {
1243
1243
  32
1244
1244
  );
1245
1245
  const columnX = chartArea.x + chartArea.width + ENDPOINT_COLUMN_GAP;
1246
- const markerX = chartArea.x + chartArea.width;
1247
1246
  const showLeader = config?.showLeader === true;
1248
1247
  const entries = provisional.map((p, i) => {
1249
1248
  const labelY = sweptTops[i];
@@ -1260,7 +1259,7 @@ function computeEndpointLabels(spec, marks, theme, chartArea, strategy) {
1260
1259
  };
1261
1260
  if (showMarker) {
1262
1261
  entry.marker = {
1263
- x: markerX,
1262
+ x: p.dataX,
1264
1263
  y: p.dataY,
1265
1264
  fill: markerFill,
1266
1265
  stroke: config?.markerStyle?.stroke ?? p.color,
@@ -1493,8 +1492,8 @@ function computeBarMarks(spec, scales, _chartArea, _strategy) {
1493
1492
  const categoryGroups = groupByField(spec.data, yChannel.field);
1494
1493
  const needsStacking = Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
1495
1494
  if (needsStacking) {
1496
- const stackDisabled = xChannel.stack === null || xChannel.stack === false;
1497
- if (stackDisabled) {
1495
+ const stackEnabled = xChannel.stack === true || xChannel.stack === "zero" || xChannel.stack === "normalize" || xChannel.stack === "center";
1496
+ if (!stackEnabled) {
1498
1497
  marks = computeGroupedBars(
1499
1498
  spec.data,
1500
1499
  xChannel.field,
@@ -1738,8 +1737,8 @@ function computeSimpleBars(data, valueField, categoryField, xScale, yScale, band
1738
1737
  import {
1739
1738
  buildD3Formatter,
1740
1739
  estimateTextWidth as estimateTextWidth4,
1741
- findAccessibleColor,
1742
1740
  getRepresentativeColor,
1741
+ pickLabelColor,
1743
1742
  resolveCollisions
1744
1743
  } from "@opendata-ai/openchart-core";
1745
1744
 
@@ -1806,7 +1805,7 @@ function computeBarLabels(marks, _chartArea, density = "auto", labelFormat, labe
1806
1805
  if (labelPrefix) valuePart = labelPrefix + valuePart;
1807
1806
  const textWidth = estimateTextWidth4(valuePart, LABEL_FONT_SIZE, LABEL_FONT_WEIGHT);
1808
1807
  const textHeight = LABEL_FONT_SIZE * 1.2;
1809
- const isStacked2 = mark.cornerRadius === 0;
1808
+ const isStacked2 = mark.stackGroup !== void 0;
1810
1809
  const isInside = mark.width >= MIN_WIDTH_FOR_INSIDE_LABEL;
1811
1810
  const isNegative = Number.isFinite(rawNum) ? rawNum < 0 : false;
1812
1811
  const bgColor = getRepresentativeColor(mark.fill);
@@ -1815,16 +1814,16 @@ function computeBarLabels(marks, _chartArea, density = "auto", labelFormat, labe
1815
1814
  let textAnchor;
1816
1815
  if (isStacked2 && isInside) {
1817
1816
  anchorX = mark.x + mark.width / 2;
1818
- fill = findAccessibleColor("#ffffff", bgColor, 4.5);
1817
+ fill = pickLabelColor(bgColor);
1819
1818
  textAnchor = "middle";
1820
1819
  } else if (isInside) {
1821
1820
  if (isNegative) {
1822
1821
  anchorX = mark.x + LABEL_PADDING;
1823
- fill = findAccessibleColor("#ffffff", bgColor, 4.5);
1822
+ fill = pickLabelColor(bgColor);
1824
1823
  textAnchor = "start";
1825
1824
  } else {
1826
1825
  anchorX = mark.x + mark.width - LABEL_PADDING;
1827
- fill = findAccessibleColor("#ffffff", bgColor, 4.5);
1826
+ fill = pickLabelColor(bgColor);
1828
1827
  textAnchor = "end";
1829
1828
  }
1830
1829
  } else {
@@ -1944,8 +1943,8 @@ function computeColumnMarks(spec, scales, _chartArea, _strategy) {
1944
1943
  const categoryGroups = groupByField(spec.data, xChannel.field);
1945
1944
  const needsStacking = Array.from(categoryGroups.values()).some((rows) => rows.length > 1);
1946
1945
  if (needsStacking) {
1947
- const stackDisabled = yChannel.stack === null || yChannel.stack === false;
1948
- if (stackDisabled) {
1946
+ const stackEnabled = yChannel.stack === true || yChannel.stack === "zero" || yChannel.stack === "normalize" || yChannel.stack === "center";
1947
+ if (!stackEnabled) {
1949
1948
  marks = computeGroupedColumns(
1950
1949
  spec.data,
1951
1950
  xChannel.field,
@@ -11018,8 +11017,8 @@ function computeScales(spec, chartArea, data) {
11018
11017
  if (encoding.x) {
11019
11018
  let xData = data;
11020
11019
  let xChannel = encoding.x;
11021
- const xStackDisabled = encoding.x.stack === null || encoding.x.stack === false;
11022
- if (spec.markType === "bar" && encoding.color && encoding.x.type === "quantitative" && !xStackDisabled) {
11020
+ const xStackEnabled = encoding.x.stack === true || encoding.x.stack === "zero" || encoding.x.stack === "normalize" || encoding.x.stack === "center";
11021
+ if (spec.markType === "bar" && encoding.color && encoding.x.type === "quantitative" && xStackEnabled) {
11023
11022
  if (encoding.x.stack === "normalize") {
11024
11023
  xChannel = { ...encoding.x, scale: { ...encoding.x.scale, domain: [0, 1], nice: false } };
11025
11024
  } else if (encoding.x.stack === "center") {
@@ -11074,7 +11073,7 @@ function computeScales(spec, chartArea, data) {
11074
11073
  const stackProp = encoding.y.stack;
11075
11074
  const isExplicitlyStacked = stackProp === true || stackProp === "zero" || stackProp === "normalize" || stackProp === "center";
11076
11075
  const isAreaStacked = spec.markType === "area" && isExplicitlyStacked;
11077
- const isBarStacked = isVerticalBar && stackProp !== null && stackProp !== false;
11076
+ const isBarStacked = isVerticalBar && isExplicitlyStacked;
11078
11077
  const hasStackingGroup = isBarStacked && encoding.color !== void 0;
11079
11078
  const userRequestedStack = isExplicitlyStacked;
11080
11079
  const isLineOrArea2 = spec.markType === "line" || spec.markType === "area";