@opendata-ai/openchart-vanilla 6.24.2 → 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 +65 -47
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/src/renderers/axes.ts +72 -57
package/dist/index.js
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
|
|
3696
|
-
|
|
3697
|
-
|
|
3698
|
-
|
|
3699
|
-
|
|
3700
|
-
|
|
3701
|
-
|
|
3702
|
-
|
|
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
|
-
|
|
3716
|
-
const
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
|
|
3736
|
-
|
|
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
|