@svgrid/grid 3.0.0 → 3.0.2
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/CHANGELOG.md +116 -88
- package/README.md +199 -199
- package/dist/FlexRender.svelte +96 -96
- package/dist/GridFooter.svelte +190 -181
- package/dist/GridFooter.svelte.d.ts +8 -0
- package/dist/GridMenus.svelte +18 -10
- package/dist/GridMenus.svelte.d.ts +2 -1
- package/dist/SvAutoComplete.svelte +169 -169
- package/dist/SvAvatar.svelte +75 -75
- package/dist/SvCalendar.svelte +503 -503
- package/dist/SvCarousel.svelte +141 -141
- package/dist/SvCheckBox.svelte +102 -102
- package/dist/SvCircularProgress.svelte +109 -109
- package/dist/SvColorInput.svelte +181 -181
- package/dist/SvComboBox.svelte +279 -279
- package/dist/SvContextMenu.svelte +116 -116
- package/dist/SvCountryInput.svelte +163 -163
- package/dist/SvDrawer.svelte +254 -254
- package/dist/SvDropDownList.svelte +378 -378
- package/dist/SvDurationInput.svelte +126 -126
- package/dist/SvField.svelte +293 -293
- package/dist/SvForm.svelte +437 -437
- package/dist/SvGrid.controller.svelte.d.ts +17 -0
- package/dist/SvGrid.controller.svelte.js +128 -14
- package/dist/SvGrid.css +79 -10
- package/dist/SvGrid.svelte +191 -186
- package/dist/SvGrid.types.d.ts +42 -1
- package/dist/SvGridCellEditor.svelte +748 -744
- package/dist/SvGridChart.svelte +2246 -1716
- package/dist/SvGridChart.svelte.d.ts +63 -1
- package/dist/SvGridChartPanel.svelte +633 -485
- package/dist/SvGridChartView.svelte +79 -70
- package/dist/SvGridChartView.svelte.d.ts +7 -0
- package/dist/SvGridDropdown.svelte +728 -728
- package/dist/SvGridSelect.svelte +270 -270
- package/dist/SvGroupCell.svelte +141 -116
- package/dist/SvGroupCell.svelte.d.ts +8 -0
- package/dist/SvListBox.svelte +334 -334
- package/dist/SvMaskedInput.svelte +122 -122
- package/dist/SvMenu.svelte +124 -124
- package/dist/SvMenuList.svelte +146 -146
- package/dist/SvMultiSelect.svelte +293 -293
- package/dist/SvNumberInput.svelte +172 -172
- package/dist/SvOtpInput.svelte +158 -158
- package/dist/SvPasswordInput.svelte +151 -151
- package/dist/SvPhoneInput.svelte +133 -133
- package/dist/SvPopover.svelte +197 -197
- package/dist/SvProgress.svelte +116 -116
- package/dist/SvRadioGroup.svelte +107 -107
- package/dist/SvRating.svelte +112 -112
- package/dist/SvResult.svelte +73 -73
- package/dist/SvRichText.svelte +211 -211
- package/dist/SvRowGroupPanel.svelte +186 -170
- package/dist/SvRowGroupPanel.svelte.d.ts +8 -0
- package/dist/SvScrollArea.svelte +61 -61
- package/dist/SvSlider.svelte +203 -203
- package/dist/SvSwitchButton.svelte +108 -108
- package/dist/SvTagsInput.svelte +115 -115
- package/dist/SvTextInput.svelte +147 -147
- package/dist/SvTimePicker.svelte +245 -245
- package/dist/SvToaster.svelte +159 -159
- package/dist/SvToggleButton.svelte +85 -85
- package/dist/SvTooltip.svelte +161 -161
- package/dist/SvTour.svelte +208 -208
- package/dist/SvTree.svelte +444 -444
- package/dist/SvTreeSelect.svelte +239 -239
- package/dist/ai.d.ts +11 -2
- package/dist/ai.js +51 -7
- package/dist/cdn/GridMenus-DyFA-QxA.js +602 -0
- package/dist/cdn/GridMenus-M2XP9t0_.js +603 -0
- package/dist/cdn/{SvDateRangeInput-DflbiP7N.js → SvDateRangeInput-CaOuMs8O.js} +1 -1
- package/dist/cdn/{SvDateRangeInput-Bh0A0JkF.js → SvDateRangeInput-DMLKmGEc.js} +1 -1
- package/dist/cdn/{SvDateTimePicker-Bivn8dAP.js → SvDateTimePicker-CCbDZNZB.js} +1 -1
- package/dist/cdn/{SvDateTimePicker-BWwpfB_o.js → SvDateTimePicker-sonaH0oh.js} +1 -1
- package/dist/cdn/{SvGridCellEditor-Ba7rY3eu.js → SvGridCellEditor-BWnTi2N7.js} +2 -2
- package/dist/cdn/{SvGridCellEditor-AXL8cHGO.js → SvGridCellEditor-CjEJMJKc.js} +2 -2
- package/dist/cdn/SvGridChart-DAb9RbRs.js +1480 -0
- package/dist/cdn/SvGridChart-Yl-IXZFO.js +1481 -0
- package/dist/cdn/SvGridChartPanel-DayQpDsR.js +834 -0
- package/dist/cdn/SvGridChartPanel-aqf8n-vJ.js +810 -0
- package/dist/cdn/{SvGridChartView-eSPuJE6g.js → SvGridChartView-CxfakxR0.js} +5 -3
- package/dist/cdn/{SvGridChartView-SmPW10dI.js → SvGridChartView-Dm_YEx9L.js} +5 -3
- package/dist/cdn/{SvGridDropdown-B1ZcLpgs.js → SvGridDropdown-D0VdjeR8.js} +1 -1
- package/dist/cdn/{SvGridDropdown-CtdbHcIS.js → SvGridDropdown-D13MtJ2j.js} +1 -1
- package/dist/cdn/cell-formatting-C2Hf5gqd.js +86 -0
- package/dist/cdn/chart-CKJRCPOk.js +1652 -0
- package/dist/cdn/{date-format-DZT7T1wf.js → date-format-BNii4zeD.js} +2 -2
- package/dist/cdn/{date-format-CcP1tafP.js → date-format-BnnHlqGw.js} +2 -2
- package/dist/cdn/{export-format-Cv1Dll6k.js → export-format-CUDLy2yn.js} +84 -168
- package/dist/cdn/{src-B_YS5AOc.js → src-BJ2opd0j.js} +3642 -3450
- package/dist/cdn/{src-DYXXpuSk.js → src-DNbz94Ct.js} +8649 -8457
- package/dist/cdn/svgrid.js +16 -15
- package/dist/cdn/svgrid.svelte-external.js +16 -15
- package/dist/cell-formatting.d.ts +7 -0
- package/dist/cell-formatting.js +7 -1
- package/dist/chart-export.d.ts +23 -2
- package/dist/chart-export.js +88 -14
- package/dist/chart.d.ts +410 -18
- package/dist/chart.js +824 -24
- package/dist/editing.js +22 -13
- package/dist/grid-icons.d.ts +49 -0
- package/dist/grid-icons.js +86 -0
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/package.json +1 -1
- package/src/FlexRender.svelte +96 -96
- package/src/GridFooter.svelte +190 -181
- package/src/GridMenus.svelte +18 -10
- package/src/SvAutoComplete.svelte +169 -169
- package/src/SvAvatar.svelte +75 -75
- package/src/SvCalendar.svelte +503 -503
- package/src/SvCalendar.test.ts +226 -226
- package/src/SvCarousel.svelte +141 -141
- package/src/SvCheckBox.svelte +102 -102
- package/src/SvCircularProgress.svelte +109 -109
- package/src/SvColorInput.svelte +181 -181
- package/src/SvComboBox.svelte +279 -279
- package/src/SvContextMenu.svelte +116 -116
- package/src/SvCountryInput.svelte +163 -163
- package/src/SvDrawer.svelte +254 -254
- package/src/SvDropDownList.svelte +378 -378
- package/src/SvDurationInput.svelte +126 -126
- package/src/SvField.svelte +293 -293
- package/src/SvForm.svelte +437 -437
- package/src/SvForm.test.ts +411 -411
- package/src/SvGrid.controller.svelte.ts +146 -13
- package/src/SvGrid.css +79 -10
- package/src/SvGrid.svelte +191 -186
- package/src/SvGrid.types.ts +2133 -2092
- package/src/SvGridCellEditor.svelte +748 -744
- package/src/SvGridChart.svelte +2246 -1716
- package/src/SvGridChart.test.ts +243 -1
- package/src/SvGridChartPanel.svelte +633 -485
- package/src/SvGridChartView.svelte +79 -70
- package/src/SvGridDropdown.svelte +728 -728
- package/src/SvGridSelect.svelte +270 -270
- package/src/SvGroupCell.svelte +141 -116
- package/src/SvListBox.svelte +334 -334
- package/src/SvMaskedInput.svelte +122 -122
- package/src/SvMenu.svelte +124 -124
- package/src/SvMenu.test.ts +97 -97
- package/src/SvMenuList.svelte +146 -146
- package/src/SvMultiSelect.svelte +293 -293
- package/src/SvNumberInput.svelte +172 -172
- package/src/SvOtpInput.svelte +158 -158
- package/src/SvPasswordInput.svelte +151 -151
- package/src/SvPhoneInput.svelte +133 -133
- package/src/SvPopover.svelte +197 -197
- package/src/SvProgress.svelte +116 -116
- package/src/SvRadioGroup.svelte +107 -107
- package/src/SvRating.svelte +112 -112
- package/src/SvResult.svelte +73 -73
- package/src/SvRichText.svelte +211 -211
- package/src/SvRowGroupPanel.svelte +186 -170
- package/src/SvScrollArea.svelte +61 -61
- package/src/SvSlider.svelte +203 -203
- package/src/SvSwitchButton.svelte +108 -108
- package/src/SvTagsInput.svelte +115 -115
- package/src/SvTextInput.svelte +147 -147
- package/src/SvTimePicker.svelte +245 -245
- package/src/SvToaster.svelte +159 -159
- package/src/SvToaster.test.ts +95 -95
- package/src/SvToggleButton.svelte +85 -85
- package/src/SvTooltip.svelte +161 -161
- package/src/SvTour.svelte +208 -208
- package/src/SvTree.svelte +444 -444
- package/src/SvTreeSelect.svelte +239 -239
- package/src/a11y/dismissable.test.ts +119 -119
- package/src/a11y/dismissable.ts +114 -114
- package/src/a11y.contract.test.ts +49 -49
- package/src/a11y.test.ts +59 -59
- package/src/a11y.ts +61 -61
- package/src/ai.test.ts +561 -502
- package/src/ai.ts +1472 -1419
- package/src/build-api.coverage.test.ts +633 -633
- package/src/build-api.ts +846 -846
- package/src/builtin-editors.grid.test.ts +83 -83
- package/src/cell-formatting.ts +177 -171
- package/src/cell-render.test.ts +513 -513
- package/src/cell-render.ts +496 -496
- package/src/cell-values.ts +148 -148
- package/src/chart-export.test.ts +112 -0
- package/src/chart-export.ts +270 -202
- package/src/chart-view.svelte.ts +36 -36
- package/src/chart.test.ts +830 -1
- package/src/chart.ts +3342 -2321
- package/src/collaboration.test.ts +104 -104
- package/src/collaboration.ts +167 -167
- package/src/column-groups.ts +78 -78
- package/src/core.performance.test.ts +30 -30
- package/src/core.ts +1865 -1865
- package/src/createAutocomplete.svelte.ts +132 -132
- package/src/createCombobox.svelte.ts +191 -191
- package/src/createCountryInput.svelte.ts +157 -157
- package/src/createDropdownList.svelte.ts +168 -168
- package/src/createForm.svelte.ts +386 -386
- package/src/createGrid.svelte.ts +42 -42
- package/src/createGrid.test.ts +10 -10
- package/src/createGridState.svelte.ts +17 -17
- package/src/createListbox.svelte.ts +250 -250
- package/src/createMenu.svelte.ts +224 -224
- package/src/createPopoverSelect.svelte.ts +213 -213
- package/src/createSlider.svelte.ts +191 -191
- package/src/createTooltip.svelte.ts +144 -144
- package/src/createTree.svelte.ts +322 -322
- package/src/datetime/date-core.ts +206 -206
- package/src/datetime/date-restrict.ts +61 -61
- package/src/datetime/timezone.ts +135 -135
- package/src/dock-manager-model.ts +596 -596
- package/src/dock-model.ts +374 -374
- package/src/editing.test.ts +974 -974
- package/src/editing.ts +618 -609
- package/src/editor-contract.ts +171 -171
- package/src/editor-registry.grid.test.ts +144 -144
- package/src/editor-registry.ts +122 -122
- package/src/export-data-api.test.ts +126 -126
- package/src/export-format.test.ts +107 -107
- package/src/export-format.ts +601 -601
- package/src/filter-operators.ts +160 -160
- package/src/filtering/excel-filters.ts +325 -325
- package/src/flex-render.ts +3 -3
- package/src/form-field.ts +127 -127
- package/src/grid-icons.test.ts +46 -0
- package/src/grid-icons.ts +184 -0
- package/src/group-display.test.ts +167 -167
- package/src/group-display.ts +200 -200
- package/src/headless.ts +87 -87
- package/src/icon-overrides.grid.test.ts +188 -0
- package/src/icon-seam.test.ts +100 -0
- package/src/index.ts +19 -0
- package/src/js-scroller.svelte.ts +173 -173
- package/src/keyboard-handlers.ts +270 -270
- package/src/keyboard.test.ts +59 -59
- package/src/keyboard.ts +97 -97
- package/src/list-nav.test.ts +49 -49
- package/src/list-nav.ts +29 -29
- package/src/list-option.test.ts +56 -56
- package/src/list-option.ts +179 -179
- package/src/menus.ts +597 -597
- package/src/merge-objects.ts +48 -48
- package/src/overlays.test.ts +90 -90
- package/src/positioning.ts +268 -268
- package/src/render-component.ts +28 -28
- package/src/row-drag.test.ts +401 -401
- package/src/row-drag.ts +419 -419
- package/src/row-resize.test.ts +524 -524
- package/src/row-resize.ts +228 -228
- package/src/scheduler-ical.ts +181 -181
- package/src/scheduler-model.test.ts +562 -562
- package/src/scheduler-model.ts +873 -873
- package/src/selection.test.ts +885 -885
- package/src/server-data-source.test.ts +383 -383
- package/src/server-data-source.ts +469 -469
- package/src/sparkline.test.ts +68 -68
- package/src/sparkline.ts +169 -169
- package/src/spreadsheet.test.ts +488 -488
- package/src/spreadsheet.ts +312 -312
- package/src/static-functions.ts +11 -11
- package/src/subscribe.ts +38 -38
- package/src/summaries.ts +113 -113
- package/src/svgrid-wrapper.types.ts +563 -563
- package/src/svgrid.async-editor-options.test.ts +273 -273
- package/src/svgrid.auto-row-height.test.ts +204 -204
- package/src/svgrid.behavior.test.ts +910 -910
- package/src/svgrid.charting.test.ts +654 -534
- package/src/svgrid.comments-autocomplete.test.ts +127 -127
- package/src/svgrid.context-menu.test.ts +147 -147
- package/src/svgrid.features.test.ts +157 -157
- package/src/svgrid.filter-depth.test.ts +163 -163
- package/src/svgrid.filter-menu-listbox.svelte.test.ts +382 -377
- package/src/svgrid.filter-menu-scroll.test.ts +112 -112
- package/src/svgrid.grand-total.test.ts +188 -188
- package/src/svgrid.group-display-mode.test.ts +171 -171
- package/src/svgrid.group-footers.test.ts +121 -121
- package/src/svgrid.group-pagination.test.ts +153 -153
- package/src/svgrid.new-features.wrapper.test.ts +251 -251
- package/src/svgrid.tree-data.test.ts +186 -186
- package/src/svgrid.wrapper.test.ts +63 -63
- package/src/svgriddropdown.async-panel.svelte.test.ts +195 -195
- package/src/test-setup.ts +62 -62
- package/src/themes/index.ts +288 -288
- package/src/toast-store.svelte.ts +250 -250
- package/src/toast-store.test.ts +147 -147
- package/src/tree-row-model.test.ts +168 -168
- package/src/ui-buttons.test.ts +144 -144
- package/src/ui-inputs.test.ts +118 -118
- package/src/ui-localization.test.ts +113 -113
- package/src/ui-range.test.ts +70 -70
- package/src/ui-selection.test.ts +155 -155
- package/src/ui-tier1.test.ts +142 -142
- package/src/virtual.test.ts +88 -88
- 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 +322 -322
- package/dist/cdn/GridMenus-DMihUtma.js +0 -600
- package/dist/cdn/GridMenus-nmNDj1a3.js +0 -601
- package/dist/cdn/SvGridChart-Bs2GIR2Q.js +0 -1202
- package/dist/cdn/SvGridChart-CwhFz7GV.js +0 -1203
- package/dist/cdn/SvGridChartPanel-1WXuStzM.js +0 -561
- package/dist/cdn/SvGridChartPanel-e5_nqNP9.js +0 -585
- package/dist/cdn/chart-i4XcXyHJ.js +0 -1214
package/src/SvGridChart.test.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
-
import { mount, unmount } from 'svelte'
|
|
2
|
+
import { mount, unmount, createRawSnippet, flushSync } from 'svelte'
|
|
3
3
|
import SvGridChart from './SvGridChart.svelte'
|
|
4
4
|
import type { ChartSpec } from './chart'
|
|
5
5
|
|
|
@@ -67,3 +67,245 @@ describe('SvGridChart horizontal bars', () => {
|
|
|
67
67
|
expect(axisText).toContain('Grace')
|
|
68
68
|
})
|
|
69
69
|
})
|
|
70
|
+
|
|
71
|
+
describe('SvGridChart candlesticks', () => {
|
|
72
|
+
const bars = [
|
|
73
|
+
{ o: 100, h: 110, l: 95, c: 105 },
|
|
74
|
+
{ o: 105, h: 108, l: 99, c: 101 },
|
|
75
|
+
]
|
|
76
|
+
const priced = (type: 'candlestick' | 'ohlc'): ChartSpec => ({
|
|
77
|
+
type,
|
|
78
|
+
categories: ['2026-03-02', '2026-03-03'],
|
|
79
|
+
series: [{ label: 'ACME', values: bars.map((b) => b.c), ohlc: bars }],
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
it('draws a body and a wick per bar', () => {
|
|
83
|
+
const el = render(priced('candlestick'))
|
|
84
|
+
expect(el.querySelectorAll('rect.sv-grid-chart-candle')).toHaveLength(2)
|
|
85
|
+
expect(el.querySelectorAll('line.sv-grid-chart-wick')).toHaveLength(2)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('a rising candle is hollow, a falling one filled', () => {
|
|
89
|
+
const el = render(priced('candlestick'))
|
|
90
|
+
const [up, down] = [...el.querySelectorAll('rect.sv-grid-chart-candle')]
|
|
91
|
+
expect(up!.getAttribute('fill')).toBe('none')
|
|
92
|
+
expect(down!.getAttribute('fill')).not.toBe('none')
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('ohlc draws three ticks per bar and no body', () => {
|
|
96
|
+
const el = render(priced('ohlc'))
|
|
97
|
+
expect(el.querySelectorAll('line.sv-grid-chart-ohlc')).toHaveLength(6)
|
|
98
|
+
expect(el.querySelectorAll('rect.sv-grid-chart-candle')).toHaveLength(0)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
it('gives a screen reader the four real prices, not just the closes', () => {
|
|
102
|
+
const el = render(priced('candlestick'))
|
|
103
|
+
const head = [...el.querySelectorAll('th')].map((t) => t.textContent)
|
|
104
|
+
expect(head).toEqual(['Date', 'Series', 'Open', 'High', 'Low', 'Close'])
|
|
105
|
+
})
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
describe('dense charts (more categories than pixels)', () => {
|
|
109
|
+
const line = (n: number): ChartSpec => ({
|
|
110
|
+
type: 'line',
|
|
111
|
+
categories: Array.from({ length: n }, (_, i) => `c${i}`),
|
|
112
|
+
series: [{ label: 's', values: Array.from({ length: n }, (_, i) => Math.sin(i / 7) * 50 + 60) }],
|
|
113
|
+
width: 800,
|
|
114
|
+
height: 400,
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('draws a dot and a hit rect per point while there is room', () => {
|
|
118
|
+
const el = render(line(40)) // 800px / 40 = 20px a category
|
|
119
|
+
expect(el.querySelectorAll('.sv-grid-chart-dot').length).toBe(40)
|
|
120
|
+
expect(el.querySelectorAll('.sv-grid-chart-cat-hit').length).toBe(40)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('collapses the dots and the hit layer once categories go sub-pixel', () => {
|
|
124
|
+
// 800px / 5000 = 0.16px a category. Per-category machinery here is not just
|
|
125
|
+
// slow, it is useless: the dots overlap into a smear and a hit rect is
|
|
126
|
+
// narrower than the pointer.
|
|
127
|
+
const el = render(line(5000))
|
|
128
|
+
expect(el.querySelectorAll('.sv-grid-chart-dot').length).toBe(0)
|
|
129
|
+
const hits = el.querySelectorAll('.sv-grid-chart-cat-hit')
|
|
130
|
+
expect(hits.length).toBe(1)
|
|
131
|
+
expect(hits[0]!.getAttribute('data-dense')).toBe('true')
|
|
132
|
+
// The line itself is still drawn in full - this is about the marks on it,
|
|
133
|
+
// not about dropping data.
|
|
134
|
+
expect(el.querySelector('.sv-grid-chart-linepath')).toBeTruthy()
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('keeps the aria-label off the render path when dense', () => {
|
|
138
|
+
// Each per-category rect labels itself by calling catRows(), so 5000 rects
|
|
139
|
+
// meant 5000 tooltip-row computations before anything was hovered.
|
|
140
|
+
const el = render(line(5000))
|
|
141
|
+
const label = el.querySelector('.sv-grid-chart-cat-hit')!.getAttribute('aria-label')!
|
|
142
|
+
expect(label).toContain('5000 points')
|
|
143
|
+
expect(label).toContain('Arrow keys')
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
it('caps the screen-reader table and says so in the caption', () => {
|
|
147
|
+
const el = render(line(5000))
|
|
148
|
+
const rows = el.querySelectorAll('.sv-grid-chart-sr-only tbody tr')
|
|
149
|
+
expect(rows.length).toBe(1000)
|
|
150
|
+
expect(el.querySelector('.sv-grid-chart-sr-only caption')!.textContent).toContain('first 1000 of 5000')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('leaves a small chart entirely alone', () => {
|
|
154
|
+
const el = render(line(40))
|
|
155
|
+
expect(el.querySelector('.sv-grid-chart-sr-only tbody')!.children.length).toBe(40)
|
|
156
|
+
expect(el.querySelector('.sv-grid-chart-sr-only caption')!.textContent).not.toContain('first')
|
|
157
|
+
expect(el.querySelector('[data-dense]')).toBeNull()
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('does not collapse a bar chart, whose marks ARE the data', () => {
|
|
161
|
+
// Dropping dots loses nothing because the line still shows the shape.
|
|
162
|
+
// Dropping bars would draw an empty chart, so density only governs the
|
|
163
|
+
// dot / hit / label / table layers, never the marks themselves.
|
|
164
|
+
//
|
|
165
|
+
// 1200 rather than 5000 only because jsdom takes seconds to build that many
|
|
166
|
+
// <rect> nodes; 1200 at 800px is already 0.67px a bar, well inside dense.
|
|
167
|
+
const el = render({ ...line(1200), type: 'bar' })
|
|
168
|
+
expect(el.querySelectorAll('.sv-grid-chart-bar').length).toBe(1200)
|
|
169
|
+
expect(el.querySelector('[data-dense]')).toBeTruthy()
|
|
170
|
+
})
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
describe('custom-series seam (underlay / overlay snippets)', () => {
|
|
174
|
+
const spec: ChartSpec = {
|
|
175
|
+
type: 'bar',
|
|
176
|
+
categories: ['a', 'b', 'c'],
|
|
177
|
+
series: [{ label: 's', values: [10, 20, 30] }],
|
|
178
|
+
width: 500,
|
|
179
|
+
height: 300,
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
it('renders both snippets inside the chart svg', () => {
|
|
183
|
+
const el = render(spec, {
|
|
184
|
+
underlay: createRawSnippet(() => ({ render: () => `<rect class="my-under" />` })),
|
|
185
|
+
overlay: createRawSnippet(() => ({ render: () => `<rect class="my-over" />` })),
|
|
186
|
+
})
|
|
187
|
+
expect(el.querySelector('.sv-grid-chart-svg .my-under')).toBeTruthy()
|
|
188
|
+
expect(el.querySelector('.sv-grid-chart-svg .my-over')).toBeTruthy()
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('puts the underlay beneath the bars and the overlay above them', () => {
|
|
192
|
+
const el = render(spec, {
|
|
193
|
+
underlay: createRawSnippet(() => ({ render: () => `<rect class="my-under" />` })),
|
|
194
|
+
overlay: createRawSnippet(() => ({ render: () => `<rect class="my-over" />` })),
|
|
195
|
+
})
|
|
196
|
+
// SVG paints in document order, so position IS z-order.
|
|
197
|
+
const nodes = [...el.querySelectorAll('.sv-grid-chart-svg *')]
|
|
198
|
+
const under = nodes.findIndex((n) => n.classList.contains('my-under'))
|
|
199
|
+
const bar = nodes.findIndex((n) => n.classList.contains('sv-grid-chart-bar'))
|
|
200
|
+
const over = nodes.findIndex((n) => n.classList.contains('my-over'))
|
|
201
|
+
expect(under).toBeGreaterThanOrEqual(0)
|
|
202
|
+
expect(under).toBeLessThan(bar)
|
|
203
|
+
expect(bar).toBeLessThan(over)
|
|
204
|
+
})
|
|
205
|
+
|
|
206
|
+
it('keeps the hit layer above the overlay, so tooltips still work', () => {
|
|
207
|
+
// A custom mark must not be able to swallow the tooltips, the keyboard
|
|
208
|
+
// navigation or the drill clicks.
|
|
209
|
+
const el = render(spec, {
|
|
210
|
+
overlay: createRawSnippet(() => ({ render: () => `<rect class="my-over" />` })),
|
|
211
|
+
})
|
|
212
|
+
const nodes = [...el.querySelectorAll('.sv-grid-chart-svg *')]
|
|
213
|
+
const over = nodes.findIndex((n) => n.classList.contains('my-over'))
|
|
214
|
+
const hit = nodes.findIndex((n) => n.classList.contains('sv-grid-chart-cat-hit'))
|
|
215
|
+
expect(hit).toBeGreaterThan(over)
|
|
216
|
+
})
|
|
217
|
+
|
|
218
|
+
it('draws nothing extra when no snippet is passed', () => {
|
|
219
|
+
const el = render(spec)
|
|
220
|
+
expect(el.querySelector('.my-over')).toBeNull()
|
|
221
|
+
expect(el.querySelector('.sv-grid-chart-bar')).toBeTruthy()
|
|
222
|
+
})
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
describe('interactive annotations', () => {
|
|
226
|
+
const spec: ChartSpec = {
|
|
227
|
+
type: 'bar',
|
|
228
|
+
categories: ['a', 'b', 'c'],
|
|
229
|
+
series: [{ label: 's', values: [10, 20, 30] }],
|
|
230
|
+
width: 500,
|
|
231
|
+
height: 300,
|
|
232
|
+
}
|
|
233
|
+
const noted: ChartSpec = { ...spec, annotations: [{ at: { category: 'b' }, label: 'deploy' }] }
|
|
234
|
+
|
|
235
|
+
it('shows no toggle unless asked for', () => {
|
|
236
|
+
const el = render(spec, { toolbar: true })
|
|
237
|
+
expect([...el.querySelectorAll('.sv-grid-chart-tool')].some((b) => b.textContent?.includes('Annotate'))).toBe(false)
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
it('adds an Annotate toggle, off to begin with', () => {
|
|
241
|
+
const el = render(spec, { annotatable: true })
|
|
242
|
+
const btn = [...el.querySelectorAll('.sv-grid-chart-tool')].find((b) => b.textContent?.includes('Annotate'))!
|
|
243
|
+
expect(btn).toBeTruthy()
|
|
244
|
+
expect(btn.getAttribute('aria-pressed')).toBe('false')
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
it('reports the data point picked, not a pixel', () => {
|
|
248
|
+
const seen: unknown[] = []
|
|
249
|
+
const el = render(spec, { annotatable: true, onAnnotate: (a: unknown) => seen.push(a) })
|
|
250
|
+
const btn = [...el.querySelectorAll('.sv-grid-chart-tool')].find((b) => b.textContent?.includes('Annotate'))! as HTMLButtonElement
|
|
251
|
+
btn.click()
|
|
252
|
+
flushSync()
|
|
253
|
+
;(el.querySelectorAll('.sv-grid-chart-cat-hit')[1] as SVGElement).dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
254
|
+
flushSync()
|
|
255
|
+
// Anchored to a category, so the note survives a re-layout, a re-sort or a
|
|
256
|
+
// zoom - which a pixel would not.
|
|
257
|
+
expect(seen).toEqual([{ category: 'b', index: 1, value: 20 }])
|
|
258
|
+
})
|
|
259
|
+
|
|
260
|
+
it('takes over the drill gesture rather than firing both', () => {
|
|
261
|
+
const drills: unknown[] = []
|
|
262
|
+
const notes: unknown[] = []
|
|
263
|
+
const el = render(spec, {
|
|
264
|
+
annotatable: true,
|
|
265
|
+
onSelect: (s: unknown) => drills.push(s),
|
|
266
|
+
onAnnotate: (a: unknown) => notes.push(a),
|
|
267
|
+
})
|
|
268
|
+
const hit = () => (el.querySelectorAll('.sv-grid-chart-cat-hit')[0] as SVGElement).dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
269
|
+
hit()
|
|
270
|
+
flushSync()
|
|
271
|
+
expect(drills).toHaveLength(1)
|
|
272
|
+
expect(notes).toHaveLength(0)
|
|
273
|
+
|
|
274
|
+
const btn = [...el.querySelectorAll('.sv-grid-chart-tool')].find((b) => b.textContent?.includes('Annotate'))! as HTMLButtonElement
|
|
275
|
+
btn.click()
|
|
276
|
+
flushSync()
|
|
277
|
+
hit()
|
|
278
|
+
flushSync()
|
|
279
|
+
expect(notes).toHaveLength(1)
|
|
280
|
+
expect(drills).toHaveLength(1) // not both
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
it('makes existing markers removable, by mouse and by keyboard', () => {
|
|
284
|
+
const removed: number[] = []
|
|
285
|
+
const el = render(noted, { annotatable: true, onAnnotationRemove: (i: number) => removed.push(i) })
|
|
286
|
+
const marker = () => el.querySelector('.sv-grid-chart-annotation-marker') as SVGElement
|
|
287
|
+
// Inert until the mode is on.
|
|
288
|
+
expect(marker().getAttribute('role')).toBeNull()
|
|
289
|
+
marker().dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
290
|
+
expect(removed).toEqual([])
|
|
291
|
+
|
|
292
|
+
const btn = [...el.querySelectorAll('.sv-grid-chart-tool')].find((b) => b.textContent?.includes('Annotate'))! as HTMLButtonElement
|
|
293
|
+
btn.click()
|
|
294
|
+
flushSync()
|
|
295
|
+
expect(marker().getAttribute('role')).toBe('button')
|
|
296
|
+
expect(marker().getAttribute('tabindex')).toBe('0')
|
|
297
|
+
marker().dispatchEvent(new MouseEvent('click', { bubbles: true }))
|
|
298
|
+
flushSync()
|
|
299
|
+
expect(removed).toEqual([0])
|
|
300
|
+
|
|
301
|
+
marker().dispatchEvent(new KeyboardEvent('keydown', { key: 'Enter', bubbles: true }))
|
|
302
|
+
flushSync()
|
|
303
|
+
expect(removed).toEqual([0, 0])
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
it('renders annotations normally when the mode is off', () => {
|
|
307
|
+
const el = render(noted)
|
|
308
|
+
expect(el.querySelectorAll('.sv-grid-chart-annotation-marker')).toHaveLength(1)
|
|
309
|
+
expect(el.querySelector('.sv-grid-chart-annotation-label')!.textContent).toBe('deploy')
|
|
310
|
+
})
|
|
311
|
+
})
|