@classic-homes/charts-svelte 0.3.2 → 0.4.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.
@@ -11,9 +11,11 @@
11
11
  buildDataLabel,
12
12
  buildDataZoom,
13
13
  buildLegend,
14
+ buildStackTotalSeries,
14
15
  buildTooltip,
15
16
  categoryTable,
16
17
  chartFormatters,
18
+ formatValue,
17
19
  generateBarChartDescription,
18
20
  getChartColors,
19
21
  gridInset,
@@ -22,8 +24,10 @@
22
24
  resolveChartHeight,
23
25
  resolveValueFormatter,
24
26
  seriesLabelLookup,
27
+ stackTotals,
25
28
  toPercentStack,
26
29
  withPointLabels,
30
+ withEndLabelInset,
27
31
  withReferenceMarks,
28
32
  withZoomInset,
29
33
  } from '@classic-homes/charts-core';
@@ -64,6 +68,7 @@
64
68
  orientation = 'vertical',
65
69
  stacked = false,
66
70
  showValues = false,
71
+ showTotal = false,
67
72
  valueFormat,
68
73
  locale,
69
74
  labelFormatter,
@@ -159,6 +164,26 @@
159
164
  },
160
165
  }));
161
166
 
167
+ // Totals use the value format, not the percent one: they show the raw sum
168
+ const format = resolveValueFormatter(valueFormat, locale);
169
+ const totalSeries = showTotal
170
+ ? buildStackTotalSeries(data.categories, data.series, {
171
+ stacked,
172
+ position: labelPosition,
173
+ format,
174
+ axisType: categoryAxisType,
175
+ })
176
+ : [];
177
+
178
+ // Labels past the end of horizontal bars need room beside the plot
179
+ const endLabels = !isHorizontal
180
+ ? []
181
+ : totalSeries.length
182
+ ? [...stackTotals(data.series, stacked).values()].flat().map((t) => formatValue(t, format))
183
+ : showValues
184
+ ? plotted.flatMap((s) => s.data.map((value) => formatValue(value, formatters.format)))
185
+ : [];
186
+
162
187
  return mergeChartOption(
163
188
  {
164
189
  grid: {
@@ -167,7 +192,10 @@
167
192
  bottom: '3%',
168
193
  containLabel: true,
169
194
  ...withZoomInset(
170
- gridInset(legendConfig, builtInLegend, xAxisConfig, yAxisConfig),
195
+ withEndLabelInset(
196
+ gridInset(legendConfig, builtInLegend, xAxisConfig, yAxisConfig),
197
+ endLabels
198
+ ),
171
199
  dataZoom,
172
200
  zoomAxis
173
201
  ),
@@ -200,7 +228,7 @@
200
228
  isHorizontal ? categoryAxis : valueAxis,
201
229
  isHorizontal ? yAxisConfig : formatters.axis(yAxisConfig)
202
230
  ),
203
- series: withReferenceMarks(series, referenceLines, referenceBands, {
231
+ series: withReferenceMarks([...series, ...totalSeries], referenceLines, referenceBands, {
204
232
  valueAxis: isHorizontal ? 'x' : 'y',
205
233
  inverse: isHorizontal,
206
234
  format: formatters.format,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@classic-homes/charts-svelte",
3
- "version": "0.3.2",
3
+ "version": "0.4.0",
4
4
  "description": "Svelte ECharts components for Classic Theme",
5
5
  "type": "module",
6
6
  "svelte": "./dist/lib/index.js",