@opendata-ai/openchart-vanilla 6.24.2 → 6.25.1

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
@@ -3632,10 +3632,15 @@ function renderAnnotations(parent, layout) {
3632
3632
  }
3633
3633
 
3634
3634
  // src/renderers/axes.ts
3635
- import { estimateTextWidth as estimateTextWidth2 } from "@opendata-ai/openchart-core";
3635
+ import {
3636
+ estimateTextWidth as estimateTextWidth2,
3637
+ getAxisTitleOffset,
3638
+ TICK_LABEL_OFFSET
3639
+ } from "@opendata-ai/openchart-core";
3636
3640
  function renderAxis(parent, axis, orientation, layout) {
3637
3641
  const g = createSVGElement("g");
3638
- g.setAttribute("class", `oc-axis oc-axis-${orientation}`);
3642
+ const isRight = orientation === "y" && axis.orient === "right";
3643
+ g.setAttribute("class", `oc-axis oc-axis-${isRight ? "y2" : orientation}`);
3639
3644
  const { area } = layout;
3640
3645
  if (orientation === "x") {
3641
3646
  const line = createSVGElement("line");
@@ -3678,65 +3683,71 @@ function renderAxis(parent, axis, orientation, layout) {
3678
3683
  const label = createSVGElement("text");
3679
3684
  label.setAttribute("class", "oc-axis-tick");
3680
3685
  setAttrs(label, {
3681
- x: area.x - 6,
3686
+ x: isRight ? area.x + area.width + TICK_LABEL_OFFSET : area.x - TICK_LABEL_OFFSET,
3682
3687
  y: tick.position,
3683
- "text-anchor": "end",
3688
+ "text-anchor": isRight ? "start" : "end",
3684
3689
  "dominant-baseline": "central"
3685
3690
  });
3686
3691
  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;
3692
+ if (!isRight) {
3693
+ const availableWidth = area.x - TICK_LABEL_OFFSET;
3694
+ const fontSize = axis.tickLabelStyle.fontSize;
3695
+ const fontWeight = axis.tickLabelStyle.fontWeight;
3696
+ const fullWidth = estimateTextWidth2(tick.label, fontSize, fontWeight);
3697
+ if (fullWidth > availableWidth && availableWidth > 20) {
3698
+ const ellipsis = "\u2026";
3699
+ const ellipsisWidth = estimateTextWidth2(ellipsis, fontSize, fontWeight);
3700
+ let lo = 0;
3701
+ let hi = tick.label.length;
3702
+ while (lo < hi) {
3703
+ const mid = lo + hi + 1 >>> 1;
3704
+ const candidate = tick.label.slice(0, mid);
3705
+ if (estimateTextWidth2(candidate, fontSize, fontWeight) + ellipsisWidth <= availableWidth) {
3706
+ lo = mid;
3707
+ } else {
3708
+ hi = mid - 1;
3709
+ }
3703
3710
  }
3711
+ label.textContent = lo > 0 ? tick.label.slice(0, lo).trimEnd() + ellipsis : ellipsis;
3712
+ const titleEl = createSVGElement("title");
3713
+ titleEl.textContent = tick.label;
3714
+ label.appendChild(titleEl);
3715
+ } else {
3716
+ label.textContent = tick.label;
3704
3717
  }
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
3718
  } else {
3710
3719
  label.textContent = tick.label;
3711
3720
  }
3712
3721
  g.appendChild(label);
3713
3722
  }
3714
3723
  }
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
- });
3724
+ if (!isRight) {
3725
+ for (const gridline of axis.gridlines) {
3726
+ const gl = createSVGElement("line");
3727
+ gl.setAttribute("class", "oc-gridline");
3728
+ if (orientation === "y") {
3729
+ setAttrs(gl, {
3730
+ x1: area.x,
3731
+ y1: gridline.position,
3732
+ x2: area.x + area.width,
3733
+ y2: gridline.position,
3734
+ stroke: layout.theme.colors.gridline,
3735
+ "stroke-width": 1,
3736
+ "stroke-opacity": 0.6
3737
+ });
3738
+ } else {
3739
+ setAttrs(gl, {
3740
+ x1: gridline.position,
3741
+ y1: area.y,
3742
+ x2: gridline.position,
3743
+ y2: area.y + area.height,
3744
+ stroke: layout.theme.colors.gridline,
3745
+ "stroke-width": 1,
3746
+ "stroke-opacity": 0.6
3747
+ });
3748
+ }
3749
+ g.appendChild(gl);
3738
3750
  }
3739
- g.appendChild(gl);
3740
3751
  }
3741
3752
  if (axis.label && axis.labelStyle) {
3742
3753
  const axisLabel = createSVGElement("text");
@@ -3764,12 +3775,22 @@ function renderAxis(parent, axis, orientation, layout) {
3764
3775
  y: titleY,
3765
3776
  "text-anchor": "middle"
3766
3777
  });
3778
+ } else if (isRight) {
3779
+ const titleOffset = getAxisTitleOffset(layout.dimensions.width);
3780
+ const titleX = area.x + area.width + titleOffset;
3781
+ setAttrs(axisLabel, {
3782
+ x: titleX,
3783
+ y: area.y + area.height / 2,
3784
+ "text-anchor": "middle",
3785
+ transform: `rotate(90, ${titleX}, ${area.y + area.height / 2})`
3786
+ });
3767
3787
  } else {
3788
+ const titleOffset = getAxisTitleOffset(layout.dimensions.width);
3768
3789
  setAttrs(axisLabel, {
3769
- x: area.x - 45,
3790
+ x: area.x - titleOffset,
3770
3791
  y: area.y + area.height / 2,
3771
3792
  "text-anchor": "middle",
3772
- transform: `rotate(-90, ${area.x - 45}, ${area.y + area.height / 2})`
3793
+ transform: `rotate(-90, ${area.x - titleOffset}, ${area.y + area.height / 2})`
3773
3794
  });
3774
3795
  }
3775
3796
  g.appendChild(axisLabel);
@@ -3783,6 +3804,9 @@ function renderAxes(parent, layout) {
3783
3804
  if (layout.axes.y) {
3784
3805
  renderAxis(parent, layout.axes.y, "y", layout);
3785
3806
  }
3807
+ if (layout.axes.y2) {
3808
+ renderAxis(parent, layout.axes.y2, "y", layout);
3809
+ }
3786
3810
  }
3787
3811
 
3788
3812
  // src/renderers/brand.ts