@blotch/dolan 22.2.1 → 22.2.3
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/commands/add.d.ts +6 -2
- package/dist/commands/add.js +32 -10
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/add.test.js +129 -9
- package/dist/commands/add.test.js.map +1 -1
- package/dist/commands/diff.d.ts +2 -1
- package/dist/commands/diff.js +38 -25
- package/dist/commands/diff.js.map +1 -1
- package/dist/commands/diff.test.js +72 -11
- package/dist/commands/diff.test.js.map +1 -1
- package/dist/commands/doctor.js +41 -27
- package/dist/commands/doctor.js.map +1 -1
- package/dist/commands/doctor.test.js +93 -9
- package/dist/commands/doctor.test.js.map +1 -1
- package/dist/commands/eject.js +7 -0
- package/dist/commands/eject.js.map +1 -1
- package/dist/commands/eject.test.js +39 -0
- package/dist/commands/eject.test.js.map +1 -1
- package/dist/commands/info.js +3 -2
- package/dist/commands/info.js.map +1 -1
- package/dist/commands/init.d.ts +37 -1
- package/dist/commands/init.js +149 -40
- package/dist/commands/init.js.map +1 -1
- package/dist/commands/init.test.js +285 -26
- package/dist/commands/init.test.js.map +1 -1
- package/dist/commands/install-packages.d.ts +6 -0
- package/dist/commands/install-packages.js +20 -0
- package/dist/commands/install-packages.js.map +1 -0
- package/dist/commands/install-packages.test.d.ts +1 -0
- package/dist/commands/install-packages.test.js +55 -0
- package/dist/commands/install-packages.test.js.map +1 -0
- package/dist/commands/list.js +21 -14
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/list.test.js +62 -5
- package/dist/commands/list.test.js.map +1 -1
- package/dist/commands/outdated.js +11 -10
- package/dist/commands/outdated.js.map +1 -1
- package/dist/commands/outdated.test.js +20 -5
- package/dist/commands/outdated.test.js.map +1 -1
- package/dist/commands/remove.d.ts +4 -0
- package/dist/commands/remove.js +17 -4
- package/dist/commands/remove.js.map +1 -1
- package/dist/commands/remove.test.js +53 -2
- package/dist/commands/remove.test.js.map +1 -1
- package/dist/commands/update.d.ts +6 -0
- package/dist/commands/update.js +59 -24
- package/dist/commands/update.js.map +1 -1
- package/dist/commands/update.test.js +273 -31
- package/dist/commands/update.test.js.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +8 -0
- package/dist/registry.js +32 -24
- package/dist/registry.js.map +1 -1
- package/dist/registry.test.js +76 -37
- package/dist/registry.test.js.map +1 -1
- package/dist/testing/set-input-signal.d.ts +13 -0
- package/dist/testing/set-input-signal.js +20 -0
- package/dist/testing/set-input-signal.js.map +1 -0
- package/dist/testing/set-input-signal.test.d.ts +1 -0
- package/dist/testing/set-input-signal.test.js +20 -0
- package/dist/testing/set-input-signal.test.js.map +1 -0
- package/dist/ui/components/action-sheet/action-sheet.test.ts +48 -1
- package/dist/ui/components/action-sheet/action-sheet.ts +37 -9
- package/dist/ui/components/alert-dialog/alert-dialog.test.ts +49 -2
- package/dist/ui/components/alert-dialog/alert-dialog.ts +43 -12
- package/dist/ui/components/area-chart/area-chart-render.test.ts +52 -110
- package/dist/ui/components/area-chart/area-chart.test.ts +59 -146
- package/dist/ui/components/area-chart/area-chart.ts +100 -315
- package/dist/ui/components/area-chart/index.ts +2 -3
- package/dist/ui/components/bar-chart/bar-chart-render.test.ts +47 -163
- package/dist/ui/components/bar-chart/bar-chart.test.ts +82 -58
- package/dist/ui/components/bar-chart/bar-chart.ts +140 -294
- package/dist/ui/components/bar-chart/index.ts +3 -3
- package/dist/ui/components/bottom-sheet/bottom-sheet.test.ts +191 -9
- package/dist/ui/components/bottom-sheet/bottom-sheet.ts +136 -20
- package/dist/ui/components/button/button-render.test.ts +19 -0
- package/dist/ui/components/button/button.test.ts +2 -15
- package/dist/ui/components/button/button.ts +18 -2
- package/dist/ui/components/button-group/button-group.test.ts +2 -21
- package/dist/ui/components/candlestick-chart/candlestick-chart-render.test.ts +48 -163
- package/dist/ui/components/candlestick-chart/candlestick-chart.test.ts +107 -85
- package/dist/ui/components/candlestick-chart/candlestick-chart.ts +150 -323
- package/dist/ui/components/candlestick-chart/index.ts +3 -4
- package/dist/ui/components/chart/chart-focus.test.ts +132 -0
- package/dist/ui/components/chart/chart-focus.ts +115 -0
- package/dist/ui/components/chart/chart-presets.test.ts +139 -0
- package/dist/ui/components/chart/chart-presets.ts +271 -0
- package/dist/ui/components/chart/chart-render.test.ts +730 -0
- package/dist/ui/components/chart/chart-scene.test.ts +589 -0
- package/dist/ui/components/chart/chart-scene.ts +483 -0
- package/dist/ui/components/chart/chart-theme.test.ts +85 -0
- package/dist/ui/components/chart/chart-theme.ts +198 -0
- package/dist/ui/components/chart/chart-zoom.test.ts +159 -0
- package/dist/ui/components/chart/chart-zoom.ts +162 -0
- package/dist/ui/components/chart/chart.ts +921 -0
- package/dist/ui/components/chart/index.ts +24 -0
- package/dist/ui/components/dialog/dialog.test.ts +49 -2
- package/dist/ui/components/dialog/dialog.ts +43 -12
- package/dist/ui/components/icon/icon-theme.test.ts +133 -0
- package/dist/ui/components/icon/icon-theme.ts +204 -0
- package/dist/ui/components/icon/icon.test.ts +51 -2
- package/dist/ui/components/icon/icon.ts +38 -21
- package/dist/ui/components/line-chart/index.ts +2 -3
- package/dist/ui/components/line-chart/line-chart-render.test.ts +69 -107
- package/dist/ui/components/line-chart/line-chart.test.ts +63 -67
- package/dist/ui/components/line-chart/line-chart.ts +83 -241
- package/dist/ui/components/list/list.test.ts +69 -2
- package/dist/ui/components/list/list.ts +21 -15
- package/dist/ui/components/nav-drawer/nav-drawer.test.ts +80 -1
- package/dist/ui/components/nav-drawer/nav-drawer.ts +66 -11
- package/dist/ui/components/pagination/pagination.test.ts +62 -0
- package/dist/ui/components/pagination/pagination.ts +55 -8
- package/dist/ui/components/scatter-chart/index.ts +2 -3
- package/dist/ui/components/scatter-chart/scatter-chart-render.test.ts +51 -144
- package/dist/ui/components/scatter-chart/scatter-chart.test.ts +57 -47
- package/dist/ui/components/scatter-chart/scatter-chart.ts +104 -250
- package/dist/ui/components/scroll-area/scroll-area.test.ts +37 -2
- package/dist/ui/components/scroll-area/scroll-area.ts +8 -8
- package/dist/ui/components/spinner/spinner.test.ts +27 -0
- package/dist/ui/components/spinner/spinner.ts +33 -23
- package/dist/ui/components/toast/toast.test.ts +37 -0
- package/dist/ui/components/toast/toast.ts +20 -4
- package/dist/ui/theme/chart-colors.test.ts +30 -0
- package/dist/ui/theme/dark.css +8 -0
- package/dist/ui/theme/default.css +8 -0
- package/dist/ui/theme/icon-colors.test.ts +30 -0
- package/dist/ui/theme/tailwind-plugin.ts +10 -1
- package/dist/utils/installed.d.ts +17 -0
- package/dist/utils/installed.js +27 -0
- package/dist/utils/installed.js.map +1 -0
- package/dist/utils/installed.test.d.ts +1 -0
- package/dist/utils/installed.test.js +41 -0
- package/dist/utils/installed.test.js.map +1 -0
- package/dist/utils/interactive.d.ts +9 -0
- package/dist/utils/interactive.js +10 -0
- package/dist/utils/interactive.js.map +1 -0
- package/dist/utils/interactive.test.d.ts +1 -0
- package/dist/utils/interactive.test.js +24 -0
- package/dist/utils/interactive.test.js.map +1 -0
- package/dist/utils/packages.d.ts +36 -0
- package/dist/utils/packages.js +70 -0
- package/dist/utils/packages.js.map +1 -0
- package/dist/utils/packages.test.d.ts +1 -0
- package/dist/utils/packages.test.js +89 -0
- package/dist/utils/packages.test.js.map +1 -0
- package/dist/utils/resolve-paths.d.ts +17 -1
- package/dist/utils/resolve-paths.js +23 -3
- package/dist/utils/resolve-paths.js.map +1 -1
- package/dist/utils/resolve-paths.test.js +34 -2
- package/dist/utils/resolve-paths.test.js.map +1 -1
- package/package.json +5 -1
- package/dist/ui/components/cartesian-chart/cartesian-chart-render.test.ts +0 -188
- package/dist/ui/components/cartesian-chart/cartesian-chart.test.ts +0 -549
- package/dist/ui/components/cartesian-chart/cartesian-chart.ts +0 -1140
- package/dist/ui/components/cartesian-chart/index.ts +0 -18
|
@@ -1,174 +1,58 @@
|
|
|
1
|
-
import { render
|
|
1
|
+
import { render } from '@blotch/angular-lynx-testing-library';
|
|
2
|
+
import { createChartRuntime } from '@tanstack/charts/runtime';
|
|
3
|
+
import type {
|
|
4
|
+
ChartDefinition,
|
|
5
|
+
ChartPoint,
|
|
6
|
+
SceneNode,
|
|
7
|
+
SceneRect,
|
|
8
|
+
} from '@tanstack/charts/types';
|
|
2
9
|
import { describe, expect, it, vi } from 'vitest';
|
|
3
10
|
import { setInputSignal } from '../../../test-utils/set-input-signal';
|
|
4
|
-
import {
|
|
5
|
-
|
|
11
|
+
import { UiBarChart } from './bar-chart';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Every bar in a definition's scene.
|
|
15
|
+
*/
|
|
16
|
+
const bars = (definition: ChartDefinition<any, any, any>) => {
|
|
17
|
+
const scene = createChartRuntime().render(definition, {
|
|
18
|
+
width: 300,
|
|
19
|
+
height: 200,
|
|
20
|
+
});
|
|
21
|
+
const found: SceneRect[] = [];
|
|
22
|
+
const walk = (nodes: readonly SceneNode[]) => {
|
|
23
|
+
for (const node of nodes) {
|
|
24
|
+
if (node.kind === 'group') {
|
|
25
|
+
if (!node.focus) walk(node.children);
|
|
26
|
+
} else if (node.kind === 'rect') found.push(node);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
walk(scene.nodes);
|
|
30
|
+
return { scene, found };
|
|
31
|
+
};
|
|
6
32
|
|
|
7
33
|
describe('UiBarChart', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
it('folds the baseline into the y-axis domain', async () => {
|
|
14
|
-
const { componentRef } = await render(UiBarChart);
|
|
15
|
-
const inst = componentRef.instance as UiBarChart;
|
|
16
|
-
setInputSignal(inst.data, [
|
|
17
|
-
{ x: 0, y: 5 },
|
|
18
|
-
{ x: 1, y: 10 },
|
|
19
|
-
{ x: 2, y: 8 },
|
|
20
|
-
]);
|
|
21
|
-
setInputSignal(inst.baseline, 0);
|
|
22
|
-
await waitForUpdate();
|
|
23
|
-
const cast = inst as unknown as {
|
|
24
|
-
xAxis: () => { domain: readonly [number, number] };
|
|
25
|
-
yAxis: () => { domain: readonly [number, number] };
|
|
26
|
-
effectivePadding: () => { left?: number; right?: number };
|
|
27
|
-
};
|
|
28
|
-
expect(cast.yAxis().domain[0]).toBeLessThanOrEqual(0);
|
|
29
|
-
expect(cast.yAxis().domain[1]).toBeGreaterThanOrEqual(10);
|
|
30
|
-
// 3 bars → half-bar inset = 0.5 / (3-1) = 0.25
|
|
31
|
-
expect(cast.effectivePadding().left).toBeCloseTo(0.25);
|
|
32
|
-
expect(cast.effectivePadding().right).toBeCloseTo(0.25);
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('honors explicit xMin / xMax / yMin / yMax overrides', async () => {
|
|
36
|
-
const { componentRef } = await render(UiBarChart);
|
|
37
|
-
const inst = componentRef.instance as UiBarChart;
|
|
38
|
-
setInputSignal(inst.data, [
|
|
39
|
-
{ x: 0, y: 0 },
|
|
40
|
-
{ x: 10, y: 10 },
|
|
41
|
-
]);
|
|
42
|
-
setInputSignal(inst.xMin, -5);
|
|
43
|
-
setInputSignal(inst.xMax, 20);
|
|
44
|
-
setInputSignal(inst.yMin, -1);
|
|
45
|
-
setInputSignal(inst.yMax, 15);
|
|
46
|
-
await waitForUpdate();
|
|
47
|
-
const cast = inst as unknown as {
|
|
48
|
-
xAxis: () => { domain: readonly [number, number] };
|
|
49
|
-
yAxis: () => { domain: readonly [number, number] };
|
|
50
|
-
};
|
|
51
|
-
expect(cast.xAxis().domain[0]).toBeLessThanOrEqual(-5);
|
|
52
|
-
expect(cast.xAxis().domain[1]).toBeGreaterThanOrEqual(20);
|
|
53
|
-
expect(cast.yAxis().domain[0]).toBeLessThanOrEqual(-1);
|
|
54
|
-
expect(cast.yAxis().domain[1]).toBeGreaterThanOrEqual(15);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
it('single-datum series drops the half-bar padding', async () => {
|
|
58
|
-
const { componentRef } = await render(UiBarChart);
|
|
59
|
-
const inst = componentRef.instance as UiBarChart;
|
|
60
|
-
setInputSignal(inst.data, [{ x: 0, y: 5 }]);
|
|
61
|
-
await waitForUpdate();
|
|
62
|
-
const cast = inst as unknown as {
|
|
63
|
-
effectivePadding: () => { left?: number; right?: number };
|
|
64
|
-
};
|
|
65
|
-
// n === 1 → half === 0
|
|
66
|
-
expect(cast.effectivePadding().left).toBe(0);
|
|
67
|
-
expect(cast.effectivePadding().right).toBe(0);
|
|
68
|
-
});
|
|
34
|
+
type Internals = {
|
|
35
|
+
definition: () => ChartDefinition<any, any, any>;
|
|
36
|
+
onSelect(point: ChartPoint | null): void;
|
|
37
|
+
};
|
|
69
38
|
|
|
70
|
-
it('
|
|
39
|
+
it('builds its definition from its inputs', async () => {
|
|
71
40
|
const { componentRef } = await render(UiBarChart);
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
|
|
41
|
+
const chart = componentRef.instance as UiBarChart;
|
|
42
|
+
setInputSignal(chart.data, [{ x: 'a', y: 1 }]);
|
|
43
|
+
setInputSignal(chart.color, 'red');
|
|
44
|
+
const { found } = bars((chart as unknown as Internals).definition());
|
|
45
|
+
expect(found[0]!.style?.fill).toBe('red');
|
|
75
46
|
});
|
|
76
47
|
|
|
77
|
-
it('
|
|
48
|
+
it('emits the tapped datum', async () => {
|
|
78
49
|
const { componentRef } = await render(UiBarChart);
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const cast = inst as unknown as {
|
|
87
|
-
effectivePadding: () => { left?: number; right?: number };
|
|
88
|
-
};
|
|
89
|
-
// left explicitly set → wins; right still auto = 0.5
|
|
90
|
-
expect(cast.effectivePadding().left).toBeCloseTo(0.1);
|
|
91
|
-
expect(cast.effectivePadding().right).toBeCloseTo(0.5);
|
|
92
|
-
});
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
describe('UiBarSeries', () => {
|
|
96
|
-
const renderSeries = async () => {
|
|
97
|
-
const parentResult = await render(UiCartesianChart);
|
|
98
|
-
const parent = parentResult.componentRef.instance as UiCartesianChart;
|
|
99
|
-
setInputSignal(parent.xDomain, [0, 10]);
|
|
100
|
-
setInputSignal(parent.yDomain, [0, 10]);
|
|
101
|
-
await waitForUpdate();
|
|
102
|
-
const seriesResult = await render(UiBarSeries, {
|
|
103
|
-
providers: [{ provide: UiCartesianChart, useValue: parent }],
|
|
104
|
-
});
|
|
105
|
-
const series = seriesResult.componentRef.instance as UiBarSeries;
|
|
106
|
-
setInputSignal(series.data, [
|
|
107
|
-
{ x: 0, y: 2 },
|
|
108
|
-
{ x: 5, y: 8 },
|
|
109
|
-
{ x: 10, y: 5 },
|
|
110
|
-
]);
|
|
111
|
-
await waitForUpdate();
|
|
112
|
-
return { parent, series };
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
it('renders a rectangle per datum with the fallback color', async () => {
|
|
116
|
-
const { series } = await renderSeries();
|
|
117
|
-
const cast = series as unknown as {
|
|
118
|
-
bars: () => { style: string; point: { x: number; y: number } }[];
|
|
119
|
-
};
|
|
120
|
-
const bars = cast.bars();
|
|
121
|
-
expect(bars.length).toBe(3);
|
|
122
|
-
for (const b of bars) {
|
|
123
|
-
expect(b.style).toContain('background-color: var(--primary)');
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it('cycles through the per-bar palette when colors are provided', async () => {
|
|
128
|
-
const { series } = await renderSeries();
|
|
129
|
-
setInputSignal(series.colors, ['#f00', '#0f0']);
|
|
130
|
-
await waitForUpdate();
|
|
131
|
-
const cast = series as unknown as { bars: () => { style: string }[] };
|
|
132
|
-
const bars = cast.bars();
|
|
133
|
-
expect(bars[0].style).toContain('#f00');
|
|
134
|
-
expect(bars[1].style).toContain('#0f0');
|
|
135
|
-
// wraps around
|
|
136
|
-
expect(bars[2].style).toContain('#f00');
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('emits barTap with the source point when a bar is tapped', async () => {
|
|
140
|
-
const { series } = await renderSeries();
|
|
141
|
-
const cb = vi.fn();
|
|
142
|
-
series.barTap.subscribe(cb);
|
|
143
|
-
(
|
|
144
|
-
series as unknown as { onBarTap: (p: { x: number; y: number }) => void }
|
|
145
|
-
).onBarTap({ x: 1, y: 2 });
|
|
146
|
-
expect(cb).toHaveBeenCalledWith({ x: 1, y: 2 });
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
it('single-datum series uses the fallback bar width', async () => {
|
|
150
|
-
const parentResult = await render(UiCartesianChart);
|
|
151
|
-
const parent = parentResult.componentRef.instance as UiCartesianChart;
|
|
152
|
-
setInputSignal(parent.xDomain, [0, 10]);
|
|
153
|
-
setInputSignal(parent.yDomain, [0, 10]);
|
|
154
|
-
await waitForUpdate();
|
|
155
|
-
const seriesResult = await render(UiBarSeries, {
|
|
156
|
-
providers: [{ provide: UiCartesianChart, useValue: parent }],
|
|
157
|
-
});
|
|
158
|
-
const series = seriesResult.componentRef.instance as UiBarSeries;
|
|
159
|
-
setInputSignal(series.data, [{ x: 5, y: 5 }]);
|
|
160
|
-
await waitForUpdate();
|
|
161
|
-
const cast = series as unknown as { bars: () => { style: string }[] };
|
|
162
|
-
const [bar] = cast.bars();
|
|
163
|
-
// fallback = 24px
|
|
164
|
-
expect(bar.style).toContain('width: 24.00px');
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it('clamps the baseline into the plot when it lies outside the domain', async () => {
|
|
168
|
-
const { series } = await renderSeries();
|
|
169
|
-
setInputSignal(series.baseline, 999);
|
|
170
|
-
await waitForUpdate();
|
|
171
|
-
const cast = series as unknown as { bars: () => { style: string }[] };
|
|
172
|
-
expect(cast.bars().length).toBe(3);
|
|
50
|
+
const chart = componentRef.instance as UiBarChart;
|
|
51
|
+
const tapped = vi.fn();
|
|
52
|
+
chart.barTap.subscribe(tapped);
|
|
53
|
+
const internals = chart as unknown as Internals;
|
|
54
|
+
internals.onSelect({ datum: { x: 'a', y: 1 } } as ChartPoint);
|
|
55
|
+
internals.onSelect(null);
|
|
56
|
+
expect(tapped.mock.calls).toEqual([[{ x: 'a', y: 1 }]]);
|
|
173
57
|
});
|
|
174
58
|
});
|
|
@@ -1,73 +1,97 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createChartRuntime } from '@tanstack/charts/runtime';
|
|
2
|
+
import type {
|
|
3
|
+
ChartDefinition,
|
|
4
|
+
SceneNode,
|
|
5
|
+
SceneRect,
|
|
6
|
+
} from '@tanstack/charts/types';
|
|
7
|
+
import { describe, expect, it } from 'vitest';
|
|
8
|
+
import { barChartDefinition } from './bar-chart';
|
|
2
9
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}));
|
|
10
|
+
/**
|
|
11
|
+
* Every bar in a definition's scene.
|
|
12
|
+
*/
|
|
13
|
+
const bars = (definition: ChartDefinition<any, any, any>) => {
|
|
14
|
+
const scene = createChartRuntime().render(definition, {
|
|
15
|
+
width: 300,
|
|
16
|
+
height: 200,
|
|
17
|
+
});
|
|
18
|
+
const found: SceneRect[] = [];
|
|
19
|
+
const walk = (nodes: readonly SceneNode[]) => {
|
|
20
|
+
for (const node of nodes) {
|
|
21
|
+
if (node.kind === 'group') {
|
|
22
|
+
if (!node.focus) walk(node.children);
|
|
23
|
+
} else if (node.kind === 'rect') found.push(node);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
walk(scene.nodes);
|
|
27
|
+
return { scene, found };
|
|
28
|
+
};
|
|
23
29
|
|
|
24
|
-
|
|
30
|
+
describe('barChartDefinition', () => {
|
|
31
|
+
const week = [
|
|
32
|
+
{ x: 'Mon', y: 5 },
|
|
33
|
+
{ x: 'Tue', y: 8 },
|
|
34
|
+
{ x: 'Wed', y: 3 },
|
|
35
|
+
];
|
|
25
36
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
expect(
|
|
33
|
-
expect(bar.height).toBe(70); // |valueY - baseY|
|
|
34
|
-
expect(bar.width).toBe(12);
|
|
35
|
-
expect(bar.left).toBe(50 - 6); // cx - barWidth/2
|
|
37
|
+
it('puts category labels on a band scale', () => {
|
|
38
|
+
const { scene, found } = bars(
|
|
39
|
+
barChartDefinition({ data: week, radius: 4 }),
|
|
40
|
+
);
|
|
41
|
+
expect(found).toHaveLength(3);
|
|
42
|
+
expect(scene.scales['x']!.bandwidth).toBeGreaterThan(0);
|
|
43
|
+
expect(found[0]!.style?.fill).toBe('var(--primary)');
|
|
36
44
|
});
|
|
37
45
|
|
|
38
|
-
it('
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expect(bar.
|
|
46
|
+
it('cycles per-bar colors on categories', () => {
|
|
47
|
+
const { found } = bars(
|
|
48
|
+
barChartDefinition({ data: week, colors: ['red', 'blue'] }),
|
|
49
|
+
);
|
|
50
|
+
expect(found.map((bar) => bar.style?.fill)).toEqual(['red', 'blue', 'red']);
|
|
43
51
|
});
|
|
44
52
|
|
|
45
|
-
it('
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
53
|
+
it('sizes bars on a band scale by barWidthRatio, clamped to 0–1', () => {
|
|
54
|
+
const wide = bars(
|
|
55
|
+
barChartDefinition({
|
|
56
|
+
data: week,
|
|
57
|
+
barWidthRatio: 2,
|
|
58
|
+
showXGrid: true,
|
|
59
|
+
xAxisLabel: 'Day',
|
|
60
|
+
}),
|
|
61
|
+
);
|
|
62
|
+
const narrow = bars(barChartDefinition({ data: week, barWidthRatio: 0.2 }));
|
|
63
|
+
expect(narrow.found[0]!.width).toBeLessThan(wide.found[0]!.width);
|
|
50
64
|
});
|
|
51
65
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
66
|
+
const series = [
|
|
67
|
+
{ x: 0, y: 4 },
|
|
68
|
+
{ x: 1, y: -2 },
|
|
69
|
+
{ x: 3, y: 6 },
|
|
70
|
+
];
|
|
56
71
|
|
|
57
|
-
it('
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
{ cx: 10, valueY: 40 },
|
|
61
|
-
{ cx: 60, valueY: 20 },
|
|
62
|
-
],
|
|
63
|
-
100,
|
|
64
|
-
8,
|
|
72
|
+
it('places numeric bars at their values, the ratio of the smallest gap wide', () => {
|
|
73
|
+
const { scene, found } = bars(
|
|
74
|
+
barChartDefinition({ data: series, barWidthRatio: 0.5 }),
|
|
65
75
|
);
|
|
66
|
-
|
|
67
|
-
expect(
|
|
76
|
+
const x = scene.scales['x']!;
|
|
77
|
+
expect(x.bandwidth).toBe(0);
|
|
78
|
+
// The x axis has half a gap of room either side for the edge bars.
|
|
79
|
+
expect(x.domain[0]).toBeLessThanOrEqual(-0.5);
|
|
80
|
+
const unit = Math.abs(x.map(1) - x.map(0));
|
|
81
|
+
// rect trims a hair off each edge, so allow a couple of pixels.
|
|
82
|
+
expect(Math.abs(found[0]!.width - unit * 0.5)).toBeLessThan(2);
|
|
83
|
+
// Negative values grow down from the baseline.
|
|
84
|
+
expect(Math.abs(found[1]!.y - scene.scales['y']!.map(0))).toBeLessThan(1);
|
|
68
85
|
});
|
|
69
86
|
|
|
70
|
-
it('
|
|
71
|
-
|
|
87
|
+
it('colors numeric bars through the color scale', () => {
|
|
88
|
+
const { found } = bars(
|
|
89
|
+
barChartDefinition({
|
|
90
|
+
data: series,
|
|
91
|
+
colors: ['red', 'blue'],
|
|
92
|
+
tooltip: false,
|
|
93
|
+
}),
|
|
94
|
+
);
|
|
95
|
+
expect(found.map((bar) => bar.style?.fill)).toEqual(['red', 'blue', 'red']);
|
|
72
96
|
});
|
|
73
97
|
});
|