@optiaxiom/proteus 0.2.0 → 0.2.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/esm/assets/src/proteus-chart/{ProteusChartTooltipContent.css.ts.vanilla-BxCxymWg.css → ProteusChartTooltipContent.css.ts.vanilla-JTr7n2a8.css} +1 -0
- package/dist/esm/proteus-chart/ProteusChart.js +16 -5
- package/dist/esm/proteus-chart/ProteusChartContext.js +7 -0
- package/dist/esm/proteus-chart/ProteusChartTooltipContent-css.js +2 -2
- package/dist/esm/proteus-chart/ProteusChartTooltipContent.js +52 -27
- package/package.json +3 -3
|
@@ -2,8 +2,10 @@
|
|
|
2
2
|
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
3
|
import { Box, theme } from '@optiaxiom/react';
|
|
4
4
|
import { get } from 'jsonpointer';
|
|
5
|
+
import { useRef } from 'react';
|
|
5
6
|
import { ResponsiveContainer, BarChart, LineChart, CartesianGrid, YAxis, XAxis, Tooltip, Bar, Line } from 'recharts';
|
|
6
7
|
import { chart } from './ProteusChart-css.js';
|
|
8
|
+
import { ProteusChartContext } from './ProteusChartContext.js';
|
|
7
9
|
import { ProteusChartTooltipContent } from './ProteusChartTooltipContent.js';
|
|
8
10
|
|
|
9
11
|
const DEFAULT_COLORS = ["#096DD9", "#E59700", "#38C56C", "#D1D8DE"];
|
|
@@ -20,11 +22,12 @@ const ProteusChart = ({
|
|
|
20
22
|
const Chart = type === "bar" ? Bar : Line;
|
|
21
23
|
const CategoryAxis = isVertical ? YAxis : XAxis;
|
|
22
24
|
const ValueAxis = isVertical ? XAxis : YAxis;
|
|
23
|
-
|
|
25
|
+
const containerRef = useRef(null);
|
|
26
|
+
return /* @__PURE__ */ jsx(ProteusChartContext.Provider, { value: containerRef, children: /* @__PURE__ */ jsx(Box, { asChild: true, ref: containerRef, ...chart(), children: /* @__PURE__ */ jsx(ResponsiveContainer, { aspect: 16 / 9, width: "100%", children: /* @__PURE__ */ jsxs(ChartComponent, { data, layout, children: [
|
|
24
27
|
/* @__PURE__ */ jsx(
|
|
25
28
|
CartesianGrid,
|
|
26
29
|
{
|
|
27
|
-
stroke: "
|
|
30
|
+
stroke: theme.colors["border.secondary"],
|
|
28
31
|
strokeDasharray: "4 4",
|
|
29
32
|
vertical: false
|
|
30
33
|
}
|
|
@@ -36,6 +39,7 @@ const ProteusChart = ({
|
|
|
36
39
|
dataKey: (row) => get(row, "/" + xAxisKey),
|
|
37
40
|
padding: { left: 16, right: 16 },
|
|
38
41
|
tick: { fill: theme.colors["fg.secondary"] },
|
|
42
|
+
tickFormatter: (value) => value.length > 30 ? value.slice(0, 30) + "\u2026" : value,
|
|
39
43
|
tickLine: false,
|
|
40
44
|
tickMargin: 8,
|
|
41
45
|
type: "category",
|
|
@@ -45,7 +49,7 @@ const ProteusChart = ({
|
|
|
45
49
|
/* @__PURE__ */ jsx(
|
|
46
50
|
ValueAxis,
|
|
47
51
|
{
|
|
48
|
-
axisLine: { stroke: "
|
|
52
|
+
axisLine: { stroke: theme.colors["border.default"] },
|
|
49
53
|
minTickGap: 32,
|
|
50
54
|
tick: { fill: theme.colors["fg.secondary"] },
|
|
51
55
|
tickFormatter: (value) => new Intl.NumberFormat(void 0, {
|
|
@@ -57,7 +61,14 @@ const ProteusChart = ({
|
|
|
57
61
|
width: isVertical ? void 0 : "auto"
|
|
58
62
|
}
|
|
59
63
|
),
|
|
60
|
-
/* @__PURE__ */ jsx(
|
|
64
|
+
/* @__PURE__ */ jsx(
|
|
65
|
+
Tooltip,
|
|
66
|
+
{
|
|
67
|
+
content: ProteusChartTooltipContent,
|
|
68
|
+
cursor: false,
|
|
69
|
+
portal: document.body
|
|
70
|
+
}
|
|
71
|
+
),
|
|
61
72
|
series.map((s, i) => /* @__PURE__ */ jsx(
|
|
62
73
|
Chart,
|
|
63
74
|
{
|
|
@@ -70,7 +81,7 @@ const ProteusChart = ({
|
|
|
70
81
|
},
|
|
71
82
|
i
|
|
72
83
|
))
|
|
73
|
-
] }) }) });
|
|
84
|
+
] }) }) }) });
|
|
74
85
|
};
|
|
75
86
|
ProteusChart.displayName = "@optiaxiom/proteus/ProteusChart";
|
|
76
87
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import './../assets/src/proteus-chart/ProteusChartTooltipContent.css.ts.vanilla-
|
|
1
|
+
import './../assets/src/proteus-chart/ProteusChartTooltipContent.css.ts.vanilla-JTr7n2a8.css';
|
|
2
2
|
import { recipe } from '@optiaxiom/react/css-runtime';
|
|
3
3
|
|
|
4
|
-
var tooltip = recipe({base:[{bg:'bg.default',border:'1',borderColor:'border.secondary',display:'grid',fontSize:'sm',gap:'6',px:'8',py:'10',rounded:'lg',shadow:'lg'},'ProteusChartTooltipContent__1gsvq810']});
|
|
4
|
+
var tooltip = recipe({base:[{bg:'bg.default',border:'1',borderColor:'border.secondary',display:'grid',fontSize:'sm',gap:'6',pointerEvents:'none',px:'8',py:'10',rounded:'lg',shadow:'lg',transition:'all'},'ProteusChartTooltipContent__1gsvq810']});
|
|
5
5
|
var value = recipe({base:[{color:'fg.default',fontWeight:'500'},'ProteusChartTooltipContent__1gsvq811']});
|
|
6
6
|
|
|
7
7
|
export { tooltip, value };
|
|
@@ -1,45 +1,70 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
3
3
|
import { Box, Group } from '@optiaxiom/react';
|
|
4
|
+
import { useRef } from 'react';
|
|
4
5
|
import { applyFormatter } from '../proteus-document/getProteusValue.js';
|
|
6
|
+
import { useProteusChartContainer } from './ProteusChartContext.js';
|
|
5
7
|
import { value, tooltip } from './ProteusChartTooltipContent-css.js';
|
|
6
8
|
|
|
9
|
+
const OFFSET = 10;
|
|
7
10
|
function ProteusChartTooltipContent({
|
|
8
11
|
active,
|
|
12
|
+
coordinate,
|
|
9
13
|
label,
|
|
10
14
|
payload
|
|
11
15
|
}) {
|
|
16
|
+
const containerRef = useProteusChartContainer();
|
|
17
|
+
const ref = useRef(null);
|
|
12
18
|
if (!active || !payload?.length) {
|
|
13
19
|
return null;
|
|
14
20
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
rounded: "xs",
|
|
31
|
-
size: "10",
|
|
32
|
-
style: { backgroundColor: item.color }
|
|
33
|
-
}
|
|
34
|
-
),
|
|
35
|
-
/* @__PURE__ */ jsx(Box, { color: "fg.tertiary", children: item.name ?? String(item.dataKey) })
|
|
36
|
-
] }),
|
|
37
|
-
/* @__PURE__ */ jsx(Box, { ...value(), children: applyFormatter(item.value, "Number") })
|
|
38
|
-
]
|
|
21
|
+
const wrapperRect = containerRef?.current?.querySelector(".recharts-wrapper")?.getBoundingClientRect();
|
|
22
|
+
const tooltipRect = ref.current?.getBoundingClientRect();
|
|
23
|
+
const cx = coordinate?.x ?? 0;
|
|
24
|
+
const cy = coordinate?.y ?? 0;
|
|
25
|
+
const th = tooltipRect?.height ?? 0;
|
|
26
|
+
const translateX = cx + OFFSET;
|
|
27
|
+
const translateY = cy - th / 2;
|
|
28
|
+
return /* @__PURE__ */ jsxs(
|
|
29
|
+
Box,
|
|
30
|
+
{
|
|
31
|
+
ref,
|
|
32
|
+
style: {
|
|
33
|
+
left: 0,
|
|
34
|
+
top: 0,
|
|
35
|
+
transform: `translate(${(wrapperRect?.left ?? 0) + translateX + window.scrollX}px, ${(wrapperRect?.top ?? 0) + translateY + window.scrollY}px)`
|
|
39
36
|
},
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
37
|
+
...tooltip(),
|
|
38
|
+
children: [
|
|
39
|
+
label && /* @__PURE__ */ jsx(Box, { fontWeight: "500", children: label }),
|
|
40
|
+
/* @__PURE__ */ jsx("div", { children: payload.filter((item) => item.type !== "none").map((item, i) => /* @__PURE__ */ jsxs(
|
|
41
|
+
Box,
|
|
42
|
+
{
|
|
43
|
+
alignItems: "center",
|
|
44
|
+
display: "flex",
|
|
45
|
+
gap: "8",
|
|
46
|
+
justifyContent: "space-between",
|
|
47
|
+
children: [
|
|
48
|
+
/* @__PURE__ */ jsxs(Group, { gap: "8", children: [
|
|
49
|
+
/* @__PURE__ */ jsx(
|
|
50
|
+
Box,
|
|
51
|
+
{
|
|
52
|
+
flex: "none",
|
|
53
|
+
rounded: "xs",
|
|
54
|
+
size: "10",
|
|
55
|
+
style: { backgroundColor: item.color }
|
|
56
|
+
}
|
|
57
|
+
),
|
|
58
|
+
/* @__PURE__ */ jsx(Box, { color: "fg.tertiary", children: item.name ?? String(item.dataKey) })
|
|
59
|
+
] }),
|
|
60
|
+
/* @__PURE__ */ jsx(Box, { ...value(), children: applyFormatter(item.value, "Number") })
|
|
61
|
+
]
|
|
62
|
+
},
|
|
63
|
+
i
|
|
64
|
+
)) })
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
);
|
|
43
68
|
}
|
|
44
69
|
|
|
45
70
|
export { ProteusChartTooltipContent };
|
package/package.json
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"url": "git+https://github.com/optimizely-axiom/optiaxiom.git"
|
|
8
8
|
},
|
|
9
9
|
"type": "module",
|
|
10
|
-
"version": "0.2.
|
|
10
|
+
"version": "0.2.1",
|
|
11
11
|
"files": [
|
|
12
12
|
"dist/**",
|
|
13
13
|
"LICENSE"
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"embla-carousel-react": "^8.6.0",
|
|
39
39
|
"jsonpointer": "^5.0.1",
|
|
40
40
|
"recharts": "^3.8.1",
|
|
41
|
-
"@optiaxiom/
|
|
42
|
-
"@optiaxiom/
|
|
41
|
+
"@optiaxiom/icons": "1.1.1",
|
|
42
|
+
"@optiaxiom/react": "1.9.28"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
45
|
"@emotion/hash": "^0.9.2",
|