@empoweredvote/ev-ui 0.10.0 → 0.10.2
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 +24 -47
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -47
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -29,6 +29,15 @@ function useTheme() {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
// src/RadarChartCore.jsx
|
|
32
|
+
var SPRING_CONFIG = { tension: 300, friction: 30 };
|
|
33
|
+
function AnimatedPolygon({ points, immediate, style }) {
|
|
34
|
+
const spring = useSpring({
|
|
35
|
+
to: { points },
|
|
36
|
+
immediate,
|
|
37
|
+
config: SPRING_CONFIG
|
|
38
|
+
});
|
|
39
|
+
return /* @__PURE__ */ React.createElement(animated.polygon, { points: spring.points, style });
|
|
40
|
+
}
|
|
32
41
|
function RadarChartCore({
|
|
33
42
|
topics,
|
|
34
43
|
data,
|
|
@@ -54,32 +63,25 @@ function RadarChartCore({
|
|
|
54
63
|
const centerY = size / 2;
|
|
55
64
|
const spokes = Object.entries(data);
|
|
56
65
|
const numSpokes = Math.max(spokes.length, 1);
|
|
57
|
-
const prevCountRef = useRef(
|
|
58
|
-
const countChanged =
|
|
66
|
+
const prevCountRef = useRef(spokes.length);
|
|
67
|
+
const countChanged = spokes.length !== prevCountRef.current;
|
|
59
68
|
useEffect2(() => {
|
|
60
|
-
prevCountRef.current =
|
|
61
|
-
}, [
|
|
69
|
+
prevCountRef.current = spokes.length;
|
|
70
|
+
}, [spokes.length]);
|
|
62
71
|
const pointsArr = spokes.map(([shortTitle, value], index) => {
|
|
63
72
|
var _a;
|
|
64
73
|
const topic = topics.find((t) => t.short_title === shortTitle);
|
|
65
74
|
const max = ((_a = topic == null ? void 0 : topic.stances) == null ? void 0 : _a.length) || 10;
|
|
66
75
|
const pct = Math.min(value / max * 10, 10);
|
|
67
76
|
const angle = 2 * Math.PI * index / numSpokes;
|
|
68
|
-
const adjusted = value === 0 ? 0 : invertedSpokes[shortTitle] ?
|
|
77
|
+
const adjusted = value === 0 ? 0 : invertedSpokes[shortTitle] ? (max + 1) * 10 / max - pct : pct;
|
|
69
78
|
const r = adjusted / 10 * radius;
|
|
70
79
|
const x = centerX + r * Math.sin(angle);
|
|
71
80
|
const y = centerY - r * Math.cos(angle);
|
|
72
81
|
return [x, y];
|
|
73
82
|
});
|
|
74
83
|
const targetPoints = pointsArr.map((p) => p.join(",")).join(" ");
|
|
75
|
-
const spring = useSpring({
|
|
76
|
-
to: { points: targetPoints },
|
|
77
|
-
immediate: countChanged,
|
|
78
|
-
reset: countChanged,
|
|
79
|
-
config: { tension: 300, friction: 30 }
|
|
80
|
-
});
|
|
81
84
|
const hasCompareData = Object.keys(compareData).length > 0;
|
|
82
|
-
const centerPoints = spokes.map(() => `${centerX},${centerY}`).join(" ");
|
|
83
85
|
let comparePoints = null;
|
|
84
86
|
let compareCoords = null;
|
|
85
87
|
if (hasCompareData) {
|
|
@@ -90,7 +92,7 @@ function RadarChartCore({
|
|
|
90
92
|
const max = ((_b = topic == null ? void 0 : topic.stances) == null ? void 0 : _b.length) || 10;
|
|
91
93
|
const pct = Math.min(value / max * 10, 10);
|
|
92
94
|
const angle = 2 * Math.PI * index / numSpokes;
|
|
93
|
-
const adjusted = value === 0 ? 0 : invertedSpokes[shortTitle] ?
|
|
95
|
+
const adjusted = value === 0 ? 0 : invertedSpokes[shortTitle] ? (max + 1) * 10 / max - pct : pct;
|
|
94
96
|
const r = adjusted / 10 * radius;
|
|
95
97
|
const x = centerX + r * Math.sin(angle);
|
|
96
98
|
const y = centerY - r * Math.cos(angle);
|
|
@@ -104,12 +106,7 @@ function RadarChartCore({
|
|
|
104
106
|
useEffect2(() => {
|
|
105
107
|
hadCompareDataRef.current = hasCompareData;
|
|
106
108
|
}, [hasCompareData]);
|
|
107
|
-
const
|
|
108
|
-
to: { points: comparePoints || centerPoints || `${centerX},${centerY}` },
|
|
109
|
-
immediate: countChanged || compareJustAppeared,
|
|
110
|
-
reset: countChanged || compareJustAppeared,
|
|
111
|
-
config: { tension: 300, friction: 30 }
|
|
112
|
-
});
|
|
109
|
+
const compareImmediate = countChanged || compareJustAppeared;
|
|
113
110
|
const labelMeta = spokes.map(([shortTitle], i) => {
|
|
114
111
|
const angle = 2 * Math.PI * i / numSpokes;
|
|
115
112
|
const sinA = Math.sin(angle);
|
|
@@ -242,22 +239,12 @@ function RadarChartCore({
|
|
|
242
239
|
lines.map((ln, idx) => /* @__PURE__ */ React.createElement("tspan", { key: idx, x: labelX, dy: idx === 0 ? "0" : `${lineHeight}` }, ln))
|
|
243
240
|
);
|
|
244
241
|
}),
|
|
245
|
-
|
|
246
|
-
|
|
242
|
+
spokes.length > 0 && /* @__PURE__ */ React.createElement(
|
|
243
|
+
AnimatedPolygon,
|
|
247
244
|
{
|
|
248
|
-
key:
|
|
245
|
+
key: `user-${spokes.length}`,
|
|
249
246
|
points: targetPoints,
|
|
250
|
-
|
|
251
|
-
fill: "rgba(124, 107, 158, 0.4)",
|
|
252
|
-
stroke: "#7C6B9E",
|
|
253
|
-
strokeWidth: 3
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
) : /* @__PURE__ */ React.createElement(
|
|
257
|
-
animated.polygon,
|
|
258
|
-
{
|
|
259
|
-
key: "user-animated",
|
|
260
|
-
points: spring.points,
|
|
247
|
+
immediate: countChanged,
|
|
261
248
|
style: {
|
|
262
249
|
fill: "rgba(124, 107, 158, 0.4)",
|
|
263
250
|
stroke: "#7C6B9E",
|
|
@@ -284,22 +271,12 @@ function RadarChartCore({
|
|
|
284
271
|
}
|
|
285
272
|
);
|
|
286
273
|
}),
|
|
287
|
-
hasCompareData && comparePoints ?
|
|
288
|
-
|
|
274
|
+
hasCompareData && comparePoints ? /* @__PURE__ */ React.createElement(
|
|
275
|
+
AnimatedPolygon,
|
|
289
276
|
{
|
|
290
|
-
key:
|
|
277
|
+
key: `compare-${spokes.length}`,
|
|
291
278
|
points: comparePoints,
|
|
292
|
-
|
|
293
|
-
fill: "rgba(90, 154, 110, 0.3)",
|
|
294
|
-
stroke: "#5A9A6E",
|
|
295
|
-
strokeWidth: 2
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
) : /* @__PURE__ */ React.createElement(
|
|
299
|
-
animated.polygon,
|
|
300
|
-
{
|
|
301
|
-
key: "compare-animated",
|
|
302
|
-
points: compareSpring.points,
|
|
279
|
+
immediate: compareImmediate,
|
|
303
280
|
style: {
|
|
304
281
|
fill: "rgba(90, 154, 110, 0.3)",
|
|
305
282
|
stroke: "#5A9A6E",
|