@empoweredvote/ev-ui 0.10.1 → 0.11.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 CHANGED
@@ -125,6 +125,15 @@ function useTheme() {
125
125
  }
126
126
 
127
127
  // src/RadarChartCore.jsx
128
+ var SPRING_CONFIG = { tension: 300, friction: 30 };
129
+ function AnimatedPolygon({ points, immediate, style }) {
130
+ const spring = (0, import_web.useSpring)({
131
+ to: { points },
132
+ immediate,
133
+ config: SPRING_CONFIG
134
+ });
135
+ return /* @__PURE__ */ import_react2.default.createElement(import_web.animated.polygon, { points: spring.points, style });
136
+ }
128
137
  function RadarChartCore({
129
138
  topics,
130
139
  data,
@@ -150,11 +159,11 @@ function RadarChartCore({
150
159
  const centerY = size / 2;
151
160
  const spokes = Object.entries(data);
152
161
  const numSpokes = Math.max(spokes.length, 1);
153
- const prevCountRef = (0, import_react3.useRef)(numSpokes);
154
- const countChanged = numSpokes !== prevCountRef.current;
162
+ const prevCountRef = (0, import_react3.useRef)(spokes.length);
163
+ const countChanged = spokes.length !== prevCountRef.current;
155
164
  (0, import_react3.useEffect)(() => {
156
- prevCountRef.current = numSpokes;
157
- }, [numSpokes]);
165
+ prevCountRef.current = spokes.length;
166
+ }, [spokes.length]);
158
167
  const pointsArr = spokes.map(([shortTitle, value], index) => {
159
168
  var _a;
160
169
  const topic = topics.find((t) => t.short_title === shortTitle);
@@ -168,14 +177,7 @@ function RadarChartCore({
168
177
  return [x, y];
169
178
  });
170
179
  const targetPoints = pointsArr.map((p) => p.join(",")).join(" ");
171
- const spring = (0, import_web.useSpring)({
172
- to: { points: targetPoints },
173
- immediate: countChanged,
174
- reset: countChanged,
175
- config: { tension: 300, friction: 30 }
176
- });
177
180
  const hasCompareData = Object.keys(compareData).length > 0;
178
- const centerPoints = spokes.map(() => `${centerX},${centerY}`).join(" ");
179
181
  let comparePoints = null;
180
182
  let compareCoords = null;
181
183
  if (hasCompareData) {
@@ -200,12 +202,7 @@ function RadarChartCore({
200
202
  (0, import_react3.useEffect)(() => {
201
203
  hadCompareDataRef.current = hasCompareData;
202
204
  }, [hasCompareData]);
203
- const compareSpring = (0, import_web.useSpring)({
204
- to: { points: comparePoints || centerPoints || `${centerX},${centerY}` },
205
- immediate: countChanged || compareJustAppeared,
206
- reset: countChanged || compareJustAppeared,
207
- config: { tension: 300, friction: 30 }
208
- });
205
+ const compareImmediate = countChanged || compareJustAppeared;
209
206
  const labelMeta = spokes.map(([shortTitle], i) => {
210
207
  const angle = 2 * Math.PI * i / numSpokes;
211
208
  const sinA = Math.sin(angle);
@@ -338,22 +335,12 @@ function RadarChartCore({
338
335
  lines.map((ln, idx) => /* @__PURE__ */ import_react2.default.createElement("tspan", { key: idx, x: labelX, dy: idx === 0 ? "0" : `${lineHeight}` }, ln))
339
336
  );
340
337
  }),
341
- countChanged ? /* @__PURE__ */ import_react2.default.createElement(
342
- "polygon",
338
+ spokes.length > 0 && /* @__PURE__ */ import_react2.default.createElement(
339
+ AnimatedPolygon,
343
340
  {
344
- key: "user-static",
341
+ key: `user-${spokes.length}`,
345
342
  points: targetPoints,
346
- style: {
347
- fill: "rgba(124, 107, 158, 0.4)",
348
- stroke: "#7C6B9E",
349
- strokeWidth: 3
350
- }
351
- }
352
- ) : /* @__PURE__ */ import_react2.default.createElement(
353
- import_web.animated.polygon,
354
- {
355
- key: "user-animated",
356
- points: spring.points,
343
+ immediate: countChanged,
357
344
  style: {
358
345
  fill: "rgba(124, 107, 158, 0.4)",
359
346
  stroke: "#7C6B9E",
@@ -380,22 +367,12 @@ function RadarChartCore({
380
367
  }
381
368
  );
382
369
  }),
383
- hasCompareData && comparePoints ? countChanged || compareJustAppeared ? /* @__PURE__ */ import_react2.default.createElement(
384
- "polygon",
370
+ hasCompareData && comparePoints ? /* @__PURE__ */ import_react2.default.createElement(
371
+ AnimatedPolygon,
385
372
  {
386
- key: "compare-static",
373
+ key: `compare-${spokes.length}`,
387
374
  points: comparePoints,
388
- style: {
389
- fill: "rgba(90, 154, 110, 0.3)",
390
- stroke: "#5A9A6E",
391
- strokeWidth: 2
392
- }
393
- }
394
- ) : /* @__PURE__ */ import_react2.default.createElement(
395
- import_web.animated.polygon,
396
- {
397
- key: "compare-animated",
398
- points: compareSpring.points,
375
+ immediate: compareImmediate,
399
376
  style: {
400
377
  fill: "rgba(90, 154, 110, 0.3)",
401
378
  stroke: "#5A9A6E",