@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.mjs CHANGED
@@ -12,9 +12,9 @@ function RadarChartCore({
12
12
  onReplaceTopic = () => {
13
13
  },
14
14
  size = 400,
15
- labelFontSize = 18,
15
+ labelFontSize = 13,
16
16
  padding = 80,
17
- labelOffset = 20,
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 fSize = adaptiveFontSize(longestLineLen, labelFontSize);
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 rawLeftPadding = Math.min(
100
- Math.max(leftLabelWidths.length ? Math.max(...leftLabelWidths) + labelOffset : 0, minPadding),
101
- maxPadding
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 * 1.4 + labelFontSize * 1.1;
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: `-${leftPadding} ${tightTop} ${size + leftPadding + rightPadding} ${tightHeight}`,
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" : "black",
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: "black",
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 fSize = adaptiveFontSize(longestLine, labelFontSize);
203
- const lineHeight = fSize * 1.1;
204
- const dynamicLabelOffset = lines.length > 1 ? labelOffset + 8 : labelOffset;
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 activeFSize = fSize * 1.5;
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
- className: "text-xl font-medium mb-1 md:text-base md:font-normal",
223
- fill: isActive ? "#E85D26" : isUnansweredLabel ? "#9ca3af" : void 0,
224
- fontWeight: isActive ? "bold" : void 0,
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 + leftPadding + rightPadding;
329
- const tx = tooltip.x + leftPadding + 12 > svgW - tipW ? tooltip.x - tipW - 12 : tooltip.x + 12;
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;