@entropix/data 0.0.0 → 1.0.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.
Files changed (50) hide show
  1. package/dist/area-chart.cjs +14 -0
  2. package/dist/area-chart.css +144 -0
  3. package/dist/area-chart.d.cts +19 -0
  4. package/dist/area-chart.d.ts +19 -0
  5. package/dist/area-chart.js +5 -0
  6. package/dist/bar-chart.cjs +14 -0
  7. package/dist/bar-chart.css +144 -0
  8. package/dist/bar-chart.d.cts +18 -0
  9. package/dist/bar-chart.d.ts +18 -0
  10. package/dist/bar-chart.js +5 -0
  11. package/dist/chunk-42HKJHUY.js +96 -0
  12. package/dist/chunk-4WXLJDQU.js +74 -0
  13. package/dist/chunk-6YAOO76S.cjs +142 -0
  14. package/dist/chunk-CMAQ7DZD.js +135 -0
  15. package/dist/chunk-FQACLZYR.js +137 -0
  16. package/dist/chunk-GCZSXJAA.cjs +77 -0
  17. package/dist/chunk-K6ZRQYSZ.cjs +131 -0
  18. package/dist/chunk-QBI5NOHT.cjs +126 -0
  19. package/dist/chunk-SDCNTA7E.cjs +275 -0
  20. package/dist/chunk-VCSKHJLZ.js +124 -0
  21. package/dist/chunk-VGT2QF7D.cjs +98 -0
  22. package/dist/chunk-WOVSQALY.cjs +137 -0
  23. package/dist/chunk-X7GZD7KZ.js +129 -0
  24. package/dist/chunk-YINCJQN6.js +271 -0
  25. package/dist/data-table.cjs +20 -0
  26. package/dist/data-table.css +227 -0
  27. package/dist/data-table.d.cts +20 -0
  28. package/dist/data-table.d.ts +20 -0
  29. package/dist/data-table.js +3 -0
  30. package/dist/index.cjs +36 -269
  31. package/dist/index.css +144 -0
  32. package/dist/index.d.cts +8 -21
  33. package/dist/index.d.ts +8 -21
  34. package/dist/index.js +7 -269
  35. package/dist/line-chart.cjs +14 -0
  36. package/dist/line-chart.css +144 -0
  37. package/dist/line-chart.d.cts +19 -0
  38. package/dist/line-chart.d.ts +19 -0
  39. package/dist/line-chart.js +5 -0
  40. package/dist/pie-chart.cjs +13 -0
  41. package/dist/pie-chart.css +144 -0
  42. package/dist/pie-chart.d.cts +15 -0
  43. package/dist/pie-chart.d.ts +15 -0
  44. package/dist/pie-chart.js +4 -0
  45. package/dist/styles/chart.css +1 -0
  46. package/dist/styles/data-table.css +1 -304
  47. package/package.json +54 -3
  48. package/dist/index.cjs.map +0 -1
  49. package/dist/index.css.map +0 -1
  50. package/dist/index.js.map +0 -1
