@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 CHANGED
@@ -103,9 +103,9 @@ function RadarChartCore({
103
103
  onReplaceTopic = () => {
104
104
  },
105
105
  size = 400,
106
- labelFontSize = 18,
106
+ labelFontSize = 13,
107
107
  padding = 80,
108
- labelOffset = 20,
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 fSize = adaptiveFontSize(longestLineLen, labelFontSize);
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 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;
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 * 1.4 + labelFontSize * 1.1;
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: `-${leftPadding} ${tightTop} ${size + leftPadding + rightPadding} ${tightHeight}`,
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" : "black",
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: "black",
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 fSize = adaptiveFontSize(longestLine, labelFontSize);
294
- const lineHeight = fSize * 1.1;
295
- const dynamicLabelOffset = lines.length > 1 ? labelOffset + 8 : labelOffset;
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 activeFSize = fSize * 1.5;
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
- 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 }
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 + leftPadding + rightPadding;
420
- const tx = tooltip.x + leftPadding + 12 > svgW - tipW ? tooltip.x - tipW - 12 : tooltip.x + 12;
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;