@opendata-ai/openchart-engine 7.0.0 → 7.0.3

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
@@ -7477,11 +7477,12 @@ function normalizeSpec(spec, warnings = []) {
7477
7477
  `Unknown spec shape. Expected mark (chart), layer, type: 'table', type: 'graph', type: 'sankey', type: 'tilemap', or type: 'barlist'.`
7478
7478
  );
7479
7479
  }
7480
- function flattenLayers(spec, parentData, parentEncoding, parentTransforms, parentWatermark) {
7480
+ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, parentWatermark, parentEndpointLabels) {
7481
7481
  const resolvedData = spec.data ?? parentData;
7482
7482
  const resolvedEncoding = parentEncoding && spec.encoding ? { ...parentEncoding, ...spec.encoding } : spec.encoding ?? parentEncoding;
7483
7483
  const resolvedTransforms = [...parentTransforms ?? [], ...spec.transform ?? []];
7484
7484
  const resolvedWatermark = spec.watermark ?? parentWatermark;
7485
+ const resolvedEndpointLabels = spec.endpointLabels ?? parentEndpointLabels;
7485
7486
  const leaves = [];
7486
7487
  for (const child of spec.layer) {
7487
7488
  if (isLayerSpec(child)) {
@@ -7491,7 +7492,8 @@ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, paren
7491
7492
  resolvedData,
7492
7493
  resolvedEncoding,
7493
7494
  resolvedTransforms,
7494
- resolvedWatermark
7495
+ resolvedWatermark,
7496
+ resolvedEndpointLabels
7495
7497
  )
7496
7498
  );
7497
7499
  } else {
@@ -7504,7 +7506,8 @@ function flattenLayers(spec, parentData, parentEncoding, parentTransforms, paren
7504
7506
  encoding: mergedEncoding,
7505
7507
  transform: mergedTransforms.length > 0 ? mergedTransforms : void 0,
7506
7508
  // Inherit parent watermark if child doesn't explicitly set one
7507
- ...child.watermark === void 0 && resolvedWatermark !== void 0 ? { watermark: resolvedWatermark } : {}
7509
+ ...child.watermark === void 0 && resolvedWatermark !== void 0 ? { watermark: resolvedWatermark } : {},
7510
+ ...child.endpointLabels === void 0 && resolvedEndpointLabels !== void 0 ? { endpointLabels: resolvedEndpointLabels } : {}
7508
7511
  });
7509
7512
  }
7510
7513
  }
@@ -9169,7 +9172,8 @@ function buildPrimarySpec(leaves, layerSpec) {
9169
9172
  theme: layerSpec.theme ?? leaves[0].theme,
9170
9173
  darkMode: layerSpec.darkMode ?? leaves[0].darkMode,
9171
9174
  watermark: layerSpec.watermark ?? leaves[0].watermark,
9172
- hiddenSeries: layerSpec.hiddenSeries ?? leaves[0].hiddenSeries
9175
+ hiddenSeries: layerSpec.hiddenSeries ?? leaves[0].hiddenSeries,
9176
+ endpointLabels: layerSpec.endpointLabels ?? leaves[0].endpointLabels
9173
9177
  };
9174
9178
  return primary;
9175
9179
  }
@@ -10332,11 +10336,12 @@ function getSparklinePad(spec) {
10332
10336
  const dotPad = 4;
10333
10337
  const dotRight = point5 === "last" || point5 === true || point5 === "endpoints" || point5 === "transparent";
10334
10338
  const dotLeft = point5 === "first" || point5 === true || point5 === "endpoints" || point5 === "transparent";
10339
+ const hasDots = dotRight || dotLeft;
10335
10340
  return {
10336
10341
  left: dotLeft ? Math.max(strokePad, dotPad) : strokePad,
10337
10342
  right: dotRight ? Math.max(strokePad, dotPad) : strokePad,
10338
- top: strokePad,
10339
- bottom: strokePad
10343
+ top: hasDots ? Math.max(strokePad, dotPad) : strokePad,
10344
+ bottom: hasDots ? Math.max(strokePad, dotPad) : strokePad
10340
10345
  };
10341
10346
  }
