@svgrid/grid 1.1.1 → 1.2.1

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.
Files changed (188) hide show
  1. package/dist/FlexRender.svelte +96 -96
  2. package/dist/SvGrid.controller.svelte.js +17 -6
  3. package/dist/SvGrid.css +2012 -2012
  4. package/dist/SvGrid.svelte +2571 -2346
  5. package/dist/SvGridDropdown.svelte +7 -3
  6. package/dist/build-api.js +2 -2
  7. package/dist/cdn/svgrid.js +13504 -0
  8. package/dist/cdn/svgrid.svelte-external.js +11188 -0
  9. package/dist/cell-values.d.ts +1 -1
  10. package/dist/cell-values.js +7 -7
  11. package/dist/column-types.js +1 -1
  12. package/dist/core.d.ts +1 -1
  13. package/dist/core.js +2 -2
  14. package/dist/summaries.js +4 -4
  15. package/package.json +12 -2
  16. package/src/FlexRender.svelte +96 -96
  17. package/src/SvGrid.controller.svelte.ts +2363 -2352
  18. package/src/SvGrid.css +2012 -2012
  19. package/src/SvGrid.svelte +2571 -2346
  20. package/src/SvGrid.types.ts +537 -537
  21. package/src/SvGridDropdown.svelte +7 -3
  22. package/src/a11y.contract.test.ts +49 -49
  23. package/src/a11y.test.ts +59 -59
  24. package/src/a11y.ts +59 -59
  25. package/src/build-api.ts +683 -683
  26. package/src/cell-formatting.ts +169 -169
  27. package/src/cell-values.ts +4 -4
  28. package/src/column-types.ts +1 -1
  29. package/src/core.performance.test.ts +30 -30
  30. package/src/core.ts +1077 -1077
  31. package/src/createGrid.svelte.ts +42 -42
  32. package/src/createGrid.test.ts +10 -10
  33. package/src/createGridState.svelte.ts +17 -17
  34. package/src/editing.ts +669 -669
  35. package/src/flex-render.ts +3 -3
  36. package/src/index.ts +208 -208
  37. package/src/keyboard.test.ts +59 -59
  38. package/src/keyboard.ts +97 -97
  39. package/src/merge-objects.ts +48 -48
  40. package/src/render-component.ts +28 -28
  41. package/src/spreadsheet.test.ts +489 -489
  42. package/src/spreadsheet.ts +304 -304
  43. package/src/static-functions.ts +11 -11
  44. package/src/subscribe.ts +38 -38
  45. package/src/summaries.ts +4 -4
  46. package/src/svgrid-wrapper.types.ts +412 -412
  47. package/src/svgrid.features.test.ts +157 -157
  48. package/src/svgrid.wrapper.test.ts +40 -40
  49. package/src/virtualization/column-virtualizer.test.ts +27 -27
  50. package/src/virtualization/column-virtualizer.ts +30 -30
  51. package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
  52. package/src/virtualization/types.ts +30 -30
  53. package/src/virtualization/virtualizer.test.ts +47 -47
  54. package/src/virtualization/virtualizer.ts +296 -296
  55. package/dist/SvGrid.helpers.test.d.ts +0 -1
  56. package/dist/SvGrid.helpers.test.js +0 -298
  57. package/dist/SvGridChart.test.d.ts +0 -1
  58. package/dist/SvGridChart.test.js +0 -62
  59. package/dist/a11y.contract.test.d.ts +0 -1
  60. package/dist/a11y.contract.test.js +0 -39
  61. package/dist/a11y.test.d.ts +0 -1
  62. package/dist/a11y.test.js +0 -44
  63. package/dist/aligned-grids.test.d.ts +0 -1
  64. package/dist/aligned-grids.test.js +0 -75
  65. package/dist/build-api.coverage.test.d.ts +0 -20
  66. package/dist/build-api.coverage.test.js +0 -505
  67. package/dist/cell-formatting.test.d.ts +0 -1
  68. package/dist/cell-formatting.test.js +0 -234
  69. package/dist/cell-render.test.d.ts +0 -1
  70. package/dist/cell-render.test.js +0 -338
  71. package/dist/chart-export.test.d.ts +0 -1
  72. package/dist/chart-export.test.js +0 -302
  73. package/dist/chart.coverage.test.d.ts +0 -1
  74. package/dist/chart.coverage.test.js +0 -748
  75. package/dist/chart.test.d.ts +0 -1
  76. package/dist/chart.test.js +0 -289
  77. package/dist/clipboard.test.d.ts +0 -1
  78. package/dist/clipboard.test.js +0 -700
  79. package/dist/collaboration.coverage.test.d.ts +0 -1
  80. package/dist/collaboration.coverage.test.js +0 -200
  81. package/dist/collaboration.test.d.ts +0 -1
  82. package/dist/collaboration.test.js +0 -65
  83. package/dist/column-groups.test.d.ts +0 -1
  84. package/dist/column-groups.test.js +0 -56
  85. package/dist/column-types.test.d.ts +0 -1
  86. package/dist/column-types.test.js +0 -62
  87. package/dist/columns.test.d.ts +0 -1
  88. package/dist/columns.test.js +0 -625
  89. package/dist/conditional-formatting.test.d.ts +0 -1
  90. package/dist/conditional-formatting.test.js +0 -87
  91. package/dist/core.coverage.test.d.ts +0 -1
  92. package/dist/core.coverage.test.js +0 -186
  93. package/dist/core.performance.test.d.ts +0 -1
  94. package/dist/core.performance.test.js +0 -29
  95. package/dist/createGrid.test.d.ts +0 -1
  96. package/dist/createGrid.test.js +0 -9
  97. package/dist/editing.test.d.ts +0 -1
  98. package/dist/editing.test.js +0 -732
  99. package/dist/editors/cell-editors.coverage.test.d.ts +0 -1
  100. package/dist/editors/cell-editors.coverage.test.js +0 -139
  101. package/dist/editors/cell-editors.test.d.ts +0 -1
  102. package/dist/editors/cell-editors.test.js +0 -75
  103. package/dist/facet-buckets.test.d.ts +0 -1
  104. package/dist/facet-buckets.test.js +0 -296
  105. package/dist/fill-patterns.test.d.ts +0 -1
  106. package/dist/fill-patterns.test.js +0 -81
  107. package/dist/filter-operators.test.d.ts +0 -1
  108. package/dist/filter-operators.test.js +0 -135
  109. package/dist/filtering/excel-filters.test.d.ts +0 -1
  110. package/dist/filtering/excel-filters.test.js +0 -116
  111. package/dist/filtering/locale-filter.test.d.ts +0 -13
  112. package/dist/filtering/locale-filter.test.js +0 -189
  113. package/dist/flex-render.test.d.ts +0 -1
  114. package/dist/flex-render.test.js +0 -142
  115. package/dist/group-aggregate.test.d.ts +0 -1
  116. package/dist/group-aggregate.test.js +0 -32
  117. package/dist/hyperformula-adapter.test.d.ts +0 -1
  118. package/dist/hyperformula-adapter.test.js +0 -205
  119. package/dist/keyboard-handlers.coverage.test.d.ts +0 -1
  120. package/dist/keyboard-handlers.coverage.test.js +0 -495
  121. package/dist/keyboard.test.d.ts +0 -1
  122. package/dist/keyboard.test.js +0 -27
  123. package/dist/menus.test.d.ts +0 -1
  124. package/dist/menus.test.js +0 -560
  125. package/dist/named-views.coverage.test.d.ts +0 -1
  126. package/dist/named-views.coverage.test.js +0 -180
  127. package/dist/named-views.test.d.ts +0 -1
  128. package/dist/named-views.test.js +0 -57
  129. package/dist/new-features.test.d.ts +0 -1
  130. package/dist/new-features.test.js +0 -183
  131. package/dist/render-component.test.d.ts +0 -1
  132. package/dist/render-component.test.js +0 -41
  133. package/dist/row-drag.test.d.ts +0 -1
  134. package/dist/row-drag.test.js +0 -142
  135. package/dist/row-resize.test.d.ts +0 -1
  136. package/dist/row-resize.test.js +0 -329
  137. package/dist/scroll-sync.test.d.ts +0 -1
  138. package/dist/scroll-sync.test.js +0 -290
  139. package/dist/selection.multi-range.test.d.ts +0 -1
  140. package/dist/selection.multi-range.test.js +0 -55
  141. package/dist/selection.test.d.ts +0 -1
  142. package/dist/selection.test.js +0 -647
  143. package/dist/server-data-source.coverage.test.d.ts +0 -1
  144. package/dist/server-data-source.coverage.test.js +0 -154
  145. package/dist/server-data-source.test.d.ts +0 -1
  146. package/dist/server-data-source.test.js +0 -81
  147. package/dist/sparkline.test.d.ts +0 -1
  148. package/dist/sparkline.test.js +0 -52
  149. package/dist/spreadsheet.test.d.ts +0 -1
  150. package/dist/spreadsheet.test.js +0 -446
  151. package/dist/subscribe.test.d.ts +0 -1
  152. package/dist/subscribe.test.js +0 -93
  153. package/dist/svgrid.api-extensions.test.d.ts +0 -14
  154. package/dist/svgrid.api-extensions.test.js +0 -334
  155. package/dist/svgrid.api.test.d.ts +0 -15
  156. package/dist/svgrid.api.test.js +0 -169
  157. package/dist/svgrid.behavior.test.d.ts +0 -15
  158. package/dist/svgrid.behavior.test.js +0 -625
  159. package/dist/svgrid.column-reorder.test.d.ts +0 -15
  160. package/dist/svgrid.column-reorder.test.js +0 -224
  161. package/dist/svgrid.comments-autocomplete.test.d.ts +0 -1
  162. package/dist/svgrid.comments-autocomplete.test.js +0 -96
  163. package/dist/svgrid.context-menu.test.d.ts +0 -1
  164. package/dist/svgrid.context-menu.test.js +0 -102
  165. package/dist/svgrid.features.test.d.ts +0 -1
  166. package/dist/svgrid.features.test.js +0 -129
  167. package/dist/svgrid.interaction.test.d.ts +0 -9
  168. package/dist/svgrid.interaction.test.js +0 -349
  169. package/dist/svgrid.locale-filtering.test.d.ts +0 -15
  170. package/dist/svgrid.locale-filtering.test.js +0 -261
  171. package/dist/svgrid.new-features.wrapper.test.d.ts +0 -1
  172. package/dist/svgrid.new-features.wrapper.test.js +0 -194
  173. package/dist/svgrid.row-pinning.test.d.ts +0 -14
  174. package/dist/svgrid.row-pinning.test.js +0 -250
  175. package/dist/svgrid.set-filter.test.d.ts +0 -17
  176. package/dist/svgrid.set-filter.test.js +0 -268
  177. package/dist/svgrid.wrapper.test.d.ts +0 -1
  178. package/dist/svgrid.wrapper.test.js +0 -59
  179. package/dist/test-setup.d.ts +0 -1
  180. package/dist/test-setup.js +0 -35
  181. package/dist/transaction.test.d.ts +0 -1
  182. package/dist/transaction.test.js +0 -89
  183. package/dist/virtualization/column-virtualizer.test.d.ts +0 -1
  184. package/dist/virtualization/column-virtualizer.test.js +0 -25
  185. package/dist/virtualization/scroll-scaling.test.d.ts +0 -1
  186. package/dist/virtualization/scroll-scaling.test.js +0 -127
  187. package/dist/virtualization/virtualizer.test.d.ts +0 -1
  188. package/dist/virtualization/virtualizer.test.js +0 -41
