@opendata-ai/openchart-vanilla 6.24.1 → 6.25.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
@@ -3610,7 +3610,7 @@ function renderAnnotation(parent, annotation, index2, bgColor) {
3610
3610
  rx: 2
3611
3611
  });
3612
3612
  g.appendChild(bgRect);
3613
- } else if (bgColor) {
3613
+ } else if (bgColor && annotation.label.halo !== false) {
3614
3614
  text.style.paintOrder = "stroke";
3615
3615
  text.style.stroke = bgColor;
3616
3616
  text.style.strokeWidth = `${Math.round(fontSize * 0.3)}px`;
@@ -3635,7 +3635,8 @@ function renderAnnotations(parent, layout) {
3635
3635
  import { estimateTextWidth as estimateTextWidth2 } from "@opendata-ai/openchart-core";
3636
3636
  function renderAxis(parent, axis, orientation, layout) {
3637
3637
  const g = createSVGElement("g");
3638
- g.setAttribute("class", `oc-axis oc-axis-${orientation}`);
3638
+ const isRight = orientation === "y" && axis.orient === "right";
3639
+ g.setAttribute("class", `oc-axis oc-axis-${isRight ? "y2" : orientation}`);
3639
3640
  const { area } = layout;
3640
3641
  if (orientation === "x") {
3641
3642
  const line = createSVGElement("line");
@@ -3678,65 +3679,71 @@ function renderAxis(parent, axis, orientation, layout) {
3678
3679
  const label = createSVGElement("text");
3679
3680
  label.setAttribute("class", "oc-axis-tick");
3680
3681
  setAttrs(label, {
3681
- x: area.x - 6,
3682
+ x: isRight ? area.x + area.width + 6 : area.x - 6,
3682
3683
  y: tick.position,
3683
- "text-anchor": "end",
3684
+ "text-anchor": isRight ? "start" : "end",
3684
3685
  "dominant-baseline": "central"
3685
3686
  });
3686
3687
  applyTextStyle(label, axis.tickLabelStyle);
3687
- const availableWidth = area.x - 6;
3688
- const fontSize = axis.tickLabelStyle.fontSize;
3689
- const fontWeight = axis.tickLabelStyle.fontWeight;
3690
- const fullWidth = estimateTextWidth2(tick.label, fontSize, fontWeight);
3691
- if (fullWidth > availableWidth && availableWidth > 20) {
3692
- const ellipsis = "\u2026";
3693
- const ellipsisWidth = estimateTextWidth2(ellipsis, fontSize, fontWeight);
3694
- let lo = 0;
3695
- let hi = tick.label.length;
3696
- while (lo < hi) {
3697
- const mid = lo + hi + 1 >>> 1;
3698
- const candidate = tick.label.slice(0, mid);
3699
- if (estimateTextWidth2(candidate, fontSize, fontWeight) + ellipsisWidth <= availableWidth) {
3700
- lo = mid;
3701
- } else {
3702
- hi = mid - 1;
3688
+ if (!isRight) {
3689
+ const availableWidth = area.x - 6;
3690
+ const fontSize = axis.tickLabelStyle.fontSize;
3691
+ const fontWeight = axis.tickLabelStyle.fontWeight;
3692
+ const fullWidth = estimateTextWidth2(tick.label, fontSize, fontWeight);
3693
+ if (fullWidth > availableWidth && availableWidth > 20) {
3694
+ const ellipsis = "\u2026";
3695
+ const ellipsisWidth = estimateTextWidth2(ellipsis, fontSize, fontWeight);
3696
+ let lo = 0;
3697
+ let hi = tick.label.length;
3698
+ while (lo < hi) {
3699
+ const mid = lo + hi + 1 >>> 1;
3700
+ const candidate = tick.label.slice(0, mid);
3701
+ if (estimateTextWidth2(candidate, fontSize, fontWeight) + ellipsisWidth <= availableWidth) {
3702
+ lo = mid;
3703
+ } else {
3704
+ hi = mid - 1;
3705
+ }
3703
3706
  }
3707
+ label.textContent = lo > 0 ? tick.label.slice(0, lo).trimEnd() + ellipsis : ellipsis;
3708
+ const titleEl = createSVGElement("title");
3709
+ titleEl.textContent = tick.label;
3710
+ label.appendChild(titleEl);
3711
+ } else {
3712
+ label.textContent = tick.label;
3704
3713
  }
3705
- label.textContent = lo > 0 ? tick.label.slice(0, lo).trimEnd() + ellipsis : ellipsis;
3706
- const titleEl = createSVGElement("title");
3707
- titleEl.textContent = tick.label;
3708
- label.appendChild(titleEl);
3709
3714
  } else {
3710
3715
  label.textContent = tick.label;
3711
3716
  }
3712
3717
  g.appendChild(label);
3713
3718
  }
3714
3719
  }
3715
- for (const gridline of axis.gridlines) {
3716
- const gl = createSVGElement("line");
3717
- gl.setAttribute("class", "oc-gridline");
3718
- if (orientation === "y") {
3719
- setAttrs(gl, {
3720
- x1: area.x,
3721
- y1: gridline.position,
3722
- x2: area.x + area.width,
3723
- y2: gridline.position,
3724
- stroke: layout.theme.colors.gridline,
3725
- "stroke-width": 1,
3726
- "stroke-opacity": 0.6
3727
- });
3728
- } else {
3729
- setAttrs(gl, {
3730
- x1: gridline.position,
3731
- y1: area.y,
3732
- x2: gridline.position,
3733
- y2: area.y + area.height,
3734
- stroke: layout.theme.colors.gridline,
3735
- "stroke-width": 1,
3736
- "stroke-opacity": 0.6
3737
- });
3720
+ if (!isRight) {
3721
+ for (const gridline of axis.gridlines) {
3722
+ const gl = createSVGElement("line");
3723
+ gl.setAttribute("class", "oc-gridline");
3724
+ if (orientation === "y") {
3725
+ setAttrs(gl, {
3726
+ x1: area.x,
3727
+ y1: gridline.position,
3728
+ x2: area.x + area.width,
3729
+ y2: gridline.position,
3730
+ stroke: layout.theme.colors.gridline,
3731
+ "stroke-width": 1,
3732
+ "stroke-opacity": 0.6
3733
+ });
3734
+ } else {
3735
+ setAttrs(gl, {
3736
+ x1: gridline.position,
3737
+ y1: area.y,
3738
+ x2: gridline.position,
3739
+ y2: area.y + area.height,
3740
+ stroke: layout.theme.colors.gridline,
3741
+ "stroke-width": 1,
3742
+ "stroke-opacity": 0.6
3743
+ });
3744
+ }
3745
+ g.appendChild(gl);
3738
3746
  }
3739
- g.appendChild(gl);
3740
3747
  }
3741
3748
  if (axis.label && axis.labelStyle) {
3742
3749
  const axisLabel = createSVGElement("text");
@@ -3764,6 +3771,14 @@ function renderAxis(parent, axis, orientation, layout) {
3764
3771
  y: titleY,
3765
3772
  "text-anchor": "middle"
3766
3773
  });
3774
+ } else if (isRight) {
3775
+ const titleX = area.x + area.width + 45;
3776
+ setAttrs(axisLabel, {
3777
+ x: titleX,
3778
+ y: area.y + area.height / 2,
3779
+ "text-anchor": "middle",
3780
+ transform: `rotate(90, ${titleX}, ${area.y + area.height / 2})`
3781
+ });
3767
3782
  } else {
3768
3783
  setAttrs(axisLabel, {
3769
3784
  x: area.x - 45,
@@ -3783,6 +3798,9 @@ function renderAxes(parent, layout) {
3783
3798
  if (layout.axes.y) {
3784
3799
  renderAxis(parent, layout.axes.y, "y", layout);
3785
3800
  }
3801
+ if (layout.axes.y2) {
3802
+ renderAxis(parent, layout.axes.y2, "y", layout);
3803
+ }
3786
3804
  }
3787
3805
 
3788
3806
  // src/renderers/brand.ts