@@ -0,0 +1,142 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var jsxRuntime = require('react/jsx-runtime');
5
+
6
+ // src/components/chart-primitives/chart-container.tsx
7
+ function ChartContainer({
8
+ height = 300,
9
+ className,
10
+ children
11
+ }) {
12
+ const containerRef = react.useRef(null);
13
+ const [width, setWidth] = react.useState(0);
14
+ const handleResize = react.useCallback(() => {
15
+ if (containerRef.current) {
16
+ setWidth(containerRef.current.clientWidth);
17
+ }
18
+ }, []);
19
+ react.useEffect(() => {
20
+ const el = containerRef.current;
21
+ if (!el) return;
22
+ handleResize();
23
+ const observer = new ResizeObserver(() => {
24
+ handleResize();
25
+ });
26
+ observer.observe(el);
27
+ return () => observer.disconnect();
28
+ }, [handleResize]);
29
+ return /* @__PURE__ */ jsxRuntime.jsx(
30
+ "div",
31
+ {
32
+ ref: containerRef,
33
+ className: className ? `entropix-chart ${className}` : "entropix-chart",
34
+ style: { position: "relative", width: "100%" },
35
+ children: width > 0 && /* @__PURE__ */ jsxRuntime.jsx(
36
+ "svg",
37
+ {
38
+ className: "entropix-chart__svg",
39
+ width,
40
+ height,
41
+ viewBox: `0 0 ${width} ${height}`,
42
+ children: children(width, height)
43
+ }
44
+ )
45
+ }
46
+ );
47
+ }
48
+ function ChartTooltip({ data, containerRef }) {
49
+ const tooltipRef = react.useRef(null);
50
+ const [position, setPosition] = react.useState({
51
+ left: 0,
52
+ top: 0
53
+ });
54
+ react.useEffect(() => {
55
+ if (!data || !tooltipRef.current || !containerRef.current) return;
56
+ const container = containerRef.current;
57
+ const tooltip = tooltipRef.current;
58
+ const containerRect = container.getBoundingClientRect();
59
+ const tooltipWidth = tooltip.offsetWidth;
60
+ const tooltipHeight = tooltip.offsetHeight;
61
+ let left = data.x + 12;
62
+ let top = data.y - tooltipHeight / 2;
63
+ if (left + tooltipWidth > containerRect.width) {
64
+ left = data.x - tooltipWidth - 12;
65
+ }
66
+ if (top < 0) {
67
+ top = 0;
68
+ }
69
+ if (top + tooltipHeight > containerRect.height) {
70
+ top = containerRect.height - tooltipHeight;
71
+ }
72
+ setPosition({ left, top });
73
+ }, [data, containerRef]);
74
+ return /* @__PURE__ */ jsxRuntime.jsx(
75
+ "div",
76
+ {
77
+ ref: tooltipRef,
78
+ className: `entropix-chart__tooltip${data ? " entropix-chart__tooltip--visible" : ""}`,
79
+ style: {
80
+ left: position.left,
81
+ top: position.top
82
+ },
83
+ children: data && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "entropix-chart__tooltip-row", children: [
84
+ /* @__PURE__ */ jsxRuntime.jsx(
85
+ "span",
86
+ {
87
+ className: "entropix-chart__tooltip-swatch",
88
+ style: { backgroundColor: data.color }
89
+ }
90
+ ),
91
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
92
+ data.series,
93
+ ": ",
94
+ data.label,
95
+ " \u2014 ",
96
+ data.value
97
+ ] })
98
+ ] })
99
+ }
100
+ );
101
+ }
102
+ function ChartLegend({ items, onToggle }) {
103
+ if (items.length === 0) return null;
104
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: "entropix-chart__legend", children: items.map((item) => /* @__PURE__ */ jsxRuntime.jsxs(
105
+ "button",
106
+ {
107
+ type: "button",
108
+ className: `entropix-chart__legend-item${!item.active ? " entropix-chart__legend-item--inactive" : ""}`,
109
+ onClick: () => onToggle(item.name),
110
+ children: [
111
+ /* @__PURE__ */ jsxRuntime.jsx(
112
+ "span",
113
+ {
114
+ className: "entropix-chart__legend-swatch",
115
+ style: { backgroundColor: item.color }
116
+ }
117
+ ),
118
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: item.name })
119
+ ]
120
+ },
121
+ item.name
122
+ )) });
123
+ }
124
+
125
+ // src/utils/chart-colors.ts
126
+ var CSS_CHART_COLORS = [
127
+ "var(--chart-series-1)",
128
+ "var(--chart-series-2)",
129
+ "var(--chart-series-3)",
130
+ "var(--chart-series-4)",
131
+ "var(--chart-series-5)",
132
+ "var(--chart-series-6)",
133
+ "var(--chart-series-7)",
134
+ "var(--chart-series-8)"
135
+ ];
136
+
137
+ exports.CSS_CHART_COLORS = CSS_CHART_COLORS;
138
+ exports.ChartContainer = ChartContainer;
139
+ exports.ChartLegend = ChartLegend;
140
+ exports.ChartTooltip = ChartTooltip;
141
+ //# sourceMappingURL=chunk-6YAOO76S.cjs.map
142
+ //# sourceMappingURL=chunk-6YAOO76S.cjs.map
@@ -0,0 +1,135 @@
1
+ import { YAxis, XAxis } from './chunk-4WXLJDQU.js';
2
+ import { CSS_CHART_COLORS, ChartContainer, ChartTooltip, ChartLegend } from './chunk-FQACLZYR.js';
3
+ import { useState, useRef, useCallback } from 'react';
4
+ import { normalizeChartData, getDataExtent, niceBounds, createLinearScale, createBandScale, computeLinePoints, describeAreaPath, describeLinePath } from '@entropix/core';
5
+ import { jsxs, jsx } from 'react/jsx-runtime';
6
+
7
+ var MARGINS = { top: 20, right: 20, bottom: 40, left: 50 };
8
+ function AreaChart({
9
+ data,
10
+ height = 300,
11
+ colors,
12
+ curved = false,
13
+ opacity = 0.3,
14
+ showGrid = true,
15
+ showTooltip = true,
16
+ showLegend = true,
17
+ xAxis,
18
+ yAxis,
19
+ className
20
+ }) {
21
+ const [hiddenSeries, setHiddenSeries] = useState(/* @__PURE__ */ new Set());
22
+ const [tooltip, setTooltip] = useState(null);
23
+ const containerRef = useRef(null);
24
+ const toggleSeries = useCallback((name) => {
25
+ setHiddenSeries((prev) => {
26
+ const next = new Set(prev);
27
+ if (next.has(name)) next.delete(name);
28
+ else next.add(name);
29
+ return next;
30
+ });
31
+ }, []);
32
+ const allSeries = normalizeChartData(data, colors ?? CSS_CHART_COLORS);
33
+ const visibleSeries = allSeries.filter((s) => !hiddenSeries.has(s.name));
34
+ const { categories, yMin, yMax } = getDataExtent(visibleSeries);
35
+ const legendItems = allSeries.map((s) => ({
36
+ name: s.name,
37
+ color: s.color,
38
+ active: !hiddenSeries.has(s.name)
39
+ }));
40
+ const handlePointEnter = useCallback(
41
+ (point, seriesName, color) => {
42
+ if (!showTooltip) return;
43
+ setTooltip({
44
+ x: point.x + MARGINS.left,
45
+ y: point.y + MARGINS.top,
46
+ series: seriesName,
47
+ label: point.label,
48
+ value: point.value,
49
+ color
50
+ });
51
+ },
52
+ [showTooltip]
53
+ );
54
+ const handlePointLeave = useCallback(() => {
55
+ setTooltip(null);
56
+ }, []);
57
+ return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: className ? `entropix-chart ${className}` : "entropix-chart", style: { position: "relative" }, children: [
58
+ /* @__PURE__ */ jsx(ChartContainer, { height, children: (width, h) => {
59
+ const innerWidth = width - MARGINS.left - MARGINS.right;
60
+ const innerHeight = h - MARGINS.top - MARGINS.bottom;
61
+ if (innerWidth <= 0 || innerHeight <= 0) return null;
62
+ const bounds = niceBounds(yMin, yMax, yAxis?.tickCount ?? 5);
63
+ const yScale = createLinearScale(
64
+ [bounds.min, bounds.max],
65
+ [innerHeight, 0]
66
+ );
67
+ const xScale = createBandScale(categories, [0, innerWidth]);
68
+ const baselineY = yScale(bounds.min);
69
+ return /* @__PURE__ */ jsxs("g", { transform: `translate(${MARGINS.left}, ${MARGINS.top})`, children: [
70
+ yAxis?.show !== false && /* @__PURE__ */ jsx(
71
+ YAxis,
72
+ {
73
+ scale: yScale,
74
+ x: 0,
75
+ width: innerWidth,
76
+ showGrid,
77
+ formatter: yAxis?.formatter
78
+ }
79
+ ),
80
+ xAxis?.show !== false && /* @__PURE__ */ jsx(
81
+ XAxis,
82
+ {
83
+ scale: xScale,
84
+ y: innerHeight,
85
+ height: innerHeight,
86
+ formatter: xAxis?.formatter
87
+ }
88
+ ),
89
+ visibleSeries.map((series) => {
90
+ const points = computeLinePoints(series, xScale, yScale);
91
+ const areaD = describeAreaPath(points, baselineY, curved);
92
+ const lineD = describeLinePath(points, curved);
93
+ return /* @__PURE__ */ jsxs("g", { children: [
94
+ /* @__PURE__ */ jsx(
95
+ "path",
96
+ {
97
+ className: "entropix-chart__area",
98
+ d: areaD,
99
+ fill: series.color,
100
+ fillOpacity: opacity
101
+ }
102
+ ),
103
+ /* @__PURE__ */ jsx(
104
+ "path",
105
+ {
106
+ className: "entropix-chart__line",
107
+ d: lineD,
108
+ stroke: series.color
109
+ }
110
+ ),
111
+ points.map((pt, i) => /* @__PURE__ */ jsx(
112
+ "circle",
113
+ {
114
+ className: "entropix-chart__point",
115
+ cx: pt.x,
116
+ cy: pt.y,
117
+ r: 3,
118
+ fill: series.color,
119
+ onMouseEnter: () => handlePointEnter(pt, series.name, series.color),
120
+ onMouseLeave: handlePointLeave
121
+ },
122
+ i
123
+ ))
124
+ ] }, series.name);
125
+ })
126
+ ] });
127
+ } }),
128
+ showTooltip && /* @__PURE__ */ jsx(ChartTooltip, { data: tooltip, containerRef }),
129
+ showLegend && allSeries.length > 1 && /* @__PURE__ */ jsx(ChartLegend, { items: legendItems, onToggle: toggleSeries })
130
+ ] });
131
+ }
132
+
133
+ export { AreaChart };
134
+ //# sourceMappingURL=chunk-CMAQ7DZD.js.map
135
+ //# sourceMappingURL=chunk-CMAQ7DZD.js.map
@@ -0,0 +1,137 @@
1
+ import { useRef, useState, useCallback, useEffect } from 'react';
2
+ import { jsx, jsxs } from 'react/jsx-runtime';
3
+
4
+ // src/components/chart-primitives/chart-container.tsx
5
+ function ChartContainer({
6
+ height = 300,
7
+ className,
8
+ children
9
+ }) {
10
+ const containerRef = useRef(null);
11
+ const [width, setWidth] = useState(0);
12
+ const handleResize = useCallback(() => {
13
+ if (containerRef.current) {
14
+ setWidth(containerRef.current.clientWidth);
15
+ }
16
+ }, []);
17
+ useEffect(() => {
18
+ const el = containerRef.current;
19
+ if (!el) return;
20
+ handleResize();
21
+ const observer = new ResizeObserver(() => {
22
+ handleResize();
23
+ });
24
+ observer.observe(el);
25
+ return () => observer.disconnect();
26
+ }, [handleResize]);
27
+ return /* @__PURE__ */ jsx(
28
+ "div",
29
+ {
30
+ ref: containerRef,
31
+ className: className ? `entropix-chart ${className}` : "entropix-chart",
32
+ style: { position: "relative", width: "100%" },
33
+ children: width > 0 && /* @__PURE__ */ jsx(
34
+ "svg",
35
+ {
36
+ className: "entropix-chart__svg",
37
+ width,
38
+ height,
39
+ viewBox: `0 0 ${width} ${height}`,
40
+ children: children(width, height)
41
+ }
42
+ )
43
+ }
44
+ );
45
+ }
46
+ function ChartTooltip({ data, containerRef }) {
47
+ const tooltipRef = useRef(null);
48
+ const [position, setPosition] = useState({
49
+ left: 0,
50
+ top: 0
51
+ });
52
+ useEffect(() => {
53
+ if (!data || !tooltipRef.current || !containerRef.current) return;
54
+ const container = containerRef.current;
55
+ const tooltip = tooltipRef.current;
56
+ const containerRect = container.getBoundingClientRect();
57
+ const tooltipWidth = tooltip.offsetWidth;
58
+ const tooltipHeight = tooltip.offsetHeight;
59
+ let left = data.x + 12;
60
+ let top = data.y - tooltipHeight / 2;
61
+ if (left + tooltipWidth > containerRect.width) {
62
+ left = data.x - tooltipWidth - 12;
63
+ }
64
+ if (top < 0) {
65
+ top = 0;
66
+ }
67
+ if (top + tooltipHeight > containerRect.height) {
68
+ top = containerRect.height - tooltipHeight;
69
+ }
70
+ setPosition({ left, top });
71
+ }, [data, containerRef]);
72
+ return /* @__PURE__ */ jsx(
73
+ "div",
74
+ {
75
+ ref: tooltipRef,
76
+ className: `entropix-chart__tooltip${data ? " entropix-chart__tooltip--visible" : ""}`,
77
+ style: {
78
+ left: position.left,
79
+ top: position.top
80
+ },
81
+ children: data && /* @__PURE__ */ jsxs("div", { className: "entropix-chart__tooltip-row", children: [
82
+ /* @__PURE__ */ jsx(
83
+ "span",
84
+ {
85
+ className: "entropix-chart__tooltip-swatch",
86
+ style: { backgroundColor: data.color }
87
+ }
88
+ ),
89
+ /* @__PURE__ */ jsxs("span", { children: [
90
+ data.series,
91
+ ": ",
92
+ data.label,
93
+ " \u2014 ",
94
+ data.value
95
+ ] })
96
+ ] })
97
+ }
98
+ );
99
+ }
100
+ function ChartLegend({ items, onToggle }) {
101
+ if (items.length === 0) return null;
102
+ return /* @__PURE__ */ jsx("div", { className: "entropix-chart__legend", children: items.map((item) => /* @__PURE__ */ jsxs(
103
+ "button",
104
+ {
105
+ type: "button",
106
+ className: `entropix-chart__legend-item${!item.active ? " entropix-chart__legend-item--inactive" : ""}`,
107
+ onClick: () => onToggle(item.name),
108
+ children: [
109
+ /* @__PURE__ */ jsx(
110
+ "span",
111
+ {
112
+ className: "entropix-chart__legend-swatch",
113
+ style: { backgroundColor: item.color }
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsx("span", { children: item.name })
117
+ ]
118
+ },
119
+ item.name
120
+ )) });
121
+ }
122
+
123
+ // src/utils/chart-colors.ts
124
+ var CSS_CHART_COLORS = [
125
+ "var(--chart-series-1)",
126
+ "var(--chart-series-2)",
127
+ "var(--chart-series-3)",
128
+ "var(--chart-series-4)",
129
+ "var(--chart-series-5)",
130
+ "var(--chart-series-6)",
131
+ "var(--chart-series-7)",
132
+ "var(--chart-series-8)"
133
+ ];
134
+
135
+ export { CSS_CHART_COLORS, ChartContainer, ChartLegend, ChartTooltip };
136
+ //# sourceMappingURL=chunk-FQACLZYR.js.map
137
+ //# sourceMappingURL=chunk-FQACLZYR.js.map
@@ -0,0 +1,77 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+
5
+ // src/components/chart-primitives/x-axis.tsx
6
+ function XAxis({ scale, y, height: _height, formatter }) {
7
+ const domain = scale.domain();
8
+ const bandwidth = scale.bandwidth();
9
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
10
+ domain.map((label) => {
11
+ const x = scale(label) + bandwidth / 2;
12
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${x}, ${y})`, children: [
13
+ /* @__PURE__ */ jsxRuntime.jsx("line", { y2: 6, stroke: "currentColor", strokeWidth: 1 }),
14
+ /* @__PURE__ */ jsxRuntime.jsx(
15
+ "text",
16
+ {
17
+ className: "entropix-chart__axis-text",
18
+ y: 18,
19
+ textAnchor: "middle",
20
+ dominantBaseline: "auto",
21
+ children: formatter ? formatter(label) : label
22
+ }
23
+ )
24
+ ] }, label);
25
+ }),
26
+ /* @__PURE__ */ jsxRuntime.jsx(
27
+ "line",
28
+ {
29
+ x1: scale.range()[0],
30
+ x2: scale.range()[1],
31
+ y1: y,
32
+ y2: y,
33
+ stroke: "currentColor",
34
+ strokeWidth: 1
35
+ }
36
+ )
37
+ ] });
38
+ }
39
+ function YAxis({
40
+ scale,
41
+ x,
42
+ width,
43
+ formatter,
44
+ showGrid = true
45
+ }) {
46
+ const ticks = scale.ticks();
47
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { children: ticks.map((tick) => {
48
+ const y = scale(tick);
49
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${x}, ${y})`, children: [
50
+ /* @__PURE__ */ jsxRuntime.jsx(
51
+ "text",
52
+ {
53
+ className: "entropix-chart__axis-text",
54
+ x: -8,
55
+ textAnchor: "end",
56
+ dominantBaseline: "middle",
57
+ children: formatter ? formatter(tick) : String(tick)
58
+ }
59
+ ),
60
+ showGrid && /* @__PURE__ */ jsxRuntime.jsx(
61
+ "line",
62
+ {
63
+ className: "entropix-chart__grid-line",
64
+ x1: 0,
65
+ x2: width,
66
+ y1: 0,
67
+ y2: 0
68
+ }
69
+ )
70
+ ] }, tick);
71
+ }) });
72
+ }
73
+
74
+ exports.XAxis = XAxis;
75
+ exports.YAxis = YAxis;
76
+ //# sourceMappingURL=chunk-GCZSXJAA.cjs.map
77
+ //# sourceMappingURL=chunk-GCZSXJAA.cjs.map
@@ -0,0 +1,131 @@
1
+ 'use strict';
2
+
3
+ var chunkGCZSXJAA_cjs = require('./chunk-GCZSXJAA.cjs');
4
+ var chunk6YAOO76S_cjs = require('./chunk-6YAOO76S.cjs');
5
+ var react = require('react');
6
+ var core = require('@entropix/core');
7
+ var jsxRuntime = require('react/jsx-runtime');
8
+
9
+ var MARGINS = { top: 20, right: 20, bottom: 40, left: 50 };
10
+ function BarChart({
11
+ data,
12
+ height = 300,
13
+ colors,
14
+ stacked = false,
15
+ showGrid = true,
16
+ showTooltip = true,
17
+ showLegend = true,
18
+ xAxis,
19
+ yAxis,
20
+ className
21
+ }) {
22
+ const [hiddenSeries, setHiddenSeries] = react.useState(/* @__PURE__ */ new Set());
23
+ const [tooltip, setTooltip] = react.useState(null);
24
+ const containerRef = react.useRef(null);
25
+ const toggleSeries = react.useCallback((name) => {
26
+ setHiddenSeries((prev) => {
27
+ const next = new Set(prev);
28
+ if (next.has(name)) {
29
+ next.delete(name);
30
+ } else {
31
+ next.add(name);
32
+ }
33
+ return next;
34
+ });
35
+ }, []);
36
+ const allSeries = core.normalizeChartData(data, colors ?? chunk6YAOO76S_cjs.CSS_CHART_COLORS);
37
+ const visibleSeries = allSeries.filter((s) => !hiddenSeries.has(s.name));
38
+ const { categories, yMin, yMax } = core.getDataExtent(visibleSeries);
39
+ const legendItems = allSeries.map((s) => ({
40
+ name: s.name,
41
+ color: s.color,
42
+ active: !hiddenSeries.has(s.name)
43
+ }));
44
+ const handleBarEnter = react.useCallback(
45
+ (rect, seriesName, event) => {
46
+ if (!showTooltip) return;
47
+ const svg = event.target.closest("svg");
48
+ if (!svg) return;
49
+ svg.getBoundingClientRect();
50
+ const container = containerRef.current;
51
+ if (!container) return;
52
+ container.getBoundingClientRect();
53
+ setTooltip({
54
+ x: rect.x + rect.width / 2 + MARGINS.left,
55
+ y: rect.y + MARGINS.top,
56
+ series: seriesName,
57
+ label: rect.label,
58
+ value: rect.value,
59
+ color: rect.color
60
+ });
61
+ },
62
+ [showTooltip]
63
+ );
64
+ const handleBarLeave = react.useCallback(() => {
65
+ setTooltip(null);
66
+ }, []);
67
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: containerRef, className: className ? `entropix-chart ${className}` : "entropix-chart", style: { position: "relative" }, children: [
68
+ /* @__PURE__ */ jsxRuntime.jsx(chunk6YAOO76S_cjs.ChartContainer, { height, children: (width, h) => {
69
+ const innerWidth = width - MARGINS.left - MARGINS.right;
70
+ const innerHeight = h - MARGINS.top - MARGINS.bottom;
71
+ if (innerWidth <= 0 || innerHeight <= 0) return null;
72
+ const bounds = core.niceBounds(yMin, yMax, yAxis?.tickCount ?? 5);
73
+ const yScale = core.createLinearScale(
74
+ [bounds.min, bounds.max],
75
+ [innerHeight, 0]
76
+ );
77
+ const xScale = core.createBandScale(categories, [0, innerWidth]);
78
+ const bars = core.computeBarGeometry(
79
+ visibleSeries,
80
+ xScale,
81
+ yScale,
82
+ innerHeight,
83
+ stacked
84
+ );
85
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { transform: `translate(${MARGINS.left}, ${MARGINS.top})`, children: [
86
+ yAxis?.show !== false && /* @__PURE__ */ jsxRuntime.jsx(
87
+ chunkGCZSXJAA_cjs.YAxis,
88
+ {
89
+ scale: yScale,
90
+ x: 0,
91
+ width: innerWidth,
92
+ showGrid,
93
+ formatter: yAxis?.formatter
94
+ }
95
+ ),
96
+ xAxis?.show !== false && /* @__PURE__ */ jsxRuntime.jsx(
97
+ chunkGCZSXJAA_cjs.XAxis,
98
+ {
99
+ scale: xScale,
100
+ y: innerHeight,
101
+ height: innerHeight,
102
+ formatter: xAxis?.formatter
103
+ }
104
+ ),
105
+ bars.map((rect, i) => {
106
+ const series = visibleSeries[rect.seriesIndex];
107
+ return /* @__PURE__ */ jsxRuntime.jsx(
108
+ "rect",
109
+ {
110
+ className: "entropix-chart__bar",
111
+ x: rect.x,
112
+ y: rect.y,
113
+ width: rect.width,
114
+ height: rect.height,
115
+ fill: rect.color,
116
+ onMouseEnter: (e) => handleBarEnter(rect, series?.name ?? "", e),
117
+ onMouseLeave: handleBarLeave
118
+ },
119
+ i
120
+ );
121
+ })
122
+ ] });
123
+ } }),
124
+ showTooltip && /* @__PURE__ */ jsxRuntime.jsx(chunk6YAOO76S_cjs.ChartTooltip, { data: tooltip, containerRef }),
125
+ showLegend && allSeries.length > 1 && /* @__PURE__ */ jsxRuntime.jsx(chunk6YAOO76S_cjs.ChartLegend, { items: legendItems, onToggle: toggleSeries })
126
+ ] });
127
+ }
128
+
129
+ exports.BarChart = BarChart;
130
+ //# sourceMappingURL=chunk-K6ZRQYSZ.cjs.map
131
+ //# sourceMappingURL=chunk-K6ZRQYSZ.cjs.map