@@ -1 +0,0 @@
1
- export {};
@@ -1,289 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { buildChart, rowsToChartSpec, niceScale } from './chart';
3
- describe('niceScale', () => {
4
- it('rounds a positive domain to nice ticks including 0', () => {
5
- const s = niceScale(0, 95);
6
- expect(s.min).toBe(0);
7
- expect(s.max).toBeGreaterThanOrEqual(95);
8
- expect(s.ticks[0]).toBe(0);
9
- });
10
- it('handles a signed domain (negatives)', () => {
11
- const s = niceScale(-40, 80);
12
- expect(s.min).toBeLessThanOrEqual(-40);
13
- expect(s.max).toBeGreaterThanOrEqual(80);
14
- expect(s.ticks).toContain(0);
15
- });
16
- });
17
- describe('buildChart', () => {
18
- it('bar: one rect per category per series, heights scale to max', () => {
19
- const g = buildChart({
20
- type: 'bar',
21
- categories: ['A', 'B'],
22
- series: [{ label: 's1', values: [10, 20] }],
23
- width: 400,
24
- height: 200,
25
- });
26
- expect(g.bars).toHaveLength(2);
27
- expect(g.bars[1].h).toBeGreaterThan(g.bars[0].h);
28
- expect(g.xTicks.map((t) => t.label)).toEqual(['A', 'B']);
29
- expect(g.bars[1]).toMatchObject({ label: 'B', series: 's1', value: 20 });
30
- });
31
- it('bar: negative values drop below the zero baseline', () => {
32
- const g = buildChart({ type: 'bar', categories: ['A', 'B'], series: [{ label: 's', values: [50, -50] }] });
33
- const baseY = g.yTicks.find((t) => t.value === 0).y;
34
- // positive bar sits above the baseline, negative bar below it
35
- expect(g.bars[0].y).toBeLessThan(baseY);
36
- expect(g.bars[1].y).toBeGreaterThanOrEqual(baseY - 0.01);
37
- expect(g.bars[1].value).toBe(-50);
38
- });
39
- it('stacked bars: same x per category, segment heights stack', () => {
40
- const g = buildChart({
41
- type: 'bar',
42
- stacked: true,
43
- categories: ['A'],
44
- series: [
45
- { label: 'x', values: [10] },
46
- { label: 'y', values: [20] },
47
- ],
48
- });
49
- expect(g.bars).toHaveLength(2);
50
- // both segments share the same x (stacked, not grouped)
51
- expect(g.bars[0].x).toBe(g.bars[1].x);
52
- });
53
- it('combo + dual axis: bar on left, line on right axis', () => {
54
- const g = buildChart({
55
- type: 'bar',
56
- categories: ['A', 'B'],
57
- series: [
58
- { label: 'rev', values: [100, 200], type: 'bar', axis: 'left' },
59
- { label: 'pct', values: [0.4, 0.9], type: 'line', axis: 'right' },
60
- ],
61
- });
62
- expect(g.bars.length).toBe(2);
63
- expect(g.lines.length).toBe(1);
64
- expect(g.hasRightAxis).toBe(true);
65
- expect(g.y2Ticks.length).toBeGreaterThan(1);
66
- });
67
- it('line: a path through every point, area closes when type=area', () => {
68
- const line = buildChart({ type: 'line', categories: ['A', 'B', 'C'], series: [{ label: 's', values: [1, 2, 3] }] });
69
- expect(line.lines[0].path.startsWith('M')).toBe(true);
70
- expect(line.lines[0].areaPath).toBe('');
71
- expect(line.lines[0].label).toBe('s');
72
- expect(line.lines[0].points.map((p) => p.value)).toEqual([1, 2, 3]);
73
- const area = buildChart({ type: 'area', categories: ['A', 'B'], series: [{ label: 's', values: [1, 2] }] });
74
- expect(area.lines[0].areaPath.endsWith('Z')).toBe(true);
75
- });
76
- it('line: null / NaN values break the line (gap) and drop the dot', () => {
77
- const g = buildChart({ type: 'line', categories: ['A', 'B', 'C', 'D'], series: [{ label: 's', values: [1, NaN, 3, 4] }] });
78
- const pts = g.lines[0].points;
79
- expect(pts.map((p) => p.defined)).toEqual([true, false, true, true]);
80
- // a gap => a second "move" command, so the path has two M's
81
- expect((g.lines[0].path.match(/M/g) ?? []).length).toBe(2);
82
- });
83
- it('area: a gap splits the fill into separate closed polygons', () => {
84
- const g = buildChart({ type: 'area', categories: ['A', 'B', 'C', 'D'], series: [{ label: 's', values: [2, NaN, 4, 5] }] });
85
- expect((g.lines[0].areaPath.match(/Z/g) ?? []).length).toBe(2);
86
- });
87
- it('axis titles reserve gutter space', () => {
88
- const plain = buildChart({ type: 'bar', categories: ['A'], series: [{ label: 's', values: [1] }] });
89
- const titled = buildChart({ type: 'bar', categories: ['A'], series: [{ label: 's', values: [1] }], yAxisTitle: 'Revenue', xAxisTitle: 'Region' });
90
- expect(titled.plot.x).toBeGreaterThan(plain.plot.x); // left gutter wider for the y title
91
- expect(titled.plot.h).toBeLessThan(plain.plot.h); // bottom gutter wider for the x title
92
- });
93
- it('pie: slice percents sum to ~100, slices have a centroid', () => {
94
- const g = buildChart({ type: 'pie', categories: ['A', 'B', 'C'], series: [{ label: 's', values: [1, 1, 2] }] });
95
- expect(g.slices).toHaveLength(3);
96
- expect(g.slices.reduce((a, s) => a + s.percent, 0)).toBeCloseTo(100);
97
- expect(g.slices[2].percent).toBeCloseTo(50);
98
- expect(Number.isFinite(g.slices[0].cx)).toBe(true);
99
- expect(g.donut).toBeNull();
100
- });
101
- it('donut: innerRadius produces a centre with the total', () => {
102
- const g = buildChart({ type: 'pie', innerRadius: 0.6, categories: ['A', 'B'], series: [{ label: 's', values: [3, 7] }] });
103
- expect(g.donut).not.toBeNull();
104
- expect(g.donut.total).toBe(10);
105
- });
106
- it('rotates x labels when there are many / long categories', () => {
107
- const many = buildChart({ type: 'bar', categories: Array.from({ length: 12 }, (_, i) => `Cat ${i}`), series: [{ label: 's', values: Array(12).fill(1) }] });
108
- expect(many.xLabelRotated).toBe(true);
109
- const few = buildChart({ type: 'bar', categories: ['A', 'B'], series: [{ label: 's', values: [1, 2] }] });
110
- expect(few.xLabelRotated).toBe(false);
111
- });
112
- it('assigns palette colors when series omit color', () => {
113
- const g = buildChart({ type: 'bar', categories: ['A'], series: [{ label: 'x', values: [1] }, { label: 'y', values: [2] }] });
114
- expect(g.legend[0].color).not.toBe(g.legend[1].color);
115
- });
116
- it('reference line: a horizontal line at the value, included in the domain', () => {
117
- const g = buildChart({
118
- type: 'bar',
119
- categories: ['A', 'B'],
120
- series: [{ label: 's', values: [10, 20] }],
121
- referenceLines: [{ value: 25, label: 'Target' }],
122
- });
123
- expect(g.referenceLines).toHaveLength(1);
124
- expect(g.referenceLines[0].label).toBe('Target');
125
- // domain stretched to include the reference value above the data max
126
- expect(g.yTicks[g.yTicks.length - 1].value).toBeGreaterThanOrEqual(25);
127
- });
128
- it('stacked100: each category fills the full plot height (0..100 axis)', () => {
129
- const g = buildChart({
130
- type: 'bar',
131
- stacked100: true,
132
- categories: ['A'],
133
- series: [
134
- { label: 'x', values: [1] },
135
- { label: 'y', values: [3] },
136
- ],
137
- });
138
- expect(g.yTicks.map((t) => t.value)).toContain(100);
139
- // two stacked segments whose heights sum to ~ the plot height
140
- const sum = g.bars.reduce((a, b) => a + b.h, 0);
141
- expect(sum).toBeCloseTo(g.plot.h, 0);
142
- // values stay the originals (not the normalized %)
143
- expect(g.bars.map((b) => b.value).sort()).toEqual([1, 3]);
144
- });
145
- it('stacked100 area: the top series reaches the 100% line, not the raw total', () => {
146
- const g = buildChart({
147
- type: 'area',
148
- stacked100: true,
149
- categories: ['A', 'B'],
150
- series: [
151
- { label: 'x', values: [200, 600] },
152
- { label: 'y', values: [600, 200] },
153
- ],
154
- });
155
- const y100 = g.yTicks.find((t) => t.value === 100).y;
156
- const y0 = g.yTicks.find((t) => t.value === 0).y;
157
- // top of the (cumulative) second area sits at the 100% gridline for every category
158
- const topPts = g.lines[1].points;
159
- for (const p of topPts)
160
- expect(p.y).toBeCloseTo(y100, 0);
161
- // and the stack stays within the plot (never below the 0 baseline)
162
- for (const l of g.lines)
163
- for (const p of l.points)
164
- expect(p.y).toBeGreaterThanOrEqual(y100 - 0.5);
165
- expect(y100).toBeLessThan(y0); // 100% is above 0 on screen
166
- });
167
- it('scatter: one dot per point, bubble radius scales with r', () => {
168
- const g = buildChart({
169
- type: 'scatter',
170
- categories: [],
171
- series: [
172
- { label: 'pts', values: [], points: [{ x: 1, y: 1, r: 1 }, { x: 5, y: 8, r: 10 }, { x: 3, y: 4, r: 5 }] },
173
- ],
174
- });
175
- expect(g.scatterPoints).toHaveLength(3);
176
- const byR = [...g.scatterPoints].sort((a, b) => a.r - b.r);
177
- expect(byR[0].r).toBeLessThan(byR[2].r); // bigger r => bigger bubble
178
- expect(g.xTicks.length).toBeGreaterThan(1);
179
- expect(g.yTicks.length).toBeGreaterThan(1);
180
- });
181
- it('horizontal bars: bars grow along x, categories run down the y axis', () => {
182
- const g = buildChart({
183
- type: 'bar',
184
- orientation: 'horizontal',
185
- categories: ['A', 'B'],
186
- series: [{ label: 's', values: [10, 30] }],
187
- width: 400,
188
- height: 200,
189
- });
190
- expect(g.orientation).toBe('horizontal');
191
- expect(g.bars).toHaveLength(2);
192
- // bigger value => wider bar (grows along x)
193
- expect(g.bars[1].w).toBeGreaterThan(g.bars[0].w);
194
- // bars share a left baseline x (value 0), differ in y (one per category band)
195
- expect(g.bars[0].x).toBeCloseTo(g.bars[1].x, 1);
196
- expect(g.bars[0].y).not.toBe(g.bars[1].y);
197
- // category labels live on the left axis, value ticks along the bottom
198
- expect(g.catTicks.map((t) => t.label)).toEqual(['A', 'B']);
199
- expect(g.valueTicks.length).toBeGreaterThan(1);
200
- });
201
- it('horizontal bars: a reference line becomes a vertical line', () => {
202
- const g = buildChart({
203
- type: 'bar',
204
- orientation: 'horizontal',
205
- categories: ['A'],
206
- series: [{ label: 's', values: [10] }],
207
- referenceLines: [{ value: 20, label: 'Goal' }],
208
- });
209
- expect(g.referenceLines).toHaveLength(0);
210
- expect(g.referenceLinesV).toHaveLength(1);
211
- expect(g.referenceLinesV[0].label).toBe('Goal');
212
- expect(Number.isFinite(g.referenceLinesV[0].x)).toBe(true);
213
- });
214
- it('horizontal falls back to vertical when a series is not a bar (combo)', () => {
215
- const g = buildChart({
216
- type: 'bar',
217
- orientation: 'horizontal',
218
- categories: ['A', 'B'],
219
- series: [
220
- { label: 'bar', values: [1, 2] },
221
- { label: 'line', values: [3, 4], type: 'line' },
222
- ],
223
- });
224
- expect(g.orientation).toBe('vertical');
225
- });
226
- it('time axis: irregular date gaps map to proportional x positions', () => {
227
- const g = buildChart({
228
- type: 'line',
229
- xType: 'time',
230
- categories: ['2024-01-01', '2024-01-02', '2024-02-01'],
231
- series: [{ label: 's', values: [1, 2, 3] }],
232
- });
233
- const xs = g.lines[0].points.map((p) => p.x);
234
- // gap 1->2 (1 day) is far smaller than gap 2->3 (31 days)
235
- expect(xs[1] - xs[0]).toBeLessThan(xs[2] - xs[1]);
236
- expect(g.xLabelRotated).toBe(false);
237
- });
238
- });
239
- describe('rowsToChartSpec', () => {
240
- const rows = [
241
- { region: 'EMEA', product: 'A', revenue: 100, cost: 60 },
242
- { region: 'EMEA', product: 'B', revenue: 50, cost: 20 },
243
- { region: 'APAC', product: 'A', revenue: 200, cost: 90 },
244
- ];
245
- it('groups by category and sums one value field', () => {
246
- const spec = rowsToChartSpec(rows, { type: 'bar', category: 'region', value: 'revenue' });
247
- expect(spec.categories).toEqual(['EMEA', 'APAC']);
248
- expect(spec.series).toHaveLength(1);
249
- expect(spec.series[0].values).toEqual([150, 200]);
250
- });
251
- it('multiple value fields => one series each', () => {
252
- const spec = rowsToChartSpec(rows, { type: 'bar', category: 'region', value: ['revenue', 'cost'] });
253
- expect(spec.series.map((s) => s.label)).toEqual(['revenue', 'cost']);
254
- expect(spec.series[1].values).toEqual([80, 90]);
255
- });
256
- it('series field => pivot into one series per distinct value', () => {
257
- const spec = rowsToChartSpec(rows, { type: 'bar', category: 'region', value: 'revenue', series: 'product' });
258
- expect(spec.series.map((s) => s.label).sort()).toEqual(['A', 'B']);
259
- const a = spec.series.find((s) => s.label === 'A');
260
- // EMEA/A = 100, APAC/A = 200
261
- expect(a.values).toEqual([100, 200]);
262
- });
263
- it('supports avg and count reducers', () => {
264
- expect(rowsToChartSpec(rows, { type: 'bar', category: 'region', value: 'revenue', reduce: 'avg' }).series[0].values).toEqual([75, 200]);
265
- expect(rowsToChartSpec(rows, { type: 'bar', category: 'region', value: 'revenue', reduce: 'count' }).series[0].values).toEqual([2, 1]);
266
- });
267
- it('sorts categories by total value descending', () => {
268
- const spec = rowsToChartSpec(rows, { type: 'bar', category: 'region', value: 'revenue', sort: 'value-desc' });
269
- // APAC (200) outranks EMEA (150)
270
- expect(spec.categories).toEqual(['APAC', 'EMEA']);
271
- expect(spec.series[0].values).toEqual([200, 150]);
272
- });
273
- it('topN buckets the remainder into an "Other" category', () => {
274
- const many = [
275
- { cat: 'A', v: 100 },
276
- { cat: 'B', v: 50 },
277
- { cat: 'C', v: 30 },
278
- { cat: 'D', v: 20 },
279
- ];
280
- const spec = rowsToChartSpec(many, { type: 'bar', category: 'cat', value: 'v', topN: 2 });
281
- expect(spec.categories).toEqual(['A', 'B', 'Other']);
282
- // Other = C + D = 50
283
- expect(spec.series[0].values).toEqual([100, 50, 50]);
284
- });
285
- it('stacked100 flag passes through to the spec', () => {
286
- const spec = rowsToChartSpec(rows, { type: 'bar', category: 'region', value: ['revenue', 'cost'], stacked100: true });
287
- expect(spec.stacked100).toBe(true);
288
- });
289
- });
@@ -1 +0,0 @@
1
- export {};