@esic-lab/data-core-ui 0.0.72 → 0.0.73
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.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +54 -52
- package/dist/index.mjs +54 -52
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -645,9 +645,10 @@ type Props = {
|
|
|
645
645
|
yLabel?: string;
|
|
646
646
|
xLabel?: string;
|
|
647
647
|
modeLabel?: "line" | "45";
|
|
648
|
+
layout?: "vertical" | "horizontal";
|
|
648
649
|
colorPalette?: string[];
|
|
649
650
|
};
|
|
650
|
-
declare const BarChart: ({ data, height, margin, yLabel, xLabel, modeLabel, colorPalette, }: Props) => react_jsx_runtime.JSX.Element;
|
|
651
|
+
declare const BarChart: ({ data, height, margin, yLabel, xLabel, modeLabel, colorPalette, layout, }: Props) => react_jsx_runtime.JSX.Element;
|
|
651
652
|
|
|
652
653
|
interface PieChartProps {
|
|
653
654
|
title?: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -645,9 +645,10 @@ type Props = {
|
|
|
645
645
|
yLabel?: string;
|
|
646
646
|
xLabel?: string;
|
|
647
647
|
modeLabel?: "line" | "45";
|
|
648
|
+
layout?: "vertical" | "horizontal";
|
|
648
649
|
colorPalette?: string[];
|
|
649
650
|
};
|
|
650
|
-
declare const BarChart: ({ data, height, margin, yLabel, xLabel, modeLabel, colorPalette, }: Props) => react_jsx_runtime.JSX.Element;
|
|
651
|
+
declare const BarChart: ({ data, height, margin, yLabel, xLabel, modeLabel, colorPalette, layout, }: Props) => react_jsx_runtime.JSX.Element;
|
|
651
652
|
|
|
652
653
|
interface PieChartProps {
|
|
653
654
|
title?: string;
|
package/dist/index.js
CHANGED
|
@@ -4702,7 +4702,8 @@ var BarChart = ({
|
|
|
4702
4702
|
yLabel,
|
|
4703
4703
|
xLabel,
|
|
4704
4704
|
modeLabel,
|
|
4705
|
-
colorPalette = defaultColorPalette
|
|
4705
|
+
colorPalette = defaultColorPalette,
|
|
4706
|
+
layout
|
|
4706
4707
|
}) => {
|
|
4707
4708
|
const svgRef = (0, import_react21.useRef)(null);
|
|
4708
4709
|
const gRef = (0, import_react21.useRef)(null);
|
|
@@ -4734,69 +4735,69 @@ var BarChart = ({
|
|
|
4734
4735
|
const innerW = width - margin.left - margin.right;
|
|
4735
4736
|
const innerH = height - margin.top - margin.bottom;
|
|
4736
4737
|
svg.attr("width", width).attr("height", height);
|
|
4737
|
-
const
|
|
4738
|
-
|
|
4739
|
-
const
|
|
4740
|
-
const
|
|
4741
|
-
const
|
|
4742
|
-
const
|
|
4743
|
-
|
|
4744
|
-
|
|
4745
|
-
|
|
4746
|
-
|
|
4747
|
-
|
|
4748
|
-
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
const
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
|
|
4755
|
-
|
|
4738
|
+
const isHorizontal = layout === "horizontal";
|
|
4739
|
+
g.attr("transform", `translate(${margin.left},${margin.top})`);
|
|
4740
|
+
const xBand = d3.scaleBand().domain(xDomain).padding(0.2);
|
|
4741
|
+
const yBand = d3.scaleBand().domain(xDomain).padding(0.2);
|
|
4742
|
+
const xLin = d3.scaleLinear().domain(yDomain).nice();
|
|
4743
|
+
const yLin = d3.scaleLinear().domain(yDomain).nice();
|
|
4744
|
+
if (!isHorizontal) {
|
|
4745
|
+
xBand.range([0, innerW]);
|
|
4746
|
+
yLin.range([innerH, 0]);
|
|
4747
|
+
} else {
|
|
4748
|
+
yBand.range([0, innerH]);
|
|
4749
|
+
xLin.range([0, innerW]);
|
|
4750
|
+
}
|
|
4751
|
+
const xAxis = !isHorizontal ? d3.axisBottom(xBand).tickSizeOuter(0).tickSize(0) : d3.axisBottom(xLin).ticks(5).tickFormat(d3.format("~s"));
|
|
4752
|
+
const yAxis = !isHorizontal ? d3.axisLeft(yLin).ticks(5).tickFormat(d3.format("~s")) : d3.axisLeft(yBand).tickSizeOuter(0).tickSize(0);
|
|
4753
|
+
xAxisG.attr("transform", `translate(${margin.left},${margin.top + innerH})`).call(xAxis);
|
|
4754
|
+
yAxisG.attr("transform", `translate(${margin.left},${margin.top})`).call(yAxis);
|
|
4755
|
+
const xTickTexts = xAxisG.selectAll("text").attr("fill", "currentColor").style("font-size", "14px").style("font-family", "Kanit, sans-serif");
|
|
4756
|
+
if (!isHorizontal) {
|
|
4757
|
+
if (modeLabel === "45") {
|
|
4758
|
+
xTickTexts.attr("transform", "rotate(-45)").style("text-anchor", "end").attr("dx", "-0.8em").attr("dy", "0.15em");
|
|
4759
|
+
} else {
|
|
4760
|
+
xTickTexts.attr("transform", "rotate(0)").style("text-anchor", "middle").attr("dx", "0").attr("dy", "1.5em");
|
|
4761
|
+
}
|
|
4756
4762
|
} else {
|
|
4757
|
-
|
|
4763
|
+
xTickTexts.attr("transform", "rotate(0)").style("text-anchor", "middle");
|
|
4758
4764
|
}
|
|
4765
|
+
const grid = !isHorizontal ? d3.axisLeft(yLin).ticks(5).tickSize(-innerW).tickFormat(() => "") : d3.axisBottom(xLin).ticks(5).tickSize(-innerH).tickFormat(() => "");
|
|
4766
|
+
const gridG = svg.selectAll("g.grid").data([null]).join("g").attr("class", "grid").attr(
|
|
4767
|
+
"transform",
|
|
4768
|
+
!isHorizontal ? `translate(${margin.left},${margin.top})` : `translate(${margin.left},${margin.top + innerH})`
|
|
4769
|
+
).call(grid);
|
|
4770
|
+
gridG.selectAll("path").remove();
|
|
4771
|
+
gridG.selectAll("line").style("stroke", "gray").style("stroke-opacity", 0.1);
|
|
4772
|
+
svg.select("g.grid").lower();
|
|
4759
4773
|
yAxisG.selectAll(".y-axis-label").data(yLabel ? [yLabel] : []).join(
|
|
4760
|
-
(enter) => enter.append("text").attr("class", "y-axis-label").attr("fill", "currentColor").attr("x", -margin.left +
|
|
4774
|
+
(enter) => enter.append("text").attr("class", "y-axis-label").attr("fill", "currentColor").attr("x", !isHorizontal ? 0 : innerWidth - margin.right - margin.left + 20).attr("y", !isHorizontal ? -10 : innerHeight / 2 + margin.bottom + margin.top + 20).attr("text-anchor", "middle").style("font-size", "18px").style("font-family", "Kanit, sans-serif").text((d) => d),
|
|
4761
4775
|
(update) => update.text((d) => d)
|
|
4762
4776
|
);
|
|
4763
4777
|
xAxisG.selectAll(".x-axis-label").data(xLabel ? [xLabel] : []).join(
|
|
4764
|
-
(enter) => enter.append("text").attr("class", "x-axis-label").attr("fill", "currentColor").attr("x",
|
|
4765
|
-
(update) => update.text((d) => d)
|
|
4778
|
+
(enter) => enter.append("text").attr("class", "x-axis-label").attr("fill", "currentColor").attr("x", !isHorizontal ? innerWidth - margin.right - margin.left + 20 : 0).attr("y", !isHorizontal ? -10 : -(innerHeight / 2) - margin.bottom - margin.top - 20).attr("text-anchor", "middle").style("font-size", "18px").style("font-family", "Kanit, sans-serif").text((d) => d),
|
|
4779
|
+
(update) => update.text((d) => d)
|
|
4766
4780
|
);
|
|
4767
|
-
const t =
|
|
4781
|
+
const t = svg.transition().duration(400);
|
|
4768
4782
|
const bars = g.selectAll("rect.bar").data(data, (d) => d.x);
|
|
4769
4783
|
bars.join(
|
|
4770
|
-
// (enter) =>
|
|
4771
|
-
// enter
|
|
4772
|
-
// .append("rect")
|
|
4773
|
-
// .attr("class", "bar")
|
|
4774
|
-
// .attr("x", (d) => margin.left)
|
|
4775
|
-
// .attr("width", x.bandwidth())
|
|
4776
|
-
// .attr("y", () => margin.top + y(0))
|
|
4777
|
-
// .attr("height", () => innerH - y(0))
|
|
4778
|
-
// .attr("rx", 5) // rounded corners
|
|
4779
|
-
// .attr("ry", 5) // rounded corners
|
|
4780
|
-
// .style("fill", (d, i) => colorPalette[i % colorPalette.length]) // Apply color based on index
|
|
4781
|
-
// .append("title")
|
|
4782
|
-
// .text((d) => `${d.x}: ${d.y}`)
|
|
4783
|
-
// .merge(bars) // merge the existing bars after joining
|
|
4784
|
-
// .attr("width", x.bandwidth())
|
|
4785
|
-
// .attr("y", (d) => y(d.y))
|
|
4786
|
-
// .attr("height", (d) => innerH - y(d.y))
|
|
4787
|
-
// .call((enter) => enter.raise()), // Bring the new bars to the front
|
|
4788
4784
|
(enter) => {
|
|
4789
|
-
const
|
|
4790
|
-
|
|
4791
|
-
|
|
4785
|
+
const e = enter.append("rect").attr("class", "bar").attr("rx", 5).attr("ry", 5).style("fill", (d, i) => colorPalette[i % colorPalette.length]);
|
|
4786
|
+
if (!isHorizontal) {
|
|
4787
|
+
e.attr("x", (d) => xBand(d.x) ?? 0).attr("width", xBand.bandwidth()).attr("y", yLin(0)).attr("height", innerH - yLin(0));
|
|
4788
|
+
} else {
|
|
4789
|
+
e.attr("x", 0).attr("width", 0).attr("y", (d) => yBand(d.x) ?? 0).attr("height", yBand.bandwidth());
|
|
4790
|
+
}
|
|
4791
|
+
e.append("title").text((d) => `${d.x}: ${d.y}`);
|
|
4792
|
+
return e.transition(t).attr("x", (d) => !isHorizontal ? xBand(d.x) ?? 0 : 0).attr("y", (d) => !isHorizontal ? yLin(d.y) : yBand(d.x) ?? 0).attr("width", (d) => !isHorizontal ? xBand.bandwidth() : xLin(d.y)).attr("height", (d) => !isHorizontal ? innerH - yLin(d.y) : yBand.bandwidth());
|
|
4792
4793
|
},
|
|
4793
|
-
(update) => update.call((
|
|
4794
|
-
|
|
4795
|
-
(exit) => exit.transition(t).attr("y", margin.top + y(0)).attr("height", innerH - y(0)).remove()
|
|
4794
|
+
(update) => update.call((u) => u.raise()).transition(t).attr("x", (d) => !isHorizontal ? xBand(d.x) ?? 0 : 0).attr("y", (d) => !isHorizontal ? yLin(d.y) : yBand(d.x) ?? 0).attr("width", (d) => !isHorizontal ? xBand.bandwidth() : xLin(d.y)).attr("height", (d) => !isHorizontal ? innerH - yLin(d.y) : yBand.bandwidth()).style("fill", (d, i) => colorPalette[i % colorPalette.length]),
|
|
4795
|
+
(exit) => exit.transition(t).attr("width", !isHorizontal ? xBand.bandwidth() : 0).attr("height", !isHorizontal ? innerH - yLin(0) : yBand.bandwidth()).remove()
|
|
4796
4796
|
);
|
|
4797
|
-
g.selectAll("text.bar-label").data(data).
|
|
4798
|
-
|
|
4799
|
-
(
|
|
4797
|
+
const labels = g.selectAll("text.bar-label").data(data, (d) => d.x);
|
|
4798
|
+
labels.join(
|
|
4799
|
+
(enter) => enter.append("text").attr("class", "bar-label").style("font-weight", "bold").style("font-family", "Kanit, sans-serif").style("font-size", "80px").style("fill", (d, i) => colorPalette[i % colorPalette.length]).attr("text-anchor", !isHorizontal ? "middle" : "start").attr("x", (d) => !isHorizontal ? (xBand(d.x) ?? 0) + xBand.bandwidth() / 2 : xLin(d.y) + 6).attr("y", (d) => !isHorizontal ? yLin(d.y) - 6 : (yBand(d.x) ?? 0) + yBand.bandwidth() / 2 + 4).text((d) => d.y),
|
|
4800
|
+
(update) => update.transition(t).attr("text-anchor", !isHorizontal ? "middle" : "start").attr("x", (d) => !isHorizontal ? (xBand(d.x) ?? 0) + xBand.bandwidth() / 2 : xLin(d.y) + 6).attr("y", (d) => !isHorizontal ? yLin(d.y) - 6 : (yBand(d.x) ?? 0) + yBand.bandwidth() / 2 + 24).text((d) => d.y),
|
|
4800
4801
|
(exit) => exit.remove()
|
|
4801
4802
|
);
|
|
4802
4803
|
};
|
|
@@ -4804,6 +4805,7 @@ var BarChart = ({
|
|
|
4804
4805
|
render();
|
|
4805
4806
|
}, [data, height, margin, modeLabel, xDomain.toString(), yDomain.toString()]);
|
|
4806
4807
|
return /* @__PURE__ */ (0, import_jsx_runtime46.jsx)("div", { ref: containerRef, style: { width: "100%" }, children: /* @__PURE__ */ (0, import_jsx_runtime46.jsxs)("svg", { ref: svgRef, role: "img", "aria-label": "Bar chart", style: { display: "block", width: "100%", height }, children: [
|
|
4808
|
+
/* @__PURE__ */ (0, import_jsx_runtime46.jsx)("title", { children: "Bar chart" }),
|
|
4807
4809
|
/* @__PURE__ */ (0, import_jsx_runtime46.jsx)("g", { ref: gRef, transform: `translate(${margin.left},${margin.top})` }),
|
|
4808
4810
|
/* @__PURE__ */ (0, import_jsx_runtime46.jsx)("g", { ref: xAxisRef }),
|
|
4809
4811
|
/* @__PURE__ */ (0, import_jsx_runtime46.jsx)("g", { ref: yAxisRef })
|
package/dist/index.mjs
CHANGED
|
@@ -4636,7 +4636,8 @@ var BarChart = ({
|
|
|
4636
4636
|
yLabel,
|
|
4637
4637
|
xLabel,
|
|
4638
4638
|
modeLabel,
|
|
4639
|
-
colorPalette = defaultColorPalette
|
|
4639
|
+
colorPalette = defaultColorPalette,
|
|
4640
|
+
layout
|
|
4640
4641
|
}) => {
|
|
4641
4642
|
const svgRef = useRef8(null);
|
|
4642
4643
|
const gRef = useRef8(null);
|
|
@@ -4668,69 +4669,69 @@ var BarChart = ({
|
|
|
4668
4669
|
const innerW = width - margin.left - margin.right;
|
|
4669
4670
|
const innerH = height - margin.top - margin.bottom;
|
|
4670
4671
|
svg.attr("width", width).attr("height", height);
|
|
4671
|
-
const
|
|
4672
|
-
|
|
4673
|
-
const
|
|
4674
|
-
const
|
|
4675
|
-
const
|
|
4676
|
-
const
|
|
4677
|
-
|
|
4678
|
-
|
|
4679
|
-
|
|
4680
|
-
|
|
4681
|
-
|
|
4682
|
-
|
|
4683
|
-
|
|
4684
|
-
|
|
4685
|
-
const
|
|
4686
|
-
|
|
4687
|
-
|
|
4688
|
-
|
|
4689
|
-
|
|
4672
|
+
const isHorizontal = layout === "horizontal";
|
|
4673
|
+
g.attr("transform", `translate(${margin.left},${margin.top})`);
|
|
4674
|
+
const xBand = d3.scaleBand().domain(xDomain).padding(0.2);
|
|
4675
|
+
const yBand = d3.scaleBand().domain(xDomain).padding(0.2);
|
|
4676
|
+
const xLin = d3.scaleLinear().domain(yDomain).nice();
|
|
4677
|
+
const yLin = d3.scaleLinear().domain(yDomain).nice();
|
|
4678
|
+
if (!isHorizontal) {
|
|
4679
|
+
xBand.range([0, innerW]);
|
|
4680
|
+
yLin.range([innerH, 0]);
|
|
4681
|
+
} else {
|
|
4682
|
+
yBand.range([0, innerH]);
|
|
4683
|
+
xLin.range([0, innerW]);
|
|
4684
|
+
}
|
|
4685
|
+
const xAxis = !isHorizontal ? d3.axisBottom(xBand).tickSizeOuter(0).tickSize(0) : d3.axisBottom(xLin).ticks(5).tickFormat(d3.format("~s"));
|
|
4686
|
+
const yAxis = !isHorizontal ? d3.axisLeft(yLin).ticks(5).tickFormat(d3.format("~s")) : d3.axisLeft(yBand).tickSizeOuter(0).tickSize(0);
|
|
4687
|
+
xAxisG.attr("transform", `translate(${margin.left},${margin.top + innerH})`).call(xAxis);
|
|
4688
|
+
yAxisG.attr("transform", `translate(${margin.left},${margin.top})`).call(yAxis);
|
|
4689
|
+
const xTickTexts = xAxisG.selectAll("text").attr("fill", "currentColor").style("font-size", "14px").style("font-family", "Kanit, sans-serif");
|
|
4690
|
+
if (!isHorizontal) {
|
|
4691
|
+
if (modeLabel === "45") {
|
|
4692
|
+
xTickTexts.attr("transform", "rotate(-45)").style("text-anchor", "end").attr("dx", "-0.8em").attr("dy", "0.15em");
|
|
4693
|
+
} else {
|
|
4694
|
+
xTickTexts.attr("transform", "rotate(0)").style("text-anchor", "middle").attr("dx", "0").attr("dy", "1.5em");
|
|
4695
|
+
}
|
|
4690
4696
|
} else {
|
|
4691
|
-
|
|
4697
|
+
xTickTexts.attr("transform", "rotate(0)").style("text-anchor", "middle");
|
|
4692
4698
|
}
|
|
4699
|
+
const grid = !isHorizontal ? d3.axisLeft(yLin).ticks(5).tickSize(-innerW).tickFormat(() => "") : d3.axisBottom(xLin).ticks(5).tickSize(-innerH).tickFormat(() => "");
|
|
4700
|
+
const gridG = svg.selectAll("g.grid").data([null]).join("g").attr("class", "grid").attr(
|
|
4701
|
+
"transform",
|
|
4702
|
+
!isHorizontal ? `translate(${margin.left},${margin.top})` : `translate(${margin.left},${margin.top + innerH})`
|
|
4703
|
+
).call(grid);
|
|
4704
|
+
gridG.selectAll("path").remove();
|
|
4705
|
+
gridG.selectAll("line").style("stroke", "gray").style("stroke-opacity", 0.1);
|
|
4706
|
+
svg.select("g.grid").lower();
|
|
4693
4707
|
yAxisG.selectAll(".y-axis-label").data(yLabel ? [yLabel] : []).join(
|
|
4694
|
-
(enter) => enter.append("text").attr("class", "y-axis-label").attr("fill", "currentColor").attr("x", -margin.left +
|
|
4708
|
+
(enter) => enter.append("text").attr("class", "y-axis-label").attr("fill", "currentColor").attr("x", !isHorizontal ? 0 : innerWidth - margin.right - margin.left + 20).attr("y", !isHorizontal ? -10 : innerHeight / 2 + margin.bottom + margin.top + 20).attr("text-anchor", "middle").style("font-size", "18px").style("font-family", "Kanit, sans-serif").text((d) => d),
|
|
4695
4709
|
(update) => update.text((d) => d)
|
|
4696
4710
|
);
|
|
4697
4711
|
xAxisG.selectAll(".x-axis-label").data(xLabel ? [xLabel] : []).join(
|
|
4698
|
-
(enter) => enter.append("text").attr("class", "x-axis-label").attr("fill", "currentColor").attr("x",
|
|
4699
|
-
(update) => update.text((d) => d)
|
|
4712
|
+
(enter) => enter.append("text").attr("class", "x-axis-label").attr("fill", "currentColor").attr("x", !isHorizontal ? innerWidth - margin.right - margin.left + 20 : 0).attr("y", !isHorizontal ? -10 : -(innerHeight / 2) - margin.bottom - margin.top - 20).attr("text-anchor", "middle").style("font-size", "18px").style("font-family", "Kanit, sans-serif").text((d) => d),
|
|
4713
|
+
(update) => update.text((d) => d)
|
|
4700
4714
|
);
|
|
4701
|
-
const t =
|
|
4715
|
+
const t = svg.transition().duration(400);
|
|
4702
4716
|
const bars = g.selectAll("rect.bar").data(data, (d) => d.x);
|
|
4703
4717
|
bars.join(
|
|
4704
|
-
// (enter) =>
|
|
4705
|
-
// enter
|
|
4706
|
-
// .append("rect")
|
|
4707
|
-
// .attr("class", "bar")
|
|
4708
|
-
// .attr("x", (d) => margin.left)
|
|
4709
|
-
// .attr("width", x.bandwidth())
|
|
4710
|
-
// .attr("y", () => margin.top + y(0))
|
|
4711
|
-
// .attr("height", () => innerH - y(0))
|
|
4712
|
-
// .attr("rx", 5) // rounded corners
|
|
4713
|
-
// .attr("ry", 5) // rounded corners
|
|
4714
|
-
// .style("fill", (d, i) => colorPalette[i % colorPalette.length]) // Apply color based on index
|
|
4715
|
-
// .append("title")
|
|
4716
|
-
// .text((d) => `${d.x}: ${d.y}`)
|
|
4717
|
-
// .merge(bars) // merge the existing bars after joining
|
|
4718
|
-
// .attr("width", x.bandwidth())
|
|
4719
|
-
// .attr("y", (d) => y(d.y))
|
|
4720
|
-
// .attr("height", (d) => innerH - y(d.y))
|
|
4721
|
-
// .call((enter) => enter.raise()), // Bring the new bars to the front
|
|
4722
4718
|
(enter) => {
|
|
4723
|
-
const
|
|
4724
|
-
|
|
4725
|
-
|
|
4719
|
+
const e = enter.append("rect").attr("class", "bar").attr("rx", 5).attr("ry", 5).style("fill", (d, i) => colorPalette[i % colorPalette.length]);
|
|
4720
|
+
if (!isHorizontal) {
|
|
4721
|
+
e.attr("x", (d) => xBand(d.x) ?? 0).attr("width", xBand.bandwidth()).attr("y", yLin(0)).attr("height", innerH - yLin(0));
|
|
4722
|
+
} else {
|
|
4723
|
+
e.attr("x", 0).attr("width", 0).attr("y", (d) => yBand(d.x) ?? 0).attr("height", yBand.bandwidth());
|
|
4724
|
+
}
|
|
4725
|
+
e.append("title").text((d) => `${d.x}: ${d.y}`);
|
|
4726
|
+
return e.transition(t).attr("x", (d) => !isHorizontal ? xBand(d.x) ?? 0 : 0).attr("y", (d) => !isHorizontal ? yLin(d.y) : yBand(d.x) ?? 0).attr("width", (d) => !isHorizontal ? xBand.bandwidth() : xLin(d.y)).attr("height", (d) => !isHorizontal ? innerH - yLin(d.y) : yBand.bandwidth());
|
|
4726
4727
|
},
|
|
4727
|
-
(update) => update.call((
|
|
4728
|
-
|
|
4729
|
-
(exit) => exit.transition(t).attr("y", margin.top + y(0)).attr("height", innerH - y(0)).remove()
|
|
4728
|
+
(update) => update.call((u) => u.raise()).transition(t).attr("x", (d) => !isHorizontal ? xBand(d.x) ?? 0 : 0).attr("y", (d) => !isHorizontal ? yLin(d.y) : yBand(d.x) ?? 0).attr("width", (d) => !isHorizontal ? xBand.bandwidth() : xLin(d.y)).attr("height", (d) => !isHorizontal ? innerH - yLin(d.y) : yBand.bandwidth()).style("fill", (d, i) => colorPalette[i % colorPalette.length]),
|
|
4729
|
+
(exit) => exit.transition(t).attr("width", !isHorizontal ? xBand.bandwidth() : 0).attr("height", !isHorizontal ? innerH - yLin(0) : yBand.bandwidth()).remove()
|
|
4730
4730
|
);
|
|
4731
|
-
g.selectAll("text.bar-label").data(data).
|
|
4732
|
-
|
|
4733
|
-
(
|
|
4731
|
+
const labels = g.selectAll("text.bar-label").data(data, (d) => d.x);
|
|
4732
|
+
labels.join(
|
|
4733
|
+
(enter) => enter.append("text").attr("class", "bar-label").style("font-weight", "bold").style("font-family", "Kanit, sans-serif").style("font-size", "80px").style("fill", (d, i) => colorPalette[i % colorPalette.length]).attr("text-anchor", !isHorizontal ? "middle" : "start").attr("x", (d) => !isHorizontal ? (xBand(d.x) ?? 0) + xBand.bandwidth() / 2 : xLin(d.y) + 6).attr("y", (d) => !isHorizontal ? yLin(d.y) - 6 : (yBand(d.x) ?? 0) + yBand.bandwidth() / 2 + 4).text((d) => d.y),
|
|
4734
|
+
(update) => update.transition(t).attr("text-anchor", !isHorizontal ? "middle" : "start").attr("x", (d) => !isHorizontal ? (xBand(d.x) ?? 0) + xBand.bandwidth() / 2 : xLin(d.y) + 6).attr("y", (d) => !isHorizontal ? yLin(d.y) - 6 : (yBand(d.x) ?? 0) + yBand.bandwidth() / 2 + 24).text((d) => d.y),
|
|
4734
4735
|
(exit) => exit.remove()
|
|
4735
4736
|
);
|
|
4736
4737
|
};
|
|
@@ -4738,6 +4739,7 @@ var BarChart = ({
|
|
|
4738
4739
|
render();
|
|
4739
4740
|
}, [data, height, margin, modeLabel, xDomain.toString(), yDomain.toString()]);
|
|
4740
4741
|
return /* @__PURE__ */ jsx46("div", { ref: containerRef, style: { width: "100%" }, children: /* @__PURE__ */ jsxs37("svg", { ref: svgRef, role: "img", "aria-label": "Bar chart", style: { display: "block", width: "100%", height }, children: [
|
|
4742
|
+
/* @__PURE__ */ jsx46("title", { children: "Bar chart" }),
|
|
4741
4743
|
/* @__PURE__ */ jsx46("g", { ref: gRef, transform: `translate(${margin.left},${margin.top})` }),
|
|
4742
4744
|
/* @__PURE__ */ jsx46("g", { ref: xAxisRef }),
|
|
4743
4745
|
/* @__PURE__ */ jsx46("g", { ref: yAxisRef })
|