@empoweredvote/ev-ui 0.8.0 → 0.8.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/index.js +10 -108
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -108
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -103,9 +103,7 @@ function RadarChartCore({
|
|
|
103
103
|
onReplaceTopic = () => {
|
|
104
104
|
},
|
|
105
105
|
size = 400,
|
|
106
|
-
labelFontSize = 18,
|
|
107
106
|
padding = 80,
|
|
108
|
-
labelOffset = 20,
|
|
109
107
|
tightFit = false,
|
|
110
108
|
activeSpoke = null,
|
|
111
109
|
writeIns = {}
|
|
@@ -173,40 +171,15 @@ function RadarChartCore({
|
|
|
173
171
|
};
|
|
174
172
|
if (countChanged || compareJustAppeared) compareSpringBase.from = compareSpringBase.to;
|
|
175
173
|
const compareSpring = (0, import_web.useSpring)(compareSpringBase);
|
|
176
|
-
const labelMeta = spokes.map(([shortTitle], i) => {
|
|
177
|
-
const angle = 2 * Math.PI * i / numSpokes;
|
|
178
|
-
const lines = wrapLabel(shortTitle, 12);
|
|
179
|
-
const longestLineLen = lines.reduce((m, ln) => ln.length > m ? ln.length : m, 0);
|
|
180
|
-
const fSize = adaptiveFontSize(longestLineLen, labelFontSize);
|
|
181
|
-
const estimatedWidth = longestLineLen * fSize * 0.6;
|
|
182
|
-
const sinA = Math.sin(angle);
|
|
183
|
-
const side = sinA < -0.1 ? "left" : sinA > 0.1 ? "right" : "center";
|
|
184
|
-
return { estimatedWidth, side };
|
|
185
|
-
});
|
|
186
|
-
const leftLabelWidths = labelMeta.filter((m) => m.side === "left").map((m) => m.estimatedWidth);
|
|
187
|
-
const rightLabelWidths = labelMeta.filter((m) => m.side === "right").map((m) => m.estimatedWidth);
|
|
188
|
-
const minPadding = 40;
|
|
189
|
-
const maxPadding = padding * 2;
|
|
190
|
-
const rawLeftPadding = Math.min(
|
|
191
|
-
Math.max(leftLabelWidths.length ? Math.max(...leftLabelWidths) + labelOffset : 0, minPadding),
|
|
192
|
-
maxPadding
|
|
193
|
-
);
|
|
194
|
-
const rawRightPadding = Math.min(
|
|
195
|
-
Math.max(rightLabelWidths.length ? Math.max(...rightLabelWidths) + labelOffset : 0, minPadding),
|
|
196
|
-
maxPadding
|
|
197
|
-
);
|
|
198
|
-
const symmetricPadding = Math.max(rawLeftPadding, rawRightPadding);
|
|
199
|
-
const leftPadding = symmetricPadding;
|
|
200
|
-
const rightPadding = symmetricPadding;
|
|
201
|
-
const verticalPadding = padding;
|
|
202
174
|
const spokeExtension = spokes.reduce((acc, [shortTitle]) => {
|
|
203
175
|
const userAdj = calcAdjusted(data[shortTitle], shortTitle);
|
|
204
176
|
const cmpAdj = hasCompareData && compareData[shortTitle] ? calcAdjusted(compareData[shortTitle], shortTitle) : 0;
|
|
205
177
|
acc[shortTitle] = userAdj > 10 || cmpAdj > 10;
|
|
206
178
|
return acc;
|
|
207
179
|
}, {});
|
|
208
|
-
|
|
209
|
-
let
|
|
180
|
+
const sidePadding = 20;
|
|
181
|
+
let tightTop = -sidePadding;
|
|
182
|
+
let tightHeight = size + sidePadding * 2;
|
|
210
183
|
if (tightFit && numSpokes > 0) {
|
|
211
184
|
let yMin = Infinity, yMax = -Infinity;
|
|
212
185
|
for (let i = 0; i < numSpokes; i++) {
|
|
@@ -216,9 +189,8 @@ function RadarChartCore({
|
|
|
216
189
|
if (y < yMin) yMin = y;
|
|
217
190
|
if (y > yMax) yMax = y;
|
|
218
191
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
tightHeight = yMax + labelMargin - tightTop;
|
|
192
|
+
tightTop = yMin - sidePadding;
|
|
193
|
+
tightHeight = yMax + sidePadding - tightTop;
|
|
222
194
|
}
|
|
223
195
|
const guidePolygons = [];
|
|
224
196
|
for (let level = 1; level <= 5; level++) {
|
|
@@ -246,7 +218,7 @@ function RadarChartCore({
|
|
|
246
218
|
"svg",
|
|
247
219
|
{
|
|
248
220
|
className: "w-full h-auto max-h-full",
|
|
249
|
-
viewBox: `-${
|
|
221
|
+
viewBox: `-${sidePadding} ${tightTop} ${size + sidePadding * 2} ${tightHeight}`,
|
|
250
222
|
preserveAspectRatio: "xMidYMid meet",
|
|
251
223
|
onMouseLeave: () => setTooltip(null)
|
|
252
224
|
},
|
|
@@ -266,7 +238,7 @@ function RadarChartCore({
|
|
|
266
238
|
y1: centerY,
|
|
267
239
|
x2: endX,
|
|
268
240
|
y2: endY,
|
|
269
|
-
stroke: isUnanswered ? "#9ca3af" : "
|
|
241
|
+
stroke: isUnanswered ? "#9ca3af" : "#aaa",
|
|
270
242
|
strokeDasharray: isUnanswered ? "4 3" : void 0,
|
|
271
243
|
opacity: isUnanswered ? 0.6 : 1
|
|
272
244
|
}
|
|
@@ -277,48 +249,12 @@ function RadarChartCore({
|
|
|
277
249
|
y1: endY,
|
|
278
250
|
x2: extX,
|
|
279
251
|
y2: extY,
|
|
280
|
-
stroke: "
|
|
252
|
+
stroke: "#aaa",
|
|
281
253
|
strokeDasharray: "4 4",
|
|
282
254
|
opacity: 0.4
|
|
283
255
|
}
|
|
284
256
|
));
|
|
285
257
|
}),
|
|
286
|
-
spokes.map(([shortTitle], i) => {
|
|
287
|
-
const angle = 2 * Math.PI * i / numSpokes;
|
|
288
|
-
const cosA = Math.cos(angle);
|
|
289
|
-
const isBottom = cosA < -0.5;
|
|
290
|
-
const isTop = cosA > 0.5;
|
|
291
|
-
const lines = wrapLabel(shortTitle, 12);
|
|
292
|
-
const longestLine = lines.reduce((m, ln) => ln.length > m ? ln.length : m, 0);
|
|
293
|
-
const fSize = adaptiveFontSize(longestLine, labelFontSize);
|
|
294
|
-
const lineHeight = fSize * 1.1;
|
|
295
|
-
const dynamicLabelOffset = lines.length > 1 ? labelOffset + 8 : labelOffset;
|
|
296
|
-
const offset2 = radius + dynamicLabelOffset;
|
|
297
|
-
const labelX = centerX + offset2 * Math.sin(angle);
|
|
298
|
-
let labelY = centerY - offset2 * Math.cos(angle);
|
|
299
|
-
if (isTop && lines.length > 1) labelY -= (lines.length - 1) * lineHeight;
|
|
300
|
-
const isActive = shortTitle === activeSpoke;
|
|
301
|
-
const isUnansweredLabel = !!unansweredSpokes[shortTitle];
|
|
302
|
-
const activeFSize = fSize * 1.5;
|
|
303
|
-
const displayFSize = isActive ? activeFSize : fSize;
|
|
304
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
305
|
-
"text",
|
|
306
|
-
{
|
|
307
|
-
key: `label-${shortTitle}`,
|
|
308
|
-
x: labelX,
|
|
309
|
-
y: labelY,
|
|
310
|
-
textAnchor: "middle",
|
|
311
|
-
dominantBaseline: isBottom ? "hanging" : "auto",
|
|
312
|
-
onClick: () => onReplaceTopic(shortTitle),
|
|
313
|
-
className: "text-xl font-medium mb-1 md:text-base md:font-normal",
|
|
314
|
-
fill: isActive ? "#E85D26" : isUnansweredLabel ? "#9ca3af" : void 0,
|
|
315
|
-
fontWeight: isActive ? "bold" : void 0,
|
|
316
|
-
style: { cursor: "pointer", userSelect: "none", fontSize: displayFSize }
|
|
317
|
-
},
|
|
318
|
-
isUnansweredLabel && /* @__PURE__ */ import_react.default.createElement("title", null, "No stance on file for this topic."),
|
|
319
|
-
lines.map((ln, idx) => /* @__PURE__ */ import_react.default.createElement("tspan", { key: idx, x: labelX, dy: idx === 0 ? "0" : `${lineHeight}` }, ln))
|
|
320
|
-
);
|
|
321
|
-
}),
|
|
322
258
|
countChanged ? /* @__PURE__ */ import_react.default.createElement(
|
|
323
259
|
"polygon",
|
|
324
260
|
{
|
|
@@ -416,8 +352,8 @@ function RadarChartCore({
|
|
|
416
352
|
tooltip && (() => {
|
|
417
353
|
const tipW = 190;
|
|
418
354
|
const tipH = 70;
|
|
419
|
-
const svgW = size +
|
|
420
|
-
const tx = tooltip.x +
|
|
355
|
+
const svgW = size + sidePadding * 2;
|
|
356
|
+
const tx = tooltip.x + sidePadding + 12 > svgW - tipW ? tooltip.x - tipW - 12 : tooltip.x + 12;
|
|
421
357
|
const ty = tooltip.y - 10;
|
|
422
358
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
423
359
|
"foreignObject",
|
|
@@ -451,40 +387,6 @@ function RadarChartCore({
|
|
|
451
387
|
})()
|
|
452
388
|
);
|
|
453
389
|
}
|
|
454
|
-
function adaptiveFontSize(longestLineLen, baseFSize) {
|
|
455
|
-
return Math.max(baseFSize, 10);
|
|
456
|
-
}
|
|
457
|
-
function wrapLabel(label, maxChars = 12) {
|
|
458
|
-
const str = String(label);
|
|
459
|
-
let rawWords;
|
|
460
|
-
if (str.includes("/")) {
|
|
461
|
-
rawWords = str.split("/").reduce((acc, segment, idx, arr) => {
|
|
462
|
-
const part = idx < arr.length - 1 ? segment + "/" : segment;
|
|
463
|
-
if (part.trim()) acc.push(part.trim());
|
|
464
|
-
return acc;
|
|
465
|
-
}, []);
|
|
466
|
-
} else {
|
|
467
|
-
rawWords = str.split(/\s+/);
|
|
468
|
-
}
|
|
469
|
-
const lines = [];
|
|
470
|
-
let line = "";
|
|
471
|
-
for (const word of rawWords) {
|
|
472
|
-
if (line === "") {
|
|
473
|
-
line = word;
|
|
474
|
-
} else if ((line + " " + word).length <= maxChars) {
|
|
475
|
-
line += " " + word;
|
|
476
|
-
} else {
|
|
477
|
-
lines.push(line);
|
|
478
|
-
line = word;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
if (line) lines.push(line);
|
|
482
|
-
if (lines.length > 2) {
|
|
483
|
-
const overflow = lines.splice(2).join(" ");
|
|
484
|
-
lines[1] = lines[1] + " " + overflow;
|
|
485
|
-
}
|
|
486
|
-
return lines;
|
|
487
|
-
}
|
|
488
390
|
|
|
489
391
|
// src/Header.jsx
|
|
490
392
|
var import_react3 = __toESM(require("react"));
|