@empoweredvote/ev-ui 0.8.0 → 0.8.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 +25 -40
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +25 -40
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -103,9 +103,9 @@ function RadarChartCore({
|
|
|
103
103
|
onReplaceTopic = () => {
|
|
104
104
|
},
|
|
105
105
|
size = 400,
|
|
106
|
-
labelFontSize =
|
|
106
|
+
labelFontSize = 13,
|
|
107
107
|
padding = 80,
|
|
108
|
-
labelOffset =
|
|
108
|
+
labelOffset = 32,
|
|
109
109
|
tightFit = false,
|
|
110
110
|
activeSpoke = null,
|
|
111
111
|
writeIns = {}
|
|
@@ -173,12 +173,17 @@ function RadarChartCore({
|
|
|
173
173
|
};
|
|
174
174
|
if (countChanged || compareJustAppeared) compareSpringBase.from = compareSpringBase.to;
|
|
175
175
|
const compareSpring = (0, import_web.useSpring)(compareSpringBase);
|
|
176
|
+
const spokeExtension = spokes.reduce((acc, [shortTitle]) => {
|
|
177
|
+
const userAdj = calcAdjusted(data[shortTitle], shortTitle);
|
|
178
|
+
const cmpAdj = hasCompareData && compareData[shortTitle] ? calcAdjusted(compareData[shortTitle], shortTitle) : 0;
|
|
179
|
+
acc[shortTitle] = userAdj > 10 || cmpAdj > 10;
|
|
180
|
+
return acc;
|
|
181
|
+
}, {});
|
|
176
182
|
const labelMeta = spokes.map(([shortTitle], i) => {
|
|
177
183
|
const angle = 2 * Math.PI * i / numSpokes;
|
|
178
184
|
const lines = wrapLabel(shortTitle, 12);
|
|
179
185
|
const longestLineLen = lines.reduce((m, ln) => ln.length > m ? ln.length : m, 0);
|
|
180
|
-
const
|
|
181
|
-
const estimatedWidth = longestLineLen * fSize * 0.6;
|
|
186
|
+
const estimatedWidth = longestLineLen * labelFontSize * 0.55;
|
|
182
187
|
const sinA = Math.sin(angle);
|
|
183
188
|
const side = sinA < -0.1 ? "left" : sinA > 0.1 ? "right" : "center";
|
|
184
189
|
return { estimatedWidth, side };
|
|
@@ -187,24 +192,10 @@ function RadarChartCore({
|
|
|
187
192
|
const rightLabelWidths = labelMeta.filter((m) => m.side === "right").map((m) => m.estimatedWidth);
|
|
188
193
|
const minPadding = 40;
|
|
189
194
|
const maxPadding = padding * 2;
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
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;
|
|
195
|
+
const rawLeft = Math.min(Math.max(leftLabelWidths.length ? Math.max(...leftLabelWidths) + labelOffset : 0, minPadding), maxPadding);
|
|
196
|
+
const rawRight = Math.min(Math.max(rightLabelWidths.length ? Math.max(...rightLabelWidths) + labelOffset : 0, minPadding), maxPadding);
|
|
197
|
+
const sidePadding = Math.max(rawLeft, rawRight);
|
|
201
198
|
const verticalPadding = padding;
|
|
202
|
-
const spokeExtension = spokes.reduce((acc, [shortTitle]) => {
|
|
203
|
-
const userAdj = calcAdjusted(data[shortTitle], shortTitle);
|
|
204
|
-
const cmpAdj = hasCompareData && compareData[shortTitle] ? calcAdjusted(compareData[shortTitle], shortTitle) : 0;
|
|
205
|
-
acc[shortTitle] = userAdj > 10 || cmpAdj > 10;
|
|
206
|
-
return acc;
|
|
207
|
-
}, {});
|
|
208
199
|
let tightTop = -verticalPadding;
|
|
209
200
|
let tightHeight = size + verticalPadding * 2;
|
|
210
201
|
if (tightFit && numSpokes > 0) {
|
|
@@ -216,7 +207,7 @@ function RadarChartCore({
|
|
|
216
207
|
if (y < yMin) yMin = y;
|
|
217
208
|
if (y > yMax) yMax = y;
|
|
218
209
|
}
|
|
219
|
-
const labelMargin = labelOffset + labelFontSize *
|
|
210
|
+
const labelMargin = labelOffset + labelFontSize * 2.5;
|
|
220
211
|
tightTop = yMin - labelMargin;
|
|
221
212
|
tightHeight = yMax + labelMargin - tightTop;
|
|
222
213
|
}
|
|
@@ -246,7 +237,7 @@ function RadarChartCore({
|
|
|
246
237
|
"svg",
|
|
247
238
|
{
|
|
248
239
|
className: "w-full h-auto max-h-full",
|
|
249
|
-
viewBox: `-${
|
|
240
|
+
viewBox: `-${sidePadding} ${tightTop} ${size + sidePadding * 2} ${tightHeight}`,
|
|
250
241
|
preserveAspectRatio: "xMidYMid meet",
|
|
251
242
|
onMouseLeave: () => setTooltip(null)
|
|
252
243
|
},
|
|
@@ -266,7 +257,7 @@ function RadarChartCore({
|
|
|
266
257
|
y1: centerY,
|
|
267
258
|
x2: endX,
|
|
268
259
|
y2: endY,
|
|
269
|
-
stroke: isUnanswered ? "#9ca3af" : "
|
|
260
|
+
stroke: isUnanswered ? "#9ca3af" : "#aaa",
|
|
270
261
|
strokeDasharray: isUnanswered ? "4 3" : void 0,
|
|
271
262
|
opacity: isUnanswered ? 0.6 : 1
|
|
272
263
|
}
|
|
@@ -277,7 +268,7 @@ function RadarChartCore({
|
|
|
277
268
|
y1: endY,
|
|
278
269
|
x2: extX,
|
|
279
270
|
y2: extY,
|
|
280
|
-
stroke: "
|
|
271
|
+
stroke: "#aaa",
|
|
281
272
|
strokeDasharray: "4 4",
|
|
282
273
|
opacity: 0.4
|
|
283
274
|
}
|
|
@@ -290,17 +281,15 @@ function RadarChartCore({
|
|
|
290
281
|
const isTop = cosA > 0.5;
|
|
291
282
|
const lines = wrapLabel(shortTitle, 12);
|
|
292
283
|
const longestLine = lines.reduce((m, ln) => ln.length > m ? ln.length : m, 0);
|
|
293
|
-
const
|
|
294
|
-
const
|
|
295
|
-
const
|
|
296
|
-
const offset2 = radius + dynamicLabelOffset;
|
|
284
|
+
const lineHeight = labelFontSize * 1.2;
|
|
285
|
+
const dynamicOffset = lines.length > 1 ? labelOffset + 6 : labelOffset;
|
|
286
|
+
const offset2 = radius + dynamicOffset;
|
|
297
287
|
const labelX = centerX + offset2 * Math.sin(angle);
|
|
298
288
|
let labelY = centerY - offset2 * Math.cos(angle);
|
|
299
289
|
if (isTop && lines.length > 1) labelY -= (lines.length - 1) * lineHeight;
|
|
300
290
|
const isActive = shortTitle === activeSpoke;
|
|
301
291
|
const isUnansweredLabel = !!unansweredSpokes[shortTitle];
|
|
302
|
-
const
|
|
303
|
-
const displayFSize = isActive ? activeFSize : fSize;
|
|
292
|
+
const fSize = isActive ? labelFontSize * 1.2 : labelFontSize;
|
|
304
293
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
305
294
|
"text",
|
|
306
295
|
{
|
|
@@ -310,10 +299,9 @@ function RadarChartCore({
|
|
|
310
299
|
textAnchor: "middle",
|
|
311
300
|
dominantBaseline: isBottom ? "hanging" : "auto",
|
|
312
301
|
onClick: () => onReplaceTopic(shortTitle),
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
style: { cursor: "pointer", userSelect: "none", fontSize: displayFSize }
|
|
302
|
+
fill: isActive ? "#E85D26" : isUnansweredLabel ? "#9ca3af" : "#555",
|
|
303
|
+
fontWeight: isActive ? "bold" : "normal",
|
|
304
|
+
style: { cursor: "pointer", userSelect: "none", fontSize: fSize, fontFamily: "sans-serif" }
|
|
317
305
|
},
|
|
318
306
|
isUnansweredLabel && /* @__PURE__ */ import_react.default.createElement("title", null, "No stance on file for this topic."),
|
|
319
307
|
lines.map((ln, idx) => /* @__PURE__ */ import_react.default.createElement("tspan", { key: idx, x: labelX, dy: idx === 0 ? "0" : `${lineHeight}` }, ln))
|
|
@@ -416,8 +404,8 @@ function RadarChartCore({
|
|
|
416
404
|
tooltip && (() => {
|
|
417
405
|
const tipW = 190;
|
|
418
406
|
const tipH = 70;
|
|
419
|
-
const svgW = size +
|
|
420
|
-
const tx = tooltip.x +
|
|
407
|
+
const svgW = size + sidePadding * 2;
|
|
408
|
+
const tx = tooltip.x + sidePadding + 12 > svgW - tipW ? tooltip.x - tipW - 12 : tooltip.x + 12;
|
|
421
409
|
const ty = tooltip.y - 10;
|
|
422
410
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
423
411
|
"foreignObject",
|
|
@@ -451,9 +439,6 @@ function RadarChartCore({
|
|
|
451
439
|
})()
|
|
452
440
|
);
|
|
453
441
|
}
|
|
454
|
-
function adaptiveFontSize(longestLineLen, baseFSize) {
|
|
455
|
-
return Math.max(baseFSize, 10);
|
|
456
|
-
}
|
|
457
442
|
function wrapLabel(label, maxChars = 12) {
|
|
458
443
|
const str = String(label);
|
|
459
444
|
let rawWords;
|