@opendata-ai/openchart-engine 8.0.0-rc.10 → 8.0.0-rc.12
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/index.d.ts +7 -0
- package/dist/index.js +123 -54
- package/dist/index.js.map +1 -1
- package/package.json +3 -4
- package/src/__test-fixtures__/specs.ts +0 -182
- package/src/__tests__/__snapshots__/compile-snapshot.test.ts.snap +0 -2401
- package/src/__tests__/annotation-behavior.test.ts +0 -852
- package/src/__tests__/axes.test.ts +0 -1579
- package/src/__tests__/compile-animation.test.ts +0 -161
- package/src/__tests__/compile-chart.test.ts +0 -1303
- package/src/__tests__/compile-footnotes.test.ts +0 -277
- package/src/__tests__/compile-layer.test.ts +0 -969
- package/src/__tests__/compile-snapshot.test.ts +0 -156
- package/src/__tests__/compound-labels.test.ts +0 -147
- package/src/__tests__/dimensions.test.ts +0 -918
- package/src/__tests__/encoding-sugar.test.ts +0 -390
- package/src/__tests__/facet.test.ts +0 -359
- package/src/__tests__/helpers/invariants.ts +0 -299
- package/src/__tests__/known-bugs.test.ts +0 -566
- package/src/__tests__/layout-fuzz.test.ts +0 -358
- package/src/__tests__/layout-invariants.test.ts +0 -535
- package/src/__tests__/legend.test.ts +0 -721
- package/src/__tests__/mark-keys.test.ts +0 -294
- package/src/__tests__/ranking-recipes.test.ts +0 -260
- package/src/__tests__/rotation.test.ts +0 -83
- package/src/__tests__/scales.test.ts +0 -323
- package/src/__tests__/series-search.test.ts +0 -92
- package/src/__tests__/spec-sugar.test.ts +0 -801
- package/src/__tests__/you-draw-it.test.ts +0 -160
- package/src/annotations/__tests__/compute.test.ts +0 -1672
- package/src/annotations/__tests__/geometry.test.ts +0 -66
- package/src/annotations/__tests__/placement-fuzz.test.ts +0 -256
- package/src/annotations/__tests__/placement-invariants.test.ts +0 -345
- package/src/annotations/__tests__/placement.test.ts +0 -316
- package/src/annotations/__tests__/resolve-text.test.ts +0 -788
- package/src/annotations/__tests__/rich-text.test.ts +0 -91
- package/src/annotations/__tests__/thinning.test.ts +0 -285
- package/src/annotations/collisions.ts +0 -326
- package/src/annotations/compute.ts +0 -333
- package/src/annotations/constants.ts +0 -162
- package/src/annotations/geometry.ts +0 -376
- package/src/annotations/move.ts +0 -135
- package/src/annotations/placement.ts +0 -636
- package/src/annotations/position.ts +0 -131
- package/src/annotations/resolve-range.ts +0 -117
- package/src/annotations/resolve-refline.ts +0 -157
- package/src/annotations/resolve-text.ts +0 -545
- package/src/annotations/rich-text.ts +0 -65
- package/src/annotations/thinning.ts +0 -190
- package/src/barlist/__tests__/compile-barlist.test.ts +0 -200
- package/src/barlist/compile-barlist.ts +0 -391
- package/src/barlist/types.ts +0 -28
- package/src/charts/__tests__/post-process.test.ts +0 -237
- package/src/charts/__tests__/registry.test.ts +0 -116
- package/src/charts/__tests__/utils.test.ts +0 -195
- package/src/charts/_shared/__tests__/density-filter.test.ts +0 -32
- package/src/charts/_shared/density-filter.ts +0 -26
- package/src/charts/_shared/format-label-value.ts +0 -16
- package/src/charts/bar/__tests__/compute.test.ts +0 -934
- package/src/charts/bar/__tests__/gradient-orient.test.ts +0 -127
- package/src/charts/bar/__tests__/labels.test.ts +0 -292
- package/src/charts/bar/compute.ts +0 -539
- package/src/charts/bar/index.ts +0 -60
- package/src/charts/bar/labels.ts +0 -311
- package/src/charts/beeswarm/__tests__/compute.test.ts +0 -280
- package/src/charts/beeswarm/__tests__/dodge.test.ts +0 -148
- package/src/charts/beeswarm/compute.ts +0 -203
- package/src/charts/beeswarm/dodge.ts +0 -155
- package/src/charts/beeswarm/index.ts +0 -32
- package/src/charts/builtin.ts +0 -75
- package/src/charts/calendar/__tests__/compute.test.ts +0 -417
- package/src/charts/calendar/compute.ts +0 -319
- package/src/charts/calendar/index.ts +0 -32
- package/src/charts/column/__tests__/compute.test.ts +0 -540
- package/src/charts/column/__tests__/labels.test.ts +0 -179
- package/src/charts/column/compute.ts +0 -493
- package/src/charts/column/index.ts +0 -53
- package/src/charts/column/labels.ts +0 -229
- package/src/charts/dot/__tests__/compute.test.ts +0 -380
- package/src/charts/dot/__tests__/labels.test.ts +0 -98
- package/src/charts/dot/compute.ts +0 -285
- package/src/charts/dot/index.ts +0 -62
- package/src/charts/dot/labels.ts +0 -121
- package/src/charts/line/__tests__/compute.test.ts +0 -1194
- package/src/charts/line/__tests__/curves.test.ts +0 -51
- package/src/charts/line/__tests__/labels.test.ts +0 -94
- package/src/charts/line/__tests__/mark-options.test.ts +0 -175
- package/src/charts/line/area.ts +0 -484
- package/src/charts/line/compute.ts +0 -356
- package/src/charts/line/curves.ts +0 -85
- package/src/charts/line/index.ts +0 -176
- package/src/charts/line/labels.ts +0 -177
- package/src/charts/parliament/__tests__/compute.test.ts +0 -411
- package/src/charts/parliament/compute.ts +0 -313
- package/src/charts/parliament/index.ts +0 -32
- package/src/charts/pie/__tests__/compute.test.ts +0 -384
- package/src/charts/pie/__tests__/labels.test.ts +0 -132
- package/src/charts/pie/compute.ts +0 -324
- package/src/charts/pie/index.ts +0 -49
- package/src/charts/pie/labels.ts +0 -143
- package/src/charts/post-process.ts +0 -229
- package/src/charts/range/__tests__/compute.test.ts +0 -486
- package/src/charts/range/compute.ts +0 -273
- package/src/charts/range/index.ts +0 -82
- package/src/charts/range/labels.ts +0 -169
- package/src/charts/rect/__tests__/compute.test.ts +0 -120
- package/src/charts/rect/index.ts +0 -127
- package/src/charts/registry.ts +0 -72
- package/src/charts/rule/index.ts +0 -139
- package/src/charts/scatter/__tests__/compute.test.ts +0 -488
- package/src/charts/scatter/__tests__/trendline.test.ts +0 -191
- package/src/charts/scatter/compute.ts +0 -192
- package/src/charts/scatter/index.ts +0 -46
- package/src/charts/scatter/trendline.ts +0 -100
- package/src/charts/text/__tests__/compute.test.ts +0 -307
- package/src/charts/text/index.ts +0 -141
- package/src/charts/tick/__tests__/compute.test.ts +0 -75
- package/src/charts/tick/index.ts +0 -99
- package/src/charts/utils.ts +0 -170
- package/src/charts/waffle/__tests__/compute.test.ts +0 -305
- package/src/charts/waffle/compute.ts +0 -197
- package/src/charts/waffle/index.ts +0 -31
- package/src/compile/__tests__/color-scale-range.test.ts +0 -158
- package/src/compile/__tests__/color-scale-reverse.test.ts +0 -89
- package/src/compile/__tests__/data-clip.test.ts +0 -127
- package/src/compile/__tests__/fill-patterns.test.ts +0 -154
- package/src/compile/__tests__/size-scale.test.ts +0 -108
- package/src/compile/__tests__/watermark-obstacle.test.ts +0 -93
- package/src/compile/color-scale-range.ts +0 -101
- package/src/compile/data-clip.ts +0 -48
- package/src/compile/fill-patterns.ts +0 -74
- package/src/compile/layer.ts +0 -630
- package/src/compile/size-scale.ts +0 -141
- package/src/compile/spec-sugar.ts +0 -767
- package/src/compile/watermark-obstacle.ts +0 -54
- package/src/compile/you-draw-it.ts +0 -123
- package/src/compile.ts +0 -1548
- package/src/compiler/__tests__/a11y-warnings.test.ts +0 -148
- package/src/compiler/__tests__/animation.test.ts +0 -177
- package/src/compiler/__tests__/compile.test.ts +0 -87
- package/src/compiler/__tests__/fixtures/vl-parity/axis-null.json +0 -19
- package/src/compiler/__tests__/fixtures/vl-parity/color-value.json +0 -20
- package/src/compiler/__tests__/fixtures/vl-parity/count-aggregate.json +0 -22
- package/src/compiler/__tests__/fixtures/vl-parity/data-values.json +0 -19
- package/src/compiler/__tests__/fixtures/vl-parity/layer-axis-null.json +0 -14
- package/src/compiler/__tests__/fixtures/vl-parity/layer-count.json +0 -34
- package/src/compiler/__tests__/fixtures/vl-parity/layer-data-values.json +0 -22
- package/src/compiler/__tests__/fixtures/vl-parity/layer-legend-null.json +0 -41
- package/src/compiler/__tests__/fixtures/vl-parity/layer-scheme.json +0 -38
- package/src/compiler/__tests__/fixtures/vl-parity/layer-sort.json +0 -28
- package/src/compiler/__tests__/fixtures/vl-parity/layer-theta.json +0 -28
- package/src/compiler/__tests__/fixtures/vl-parity/layer-title.json +0 -30
- package/src/compiler/__tests__/fixtures/vl-parity/layer-value-def.json +0 -29
- package/src/compiler/__tests__/fixtures/vl-parity/legend-null.json +0 -32
- package/src/compiler/__tests__/fixtures/vl-parity/scheme.json +0 -25
- package/src/compiler/__tests__/fixtures/vl-parity/sort-by-value.json +0 -19
- package/src/compiler/__tests__/fixtures/vl-parity/theta-arc.json +0 -19
- package/src/compiler/__tests__/fixtures/vl-parity/title-subtitle.json +0 -21
- package/src/compiler/__tests__/fixtures/vl-parity/width-height.json +0 -23
- package/src/compiler/__tests__/keys.test.ts +0 -83
- package/src/compiler/__tests__/normalize-highlight.test.ts +0 -103
- package/src/compiler/__tests__/normalize.test.ts +0 -399
- package/src/compiler/__tests__/sparkline-defaults.test.ts +0 -153
- package/src/compiler/__tests__/validate-did-you-mean.test.ts +0 -170
- package/src/compiler/__tests__/validate-highlight.test.ts +0 -112
- package/src/compiler/__tests__/validate-near-miss.test.ts +0 -251
- package/src/compiler/__tests__/validate.test.ts +0 -731
- package/src/compiler/__tests__/vl-parity.test.ts +0 -68
- package/src/compiler/a11y-warnings.ts +0 -110
- package/src/compiler/animation.ts +0 -142
- package/src/compiler/index.ts +0 -47
- package/src/compiler/keys.ts +0 -55
- package/src/compiler/normalize.ts +0 -734
- package/src/compiler/sparkline-defaults.ts +0 -138
- package/src/compiler/types.ts +0 -241
- package/src/compiler/validate.ts +0 -2093
- package/src/endpoint-labels/__tests__/compute.test.ts +0 -587
- package/src/endpoint-labels/compute.ts +0 -621
- package/src/endpoint-labels/constants.ts +0 -54
- package/src/endpoint-labels/format.ts +0 -60
- package/src/endpoint-labels/predict.ts +0 -139
- package/src/format/__tests__/field-format.test.ts +0 -164
- package/src/format/field-format.ts +0 -27
- package/src/geo/__tests__/compile-map.test.ts +0 -1128
- package/src/geo/compile-map.ts +0 -1376
- package/src/geo/join.ts +0 -115
- package/src/geo/projections.ts +0 -65
- package/src/geo/types.ts +0 -26
- package/src/graphs/__tests__/community.test.ts +0 -228
- package/src/graphs/__tests__/compile-graph.test.ts +0 -396
- package/src/graphs/__tests__/encoding.test.ts +0 -415
- package/src/graphs/community.ts +0 -92
- package/src/graphs/compile-graph.ts +0 -329
- package/src/graphs/encoding.ts +0 -356
- package/src/graphs/types.ts +0 -106
- package/src/index.ts +0 -177
- package/src/layout/__tests__/metrics.test.ts +0 -97
- package/src/layout/__tests__/scales-highlight.test.ts +0 -192
- package/src/layout/axes/rotation.ts +0 -152
- package/src/layout/axes/thinning.ts +0 -98
- package/src/layout/axes/ticks.ts +0 -409
- package/src/layout/axes.ts +0 -757
- package/src/layout/dimensions.ts +0 -912
- package/src/layout/facet.ts +0 -91
- package/src/layout/gridlines.ts +0 -84
- package/src/layout/metrics.ts +0 -132
- package/src/layout/plan.ts +0 -631
- package/src/layout/scales.ts +0 -1053
- package/src/layout/shared.ts +0 -44
- package/src/legend/__tests__/continuous.test.ts +0 -318
- package/src/legend/__tests__/redundancy.test.ts +0 -108
- package/src/legend/__tests__/size.test.ts +0 -348
- package/src/legend/__tests__/suppression.test.ts +0 -382
- package/src/legend/compute.ts +0 -748
- package/src/legend/continuous.ts +0 -327
- package/src/legend/size.ts +0 -407
- package/src/legend/suppression.ts +0 -226
- package/src/legend/wrap.ts +0 -117
- package/src/sankey/__tests__/compile-sankey.test.ts +0 -458
- package/src/sankey/__tests__/layout.test.ts +0 -165
- package/src/sankey/__tests__/node-label-wrap.test.ts +0 -114
- package/src/sankey/__tests__/node-sort.test.ts +0 -45
- package/src/sankey/compile-sankey.ts +0 -706
- package/src/sankey/layout.ts +0 -184
- package/src/sankey/types.ts +0 -41
- package/src/tables/__tests__/bar-column.test.ts +0 -147
- package/src/tables/__tests__/category-colors.test.ts +0 -230
- package/src/tables/__tests__/compile-table.test.ts +0 -236
- package/src/tables/__tests__/format-cells.test.ts +0 -143
- package/src/tables/__tests__/heatmap.test.ts +0 -148
- package/src/tables/__tests__/pagination.test.ts +0 -78
- package/src/tables/__tests__/search.test.ts +0 -94
- package/src/tables/__tests__/sort.test.ts +0 -107
- package/src/tables/__tests__/sparkline.test.ts +0 -122
- package/src/tables/bar-column.ts +0 -94
- package/src/tables/category-colors.ts +0 -78
- package/src/tables/compile-table.ts +0 -427
- package/src/tables/format-cells.ts +0 -115
- package/src/tables/heatmap.ts +0 -141
- package/src/tables/pagination.ts +0 -46
- package/src/tables/search.ts +0 -66
- package/src/tables/sort.ts +0 -69
- package/src/tables/sparkline.ts +0 -113
- package/src/tables/utils.ts +0 -16
- package/src/tilemap/__tests__/compile-tilemap.test.ts +0 -576
- package/src/tilemap/compile-tilemap.ts +0 -755
- package/src/tilemap/layout.ts +0 -172
- package/src/tilemap/types.ts +0 -33
- package/src/tooltips/__tests__/compute.test.ts +0 -582
- package/src/tooltips/compute.ts +0 -700
- package/src/transforms/__tests__/aggregate.test.ts +0 -159
- package/src/transforms/__tests__/bin.test.ts +0 -88
- package/src/transforms/__tests__/calculate.test.ts +0 -146
- package/src/transforms/__tests__/conditional.test.ts +0 -127
- package/src/transforms/__tests__/filter-relative.test.ts +0 -202
- package/src/transforms/__tests__/filter.test.ts +0 -59
- package/src/transforms/__tests__/fold.test.ts +0 -79
- package/src/transforms/__tests__/index.test.ts +0 -93
- package/src/transforms/__tests__/predicates.test.ts +0 -193
- package/src/transforms/__tests__/timeunit.test.ts +0 -129
- package/src/transforms/__tests__/window.test.ts +0 -286
- package/src/transforms/aggregate.ts +0 -131
- package/src/transforms/bin.ts +0 -87
- package/src/transforms/calculate.ts +0 -60
- package/src/transforms/conditional.ts +0 -46
- package/src/transforms/filter.ts +0 -122
- package/src/transforms/fold.ts +0 -49
- package/src/transforms/index.ts +0 -60
- package/src/transforms/predicates.ts +0 -123
- package/src/transforms/timeunit.ts +0 -88
- package/src/transforms/window.ts +0 -185
|
@@ -1,801 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the pre-validation VL-idiom sugar expansion (expandSpecSugar)
|
|
3
|
-
* and its deprecation warnings.
|
|
4
|
-
*
|
|
5
|
-
* Covers: data {values} unwrapping, top-level title/subtitle, bare value
|
|
6
|
-
* defs, channel-level legend, axis: null, scale.scheme resolution, theta as
|
|
7
|
-
* the arc value channel, count-without-field, VL sort forms, width/height
|
|
8
|
-
* fixed sizing, strokeDash on line marks, and the exactly-one-warning
|
|
9
|
-
* contract for v8-deprecated surface (radius/shape/href/order, $schema).
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
import type { LayerSpec, LineMark } from '@opendata-ai/openchart-core';
|
|
13
|
-
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
14
|
-
import { compileChart, compileLayer, expandSpecSugar } from '../compile';
|
|
15
|
-
|
|
16
|
-
const OPTIONS = { width: 600, height: 400 };
|
|
17
|
-
|
|
18
|
-
let warnSpy: ReturnType<typeof vi.spyOn>;
|
|
19
|
-
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
warnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
22
|
-
});
|
|
23
|
-
|
|
24
|
-
afterEach(() => {
|
|
25
|
-
warnSpy.mockRestore();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
/** Collect the console.warn messages captured by the spy. */
|
|
29
|
-
function warned(): string[] {
|
|
30
|
-
return warnSpy.mock.calls.map((call) => String(call[0]));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// ---------------------------------------------------------------------------
|
|
34
|
-
// data: { values } unwrapping
|
|
35
|
-
// ---------------------------------------------------------------------------
|
|
36
|
-
|
|
37
|
-
describe('data: { values } unwrapping', () => {
|
|
38
|
-
it('unwraps the VL object form to a bare array', () => {
|
|
39
|
-
const result = expandSpecSugar({
|
|
40
|
-
mark: 'bar',
|
|
41
|
-
data: { values: [{ cat: 'A', value: 1 }] },
|
|
42
|
-
encoding: {
|
|
43
|
-
x: { field: 'cat', type: 'nominal' },
|
|
44
|
-
y: { field: 'value', type: 'quantitative' },
|
|
45
|
-
},
|
|
46
|
-
});
|
|
47
|
-
expect(result.data).toEqual([{ cat: 'A', value: 1 }]);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it('leaves { url } in place for validation to reject', () => {
|
|
51
|
-
const spec = { mark: 'bar', data: { url: 'https://example.com/data.json' }, encoding: {} };
|
|
52
|
-
const result = expandSpecSugar(spec);
|
|
53
|
-
expect(result.data).toEqual({ url: 'https://example.com/data.json' });
|
|
54
|
-
});
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// ---------------------------------------------------------------------------
|
|
58
|
-
// Top-level title/subtitle
|
|
59
|
-
// ---------------------------------------------------------------------------
|
|
60
|
-
|
|
61
|
-
describe('top-level title/subtitle', () => {
|
|
62
|
-
const base = {
|
|
63
|
-
mark: 'bar',
|
|
64
|
-
data: [{ cat: 'A', value: 1 }],
|
|
65
|
-
encoding: {
|
|
66
|
-
x: { field: 'cat', type: 'nominal' },
|
|
67
|
-
y: { field: 'value', type: 'quantitative' },
|
|
68
|
-
},
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
it('expands a string title into chrome.title', () => {
|
|
72
|
-
const result = expandSpecSugar({ ...base, title: 'Revenue' });
|
|
73
|
-
expect(result.chrome).toEqual({ title: 'Revenue' });
|
|
74
|
-
expect('title' in result).toBe(false);
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
it('expands the { text, subtitle } object form', () => {
|
|
78
|
-
const result = expandSpecSugar({ ...base, title: { text: 'Revenue', subtitle: 'By region' } });
|
|
79
|
-
expect(result.chrome).toEqual({ title: 'Revenue', subtitle: 'By region' });
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it('expands a top-level subtitle', () => {
|
|
83
|
-
const result = expandSpecSugar({ ...base, title: 'Revenue', subtitle: 'By region' });
|
|
84
|
-
expect(result.chrome).toEqual({ title: 'Revenue', subtitle: 'By region' });
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
it('authored chrome wins over the expanded title', () => {
|
|
88
|
-
const result = expandSpecSugar({
|
|
89
|
-
...base,
|
|
90
|
-
title: 'Sugar title',
|
|
91
|
-
chrome: { title: 'Chrome title' },
|
|
92
|
-
});
|
|
93
|
-
expect((result.chrome as Record<string, unknown>).title).toBe('Chrome title');
|
|
94
|
-
});
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
// ---------------------------------------------------------------------------
|
|
98
|
-
// Top-level description (alt-text override)
|
|
99
|
-
// ---------------------------------------------------------------------------
|
|
100
|
-
|
|
101
|
-
describe('top-level description', () => {
|
|
102
|
-
const base = {
|
|
103
|
-
mark: 'bar',
|
|
104
|
-
data: [{ cat: 'A', value: 1 }],
|
|
105
|
-
encoding: {
|
|
106
|
-
x: { field: 'cat', type: 'nominal' },
|
|
107
|
-
y: { field: 'value', type: 'quantitative' },
|
|
108
|
-
},
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
it('folds description into a11y.description', () => {
|
|
112
|
-
const result = expandSpecSugar({ ...base, description: 'Bar chart of one value' });
|
|
113
|
-
expect(result.a11y).toEqual({ description: 'Bar chart of one value' });
|
|
114
|
-
expect('description' in result).toBe(false);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
it('an authored a11y.description wins over the top-level description', () => {
|
|
118
|
-
const result = expandSpecSugar({
|
|
119
|
-
...base,
|
|
120
|
-
description: 'Sugar text',
|
|
121
|
-
a11y: { description: 'Authored text' },
|
|
122
|
-
});
|
|
123
|
-
expect((result.a11y as Record<string, unknown>).description).toBe('Authored text');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('preserves other a11y fields when folding', () => {
|
|
127
|
-
const result = expandSpecSugar({ ...base, description: 'Alt', a11y: { hidden: true } });
|
|
128
|
-
expect(result.a11y).toEqual({ description: 'Alt', hidden: true });
|
|
129
|
-
});
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
// ---------------------------------------------------------------------------
|
|
133
|
-
// Bare value defs
|
|
134
|
-
// ---------------------------------------------------------------------------
|
|
135
|
-
|
|
136
|
-
describe('bare value defs', () => {
|
|
137
|
-
it('moves color: { value } to mark.fill for bar marks', () => {
|
|
138
|
-
const result = expandSpecSugar({
|
|
139
|
-
mark: 'bar',
|
|
140
|
-
data: [{ cat: 'A', value: 1 }],
|
|
141
|
-
encoding: {
|
|
142
|
-
x: { field: 'cat', type: 'nominal' },
|
|
143
|
-
y: { field: 'value', type: 'quantitative' },
|
|
144
|
-
color: { value: '#1b7fa3' },
|
|
145
|
-
},
|
|
146
|
-
});
|
|
147
|
-
expect(result.mark).toEqual({ type: 'bar', fill: '#1b7fa3' });
|
|
148
|
-
expect((result.encoding as Record<string, unknown>).color).toBeUndefined();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
it('moves color: { value } to mark.stroke for line marks', () => {
|
|
152
|
-
const result = expandSpecSugar({
|
|
153
|
-
mark: 'line',
|
|
154
|
-
data: [{ date: '2020-01-01', value: 1 }],
|
|
155
|
-
encoding: {
|
|
156
|
-
x: { field: 'date', type: 'temporal' },
|
|
157
|
-
y: { field: 'value', type: 'quantitative' },
|
|
158
|
-
color: { value: '#1b7fa3' },
|
|
159
|
-
},
|
|
160
|
-
});
|
|
161
|
-
expect(result.mark).toEqual({ type: 'line', stroke: '#1b7fa3' });
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it('moves size and opacity values to mark-level properties', () => {
|
|
165
|
-
const result = expandSpecSugar({
|
|
166
|
-
mark: 'bar',
|
|
167
|
-
data: [{ cat: 'A', value: 1 }],
|
|
168
|
-
encoding: {
|
|
169
|
-
x: { field: 'cat', type: 'nominal' },
|
|
170
|
-
y: { field: 'value', type: 'quantitative' },
|
|
171
|
-
size: { value: 20 },
|
|
172
|
-
opacity: { value: 0.5 },
|
|
173
|
-
},
|
|
174
|
-
});
|
|
175
|
-
expect(result.mark).toEqual({ type: 'bar', size: 20, opacity: 0.5 });
|
|
176
|
-
});
|
|
177
|
-
|
|
178
|
-
it('explicit mark-level values win over expanded channel constants', () => {
|
|
179
|
-
const result = expandSpecSugar({
|
|
180
|
-
mark: { type: 'bar', fill: '#explicit' },
|
|
181
|
-
data: [{ cat: 'A', value: 1 }],
|
|
182
|
-
encoding: {
|
|
183
|
-
x: { field: 'cat', type: 'nominal' },
|
|
184
|
-
y: { field: 'value', type: 'quantitative' },
|
|
185
|
-
color: { value: '#sugar' },
|
|
186
|
-
},
|
|
187
|
-
});
|
|
188
|
-
expect((result.mark as Record<string, unknown>).fill).toBe('#explicit');
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
it('leaves conditional value defs untouched', () => {
|
|
192
|
-
const color = { condition: { test: { field: 'value', gt: 0 }, value: 'red' }, value: 'gray' };
|
|
193
|
-
const result = expandSpecSugar({
|
|
194
|
-
mark: 'bar',
|
|
195
|
-
data: [{ cat: 'A', value: 1 }],
|
|
196
|
-
encoding: {
|
|
197
|
-
x: { field: 'cat', type: 'nominal' },
|
|
198
|
-
y: { field: 'value', type: 'quantitative' },
|
|
199
|
-
color,
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
expect((result.encoding as Record<string, unknown>).color).toEqual(color);
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
// ---------------------------------------------------------------------------
|
|
207
|
-
// Channel-level legend
|
|
208
|
-
// ---------------------------------------------------------------------------
|
|
209
|
-
|
|
210
|
-
describe('channel-level legend on color', () => {
|
|
211
|
-
const base = {
|
|
212
|
-
mark: 'line',
|
|
213
|
-
data: [
|
|
214
|
-
{ date: '2020-01-01', value: 1, group: 'A' },
|
|
215
|
-
{ date: '2021-01-01', value: 2, group: 'A' },
|
|
216
|
-
],
|
|
217
|
-
encoding: {
|
|
218
|
-
x: { field: 'date', type: 'temporal' },
|
|
219
|
-
y: { field: 'value', type: 'quantitative' },
|
|
220
|
-
},
|
|
221
|
-
};
|
|
222
|
-
|
|
223
|
-
it('legend: null hides the legend via the top-level config', () => {
|
|
224
|
-
const result = expandSpecSugar({
|
|
225
|
-
...base,
|
|
226
|
-
encoding: {
|
|
227
|
-
...base.encoding,
|
|
228
|
-
color: { field: 'group', type: 'nominal', legend: null },
|
|
229
|
-
},
|
|
230
|
-
});
|
|
231
|
-
expect(result.legend).toEqual({ show: false });
|
|
232
|
-
expect((result.encoding as Record<string, Record<string, unknown>>).color.legend).toBe(
|
|
233
|
-
undefined,
|
|
234
|
-
);
|
|
235
|
-
});
|
|
236
|
-
|
|
237
|
-
it('a channel legend config merges into the top-level legend, top level winning', () => {
|
|
238
|
-
const result = expandSpecSugar({
|
|
239
|
-
...base,
|
|
240
|
-
legend: { position: 'bottom' },
|
|
241
|
-
encoding: {
|
|
242
|
-
...base.encoding,
|
|
243
|
-
color: { field: 'group', type: 'nominal', legend: { position: 'top', columns: 2 } },
|
|
244
|
-
},
|
|
245
|
-
});
|
|
246
|
-
expect(result.legend).toEqual({ position: 'bottom', columns: 2 });
|
|
247
|
-
});
|
|
248
|
-
});
|
|
249
|
-
|
|
250
|
-
// ---------------------------------------------------------------------------
|
|
251
|
-
// axis: null and scale.scheme
|
|
252
|
-
// ---------------------------------------------------------------------------
|
|
253
|
-
|
|
254
|
-
describe('axis: null and scale.scheme', () => {
|
|
255
|
-
it('converts axis: null to axis: false', () => {
|
|
256
|
-
const result = expandSpecSugar({
|
|
257
|
-
mark: 'bar',
|
|
258
|
-
data: [{ cat: 'A', value: 1 }],
|
|
259
|
-
encoding: {
|
|
260
|
-
x: { field: 'cat', type: 'nominal', axis: null },
|
|
261
|
-
y: { field: 'value', type: 'quantitative' },
|
|
262
|
-
},
|
|
263
|
-
});
|
|
264
|
-
expect((result.encoding as Record<string, Record<string, unknown>>).x.axis).toBe(false);
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
it('resolves scheme names (including VL aliases) to scale.range', () => {
|
|
268
|
-
const result = expandSpecSugar({
|
|
269
|
-
mark: 'bar',
|
|
270
|
-
data: [{ cat: 'A', value: 1 }],
|
|
271
|
-
encoding: {
|
|
272
|
-
x: { field: 'cat', type: 'nominal' },
|
|
273
|
-
y: { field: 'value', type: 'quantitative' },
|
|
274
|
-
color: { field: 'value', type: 'quantitative', scale: { scheme: 'blues' } },
|
|
275
|
-
},
|
|
276
|
-
});
|
|
277
|
-
const colorScale = (result.encoding as Record<string, Record<string, unknown>>).color
|
|
278
|
-
.scale as Record<string, unknown>;
|
|
279
|
-
expect(colorScale.scheme).toBeUndefined();
|
|
280
|
-
expect(Array.isArray(colorScale.range)).toBe(true);
|
|
281
|
-
expect((colorScale.range as string[]).length).toBeGreaterThan(2);
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it('leaves unknown scheme names for validation, which rejects with the supported list', () => {
|
|
285
|
-
expect(() =>
|
|
286
|
-
compileChart(
|
|
287
|
-
{
|
|
288
|
-
mark: 'bar',
|
|
289
|
-
data: [{ cat: 'A', value: 1 }],
|
|
290
|
-
encoding: {
|
|
291
|
-
x: { field: 'cat', type: 'nominal' },
|
|
292
|
-
y: { field: 'value', type: 'quantitative' },
|
|
293
|
-
color: { field: 'value', type: 'quantitative', scale: { scheme: 'viridis' } },
|
|
294
|
-
},
|
|
295
|
-
},
|
|
296
|
-
OPTIONS,
|
|
297
|
-
),
|
|
298
|
-
).toThrow(/not a supported scheme name/);
|
|
299
|
-
});
|
|
300
|
-
});
|
|
301
|
-
|
|
302
|
-
// ---------------------------------------------------------------------------
|
|
303
|
-
// theta as the arc value channel
|
|
304
|
-
// ---------------------------------------------------------------------------
|
|
305
|
-
|
|
306
|
-
describe('theta on arc marks', () => {
|
|
307
|
-
const data = [
|
|
308
|
-
{ category: 'A', amount: 30 },
|
|
309
|
-
{ category: 'B', amount: 70 },
|
|
310
|
-
];
|
|
311
|
-
|
|
312
|
-
it('uses theta as the canonical value channel (no warning)', () => {
|
|
313
|
-
const layout = compileChart(
|
|
314
|
-
{
|
|
315
|
-
mark: 'arc',
|
|
316
|
-
data,
|
|
317
|
-
encoding: {
|
|
318
|
-
theta: { field: 'amount', type: 'quantitative' },
|
|
319
|
-
color: { field: 'category', type: 'nominal' },
|
|
320
|
-
},
|
|
321
|
-
},
|
|
322
|
-
OPTIONS,
|
|
323
|
-
);
|
|
324
|
-
const arcs = layout.marks.filter((m) => m.type === 'arc');
|
|
325
|
-
expect(arcs.length).toBe(2);
|
|
326
|
-
expect(warned()).toEqual([]);
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
it('warns once when only the deprecated y alias is used', () => {
|
|
330
|
-
const layout = compileChart(
|
|
331
|
-
{
|
|
332
|
-
mark: 'arc',
|
|
333
|
-
data,
|
|
334
|
-
encoding: {
|
|
335
|
-
y: { field: 'amount', type: 'quantitative' },
|
|
336
|
-
color: { field: 'category', type: 'nominal' },
|
|
337
|
-
},
|
|
338
|
-
},
|
|
339
|
-
OPTIONS,
|
|
340
|
-
);
|
|
341
|
-
const arcs = layout.marks.filter((m) => m.type === 'arc');
|
|
342
|
-
expect(arcs.length).toBe(2);
|
|
343
|
-
const messages = warned().filter((m) => m.includes('encoding.y'));
|
|
344
|
-
expect(messages).toHaveLength(1);
|
|
345
|
-
expect(messages[0]).toContain('v8');
|
|
346
|
-
expect(messages[0]).toContain('theta');
|
|
347
|
-
});
|
|
348
|
-
|
|
349
|
-
it('prefers theta over y when both are present (theta is canonical)', () => {
|
|
350
|
-
const layout = compileChart(
|
|
351
|
-
{
|
|
352
|
-
mark: 'arc',
|
|
353
|
-
data,
|
|
354
|
-
encoding: {
|
|
355
|
-
y: { field: 'category', type: 'quantitative' },
|
|
356
|
-
theta: { field: 'amount', type: 'quantitative' },
|
|
357
|
-
color: { field: 'category', type: 'nominal' },
|
|
358
|
-
},
|
|
359
|
-
},
|
|
360
|
-
OPTIONS,
|
|
361
|
-
);
|
|
362
|
-
const arcs = layout.marks.filter((m) => m.type === 'arc');
|
|
363
|
-
expect(arcs.length).toBe(2);
|
|
364
|
-
expect(warned()).toEqual([
|
|
365
|
-
'[openchart] encoding.theta and encoding.y are both set on arc; theta takes precedence and y was dropped.',
|
|
366
|
-
]);
|
|
367
|
-
});
|
|
368
|
-
|
|
369
|
-
it('does not warn when theta and y are identical', () => {
|
|
370
|
-
const layout = compileChart(
|
|
371
|
-
{
|
|
372
|
-
mark: 'arc',
|
|
373
|
-
data,
|
|
374
|
-
encoding: {
|
|
375
|
-
y: { field: 'amount', type: 'quantitative' },
|
|
376
|
-
theta: { field: 'amount', type: 'quantitative' },
|
|
377
|
-
color: { field: 'category', type: 'nominal' },
|
|
378
|
-
},
|
|
379
|
-
},
|
|
380
|
-
OPTIONS,
|
|
381
|
-
);
|
|
382
|
-
const arcs = layout.marks.filter((m) => m.type === 'arc');
|
|
383
|
-
expect(arcs.length).toBe(2);
|
|
384
|
-
expect(warned()).toEqual([]);
|
|
385
|
-
});
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
// ---------------------------------------------------------------------------
|
|
389
|
-
// aggregate: 'count' without a field
|
|
390
|
-
// ---------------------------------------------------------------------------
|
|
391
|
-
|
|
392
|
-
describe('count aggregate without a field', () => {
|
|
393
|
-
it('desugars to an aggregate transform grouped by the other channels', () => {
|
|
394
|
-
const result = expandSpecSugar({
|
|
395
|
-
mark: 'bar',
|
|
396
|
-
data: [
|
|
397
|
-
{ cat: 'A', v: 1 },
|
|
398
|
-
{ cat: 'A', v: 2 },
|
|
399
|
-
{ cat: 'B', v: 3 },
|
|
400
|
-
],
|
|
401
|
-
encoding: {
|
|
402
|
-
x: { field: 'cat', type: 'nominal' },
|
|
403
|
-
y: { aggregate: 'count', type: 'quantitative' },
|
|
404
|
-
},
|
|
405
|
-
});
|
|
406
|
-
expect(result.transform).toEqual([
|
|
407
|
-
{ aggregate: [{ op: 'count', field: '__count', as: '__count' }], groupby: ['cat'] },
|
|
408
|
-
]);
|
|
409
|
-
expect((result.encoding as Record<string, unknown>).y).toEqual({
|
|
410
|
-
field: '__count',
|
|
411
|
-
type: 'quantitative',
|
|
412
|
-
title: 'Count',
|
|
413
|
-
});
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
it('compiles the count spec with row counts as values', () => {
|
|
417
|
-
const layout = compileChart(
|
|
418
|
-
{
|
|
419
|
-
mark: 'bar',
|
|
420
|
-
data: [
|
|
421
|
-
{ cat: 'A', v: 1 },
|
|
422
|
-
{ cat: 'A', v: 2 },
|
|
423
|
-
{ cat: 'B', v: 3 },
|
|
424
|
-
],
|
|
425
|
-
encoding: {
|
|
426
|
-
x: { field: 'cat', type: 'nominal' },
|
|
427
|
-
y: { aggregate: 'count' },
|
|
428
|
-
},
|
|
429
|
-
},
|
|
430
|
-
OPTIONS,
|
|
431
|
-
);
|
|
432
|
-
expect(layout.marks.filter((m) => m.type === 'rect')).toHaveLength(2);
|
|
433
|
-
});
|
|
434
|
-
});
|
|
435
|
-
|
|
436
|
-
// ---------------------------------------------------------------------------
|
|
437
|
-
// VL sort forms
|
|
438
|
-
// ---------------------------------------------------------------------------
|
|
439
|
-
|
|
440
|
-
describe('VL sort forms', () => {
|
|
441
|
-
const data = [
|
|
442
|
-
{ cat: 'A', value: 20 },
|
|
443
|
-
{ cat: 'B', value: 50 },
|
|
444
|
-
{ cat: 'C', value: 10 },
|
|
445
|
-
];
|
|
446
|
-
const base = {
|
|
447
|
-
mark: 'bar',
|
|
448
|
-
data,
|
|
449
|
-
encoding: {
|
|
450
|
-
x: { field: 'cat', type: 'nominal' },
|
|
451
|
-
y: { field: 'value', type: 'quantitative' },
|
|
452
|
-
},
|
|
453
|
-
};
|
|
454
|
-
|
|
455
|
-
function domainFor(sort: unknown): unknown {
|
|
456
|
-
const result = expandSpecSugar({
|
|
457
|
-
...base,
|
|
458
|
-
encoding: {
|
|
459
|
-
...base.encoding,
|
|
460
|
-
x: { ...base.encoding.x, sort },
|
|
461
|
-
},
|
|
462
|
-
});
|
|
463
|
-
const x = (result.encoding as Record<string, Record<string, unknown>>).x;
|
|
464
|
-
expect(x.sort).toBeUndefined();
|
|
465
|
-
return (x.scale as Record<string, unknown> | undefined)?.domain;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
it("resolves sort: '-y' to a value-descending domain", () => {
|
|
469
|
-
expect(domainFor('-y')).toEqual(['B', 'A', 'C']);
|
|
470
|
-
});
|
|
471
|
-
|
|
472
|
-
it("resolves sort: 'y' to a value-ascending domain", () => {
|
|
473
|
-
expect(domainFor('y')).toEqual(['C', 'A', 'B']);
|
|
474
|
-
});
|
|
475
|
-
|
|
476
|
-
it('resolves a value-array sort with unlisted values appended in data order', () => {
|
|
477
|
-
expect(domainFor(['C', 'B'])).toEqual(['C', 'B', 'A']);
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
it('resolves the { field, op, order } object form', () => {
|
|
481
|
-
expect(domainFor({ field: 'value', op: 'max', order: 'descending' })).toEqual(['B', 'A', 'C']);
|
|
482
|
-
});
|
|
483
|
-
|
|
484
|
-
it('sums duplicate category values before comparing (VL default op)', () => {
|
|
485
|
-
const result = expandSpecSugar({
|
|
486
|
-
...base,
|
|
487
|
-
data: [
|
|
488
|
-
{ cat: 'A', value: 10 },
|
|
489
|
-
{ cat: 'A', value: 45 },
|
|
490
|
-
{ cat: 'B', value: 50 },
|
|
491
|
-
],
|
|
492
|
-
encoding: {
|
|
493
|
-
...base.encoding,
|
|
494
|
-
x: { ...base.encoding.x, sort: '-y' },
|
|
495
|
-
},
|
|
496
|
-
});
|
|
497
|
-
const x = (result.encoding as Record<string, Record<string, unknown>>).x;
|
|
498
|
-
expect((x.scale as Record<string, unknown>).domain).toEqual(['A', 'B']);
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
it('drops the sort when an explicit scale.domain is present', () => {
|
|
502
|
-
const result = expandSpecSugar({
|
|
503
|
-
...base,
|
|
504
|
-
encoding: {
|
|
505
|
-
...base.encoding,
|
|
506
|
-
x: { ...base.encoding.x, sort: '-y', scale: { domain: ['C', 'B', 'A'] } },
|
|
507
|
-
},
|
|
508
|
-
});
|
|
509
|
-
const x = (result.encoding as Record<string, Record<string, unknown>>).x;
|
|
510
|
-
expect(x.sort).toBeUndefined();
|
|
511
|
-
expect((x.scale as Record<string, unknown>).domain).toEqual(['C', 'B', 'A']);
|
|
512
|
-
});
|
|
513
|
-
|
|
514
|
-
it('passes canonical ascending/descending/null values through untouched', () => {
|
|
515
|
-
const result = expandSpecSugar({
|
|
516
|
-
...base,
|
|
517
|
-
encoding: {
|
|
518
|
-
...base.encoding,
|
|
519
|
-
x: { ...base.encoding.x, sort: 'descending' },
|
|
520
|
-
},
|
|
521
|
-
});
|
|
522
|
-
expect((result.encoding as Record<string, Record<string, unknown>>).x.sort).toBe('descending');
|
|
523
|
-
});
|
|
524
|
-
});
|
|
525
|
-
|
|
526
|
-
// ---------------------------------------------------------------------------
|
|
527
|
-
// width/height fixed sizing
|
|
528
|
-
// ---------------------------------------------------------------------------
|
|
529
|
-
|
|
530
|
-
describe('top-level width/height', () => {
|
|
531
|
-
it('overrides the container-derived compile dimensions', () => {
|
|
532
|
-
const layout = compileChart(
|
|
533
|
-
{
|
|
534
|
-
mark: 'bar',
|
|
535
|
-
width: 400,
|
|
536
|
-
height: 300,
|
|
537
|
-
data: [{ cat: 'A', value: 1 }],
|
|
538
|
-
encoding: {
|
|
539
|
-
x: { field: 'cat', type: 'nominal' },
|
|
540
|
-
y: { field: 'value', type: 'quantitative' },
|
|
541
|
-
},
|
|
542
|
-
},
|
|
543
|
-
{ width: 800, height: 600 },
|
|
544
|
-
);
|
|
545
|
-
expect(layout.dimensions).toEqual({ width: 400, height: 300 });
|
|
546
|
-
});
|
|
547
|
-
|
|
548
|
-
it('implies responsive: false when both width and height are set', () => {
|
|
549
|
-
const result = expandSpecSugar({
|
|
550
|
-
mark: 'bar',
|
|
551
|
-
width: 400,
|
|
552
|
-
height: 300,
|
|
553
|
-
data: [{ cat: 'A', value: 1 }],
|
|
554
|
-
encoding: {
|
|
555
|
-
x: { field: 'cat', type: 'nominal' },
|
|
556
|
-
y: { field: 'value', type: 'quantitative' },
|
|
557
|
-
},
|
|
558
|
-
});
|
|
559
|
-
expect(result.responsive).toBe(false);
|
|
560
|
-
});
|
|
561
|
-
|
|
562
|
-
it('respects an explicit responsive value', () => {
|
|
563
|
-
const result = expandSpecSugar({
|
|
564
|
-
mark: 'bar',
|
|
565
|
-
width: 400,
|
|
566
|
-
height: 300,
|
|
567
|
-
responsive: true,
|
|
568
|
-
data: [{ cat: 'A', value: 1 }],
|
|
569
|
-
encoding: {
|
|
570
|
-
x: { field: 'cat', type: 'nominal' },
|
|
571
|
-
y: { field: 'value', type: 'quantitative' },
|
|
572
|
-
},
|
|
573
|
-
});
|
|
574
|
-
expect(result.responsive).toBe(true);
|
|
575
|
-
});
|
|
576
|
-
});
|
|
577
|
-
|
|
578
|
-
// ---------------------------------------------------------------------------
|
|
579
|
-
// strokeDash on line marks
|
|
580
|
-
// ---------------------------------------------------------------------------
|
|
581
|
-
|
|
582
|
-
describe('strokeDash on line marks', () => {
|
|
583
|
-
const data = [
|
|
584
|
-
{ date: '2020-01-01', value: 1, scenario: 'actual' },
|
|
585
|
-
{ date: '2021-01-01', value: 2, scenario: 'actual' },
|
|
586
|
-
{ date: '2020-01-01', value: 1.5, scenario: 'forecast' },
|
|
587
|
-
{ date: '2021-01-01', value: 3, scenario: 'forecast' },
|
|
588
|
-
];
|
|
589
|
-
|
|
590
|
-
it('assigns dash patterns per series when strokeDash matches the color field', () => {
|
|
591
|
-
const layout = compileChart(
|
|
592
|
-
{
|
|
593
|
-
mark: 'line',
|
|
594
|
-
data,
|
|
595
|
-
encoding: {
|
|
596
|
-
x: { field: 'date', type: 'temporal' },
|
|
597
|
-
y: { field: 'value', type: 'quantitative' },
|
|
598
|
-
color: { field: 'scenario', type: 'nominal' },
|
|
599
|
-
strokeDash: { field: 'scenario', type: 'nominal' },
|
|
600
|
-
},
|
|
601
|
-
},
|
|
602
|
-
OPTIONS,
|
|
603
|
-
);
|
|
604
|
-
const lines = layout.marks.filter((m): m is LineMark => m.type === 'line');
|
|
605
|
-
expect(lines).toHaveLength(2);
|
|
606
|
-
const byKey = new Map(lines.map((l) => [l.seriesKey, l.strokeDasharray]));
|
|
607
|
-
expect(byKey.get('actual')).toBeUndefined(); // first value renders solid
|
|
608
|
-
expect(byKey.get('forecast')).toBe('6 4');
|
|
609
|
-
});
|
|
610
|
-
|
|
611
|
-
it('groups by the strokeDash field when no color channel is present', () => {
|
|
612
|
-
const layout = compileChart(
|
|
613
|
-
{
|
|
614
|
-
mark: 'line',
|
|
615
|
-
data,
|
|
616
|
-
encoding: {
|
|
617
|
-
x: { field: 'date', type: 'temporal' },
|
|
618
|
-
y: { field: 'value', type: 'quantitative' },
|
|
619
|
-
strokeDash: { field: 'scenario', type: 'nominal' },
|
|
620
|
-
},
|
|
621
|
-
},
|
|
622
|
-
OPTIONS,
|
|
623
|
-
);
|
|
624
|
-
const lines = layout.marks.filter((m): m is LineMark => m.type === 'line');
|
|
625
|
-
expect(lines).toHaveLength(2);
|
|
626
|
-
expect(lines.map((l) => l.strokeDasharray)).toEqual([undefined, '6 4']);
|
|
627
|
-
});
|
|
628
|
-
});
|
|
629
|
-
|
|
630
|
-
// ---------------------------------------------------------------------------
|
|
631
|
-
// Deprecation warnings (v8 clock)
|
|
632
|
-
// ---------------------------------------------------------------------------
|
|
633
|
-
|
|
634
|
-
describe('deprecation warnings', () => {
|
|
635
|
-
const base = {
|
|
636
|
-
mark: 'bar',
|
|
637
|
-
data: [{ cat: 'A', value: 1 }],
|
|
638
|
-
encoding: {
|
|
639
|
-
x: { field: 'cat', type: 'nominal' },
|
|
640
|
-
y: { field: 'value', type: 'quantitative' },
|
|
641
|
-
},
|
|
642
|
-
};
|
|
643
|
-
|
|
644
|
-
it.each([
|
|
645
|
-
'radius',
|
|
646
|
-
'shape',
|
|
647
|
-
'href',
|
|
648
|
-
'order',
|
|
649
|
-
] as const)('warns exactly once for the dead %s channel, naming the removal version', (channel) => {
|
|
650
|
-
compileChart(
|
|
651
|
-
{
|
|
652
|
-
...base,
|
|
653
|
-
encoding: { ...base.encoding, [channel]: { field: 'value', type: 'quantitative' } },
|
|
654
|
-
},
|
|
655
|
-
OPTIONS,
|
|
656
|
-
);
|
|
657
|
-
const messages = warned().filter((m) => m.includes(`encoding.${channel}`));
|
|
658
|
-
expect(messages).toHaveLength(1);
|
|
659
|
-
expect(messages[0]).toContain('v8');
|
|
660
|
-
});
|
|
661
|
-
|
|
662
|
-
it('warns once for $schema and strips it', () => {
|
|
663
|
-
const result = expandSpecSugar({
|
|
664
|
-
...base,
|
|
665
|
-
$schema: 'https://vega.github.io/schema/vega-lite/v5.json',
|
|
666
|
-
});
|
|
667
|
-
expect('$schema' in result).toBe(false);
|
|
668
|
-
compileChart({ ...base, $schema: 'https://vega.github.io/schema/vega-lite/v5.json' }, OPTIONS);
|
|
669
|
-
expect(warned().filter((m) => m.includes('$schema'))).toHaveLength(1);
|
|
670
|
-
});
|
|
671
|
-
|
|
672
|
-
it("warns once for the deprecated 'rule' annotation type, naming the refline replacement", () => {
|
|
673
|
-
compileChart(
|
|
674
|
-
{
|
|
675
|
-
...base,
|
|
676
|
-
annotations: [{ type: 'rule', y: 1, label: 'target' }],
|
|
677
|
-
},
|
|
678
|
-
OPTIONS,
|
|
679
|
-
);
|
|
680
|
-
const messages = warned().filter((m) => m.includes("annotation type 'rule'"));
|
|
681
|
-
expect(messages).toHaveLength(1);
|
|
682
|
-
expect(messages[0]).toContain("'refline'");
|
|
683
|
-
});
|
|
684
|
-
|
|
685
|
-
it("does not warn for the canonical 'refline' annotation type", () => {
|
|
686
|
-
compileChart(
|
|
687
|
-
{
|
|
688
|
-
...base,
|
|
689
|
-
annotations: [{ type: 'refline', y: 1, label: 'target' }],
|
|
690
|
-
},
|
|
691
|
-
OPTIONS,
|
|
692
|
-
);
|
|
693
|
-
expect(warned().filter((m) => m.includes("annotation type 'rule'"))).toHaveLength(0);
|
|
694
|
-
});
|
|
695
|
-
});
|
|
696
|
-
|
|
697
|
-
// ---------------------------------------------------------------------------
|
|
698
|
-
// Layer specs
|
|
699
|
-
// ---------------------------------------------------------------------------
|
|
700
|
-
|
|
701
|
-
describe('layer specs', () => {
|
|
702
|
-
it('applies sugar to layer children (value def, data values, sort)', () => {
|
|
703
|
-
const layout = compileLayer(
|
|
704
|
-
{
|
|
705
|
-
data: {
|
|
706
|
-
values: [
|
|
707
|
-
{ cat: 'A', value: 20 },
|
|
708
|
-
{ cat: 'B', value: 50 },
|
|
709
|
-
{ cat: 'C', value: 10 },
|
|
710
|
-
],
|
|
711
|
-
},
|
|
712
|
-
layer: [
|
|
713
|
-
{
|
|
714
|
-
mark: 'bar',
|
|
715
|
-
encoding: {
|
|
716
|
-
x: { field: 'cat', type: 'nominal', sort: '-y' },
|
|
717
|
-
y: { field: 'value', type: 'quantitative' },
|
|
718
|
-
color: { value: '#1b7fa3' },
|
|
719
|
-
},
|
|
720
|
-
},
|
|
721
|
-
],
|
|
722
|
-
} as unknown as LayerSpec,
|
|
723
|
-
OPTIONS,
|
|
724
|
-
);
|
|
725
|
-
// Sorted domain: B (50), A (20), C (10)
|
|
726
|
-
expect(layout.axes.x?.ticks.map((t) => t.label)).toEqual(['B', 'A', 'C']);
|
|
727
|
-
const rects = layout.marks.filter((m) => m.type === 'rect');
|
|
728
|
-
expect(rects).toHaveLength(3);
|
|
729
|
-
for (const rect of rects) {
|
|
730
|
-
expect((rect as { fill?: unknown }).fill).toBe('#1b7fa3');
|
|
731
|
-
}
|
|
732
|
-
});
|
|
733
|
-
|
|
734
|
-
it('emits each deprecation warning once per compile even across layer children', () => {
|
|
735
|
-
compileLayer(
|
|
736
|
-
{
|
|
737
|
-
data: [
|
|
738
|
-
{ cat: 'A', value: 1 },
|
|
739
|
-
{ cat: 'B', value: 2 },
|
|
740
|
-
],
|
|
741
|
-
layer: [
|
|
742
|
-
{
|
|
743
|
-
mark: 'bar',
|
|
744
|
-
encoding: {
|
|
745
|
-
x: { field: 'cat', type: 'nominal' },
|
|
746
|
-
y: { field: 'value', type: 'quantitative' },
|
|
747
|
-
href: { field: 'cat', type: 'nominal' },
|
|
748
|
-
},
|
|
749
|
-
},
|
|
750
|
-
{
|
|
751
|
-
mark: 'line',
|
|
752
|
-
encoding: {
|
|
753
|
-
x: { field: 'cat', type: 'ordinal' },
|
|
754
|
-
y: { field: 'value', type: 'quantitative' },
|
|
755
|
-
href: { field: 'cat', type: 'nominal' },
|
|
756
|
-
},
|
|
757
|
-
},
|
|
758
|
-
],
|
|
759
|
-
} as unknown as LayerSpec,
|
|
760
|
-
OPTIONS,
|
|
761
|
-
);
|
|
762
|
-
expect(warned().filter((m) => m.includes('encoding.href'))).toHaveLength(1);
|
|
763
|
-
});
|
|
764
|
-
});
|
|
765
|
-
|
|
766
|
-
// ---------------------------------------------------------------------------
|
|
767
|
-
// options.onWarn sink (isomorphic warning routing, no hardcoded console)
|
|
768
|
-
// ---------------------------------------------------------------------------
|
|
769
|
-
|
|
770
|
-
describe('options.onWarn warning sink', () => {
|
|
771
|
-
const deprecated = {
|
|
772
|
-
mark: 'bar',
|
|
773
|
-
data: [{ cat: 'A', value: 1 }],
|
|
774
|
-
encoding: {
|
|
775
|
-
x: { field: 'cat', type: 'nominal' },
|
|
776
|
-
y: { field: 'value', type: 'quantitative' },
|
|
777
|
-
// A dead v8 channel: guaranteed to produce a deprecation warning.
|
|
778
|
-
href: { field: 'value', type: 'quantitative' },
|
|
779
|
-
},
|
|
780
|
-
};
|
|
781
|
-
|
|
782
|
-
it('routes warnings to a host-provided sink instead of console.warn', () => {
|
|
783
|
-
const sink: string[] = [];
|
|
784
|
-
compileChart(deprecated, { ...OPTIONS, onWarn: (m) => sink.push(m) });
|
|
785
|
-
|
|
786
|
-
// The warning reached the sink...
|
|
787
|
-
expect(sink.some((m) => m.includes('encoding.href'))).toBe(true);
|
|
788
|
-
// ...and console.warn was NOT touched (the spy caught nothing).
|
|
789
|
-
expect(warned().filter((m) => m.includes('encoding.href'))).toEqual([]);
|
|
790
|
-
});
|
|
791
|
-
|
|
792
|
-
it('a no-op sink silences warnings entirely (e.g. SSR)', () => {
|
|
793
|
-
compileChart(deprecated, { ...OPTIONS, onWarn: () => {} });
|
|
794
|
-
expect(warned()).toEqual([]);
|
|
795
|
-
});
|
|
796
|
-
|
|
797
|
-
it('falls back to console.warn when no sink is provided', () => {
|
|
798
|
-
compileChart(deprecated, OPTIONS);
|
|
799
|
-
expect(warned().some((m) => m.includes('encoding.href'))).toBe(true);
|
|
800
|
-
});
|
|
801
|
-
});
|