@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.
- package/dist/FlexRender.svelte +96 -96
- package/dist/SvGrid.controller.svelte.js +17 -6
- package/dist/SvGrid.css +2012 -2012
- package/dist/SvGrid.svelte +2571 -2346
- package/dist/SvGridDropdown.svelte +7 -3
- package/dist/build-api.js +2 -2
- package/dist/cdn/svgrid.js +13504 -0
- package/dist/cdn/svgrid.svelte-external.js +11188 -0
- package/dist/cell-values.d.ts +1 -1
- package/dist/cell-values.js +7 -7
- package/dist/column-types.js +1 -1
- package/dist/core.d.ts +1 -1
- package/dist/core.js +2 -2
- package/dist/summaries.js +4 -4
- package/package.json +12 -2
- package/src/FlexRender.svelte +96 -96
- package/src/SvGrid.controller.svelte.ts +2363 -2352
- package/src/SvGrid.css +2012 -2012
- package/src/SvGrid.svelte +2571 -2346
- package/src/SvGrid.types.ts +537 -537
- package/src/SvGridDropdown.svelte +7 -3
- package/src/a11y.contract.test.ts +49 -49
- package/src/a11y.test.ts +59 -59
- package/src/a11y.ts +59 -59
- package/src/build-api.ts +683 -683
- package/src/cell-formatting.ts +169 -169
- package/src/cell-values.ts +4 -4
- package/src/column-types.ts +1 -1
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1077 -1077
- package/src/createGrid.svelte.ts +42 -42
- package/src/createGrid.test.ts +10 -10
- package/src/createGridState.svelte.ts +17 -17
- package/src/editing.ts +669 -669
- package/src/flex-render.ts +3 -3
- package/src/index.ts +208 -208
- package/src/keyboard.test.ts +59 -59
- package/src/keyboard.ts +97 -97
- package/src/merge-objects.ts +48 -48
- package/src/render-component.ts +28 -28
- package/src/spreadsheet.test.ts +489 -489
- package/src/spreadsheet.ts +304 -304
- package/src/static-functions.ts +11 -11
- package/src/subscribe.ts +38 -38
- package/src/summaries.ts +4 -4
- package/src/svgrid-wrapper.types.ts +412 -412
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.wrapper.test.ts +40 -40
- package/src/virtualization/column-virtualizer.test.ts +27 -27
- package/src/virtualization/column-virtualizer.ts +30 -30
- package/src/virtualization/svelte-virtualizer.svelte.ts +26 -26
- package/src/virtualization/types.ts +30 -30
- package/src/virtualization/virtualizer.test.ts +47 -47
- package/src/virtualization/virtualizer.ts +296 -296
- package/dist/SvGrid.helpers.test.d.ts +0 -1
- package/dist/SvGrid.helpers.test.js +0 -298
- package/dist/SvGridChart.test.d.ts +0 -1
- package/dist/SvGridChart.test.js +0 -62
- package/dist/a11y.contract.test.d.ts +0 -1
- package/dist/a11y.contract.test.js +0 -39
- package/dist/a11y.test.d.ts +0 -1
- package/dist/a11y.test.js +0 -44
- package/dist/aligned-grids.test.d.ts +0 -1
- package/dist/aligned-grids.test.js +0 -75
- package/dist/build-api.coverage.test.d.ts +0 -20
- package/dist/build-api.coverage.test.js +0 -505
- package/dist/cell-formatting.test.d.ts +0 -1
- package/dist/cell-formatting.test.js +0 -234
- package/dist/cell-render.test.d.ts +0 -1
- package/dist/cell-render.test.js +0 -338
- package/dist/chart-export.test.d.ts +0 -1
- package/dist/chart-export.test.js +0 -302
- package/dist/chart.coverage.test.d.ts +0 -1
- package/dist/chart.coverage.test.js +0 -748
- package/dist/chart.test.d.ts +0 -1
- package/dist/chart.test.js +0 -289
- package/dist/clipboard.test.d.ts +0 -1
- package/dist/clipboard.test.js +0 -700
- package/dist/collaboration.coverage.test.d.ts +0 -1
- package/dist/collaboration.coverage.test.js +0 -200
- package/dist/collaboration.test.d.ts +0 -1
- package/dist/collaboration.test.js +0 -65
- package/dist/column-groups.test.d.ts +0 -1
- package/dist/column-groups.test.js +0 -56
- package/dist/column-types.test.d.ts +0 -1
- package/dist/column-types.test.js +0 -62
- package/dist/columns.test.d.ts +0 -1
- package/dist/columns.test.js +0 -625
- package/dist/conditional-formatting.test.d.ts +0 -1
- package/dist/conditional-formatting.test.js +0 -87
- package/dist/core.coverage.test.d.ts +0 -1
- package/dist/core.coverage.test.js +0 -186
- package/dist/core.performance.test.d.ts +0 -1
- package/dist/core.performance.test.js +0 -29
- package/dist/createGrid.test.d.ts +0 -1
- package/dist/createGrid.test.js +0 -9
- package/dist/editing.test.d.ts +0 -1
- package/dist/editing.test.js +0 -732
- package/dist/editors/cell-editors.coverage.test.d.ts +0 -1
- package/dist/editors/cell-editors.coverage.test.js +0 -139
- package/dist/editors/cell-editors.test.d.ts +0 -1
- package/dist/editors/cell-editors.test.js +0 -75
- package/dist/facet-buckets.test.d.ts +0 -1
- package/dist/facet-buckets.test.js +0 -296
- package/dist/fill-patterns.test.d.ts +0 -1
- package/dist/fill-patterns.test.js +0 -81
- package/dist/filter-operators.test.d.ts +0 -1
- package/dist/filter-operators.test.js +0 -135
- package/dist/filtering/excel-filters.test.d.ts +0 -1
- package/dist/filtering/excel-filters.test.js +0 -116
- package/dist/filtering/locale-filter.test.d.ts +0 -13
- package/dist/filtering/locale-filter.test.js +0 -189
- package/dist/flex-render.test.d.ts +0 -1
- package/dist/flex-render.test.js +0 -142
- package/dist/group-aggregate.test.d.ts +0 -1
- package/dist/group-aggregate.test.js +0 -32
- package/dist/hyperformula-adapter.test.d.ts +0 -1
- package/dist/hyperformula-adapter.test.js +0 -205
- package/dist/keyboard-handlers.coverage.test.d.ts +0 -1
- package/dist/keyboard-handlers.coverage.test.js +0 -495
- package/dist/keyboard.test.d.ts +0 -1
- package/dist/keyboard.test.js +0 -27
- package/dist/menus.test.d.ts +0 -1
- package/dist/menus.test.js +0 -560
- package/dist/named-views.coverage.test.d.ts +0 -1
- package/dist/named-views.coverage.test.js +0 -180
- package/dist/named-views.test.d.ts +0 -1
- package/dist/named-views.test.js +0 -57
- package/dist/new-features.test.d.ts +0 -1
- package/dist/new-features.test.js +0 -183
- package/dist/render-component.test.d.ts +0 -1
- package/dist/render-component.test.js +0 -41
- package/dist/row-drag.test.d.ts +0 -1
- package/dist/row-drag.test.js +0 -142
- package/dist/row-resize.test.d.ts +0 -1
- package/dist/row-resize.test.js +0 -329
- package/dist/scroll-sync.test.d.ts +0 -1
- package/dist/scroll-sync.test.js +0 -290
- package/dist/selection.multi-range.test.d.ts +0 -1
- package/dist/selection.multi-range.test.js +0 -55
- package/dist/selection.test.d.ts +0 -1
- package/dist/selection.test.js +0 -647
- package/dist/server-data-source.coverage.test.d.ts +0 -1
- package/dist/server-data-source.coverage.test.js +0 -154
- package/dist/server-data-source.test.d.ts +0 -1
- package/dist/server-data-source.test.js +0 -81
- package/dist/sparkline.test.d.ts +0 -1
- package/dist/sparkline.test.js +0 -52
- package/dist/spreadsheet.test.d.ts +0 -1
- package/dist/spreadsheet.test.js +0 -446
- package/dist/subscribe.test.d.ts +0 -1
- package/dist/subscribe.test.js +0 -93
- package/dist/svgrid.api-extensions.test.d.ts +0 -14
- package/dist/svgrid.api-extensions.test.js +0 -334
- package/dist/svgrid.api.test.d.ts +0 -15
- package/dist/svgrid.api.test.js +0 -169
- package/dist/svgrid.behavior.test.d.ts +0 -15
- package/dist/svgrid.behavior.test.js +0 -625
- package/dist/svgrid.column-reorder.test.d.ts +0 -15
- package/dist/svgrid.column-reorder.test.js +0 -224
- package/dist/svgrid.comments-autocomplete.test.d.ts +0 -1
- package/dist/svgrid.comments-autocomplete.test.js +0 -96
- package/dist/svgrid.context-menu.test.d.ts +0 -1
- package/dist/svgrid.context-menu.test.js +0 -102
- package/dist/svgrid.features.test.d.ts +0 -1
- package/dist/svgrid.features.test.js +0 -129
- package/dist/svgrid.interaction.test.d.ts +0 -9
- package/dist/svgrid.interaction.test.js +0 -349
- package/dist/svgrid.locale-filtering.test.d.ts +0 -15
- package/dist/svgrid.locale-filtering.test.js +0 -261
- package/dist/svgrid.new-features.wrapper.test.d.ts +0 -1
- package/dist/svgrid.new-features.wrapper.test.js +0 -194
- package/dist/svgrid.row-pinning.test.d.ts +0 -14
- package/dist/svgrid.row-pinning.test.js +0 -250
- package/dist/svgrid.set-filter.test.d.ts +0 -17
- package/dist/svgrid.set-filter.test.js +0 -268
- package/dist/svgrid.wrapper.test.d.ts +0 -1
- package/dist/svgrid.wrapper.test.js +0 -59
- package/dist/test-setup.d.ts +0 -1
- package/dist/test-setup.js +0 -35
- package/dist/transaction.test.d.ts +0 -1
- package/dist/transaction.test.js +0 -89
- package/dist/virtualization/column-virtualizer.test.d.ts +0 -1
- package/dist/virtualization/column-virtualizer.test.js +0 -25
- package/dist/virtualization/scroll-scaling.test.d.ts +0 -1
- package/dist/virtualization/scroll-scaling.test.js +0 -127
- package/dist/virtualization/virtualizer.test.d.ts +0 -1
- package/dist/virtualization/virtualizer.test.js +0 -41
package/dist/chart.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/dist/chart.test.js
DELETED
|
@@ -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
|
-
});
|
package/dist/clipboard.test.d.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|