@classic-homes/charts-svelte 0.6.0 → 0.7.0

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.
@@ -32,6 +32,9 @@
32
32
  withGhostSeries,
33
33
  withReferenceMarks,
34
34
  withZoomInset,
35
+ selectionShowsSymbols,
36
+ withSelectedPoints,
37
+ withSelectionDescription,
35
38
  } from '@classic-homes/charts-core';
36
39
 
37
40
  import { cn } from '../../utils.js';
@@ -90,6 +93,8 @@
90
93
  showDataTable,
91
94
  exportable,
92
95
  patterns,
96
+ showDataPoints = false,
97
+ selected,
93
98
  onClick,
94
99
  onHover,
95
100
  class: className,
@@ -120,7 +125,8 @@
120
125
  const plotted = isPercent ? toPercentStack(data.series) : data.series;
121
126
  const getLabel = seriesLabelLookup(data.series);
122
127
  // ECharts hides line labels along with the symbol
123
- const showSymbol = showLabels || hasPointLabels(data.series);
128
+ const showSymbol = showDataPoints || showLabels || hasPointLabels(data.series);
129
+ const pointSize = showDataPoints ? 6 : showSymbol ? 4 : 0;
124
130
  const legendBottom = builtInLegend && (legendConfig?.position ?? 'bottom') === 'bottom';
125
131
 
126
132
  const series = data.series.map((source, index) => {
@@ -129,14 +135,20 @@
129
135
  return {
130
136
  name: source.name,
131
137
  type: 'line',
132
- data: withForecastPoints(
133
- withPointLabels(
134
- pairWithCategories(data.categories, plotted[index].data, xAxisConfig?.type),
135
- source.labels,
136
- formatters.label,
137
- { position: 'top' }
138
+ data: withSelectedPoints(
139
+ withForecastPoints(
140
+ withPointLabels(
141
+ pairWithCategories(data.categories, plotted[index].data, xAxisConfig?.type),
142
+ source.labels,
143
+ formatters.label,
144
+ { position: 'top' }
145
+ ),
146
+ source,
147
+ pointSize
138
148
  ),
139
- source
149
+ data.categories,
150
+ selected,
151
+ { pointSize, ringColor: chartColors.surface }
140
152
  ),
141
153
  smooth,
142
154
  connectNulls,
@@ -159,10 +171,10 @@
159
171
  emphasis: {
160
172
  focus: 'series',
161
173
  },
162
- // Forecast points show even when the others are hidden (size 0)
163
- ...(forecastStart(source) === undefined
164
- ? { showSymbol }
165
- : { showSymbol: true, symbolSize: showSymbol ? 4 : 0 }),
174
+ // Forecast and selected points show even when the others are hidden (size 0)
175
+ showSymbol:
176
+ showSymbol || forecastStart(source) !== undefined || selectionShowsSymbols(selected),
177
+ symbolSize: pointSize,
166
178
  };
167
179
  });
168
180
 
@@ -241,8 +253,11 @@
241
253
  });
242
254
 
243
255
  const accessibilityDescription = $derived(
244
- description ||
245
- (!isEmpty ? generateAreaChartDescription(title, data, formatters.format) : undefined)
256
+ withSelectionDescription(
257
+ description ||
258
+ (!isEmpty ? generateAreaChartDescription(title, data, formatters.format) : undefined),
259
+ selected
260
+ )
246
261
  );
247
262
 
248
263
  const dataTable = $derived(isEmpty ? undefined : categoryTable(data));
@@ -36,6 +36,10 @@
36
36
  withoutGhostSeries,
37
37
  withReferenceMarks,
38
38
  withZoomInset,
39
+ GHOST_BAR_OPACITY,
40
+ isGhostSeries,
41
+ withSelectedBars,
42
+ withSelectionDescription,
39
43
  } from '@classic-homes/charts-core';
40
44
 
41
45
  import { cn } from '../../utils.js';
@@ -94,6 +98,7 @@
94
98
  showDataTable,
95
99
  exportable,
96
100
  patterns,
101
+ selected,
97
102
  onClick,
98
103
  onHover,
99
104
  class: className,
