@opendata-ai/openchart-engine 7.2.1 → 7.2.2

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
@@ -766,16 +766,18 @@ function resolveRangeAnnotation(annotation, scales, chartArea, isDark) {
766
766
  let y2 = chartArea.y;
767
767
  let width = chartArea.width;
768
768
  let height = chartArea.height;
769
+ const extend2 = annotation.extendToEdges !== false;
770
+ const resolveEdge = (value2, scale, edge) => extend2 ? resolvePositionEdge(value2, scale, edge) : resolvePosition(value2, scale);
769
771
  if (annotation.x1 !== void 0 && annotation.x2 !== void 0) {
770
- const x1px = resolvePositionEdge(annotation.x1, scales.x, "start");
771
- const x2px = resolvePositionEdge(annotation.x2, scales.x, "end");
772
+ const x1px = resolveEdge(annotation.x1, scales.x, "start");
773
+ const x2px = resolveEdge(annotation.x2, scales.x, "end");
772
774
  if (x1px === null || x2px === null) return null;
773
775
  x2 = Math.min(x1px, x2px);
774
776
  width = Math.abs(x2px - x1px);
775
777
  }
776
778
  if (annotation.y1 !== void 0 && annotation.y2 !== void 0) {
777
- const y1px = resolvePositionEdge(annotation.y1, scales.y, "end");
778
- const y2px = resolvePositionEdge(annotation.y2, scales.y, "start");
779
+ const y1px = resolveEdge(annotation.y1, scales.y, "end");
780
+ const y2px = resolveEdge(annotation.y2, scales.y, "start");
779
781
  if (y1px === null || y2px === null) return null;
780
782
  y2 = Math.min(y1px, y2px);
781
783
  height = Math.abs(y2px - y1px);
@@ -788,7 +790,12 @@ function resolveRangeAnnotation(annotation, scales, chartArea, isDark) {
788
790
  const baseDx = centered ? 0 : anchor === "right" ? -4 : 4;
789
791
  const baseDy = 14;
790
792
  const labelDelta = applyOffset({ dx: baseDx, dy: baseDy }, annotation.labelOffset);
791
- const style = makeAnnotationLabelStyle(11, 500, void 0, isDark);
793
+ const style = makeAnnotationLabelStyle(
794
+ annotation.fontSize ?? 11,
795
+ annotation.fontWeight ?? 500,
796
+ void 0,
797
+ isDark
798
+ );
792
799
  if (centered) {
793
800
  style.textAnchor = "middle";
794
801
  } else if (anchor === "right") {
@@ -8973,9 +8980,9 @@ function compileLayerIndependent(leaves, layerSpec, options, compileChart2) {
8973
8980
  const hasRightAxisTitle = !!yAxisConfig?.title;
8974
8981
  const tickExtent = TICK_LABEL_OFFSET + rightAxisWidth;
8975
8982
  const bodyFontSize = theme.fonts?.sizes?.body ?? 13;
8976
- const axisTitleOffset = getAxisTitleOffset(options.width);
8983
+ const axisTitleOffset2 = getAxisTitleOffset(options.width);
8977
8984
  const halfGlyph = Math.ceil(bodyFontSize / 2);
8978
- const titleExtent = hasRightAxisTitle ? axisTitleOffset + halfGlyph + (options.width < BREAKPOINT_COMPACT_MAX ? 0 : AXIS_TITLE_TRAILING_PAD) : 0;
8985
+ const titleExtent = hasRightAxisTitle ? axisTitleOffset2 + halfGlyph + (options.width < BREAKPOINT_COMPACT_MAX ? 0 : AXIS_TITLE_TRAILING_PAD) : 0;
8979
8986
  const rightReserve = Math.max(tickExtent, titleExtent);
8980
8987
  const optionsWithReserve = {
8981
8988
  ...options,
@@ -10187,12 +10194,11 @@ function computeAxes(scales, chartArea, strategy, theme, measureText, dataContex
10187
10194
 
10188
10195
  // src/layout/dimensions.ts
10189
10196
  import {
10190
- AXIS_TITLE_GAP,
10191
10197
  AXIS_TITLE_TRAILING_PAD as AXIS_TITLE_TRAILING_PAD2,
10198
+ axisTitleOffset,
10192
10199
  BREAKPOINT_COMPACT_MAX as BREAKPOINT_COMPACT_MAX2,
10193
10200
  computeChrome as computeChrome3,
10194
10201
  estimateTextWidth as estimateTextWidth15,
10195
- getAxisTitleOffset as getAxisTitleOffset2,
10196
10202
  HPAD_COMPACT_FRACTION,
10197
10203
  HPAD_COMPACT_MIN,
10198
10204
  LABEL_GAP_COMPACT,
@@ -10202,7 +10208,6 @@ import {
10202
10208
  MAX_LEFT_LABEL_FRACTION_MEDIUM,
10203
10209
  MAX_LEFT_LABEL_FRACTION_MEDIUM_MAX,
10204
10210
  NARROW_VIEWPORT_MAX,
10205
- TICK_LABEL_OFFSET as TICK_LABEL_OFFSET2,
10206
10211
  TOP_PAD_EXTRA_NARROW
10207
10212
  } from "@opendata-ai/openchart-core";
10208
10213
 
@@ -10653,10 +10658,10 @@ function computeDimensions(spec, options, legendLayout, theme, strategy, waterma
10653
10658
  theme.fonts.weights.normal
10654
10659
  );
10655
10660
  }
10656
- const dynamicTitleOffset = TICK_LABEL_OFFSET2 + estTickLabelWidth + AXIS_TITLE_GAP;
10657
- const axisTitleOffset = Math.max(dynamicTitleOffset, getAxisTitleOffset2(width));
10658
- const halfGlyph = Math.ceil(theme.fonts.sizes.body / 2);
10659
- const rotatedLabelMargin = axisTitleOffset + halfGlyph + (width < BREAKPOINT_COMPACT_MAX2 ? 0 : AXIS_TITLE_TRAILING_PAD2);
10661
+ const titleFontSize = theme.fonts.sizes.body;
10662
+ const offset = axisTitleOffset(estTickLabelWidth, titleFontSize, width);
10663
+ const halfGlyph = Math.ceil(titleFontSize / 2);
10664
+ const rotatedLabelMargin = offset + halfGlyph + (width < BREAKPOINT_COMPACT_MAX2 ? 0 : AXIS_TITLE_TRAILING_PAD2);
10660
10665
  margins.left = Math.max(margins.left, hPad + rotatedLabelMargin);
10661
10666
  }
10662
10667
  if (options.rightAxisReserve && options.rightAxisReserve > 0) {
@@ -14265,17 +14270,18 @@ function compileChart(spec, options) {
14265
14270
  const chartArea = dims.chartArea;
14266
14271
  const legendArea = { ...chartArea };
14267
14272
  if ("entries" in legendLayout && legendLayout.entries.length > 0) {
14273
+ const legendInnerWidth = options.width - theme.spacing.padding - chartArea.x;
14268
14274
  const gap = legendGap(options.width);
14269
14275
  switch (legendLayout.position) {
14270
14276
  case "top":
14271
- legendArea.x = theme.spacing.padding;
14272
- legendArea.width = options.width - theme.spacing.padding * 2;
14277
+ legendArea.x = chartArea.x;
14278
+ legendArea.width = legendInnerWidth;
14273
14279
  legendArea.y -= legendLayout.bounds.height + gap;
14274
14280
  legendArea.height += legendLayout.bounds.height + gap;
14275
14281
  break;
14276
14282
  case "bottom":
14277
- legendArea.x = theme.spacing.padding;
14278
- legendArea.width = options.width - theme.spacing.padding * 2;
14283
+ legendArea.x = chartArea.x;
14284
+ legendArea.width = legendInnerWidth;
14279
14285
  legendArea.height += legendLayout.bounds.height + gap + dims.xAxisHeight;
14280
14286
  break;
14281
14287
  case "right":