10342
10347
  function computeDimensions(spec, options, legendLayout, theme, strategy, watermark = true) {
@@ -10429,7 +10434,7 @@ function computeDimensions(spec, options, legendLayout, theme, strategy, waterma
10429
10434
  const wantsMetrics = !!spec.metrics && spec.metrics.length > 0 && chromeMode !== "hidden";
10430
10435
  const tentativeMetricsHeight = wantsMetrics ? metricBarHeight() : 0;
10431
10436
  const margins = {
10432
- top: topPad + chrome.topHeight + tentativeMetricsHeight + topAxisGap,
10437
+ top: topPad + chrome.topHeight + tentativeMetricsHeight,
10433
10438
  right: hPad + (isRadial ? hPad : axisMargin),
10434
10439
  bottom: padding + chrome.bottomHeight + xAxisHeight,
10435
10440
  left: hPad + (isRadial ? hPad : axisMargin)
@@ -10584,6 +10589,7 @@ function computeDimensions(spec, options, legendLayout, theme, strategy, waterma
10584
10589
  margins.top += legendLayout.bounds.height + gap;
10585
10590
  }
10586
10591
  }
10592
+ margins.top += topAxisGap;
10587
10593
  let chartArea = {
10588
10594
  x: margins.left,
10589
10595
  y: margins.top,
@@ -10604,13 +10610,13 @@ function computeDimensions(spec, options, legendLayout, theme, strategy, waterma
10604
10610
  bottomLegendReservation
10605
10611
  );
10606
10612
  const fallbackTopAxisGap = isRadial && fallbackChrome.topHeight === 0 ? 0 : axisMargin + inlineTickOverhang;
10607
- const newTop = topPad + fallbackChrome.topHeight + fallbackTopAxisGap + tentativeMetricsHeight;
10613
+ const newTop = topPad + fallbackChrome.topHeight + tentativeMetricsHeight;
10608
10614
  const topDelta = margins.top - newTop;
10609
10615
  const newBottom = padding + fallbackChrome.bottomHeight + xAxisHeight;
10610
10616
  const bottomDelta = margins.bottom - newBottom;
10611
10617
  if (topDelta > 0 || bottomDelta > 0) {
10612
10618
  const gap = legendGap(width);
10613
- margins.top = newTop + ("entries" in legendLayout && legendLayout.entries.length > 0 && legendLayout.position === "top" ? legendLayout.bounds.height + gap : 0);
10619
+ margins.top = newTop + ("entries" in legendLayout && legendLayout.entries.length > 0 && legendLayout.position === "top" ? legendLayout.bounds.height + gap : 0) + fallbackTopAxisGap;
10614
10620
  margins.bottom = newBottom;
10615
10621
  chartArea = {
10616
10622
  x: margins.left,
@@ -14167,10 +14173,14 @@ function compileChart(spec, options) {
14167
14173
  const gap = legendGap(options.width);
14168
14174
  switch (legendLayout.position) {
14169
14175
  case "top":
14176
+ legendArea.x = theme.spacing.padding;
14177
+ legendArea.width = options.width - theme.spacing.padding * 2;
14170
14178
  legendArea.y -= legendLayout.bounds.height + gap;
14171
14179
  legendArea.height += legendLayout.bounds.height + gap;
14172
14180
  break;
14173
14181
  case "bottom":
14182
+ legendArea.x = theme.spacing.padding;
14183
+ legendArea.width = options.width - theme.spacing.padding * 2;
14174
14184
  legendArea.height += legendLayout.bounds.height + gap + dims.xAxisHeight;
14175
14185
  break;
14176
14186
  case "right":