@@ -157,15 +162,20 @@
157
162
  data.series.map((source, index) => ({
158
163
  name: source.name,
159
164
  type: 'bar',
160
- data: withForecastBars(
161
- withPointLabels(
162
- pairWithCategories(data.categories, plotted[index].data, categoryAxisType),
163
- source.labels,
164
- formatters.label,
165
- { position: labelPosition }
165
+ data: withSelectedBars(
166
+ withForecastBars(
167
+ withPointLabels(
168
+ pairWithCategories(data.categories, plotted[index].data, categoryAxisType),
169
+ source.labels,
170
+ formatters.label,
171
+ { position: labelPosition }
172
+ ),
173
+ source,
174
+ source.color || chartColors.series[index % chartColors.series.length]
166
175
  ),
167
- source,
168
- source.color || chartColors.series[index % chartColors.series.length]
176
+ data.categories,
177
+ selected,
178
+ isGhostSeries(source) ? GHOST_BAR_OPACITY : 1
169
179
  ),
170
180
  stack: stackIds[index],
171
181
  itemStyle: {
@@ -267,8 +277,11 @@
267
277
  });
268
278
 
269
279
  const accessibilityDescription = $derived(
270
- description ||
271
- (!isEmpty ? generateBarChartDescription(title, data, formatters.format) : undefined)
280
+ withSelectionDescription(
281
+ description ||
282
+ (!isEmpty ? generateBarChartDescription(title, data, formatters.format) : undefined),
283
+ selected
284
+ )
272
285
  );
273
286
 
274
287
  const dataTable = $derived(isEmpty ? undefined : categoryTable(data));
@@ -20,6 +20,8 @@
20
20
  pointLabel,
21
21
  resolveValueFormatter,
22
22
  sliceTable,
23
+ withSelectedSlices,
24
+ withSelectionDescription,
23
25
  } from '@classic-homes/charts-core';
24
26
 
25
27
  import { cn } from '../../utils.js';
@@ -72,6 +74,7 @@
72
74
  showDataTable,
73
75
  exportable,
74
76
  patterns,
77
+ selected,
75
78
  onClick,
76
79
  class: className,
77
80
  }: Props = $props();
@@ -181,12 +184,15 @@
181
184
  radius: [innerRadius, '70%'],
182
185
  center: pieCenter,
183
186
  avoidLabelOverlap: true,
184
- data: data.map((item) => ({
185
- name: item.name,
186
- value: item.value,
187
- itemStyle: item.color ? { color: item.color } : undefined,
188
- label: pointLabel(item.label, labelFormatter, { position: labelPosition }),
189
- })),
187
+ data: withSelectedSlices(
188
+ data.map((item) => ({
189
+ name: item.name,
190
+ value: item.value,
191
+ itemStyle: item.color ? { color: item.color } : undefined,
192
+ label: pointLabel(item.label, labelFormatter, { position: labelPosition }),
193
+ })),
194
+ selected
195
+ ),
190
196
  label: buildDataLabel(
191
197
  {
192
198
  show: true,
@@ -214,7 +220,10 @@
214
220
  });
215
221
 
216
222
  const accessibilityDescription = $derived(
217
- description || (!isEmpty ? generatePieChartDescription(title, data, true) : undefined)
223
+ withSelectionDescription(
224
+ description || (!isEmpty ? generatePieChartDescription(title, data, true) : undefined),
225
+ selected
226
+ )
218
227
  );
219
228
 
220
229
  const dataTable = $derived(isEmpty ? undefined : sliceTable(data));
@@ -31,6 +31,9 @@
31
31
  withGhostSeries,
32
32
  withReferenceMarks,
33
33
  withZoomInset,
34
+ selectionShowsSymbols,
35
+ withSelectedPoints,
36
+ withSelectionDescription,
34
37
  } from '@classic-homes/charts-core';
35
38
 
36
39
  import { cn } from '../../utils.js';
@@ -90,6 +93,7 @@
90
93
  showDataTable,
91
94
  exportable,
92
95
  patterns,
96
+ selected,
93
97
  onClick,
94
98
  onHover,
95
99
  class: className,
@@ -126,19 +130,25 @@
126
130
  const series = data.series.map((source, index) => ({
127
131
  name: source.name,
128
132
  type: 'line',
129
- data: withForecastPoints(
130
- withPointLabels(
131
- pairWithCategories(data.categories, plotted[index].data, xAxisConfig?.type),
132
- source.labels,
133
- formatters.label,
134
- { position: 'top' }
133
+ data: withSelectedPoints(
134
+ withForecastPoints(
135
+ withPointLabels(
136
+ pairWithCategories(data.categories, plotted[index].data, xAxisConfig?.type),
137
+ source.labels,
138
+ formatters.label,
139
+ { position: 'top' }
140
+ ),
141
+ source,
142
+ showDataPoints ? 6 : 0
135
143
  ),
136
- source,
137
- showDataPoints ? 6 : 0
144
+ data.categories,
145
+ selected,
146
+ { pointSize: showDataPoints ? 6 : 0, ringColor: chartColors.surface }
138
147
  ),
139
148
  smooth,
140
- // Forecast points show even when the others are hidden (size 0)
141
- showSymbol: showSymbol || forecastStart(source) !== undefined,
149
+ // Forecast and selected points show even when the others are hidden (size 0)
150
+ showSymbol:
151
+ showSymbol || forecastStart(source) !== undefined || selectionShowsSymbols(selected),
142
152
  symbolSize: showDataPoints ? 6 : 0,
143
153
  connectNulls,
144
154
  stack: source.stack ?? (stacked ? 'Total' : undefined),
@@ -232,8 +242,11 @@
232
242
  });
233
243
 
234
244
  const accessibilityDescription = $derived(
235
- description ||
236
- (!isEmpty ? generateLineChartDescription(title, data, formatters.format) : undefined)
245
+ withSelectionDescription(
246
+ description ||
247
+ (!isEmpty ? generateLineChartDescription(title, data, formatters.format) : undefined),
248
+ selected
249
+ )
237
250
  );
238
251
 
239
252
  const dataTable = $derived(isEmpty ? undefined : categoryTable(data));
@@ -19,6 +19,8 @@
19
19
  pointLabel,
20
20
  resolveValueFormatter,
21
21
  sliceTable,
22
+ withSelectedSlices,
23
+ withSelectionDescription,
22
24
  } from '@classic-homes/charts-core';
23
25
 
24
26
  import { cn } from '../../utils.js';
@@ -69,6 +71,7 @@
69
71
  showDataTable,
70
72
  exportable,
71
73
  patterns,
74
+ selected,
72
75
  onClick,
73
76
  class: className,
74
77
  }: Props = $props();
@@ -122,12 +125,15 @@
122
125
  type: 'pie',
123
126
  radius: innerRadius ? [innerRadius, '70%'] : '70%',
124
127
  center: legendCenter(legendConfig, showLegend && !renderLegend, ['50%', '45%']),
125
- data: data.map((item) => ({
126
- name: item.name,
127
- value: item.value,
128
- itemStyle: item.color ? { color: item.color } : undefined,
129
- label: pointLabel(item.label, labelFormatter, { position: labelPosition }),
130
- })),
128
+ data: withSelectedSlices(
129
+ data.map((item) => ({
130
+ name: item.name,
131
+ value: item.value,
132
+ itemStyle: item.color ? { color: item.color } : undefined,
133
+ label: pointLabel(item.label, labelFormatter, { position: labelPosition }),
134
+ })),
135
+ selected
136
+ ),
131
137
  label: buildDataLabel(
132
138
  {
133
139
  show: true,
@@ -152,7 +158,10 @@
152
158
  });
153
159
 
154
160
  const accessibilityDescription = $derived(
155
- description || (!isEmpty ? generatePieChartDescription(title, data, false) : undefined)
161
+ withSelectionDescription(
162
+ description || (!isEmpty ? generatePieChartDescription(title, data, false) : undefined),
163
+ selected
164
+ )
156
165
  );
157
166
 
158
167
  const dataTable = $derived(isEmpty ? undefined : sliceTable(data));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/charts-svelte",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Svelte ECharts components for Classic Theme",
5
5
  "type": "module",
6
6
  "svelte": "./dist/lib/index.js",