@empoweredvote/ev-ui 0.9.0 → 0.9.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
@@ -136,7 +136,9 @@ function RadarChartCore({
136
136
  labelFontSize = 18,
137
137
  padding = 80,
138
138
  labelOffset = 20,
139
- tightFit = false
139
+ tightFit = false,
140
+ maxLabelLines = 2,
141
+ showLabels = true
140
142
  }) {
141
143
  const { isDark } = useTheme();
142
144
  const radius = size / 2 - 40;
@@ -202,21 +204,22 @@ function RadarChartCore({
202
204
  });
203
205
  const labelMeta = spokes.map(([shortTitle], i) => {
204
206
  const angle = 2 * Math.PI * i / numSpokes;
207
+ const sinA = Math.sin(angle);
208
+ const side = sinA < -0.1 ? "left" : sinA > 0.1 ? "right" : "center";
209
+ if (!showLabels) return { estimatedWidth: 0, side };
205
210
  const baseFSize = labelFontSize;
206
- const lines = wrapLabel(shortTitle, 12);
211
+ const lines = wrapLabel(shortTitle, 12, maxLabelLines);
207
212
  const longestLineLen = lines.reduce(
208
213
  (max, ln) => ln.length > max ? ln.length : max,
209
214
  0
210
215
  );
211
216
  const fSize = adaptiveFontSize(longestLineLen, baseFSize);
212
217
  const estimatedWidth = longestLineLen * fSize * 0.6;
213
- const sinA = Math.sin(angle);
214
- const side = sinA < -0.1 ? "left" : sinA > 0.1 ? "right" : "center";
215
218
  return { estimatedWidth, side };
216
219
  });
217
220
  const leftLabelWidths = labelMeta.filter((m) => m.side === "left").map((m) => m.estimatedWidth);
218
221
  const rightLabelWidths = labelMeta.filter((m) => m.side === "right").map((m) => m.estimatedWidth);
219
- const minPadding = 40;
222
+ const minPadding = showLabels ? 40 : 10;
220
223
  const maxPadding = padding * 2;
221
224
  const rawLeftPadding = Math.min(
222
225
  Math.max(
@@ -246,7 +249,8 @@ function RadarChartCore({
246
249
  if (y < yMin) yMin = y;
247
250
  if (y > yMax) yMax = y;
248
251
  }
249
- const labelMargin = labelOffset + labelFontSize * 1.4 + labelFontSize * 1.1;
252
+ const effLabelFSize = adaptiveFontSize(12, labelFontSize);
253
+ const labelMargin = showLabels ? labelOffset + effLabelFSize * 1.1 * maxLabelLines : 8;
250
254
  tightTop = yMin - labelMargin;
251
255
  tightHeight = yMax + labelMargin - tightTop;
252
256
  }
@@ -291,14 +295,14 @@ function RadarChartCore({
291
295
  }
292
296
  );
293
297
  }),
294
- spokes.map(([shortTitle], i) => {
298
+ showLabels && spokes.map(([shortTitle], i) => {
295
299
  const angle = 2 * Math.PI * i / numSpokes;
296
300
  const anchor = angle > Math.PI ? "end" : angle < Math.PI && angle > 0 ? "start" : "middle";
297
301
  const cosA = Math.cos(angle);
298
302
  const isTop = cosA > 0.5;
299
303
  const isBottom = cosA < -0.5;
300
304
  const baseFSize = labelFontSize;
301
- const lines = wrapLabel(shortTitle, 12);
305
+ const lines = wrapLabel(shortTitle, 12, maxLabelLines);
302
306
  const longestLine = lines.reduce(
303
307
  (max, ln) => ln.length > max ? ln.length : max,
304
308
  0
@@ -439,7 +443,7 @@ function RadarChartCore({
439
443
  function adaptiveFontSize(longestLineLen, baseFSize) {
440
444
  return Math.max(baseFSize, 10);
441
445
  }
442
- function wrapLabel(label, maxChars = 12) {
446
+ function wrapLabel(label, maxChars = 12, maxLines = 2) {
443
447
  const str = String(label);
444
448
  let rawWords;
445
449
  if (str.includes("/")) {
@@ -464,9 +468,9 @@ function wrapLabel(label, maxChars = 12) {
464
468
  }
465
469
  }
466
470
  if (line) lines.push(line);
467
- if (lines.length > 2) {
468
- const overflow = lines.splice(2).join(" ");
469
- lines[1] = lines[1] + " " + overflow;
471
+ if (lines.length > maxLines) {
472
+ const overflow = lines.splice(maxLines).join(" ");
473
+ lines[maxLines - 1] = lines[maxLines - 1] + " " + overflow;
470
474
  }
471
475
  return lines;
472
476
  }
@@ -1961,9 +1965,13 @@ function PoliticianCard({
1961
1965
  style = {},
1962
1966
  badge,
1963
1967
  imageFocalPoint,
1964
- footer
1968
+ footer,
1969
+ imageWidth = "90px",
1970
+ contentStyle = {}
1965
1971
  }) {
1966
1972
  const isHorizontal = variant === "horizontal";
1973
+ const imageWidthPx = parseInt(imageWidth, 10) || 90;
1974
+ const imageMinHeight = isHorizontal ? Math.ceil(imageWidthPx * 4 / 3) : void 0;
1967
1975
  const handleCardClick = (e) => {
1968
1976
  if (e.target.closest(".ev-compass-button")) return;
1969
1977
  onClick == null ? void 0 : onClick();
@@ -1984,25 +1992,29 @@ function PoliticianCard({
1984
1992
  cursor: onClick ? "pointer" : "default",
1985
1993
  transition: "box-shadow 0.2s ease, transform 0.2s ease",
1986
1994
  position: "relative",
1987
- minHeight: isHorizontal ? "130px" : void 0,
1995
+ minHeight: imageMinHeight,
1988
1996
  height: "100%",
1989
1997
  ...style
1990
1998
  },
1991
1999
  imageWrapper: {
1992
- width: isHorizontal ? "90px" : "100%",
2000
+ // Horizontal: fixed width with 3:4 aspect ratio so portrait photos look
2001
+ // consistent regardless of card content height.
2002
+ position: "relative",
2003
+ width: isHorizontal ? imageWidth : "100%",
1993
2004
  height: isHorizontal ? "100%" : "auto",
1994
- maxHeight: isHorizontal ? "200px" : void 0,
1995
2005
  aspectRatio: isHorizontal ? void 0 : "4/5",
1996
2006
  flexShrink: 0,
1997
2007
  overflow: "hidden"
1998
2008
  },
1999
2009
  image: {
2010
+ ...isHorizontal ? { position: "absolute", top: 0, left: 0 } : {},
2000
2011
  width: "100%",
2001
2012
  height: "100%",
2002
2013
  objectFit: "cover",
2003
2014
  objectPosition: imageFocalPoint != null ? imageFocalPoint : "center 20%"
2004
2015
  },
2005
2016
  imagePlaceholder: {
2017
+ ...isHorizontal ? { position: "absolute", top: 0, left: 0 } : {},
2006
2018
  width: "100%",
2007
2019
  height: "100%",
2008
2020
  backgroundColor: colors.evTeal,
@@ -2020,7 +2032,8 @@ function PoliticianCard({
2020
2032
  padding: isHorizontal ? `${spacing[2]} ${spacing[3]}` : spacing[3],
2021
2033
  minWidth: 0,
2022
2034
  display: "flex",
2023
- flexDirection: "column"
2035
+ flexDirection: "column",
2036
+ ...contentStyle
2024
2037
  },
2025
2038
  name: {
2026
2039
  fontFamily: fonts.primary,