@r2digisolutions/components 0.21.33 → 0.21.35

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.
@@ -59,7 +59,6 @@
59
59
  const domain = $derived.by(() => {
60
60
  if (yMin !== undefined && yMax !== undefined) return { min: yMin, max: yMax };
61
61
  const auto = scaleDomain(values);
62
- /** Counts never go below zero unless the caller sets an explicit floor. */
63
62
  if (yMin !== undefined) return { min: yMin, max: Math.max(auto.max, yMin + 1) };
64
63
  if (values.length > 0 && Math.min(...values) >= 0 && auto.min < 0) {
65
64
  return { min: 0, max: auto.max };
@@ -70,18 +69,15 @@
70
69
  const line = $derived(smooth ? smoothLinePath(points) : linearLinePath(points));
71
70
  const area = $derived(areaPath(line, points, height, pad));
72
71
 
73
- const integerValues = $derived(values.every((v) => Number.isInteger(v)));
72
+ const integerValues = $derived(values.length > 0 && values.every((v) => Number.isInteger(v)));
74
73
 
75
74
  const gridYs = $derived.by(() => {
76
75
  const { min, max } = domain;
77
76
  return [0, 0.5, 1].map((t) => {
78
77
  const raw = min + t * (max - min);
79
- const label = integerValues
80
- ? String(Math.round(raw))
81
- : formatTick(raw);
82
78
  return {
83
79
  y: pad.t + (1 - t) * (height - pad.t - pad.b),
84
- label
80
+ label: integerValues ? String(Math.round(raw)) : formatTick(raw)
85
81
  };
86
82
  });
87
83
  });
@@ -106,12 +102,14 @@
106
102
  }
107
103
  </script>
108
104
 
105
+ <!--
106
+ Keep aspect ratio (h-auto, no preserveAspectRatio=none).
107
+ Stretching to a fixed CSS height warps curves/dots — as in Ads vs gestor.
108
+ -->
109
109
  <div class={['relative w-full select-none', className]}>
110
110
  <svg
111
111
  viewBox={`0 0 ${W} ${height}`}
112
- preserveAspectRatio="none"
113
- class="block w-full overflow-visible"
114
- style:height={`${height}px`}
112
+ class="h-auto w-full overflow-visible"
115
113
  role="img"
116
114
  aria-label="Area line chart"
117
115
  >
@@ -130,7 +128,7 @@
130
128
  </defs>
131
129
 
132
130
  {#if showGrid}
133
- {#each gridYs as g}
131
+ {#each gridYs as g (g.label + g.y)}
134
132
  <line
135
133
  x1={pad.l}
136
134
  x2={W - pad.r}
@@ -168,7 +166,7 @@
168
166
  />
169
167
  {/if}
170
168
 
171
- {#each points as p, i}
169
+ {#each points as p, i (i)}
172
170
  {#if showDots}
173
171
  <circle
174
172
  cx={p.x}
@@ -183,6 +181,7 @@
183
181
  {#if interactive}
184
182
  <!-- Hit area: pointer-only (no focus ring / square outline) -->
185
183
  <!-- svelte-ignore a11y_no_static_element_interactions -->
184
+ <!-- svelte-ignore a11y_click_events_have_key_events -->
186
185
  <circle
187
186
  cx={p.x}
188
187
  cy={p.y}
@@ -194,7 +193,7 @@
194
193
  {/if}
195
194
  {/each}
196
195
 
197
- {#each data as d, i}
196
+ {#each data as d, i (i)}
198
197
  {#if i === 0 || i === data.length - 1 || data.length <= 7}
199
198
  {@const p = points[i]}
200
199
  {#if p}
@@ -29,7 +29,7 @@
29
29
  }: BarChartProps = $props();
30
30
 
31
31
  const W = 420;
32
- const pad = { t: 24, r: 12, b: 40, l: 12 };
32
+ const pad = { t: 24, r: 12, b: 32, l: 12 };
33
33
  const uid = `bc-${Math.random().toString(36).slice(2, 8)}`;
34
34
  const color = 'var(--color-brand-500, #6366f1)';
35
35
 
@@ -66,10 +66,6 @@
66
66
  };
67
67
  });
68
68
 
69
- function axisLabel(label: string): string {
70
- return label.length > 14 ? `${label.slice(0, 14)}…` : label;
71
- }
72
-
73
69
  function select(i: number) {
74
70
  if (!interactive) return;
75
71
  tipIndex = tipIndex === i ? null : i;
@@ -79,9 +75,7 @@
79
75
  <div class={['relative w-full select-none', className]}>
80
76
  <svg
81
77
  viewBox={`0 0 ${W} ${height}`}
82
- preserveAspectRatio="none"
83
- class="block w-full overflow-visible"
84
- style:height={`${height}px`}
78
+ class="h-auto w-full overflow-visible"
85
79
  role="img"
86
80
  aria-label="Bar chart"
87
81
  >
@@ -115,8 +109,8 @@
115
109
  {formatTick(b.value, 0)}{unit}
116
110
  </text>
117
111
  {/if}
118
- <text x={b.cx} y={height - 8} text-anchor="middle" class="fill-muted" font-size="12">
119
- {axisLabel(b.label)}
112
+ <text x={b.cx} y={height - 8} text-anchor="middle" class="fill-muted" font-size="10">
113
+ {b.label}
120
114
  </text>
121
115
  {#if interactive}
122
116
  <!-- svelte-ignore a11y_no_static_element_interactions -->
@@ -9,9 +9,9 @@
9
9
 
10
10
  interface HorizontalBarChartProps {
11
11
  data?: HBarPoint[];
12
- /** Bar track width in viewBox units */
12
+ /** Kept for API compat — layout is CSS, not SVG viewBox */
13
13
  barWidth?: number;
14
- /** Left label column width in viewBox units */
14
+ /** Kept for API compat — label column uses CSS */
15
15
  labelWidth?: number;
16
16
  rowHeight?: number;
17
17
  interactive?: boolean;
@@ -22,7 +22,6 @@
22
22
 
23
23
  const {
24
24
  data = [],
25
- barWidth = 280,
26
25
  labelWidth = 88,
27
26
  rowHeight = 36,
28
27
  interactive = true,
@@ -32,107 +31,67 @@
32
31
  }: HorizontalBarChartProps = $props();
33
32
 
34
33
  const color = 'var(--color-brand-500, #6366f1)';
35
- const padR = 48;
36
- const W = $derived(labelWidth + barWidth + padR);
37
- const H = $derived(Math.max(data.length, 1) * rowHeight + 8);
38
- const maxLabelChars = $derived(Math.floor(labelWidth / 6.5));
39
34
 
40
35
  let tipIndex = $state<number | null>(null);
41
36
 
42
37
  const max = $derived(Math.max(...data.map((d) => d.value), 1));
43
38
 
44
- const rows = $derived(
45
- data.map((d, i) => {
46
- const ratio = Math.max(0, d.value) / max;
47
- const bw = Math.max(d.value > 0 ? 4 : 0, ratio * barWidth);
48
- const y = 4 + i * rowHeight;
49
- return { ...d, bw, y, midY: y + (rowHeight - 10) / 2 };
50
- })
51
- );
52
-
53
- function displayLabel(label: string): string {
54
- const maxChars = maxLabelChars;
55
- if (label.length <= maxChars) return label;
56
- return `${label.slice(0, Math.max(0, maxChars - 1))}…`;
57
- }
58
-
59
39
  function select(i: number) {
60
40
  if (!interactive) return;
61
41
  tipIndex = tipIndex === i ? null : i;
62
42
  }
63
43
  </script>
64
44
 
65
- <div class={['relative w-full select-none', className]}>
66
- <svg
67
- viewBox={`0 0 ${W} ${H}`}
68
- preserveAspectRatio="none"
69
- class="block w-full overflow-visible"
70
- style:height={`${H}px`}
71
- role="img"
72
- aria-label="Horizontal bar chart"
73
- >
74
- {#each rows as r, i (i)}
75
- <text
76
- x={labelWidth - 8}
77
- y={r.midY + 4}
78
- text-anchor="end"
79
- class="fill-secondary"
80
- font-size="11"
81
- >
82
- {displayLabel(r.label)}
83
- </text>
84
- <rect
85
- x={labelWidth}
86
- y={r.y + 4}
87
- width={barWidth}
88
- height={rowHeight - 14}
89
- rx="5"
90
- class="fill-surface-muted"
91
- opacity="0.6"
92
- />
93
- <rect
94
- x={labelWidth}
95
- y={r.y + 4}
96
- width={r.bw}
97
- height={rowHeight - 14}
98
- rx="5"
99
- fill={r.color ?? color}
100
- opacity={tipIndex == null || tipIndex === i ? 1 : 0.35}
101
- class="transition-opacity"
102
- />
103
- {#if showValues}
104
- <text
105
- x={labelWidth + r.bw + 6}
106
- y={r.midY + 4}
107
- class="fill-muted"
108
- font-size="10"
109
- font-weight="600"
110
- >
111
- {formatTick(r.value, 0)}{unit}
112
- </text>
113
- {/if}
114
- {#if interactive}
115
- <!-- svelte-ignore a11y_no_static_element_interactions -->
116
- <!-- svelte-ignore a11y_click_events_have_key_events -->
117
- <rect
118
- x={0}
119
- y={r.y}
120
- width={W}
121
- height={rowHeight}
122
- fill="transparent"
123
- class="cursor-pointer"
45
+ <div
46
+ class={['relative w-full select-none', className]}
47
+ role="img"
48
+ aria-label="Horizontal bar chart"
49
+ >
50
+ <ul class="flex flex-col" style:gap="2px">
51
+ {#each data as r, i (r.label + i)}
52
+ {@const ratio = Math.max(0, r.value) / max}
53
+ {@const pct = Math.max(r.value > 0 ? 1.5 : 0, ratio * 100)}
54
+ <li>
55
+ <button
56
+ type="button"
57
+ class={[
58
+ 'grid w-full items-center gap-2 rounded-lg px-0.5 py-0.5 text-left transition-opacity',
59
+ interactive && 'hover:bg-surface-overlay/80 cursor-pointer',
60
+ !interactive && 'cursor-default',
61
+ tipIndex != null && tipIndex !== i && 'opacity-40'
62
+ ]}
63
+ style:min-height={`${rowHeight}px`}
64
+ style:grid-template-columns={`minmax(0, ${labelWidth}px) minmax(0, 1fr) auto`}
124
65
  onclick={() => select(i)}
125
- />
126
- {/if}
66
+ disabled={!interactive}
67
+ >
68
+ <span
69
+ class="text-secondary truncate text-right text-xs leading-snug"
70
+ title={r.label}
71
+ >
72
+ {r.label}
73
+ </span>
74
+ <span class="bg-surface-overlay relative block h-4 overflow-hidden rounded-md">
75
+ <span
76
+ class="absolute inset-y-0 left-0 rounded-md transition-[width]"
77
+ style:width={`${pct}%`}
78
+ style:background={r.color ?? color}
79
+ ></span>
80
+ </span>
81
+ {#if showValues}
82
+ <span class="text-secondary min-w-[2ch] text-right text-xs font-semibold tabular-nums">
83
+ {formatTick(r.value, 0)}{unit}
84
+ </span>
85
+ {/if}
86
+ </button>
87
+ </li>
127
88
  {/each}
128
- </svg>
89
+ </ul>
129
90
 
130
- {#if tipIndex != null && rows[tipIndex]}
131
- {@const t = rows[tipIndex]}
91
+ {#if tipIndex != null && data[tipIndex]}
92
+ {@const t = data[tipIndex]}
132
93
  <div
133
- class="pointer-events-none absolute z-10 rounded-lg border border-border bg-surface-elevated px-2.5 py-1.5 shadow-lg"
134
- style:left={`${((labelWidth + t.bw) / W) * 100}%`}
135
- style:top={`${(t.y / H) * 100}%`}
94
+ class="pointer-events-none absolute top-0 right-0 z-10 rounded-lg border border-border bg-surface-elevated px-2.5 py-1.5 shadow-lg"
136
95
  role="status"
137
96
  >
138
97
  <p class="text-[10px] font-medium text-muted">{t.label}</p>
@@ -5,9 +5,9 @@ export interface HBarPoint {
5
5
  }
6
6
  interface HorizontalBarChartProps {
7
7
  data?: HBarPoint[];
8
- /** Bar track width in viewBox units */
8
+ /** Kept for API compat — layout is CSS, not SVG viewBox */
9
9
  barWidth?: number;
10
- /** Left label column width in viewBox units */
10
+ /** Kept for API compat — label column uses CSS */
11
11
  labelWidth?: number;
12
12
  rowHeight?: number;
13
13
  interactive?: boolean;
@@ -78,7 +78,7 @@
78
78
  })
79
79
  );
80
80
 
81
- const integerValues = $derived(allValues.every((v) => Number.isInteger(v)));
81
+ const integerValues = $derived(allValues.length > 0 && allValues.every((v) => Number.isInteger(v)));
82
82
 
83
83
  const gridYs = $derived.by(() => {
84
84
  const { min, max } = domain;
@@ -121,9 +121,7 @@
121
121
  <div class={['relative w-full select-none', className]}>
122
122
  <svg
123
123
  viewBox={`0 0 ${W} ${height}`}
124
- preserveAspectRatio="none"
125
- class="block w-full overflow-visible"
126
- style:height={`${height}px`}
124
+ class="h-auto w-full overflow-visible"
127
125
  role="img"
128
126
  aria-label="Multi-line chart"
129
127
  >
@@ -100,9 +100,7 @@
100
100
  <div class="relative w-full select-none">
101
101
  <svg
102
102
  viewBox={`0 0 ${W} ${height}`}
103
- preserveAspectRatio="none"
104
- class="block w-full overflow-visible"
105
- style:height={`${height}px`}
103
+ class="h-auto w-full overflow-visible"
106
104
  role="img"
107
105
  aria-label="Stacked bar chart"
108
106
  >
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@r2digisolutions/components",
3
- "version": "0.21.33",
3
+ "version": "0.21.35",
4
4
  "private": false,
5
5
  "description": "R2DigiSolutions Svelte 5 component library — Atomic Design, Tailwind 4, Light/Dark mode",
6
6
  "license": "MIT",