@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.mjs
CHANGED
|
@@ -12,9 +12,9 @@ function RadarChartCore({
|
|
|
12
12
|
onReplaceTopic = () => {
|
|
13
13
|
},
|
|
14
14
|
size = 400,
|
|
15
|
-
labelFontSize =
|
|
15
|
+
labelFontSize = 13,
|
|
16
16
|
padding = 80,
|
|
17
|
-
labelOffset =
|
|
17
|
+
labelOffset = 32,
|
|
18
18
|
tightFit = false,
|
|
19
19
|
activeSpoke = null,
|
|
20
20
|
writeIns = {}
|
|
@@ -82,12 +82,17 @@ function RadarChartCore({
|
|
|
82
82
|
};
|
|
83
83
|
if (countChanged || compareJustAppeared) compareSpringBase.from = compareSpringBase.to;
|
|
84
84
|
const compareSpring = useSpring(compareSpringBase);
|
|
85
|
+
const spokeExtension = spokes.reduce((acc, [shortTitle]) => {
|
|
86
|
+
const userAdj = calcAdjusted(data[shortTitle], shortTitle);
|
|
87
|
+
const cmpAdj = hasCompareData && compareData[shortTitle] ? calcAdjusted(compareData[shortTitle], shortTitle) : 0;
|
|
88
|
+
acc[shortTitle] = userAdj > 10 || cmpAdj > 10;
|
|
89
|
+
return acc;
|
|
90
|
+
}, {});
|
|
85
91
|
const labelMeta = spokes.map(([shortTitle], i) => {
|
|
86
92
|
const angle = 2 * Math.PI * i / numSpokes;
|
|
87
93
|
const lines = wrapLabel(shortTitle, 12);
|
|
88
94
|
const longestLineLen = lines.reduce((m, ln) => ln.length > m ? ln.length : m, 0);
|
|
89
|
-
const
|
|
90
|
-
const estimatedWidth = longestLineLen * fSize * 0.6;
|
|
95
|
+
const estimatedWidth = longestLineLen * labelFontSize * 0.55;
|
|
91
96
|
const sinA = Math.sin(angle);
|
|
92
97
|
const side = sinA < -0.1 ? "left" : sinA > 0.1 ? "right" : "center";
|
|
93
98
|
return { estimatedWidth, side };
|
|
@@ -96,24 +101,10 @@ function RadarChartCore({
|
|
|
96
101
|
const rightLabelWidths = labelMeta.filter((m) => m.side === "right").map((m) => m.estimatedWidth);
|
|
97
102
|
const minPadding = 40;
|
|
98
103
|
const maxPadding = padding * 2;
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
);
|
|
103
|
-
const rawRightPadding = Math.min(
|
|
104
|
-
Math.max(rightLabelWidths.length ? Math.max(...rightLabelWidths) + labelOffset : 0, minPadding),
|
|
105
|
-
maxPadding
|
|
106
|
-
);
|
|
107
|
-
const symmetricPadding = Math.max(rawLeftPadding, rawRightPadding);
|
|
108
|
-
const leftPadding = symmetricPadding;
|
|
109
|
-
const rightPadding = symmetricPadding;
|
|
104
|
+
const rawLeft = Math.min(Math.max(leftLabelWidths.length ? Math.max(...leftLabelWidths) + labelOffset : 0, minPadding), maxPadding);
|
|
105
|
+
const rawRight = Math.min(Math.max(rightLabelWidths.length ? Math.max(...rightLabelWidths) + labelOffset : 0, minPadding), maxPadding);
|
|
106
|
+
const sidePadding = Math.max(rawLeft, rawRight);
|
|
110
107
|
const verticalPadding = padding;
|
|
111
|
-
const spokeExtension = spokes.reduce((acc, [shortTitle]) => {
|
|
112
|
-
const userAdj = calcAdjusted(data[shortTitle], shortTitle);
|
|
113
|
-
const cmpAdj = hasCompareData && compareData[shortTitle] ? calcAdjusted(compareData[shortTitle], shortTitle) : 0;
|
|
114
|
-
acc[shortTitle] = userAdj > 10 || cmpAdj > 10;
|
|
115
|
-
return acc;
|
|
116
|
-
}, {});
|
|
117
108
|
let tightTop = -verticalPadding;
|
|
118
109
|
let tightHeight = size + verticalPadding * 2;
|
|
119
110
|
if (tightFit && numSpokes > 0) {
|
|
@@ -125,7 +116,7 @@ function RadarChartCore({
|
|
|
125
116
|
if (y < yMin) yMin = y;
|
|
126
117
|
if (y > yMax) yMax = y;
|
|
127
118
|
}
|
|
128
|
-
const labelMargin = labelOffset + labelFontSize *
|
|
119
|
+
const labelMargin = labelOffset + labelFontSize * 2.5;
|
|
129
120
|
tightTop = yMin - labelMargin;
|
|
130
121
|
tightHeight = yMax + labelMargin - tightTop;
|
|
131
122
|
}
|
|
@@ -155,7 +146,7 @@ function RadarChartCore({
|
|
|
155
146
|
"svg",
|
|
156
147
|
{
|
|
157
148
|
className: "w-full h-auto max-h-full",
|
|
158
|
-
viewBox: `-${
|
|
149
|
+
viewBox: `-${sidePadding} ${tightTop} ${size + sidePadding * 2} ${tightHeight}`,
|
|
159
150
|
preserveAspectRatio: "xMidYMid meet",
|
|
160
151
|
onMouseLeave: () => setTooltip(null)
|
|
161
152
|
},
|
|
@@ -175,7 +166,7 @@ function RadarChartCore({
|
|
|
175
166
|
y1: centerY,
|
|
176
167
|
x2: endX,
|
|
177
168
|
y2: endY,
|
|
178
|
-
stroke: isUnanswered ? "#9ca3af" : "
|
|
169
|
+
stroke: isUnanswered ? "#9ca3af" : "#aaa",
|
|
179
170
|
strokeDasharray: isUnanswered ? "4 3" : void 0,
|
|
180
171
|
opacity: isUnanswered ? 0.6 : 1
|
|
181
172
|
}
|
|
@@ -186,7 +177,7 @@ function RadarChartCore({
|
|
|
186
177
|
y1: endY,
|
|
187
178
|
x2: extX,
|
|
188
179
|
y2: extY,
|
|
189
|
-
stroke: "
|
|
180
|
+
stroke: "#aaa",
|
|
190
181
|
strokeDasharray: "4 4",
|
|
191
182
|
opacity: 0.4
|
|
192
183
|
}
|
|
@@ -199,17 +190,15 @@ function RadarChartCore({
|
|
|
199
190
|
const isTop = cosA > 0.5;
|
|
200
191
|
const lines = wrapLabel(shortTitle, 12);
|
|
201
192
|
const longestLine = lines.reduce((m, ln) => ln.length > m ? ln.length : m, 0);
|
|
202
|
-
const
|
|
203
|
-
const
|
|
204
|
-
const
|
|
205
|
-
const offset2 = radius + dynamicLabelOffset;
|
|
193
|
+
const lineHeight = labelFontSize * 1.2;
|
|
194
|
+
const dynamicOffset = lines.length > 1 ? labelOffset + 6 : labelOffset;
|
|
195
|
+
const offset2 = radius + dynamicOffset;
|
|
206
196
|
const labelX = centerX + offset2 * Math.sin(angle);
|
|
207
197
|
let labelY = centerY - offset2 * Math.cos(angle);
|
|
208
198
|
if (isTop && lines.length > 1) labelY -= (lines.length - 1) * lineHeight;
|
|
209
199
|
const isActive = shortTitle === activeSpoke;
|
|
210
200
|
const isUnansweredLabel = !!unansweredSpokes[shortTitle];
|
|
211
|
-
const
|
|
212
|
-
const displayFSize = isActive ? activeFSize : fSize;
|
|
201
|
+
const fSize = isActive ? labelFontSize * 1.2 : labelFontSize;
|
|
213
202
|
return /* @__PURE__ */ React.createElement(
|
|
214
203
|
"text",
|
|
215
204
|
{
|
|
@@ -219,10 +208,9 @@ function RadarChartCore({
|
|
|
219
208
|
textAnchor: "middle",
|
|
220
209
|
dominantBaseline: isBottom ? "hanging" : "auto",
|
|
221
210
|
onClick: () => onReplaceTopic(shortTitle),
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
style: { cursor: "pointer", userSelect: "none", fontSize: displayFSize }
|
|
211
|
+
fill: isActive ? "#E85D26" : isUnansweredLabel ? "#9ca3af" : "#555",
|
|
212
|
+
fontWeight: isActive ? "bold" : "normal",
|
|
213
|
+
style: { cursor: "pointer", userSelect: "none", fontSize: fSize, fontFamily: "sans-serif" }
|
|
226
214
|
},
|
|
227
215
|
isUnansweredLabel && /* @__PURE__ */ React.createElement("title", null, "No stance on file for this topic."),
|
|
228
216
|
lines.map((ln, idx) => /* @__PURE__ */ React.createElement("tspan", { key: idx, x: labelX, dy: idx === 0 ? "0" : `${lineHeight}` }, ln))
|
|
@@ -325,8 +313,8 @@ function RadarChartCore({
|
|
|
325
313
|
tooltip && (() => {
|
|
326
314
|
const tipW = 190;
|
|
327
315
|
const tipH = 70;
|
|
328
|
-
const svgW = size +
|
|
329
|
-
const tx = tooltip.x +
|
|
316
|
+
const svgW = size + sidePadding * 2;
|
|
317
|
+
const tx = tooltip.x + sidePadding + 12 > svgW - tipW ? tooltip.x - tipW - 12 : tooltip.x + 12;
|
|
330
318
|
const ty = tooltip.y - 10;
|
|
331
319
|
return /* @__PURE__ */ React.createElement(
|
|
332
320
|
"foreignObject",
|
|
@@ -360,9 +348,6 @@ function RadarChartCore({
|
|
|
360
348
|
})()
|
|
361
349
|
);
|
|
362
350
|
}
|
|
363
|
-
function adaptiveFontSize(longestLineLen, baseFSize) {
|
|
364
|
-
return Math.max(baseFSize, 10);
|
|
365
|
-
}
|
|
366
351
|
function wrapLabel(label, maxChars = 12) {
|
|
367
352
|
const str = String(label);
|
|
368
353
|
let rawWords;
|