@opendata-ai/openchart-engine 7.11.0 → 8.0.0-rc.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/dist/index.d.ts +123 -14
- package/dist/index.js +16166 -10027
- package/dist/index.js.map +1 -1
- package/package.json +11 -4
- package/src/__tests__/__snapshots__/compile-snapshot.test.ts.snap +170 -56
- package/src/__tests__/annotation-behavior.test.ts +721 -0
- package/src/__tests__/axes.test.ts +50 -3
- package/src/__tests__/compile-chart.test.ts +30 -0
- package/src/__tests__/compile-footnotes.test.ts +277 -0
- package/src/__tests__/compile-layer.test.ts +120 -1
- package/src/__tests__/helpers/invariants.ts +54 -20
- package/src/__tests__/known-bugs.test.ts +455 -2
- package/src/__tests__/legend.test.ts +69 -4
- package/src/__tests__/ranking-recipes.test.ts +260 -0
- package/src/__tests__/scales.test.ts +9 -3
- package/src/__tests__/series-search.test.ts +92 -0
- package/src/__tests__/spec-sugar.test.ts +801 -0
- package/src/__tests__/you-draw-it.test.ts +160 -0
- package/src/annotations/__tests__/compute.test.ts +207 -92
- package/src/annotations/__tests__/geometry.test.ts +66 -0
- package/src/annotations/__tests__/resolve-text.test.ts +527 -27
- package/src/annotations/__tests__/rich-text.test.ts +91 -0
- package/src/annotations/__tests__/thinning.test.ts +148 -0
- package/src/annotations/collisions.ts +130 -84
- package/src/annotations/compute.ts +83 -85
- package/src/annotations/constants.ts +116 -6
- package/src/annotations/geometry.ts +222 -77
- package/src/annotations/move.ts +135 -0
- package/src/annotations/placement.ts +62 -14
- package/src/annotations/resolve-range.ts +2 -0
- package/src/annotations/resolve-refline.ts +2 -0
- package/src/annotations/resolve-text.ts +312 -111
- package/src/annotations/rich-text.ts +65 -0
- package/src/annotations/thinning.ts +84 -10
- package/src/barlist/compile-barlist.ts +16 -6
- package/src/charts/_shared/format-label-value.ts +9 -8
- package/src/charts/bar/__tests__/compute.test.ts +57 -10
- package/src/charts/bar/__tests__/labels.test.ts +5 -4
- package/src/charts/bar/compute.ts +2 -6
- package/src/charts/bar/index.ts +8 -1
- package/src/charts/bar/labels.ts +3 -3
- package/src/charts/beeswarm/__tests__/compute.test.ts +280 -0
- package/src/charts/beeswarm/__tests__/dodge.test.ts +148 -0
- package/src/charts/beeswarm/compute.ts +203 -0
- package/src/charts/beeswarm/dodge.ts +155 -0
- package/src/charts/beeswarm/index.ts +32 -0
- package/src/charts/builtin.ts +12 -1
- package/src/charts/calendar/__tests__/compute.test.ts +417 -0
- package/src/charts/calendar/compute.ts +319 -0
- package/src/charts/calendar/index.ts +32 -0
- package/src/charts/column/__tests__/compute.test.ts +21 -7
- package/src/charts/column/__tests__/labels.test.ts +76 -1
- package/src/charts/column/compute.ts +2 -6
- package/src/charts/column/index.ts +10 -2
- package/src/charts/column/labels.ts +95 -21
- package/src/charts/dot/index.ts +8 -1
- package/src/charts/dot/labels.ts +3 -3
- package/src/charts/line/__tests__/compute.test.ts +15 -19
- package/src/charts/line/area.ts +8 -23
- package/src/charts/line/compute.ts +32 -2
- package/src/charts/parliament/__tests__/compute.test.ts +411 -0
- package/src/charts/parliament/compute.ts +313 -0
- package/src/charts/parliament/index.ts +32 -0
- package/src/charts/pie/__tests__/compute.test.ts +103 -0
- package/src/charts/pie/compute.ts +63 -8
- package/src/charts/pie/labels.ts +1 -0
- package/src/charts/range/__tests__/compute.test.ts +486 -0
- package/src/charts/range/compute.ts +273 -0
- package/src/charts/range/index.ts +82 -0
- package/src/charts/range/labels.ts +169 -0
- package/src/charts/rect/__tests__/compute.test.ts +120 -0
- package/src/charts/rect/index.ts +127 -0
- package/src/charts/scatter/compute.ts +7 -21
- package/src/charts/text/__tests__/compute.test.ts +307 -0
- package/src/charts/text/index.ts +44 -7
- package/src/charts/tick/__tests__/compute.test.ts +75 -0
- package/src/charts/tick/index.ts +7 -4
- package/src/charts/utils.ts +5 -3
- package/src/charts/waffle/__tests__/compute.test.ts +305 -0
- package/src/charts/waffle/compute.ts +197 -0
- package/src/charts/waffle/index.ts +31 -0
- package/src/compile/__tests__/color-scale-reverse.test.ts +89 -0
- package/src/compile/__tests__/data-clip.test.ts +68 -0
- package/src/compile/__tests__/fill-patterns.test.ts +154 -0
- package/src/compile/__tests__/size-scale.test.ts +108 -0
- package/src/compile/color-scale-range.ts +54 -33
- package/src/compile/data-clip.ts +21 -6
- package/src/compile/fill-patterns.ts +74 -0
- package/src/compile/layer.ts +117 -21
- package/src/compile/size-scale.ts +139 -0
- package/src/compile/spec-sugar.ts +758 -0
- package/src/compile/you-draw-it.ts +123 -0
- package/src/compile.ts +310 -103
- package/src/compiler/__tests__/a11y-warnings.test.ts +148 -0
- package/src/compiler/__tests__/fixtures/vl-parity/axis-null.json +19 -0
- package/src/compiler/__tests__/fixtures/vl-parity/color-value.json +20 -0
- package/src/compiler/__tests__/fixtures/vl-parity/count-aggregate.json +22 -0
- package/src/compiler/__tests__/fixtures/vl-parity/data-values.json +19 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-axis-null.json +14 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-count.json +34 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-data-values.json +22 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-legend-null.json +41 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-scheme.json +38 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-sort.json +28 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-theta.json +28 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-title.json +30 -0
- package/src/compiler/__tests__/fixtures/vl-parity/layer-value-def.json +29 -0
- package/src/compiler/__tests__/fixtures/vl-parity/legend-null.json +32 -0
- package/src/compiler/__tests__/fixtures/vl-parity/scheme.json +25 -0
- package/src/compiler/__tests__/fixtures/vl-parity/sort-by-value.json +19 -0
- package/src/compiler/__tests__/fixtures/vl-parity/theta-arc.json +19 -0
- package/src/compiler/__tests__/fixtures/vl-parity/title-subtitle.json +21 -0
- package/src/compiler/__tests__/fixtures/vl-parity/width-height.json +23 -0
- package/src/compiler/__tests__/keys.test.ts +3 -9
- package/src/compiler/__tests__/normalize.test.ts +65 -1
- package/src/compiler/__tests__/validate-did-you-mean.test.ts +86 -0
- package/src/compiler/__tests__/validate-near-miss.test.ts +89 -0
- package/src/compiler/__tests__/validate.test.ts +156 -0
- package/src/compiler/__tests__/vl-parity.test.ts +68 -0
- package/src/compiler/a11y-warnings.ts +110 -0
- package/src/compiler/keys.ts +5 -4
- package/src/compiler/normalize.ts +150 -7
- package/src/compiler/types.ts +11 -0
- package/src/compiler/validate.ts +664 -18
- package/src/endpoint-labels/__tests__/compute.test.ts +88 -0
- package/src/endpoint-labels/compute.ts +40 -12
- package/src/endpoint-labels/format.ts +45 -15
- package/src/endpoint-labels/predict.ts +50 -36
- package/src/format/__tests__/field-format.test.ts +164 -0
- package/src/format/field-format.ts +27 -0
- package/src/geo/__tests__/compile-map.test.ts +621 -0
- package/src/geo/compile-map.ts +856 -0
- package/src/geo/join.ts +115 -0
- package/src/geo/projections.ts +45 -0
- package/src/geo/types.ts +24 -0
- package/src/graphs/__tests__/compile-graph.test.ts +25 -0
- package/src/graphs/compile-graph.ts +27 -18
- package/src/index.ts +20 -2
- package/src/layout/axes/ticks.ts +59 -10
- package/src/layout/axes.ts +35 -6
- package/src/layout/dimensions.ts +139 -83
- package/src/layout/facet.ts +14 -3
- package/src/layout/plan.ts +83 -33
- package/src/layout/scales.ts +132 -15
- package/src/legend/__tests__/continuous.test.ts +318 -0
- package/src/legend/__tests__/size.test.ts +348 -0
- package/src/legend/__tests__/suppression.test.ts +17 -1
- package/src/legend/compute.ts +119 -13
- package/src/legend/continuous.ts +327 -0
- package/src/legend/size.ts +407 -0
- package/src/legend/suppression.ts +8 -7
- package/src/sankey/compile-sankey.ts +31 -19
- package/src/tables/format-cells.ts +16 -7
- package/src/tilemap/__tests__/compile-tilemap.test.ts +39 -0
- package/src/tilemap/compile-tilemap.ts +24 -7
- package/src/tooltips/__tests__/compute.test.ts +2 -2
- package/src/tooltips/compute.ts +422 -41
- package/src/transforms/__tests__/conditional.test.ts +18 -0
- package/src/transforms/aggregate.ts +2 -1
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Dev-mode WCAG contrast warnings.
|
|
3
|
+
*
|
|
4
|
+
* Unit tests for collectContrastWarnings plus compileChart integration:
|
|
5
|
+
* warnings only fire with { dev: true }, name both colors and the ratio,
|
|
6
|
+
* and never throw.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { resolveTheme } from '@opendata-ai/openchart-core';
|
|
10
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
11
|
+
import { compileChart } from '../../compile';
|
|
12
|
+
import { computeScales } from '../../layout/scales';
|
|
13
|
+
import { collectContrastWarnings } from '../a11y-warnings';
|
|
14
|
+
import type { NormalizedChartSpec } from '../types';
|
|
15
|
+
|
|
16
|
+
// ---------------------------------------------------------------------------
|
|
17
|
+
// Fixtures
|
|
18
|
+
// ---------------------------------------------------------------------------
|
|
19
|
+
|
|
20
|
+
const AREA = { x: 0, y: 0, width: 500, height: 300 };
|
|
21
|
+
|
|
22
|
+
/** Stacked column spec with an explicit two-color range. */
|
|
23
|
+
function stackedBarSpec(range: [string, string]) {
|
|
24
|
+
return {
|
|
25
|
+
mark: 'bar' as const,
|
|
26
|
+
data: [
|
|
27
|
+
{ month: 'Jan', series: 'A', value: 10 },
|
|
28
|
+
{ month: 'Jan', series: 'B', value: 20 },
|
|
29
|
+
{ month: 'Feb', series: 'A', value: 15 },
|
|
30
|
+
{ month: 'Feb', series: 'B', value: 25 },
|
|
31
|
+
],
|
|
32
|
+
encoding: {
|
|
33
|
+
x: { field: 'month', type: 'nominal' as const },
|
|
34
|
+
y: { field: 'value', type: 'quantitative' as const, stack: 'zero' as const },
|
|
35
|
+
color: { field: 'series', type: 'nominal' as const, scale: { range } },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function scalesFor(spec: ReturnType<typeof stackedBarSpec>) {
|
|
41
|
+
return computeScales(
|
|
42
|
+
{ ...spec, markType: 'bar' } as unknown as NormalizedChartSpec,
|
|
43
|
+
AREA,
|
|
44
|
+
spec.data,
|
|
45
|
+
);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const theme = resolveTheme({});
|
|
49
|
+
|
|
50
|
+
// ---------------------------------------------------------------------------
|
|
51
|
+
// collectContrastWarnings (unit)
|
|
52
|
+
// ---------------------------------------------------------------------------
|
|
53
|
+
|
|
54
|
+
describe('collectContrastWarnings', () => {
|
|
55
|
+
it('warns on adjacent stacked series below 3:1, naming both colors and the ratio', () => {
|
|
56
|
+
const spec = stackedBarSpec(['#1a5276', '#21618c']);
|
|
57
|
+
const warnings = collectContrastWarnings(scalesFor(spec), 'bar', theme);
|
|
58
|
+
|
|
59
|
+
const adjacent = warnings.find((w) => w.includes('Adjacent series'));
|
|
60
|
+
expect(adjacent).toBeDefined();
|
|
61
|
+
expect(adjacent).toContain('#1a5276');
|
|
62
|
+
expect(adjacent).toContain('#21618c');
|
|
63
|
+
expect(adjacent).toContain('"A"');
|
|
64
|
+
expect(adjacent).toContain('"B"');
|
|
65
|
+
expect(adjacent).toMatch(/\d\.\d{2}:1/);
|
|
66
|
+
expect(adjacent).toContain('WCAG 1.4.11');
|
|
67
|
+
// Suggested replacement is a concrete color
|
|
68
|
+
expect(adjacent).toMatch(/Nearest passing color for "B": #[0-9a-f]{6}/i);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it('stays silent for well-separated series colors', () => {
|
|
72
|
+
const spec = stackedBarSpec(['#0b3040', '#f5b942']);
|
|
73
|
+
const warnings = collectContrastWarnings(scalesFor(spec), 'bar', theme);
|
|
74
|
+
expect(warnings.filter((w) => w.includes('Adjacent series'))).toEqual([]);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('skips adjacency checks for line marks (series are not adjacent fills)', () => {
|
|
78
|
+
const spec = stackedBarSpec(['#1a5276', '#21618c']);
|
|
79
|
+
const warnings = collectContrastWarnings(scalesFor(spec), 'line', theme);
|
|
80
|
+
expect(warnings.filter((w) => w.includes('Adjacent series'))).toEqual([]);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('warns when a series color falls below 3:1 against an opaque background', () => {
|
|
84
|
+
const whiteBg = resolveTheme({ colors: { background: '#ffffff' } });
|
|
85
|
+
const spec = stackedBarSpec(['#f2f3f4', '#0b3040']);
|
|
86
|
+
const warnings = collectContrastWarnings(scalesFor(spec), 'bar', whiteBg);
|
|
87
|
+
const bg = warnings.find((w) => w.includes('against the background'));
|
|
88
|
+
expect(bg).toBeDefined();
|
|
89
|
+
expect(bg).toContain('#f2f3f4');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('warns on text tokens below 4.5:1', () => {
|
|
93
|
+
const lowContrastTheme = resolveTheme({
|
|
94
|
+
colors: { background: '#ffffff', text: '#bbbbbb' },
|
|
95
|
+
});
|
|
96
|
+
const spec = stackedBarSpec(['#0b3040', '#111111']);
|
|
97
|
+
const warnings = collectContrastWarnings(scalesFor(spec), 'bar', lowContrastTheme);
|
|
98
|
+
const text = warnings.find((w) => w.includes('theme.colors.text'));
|
|
99
|
+
expect(text).toBeDefined();
|
|
100
|
+
expect(text).toContain('WCAG 1.4.3');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('skips background-relative checks when the background is transparent (default)', () => {
|
|
104
|
+
const spec = stackedBarSpec(['#f2f3f4', '#0b3040']);
|
|
105
|
+
const warnings = collectContrastWarnings(scalesFor(spec), 'bar', theme);
|
|
106
|
+
expect(warnings.filter((w) => w.includes('against the background'))).toEqual([]);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('passes cleanly when series contrast both each other and the background', () => {
|
|
110
|
+
const spec = stackedBarSpec(['#767676', '#111111']);
|
|
111
|
+
expect(collectContrastWarnings(scalesFor(spec), 'bar', theme)).toEqual([]);
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// ---------------------------------------------------------------------------
|
|
116
|
+
// compileChart integration (dev gate)
|
|
117
|
+
// ---------------------------------------------------------------------------
|
|
118
|
+
|
|
119
|
+
describe('compileChart dev-mode gating', () => {
|
|
120
|
+
beforeEach(() => {
|
|
121
|
+
vi.spyOn(console, 'warn').mockImplementation(() => {});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
afterEach(() => {
|
|
125
|
+
vi.restoreAllMocks();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it('logs contrast warnings only when dev: true', () => {
|
|
129
|
+
const spec = stackedBarSpec(['#1a5276', '#21618c']);
|
|
130
|
+
|
|
131
|
+
compileChart(spec, { width: 600, height: 400 });
|
|
132
|
+
const withoutDev = (console.warn as ReturnType<typeof vi.fn>).mock.calls.filter((c) =>
|
|
133
|
+
String(c[0]).includes('[openchart a11y]'),
|
|
134
|
+
);
|
|
135
|
+
expect(withoutDev).toEqual([]);
|
|
136
|
+
|
|
137
|
+
compileChart(spec, { width: 600, height: 400, dev: true });
|
|
138
|
+
const withDev = (console.warn as ReturnType<typeof vi.fn>).mock.calls.filter((c) =>
|
|
139
|
+
String(c[0]).includes('[openchart a11y]'),
|
|
140
|
+
);
|
|
141
|
+
expect(withDev.length).toBeGreaterThan(0);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it('never throws, even for unparseable colors', () => {
|
|
145
|
+
const spec = stackedBarSpec(['not-a-color', 'also-not-a-color']);
|
|
146
|
+
expect(() => compileChart(spec, { width: 600, height: 400, dev: true })).not.toThrow();
|
|
147
|
+
});
|
|
148
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "bar",
|
|
5
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
6
|
+
"encoding": {
|
|
7
|
+
"x": { "field": "cat", "type": "nominal", "axis": null },
|
|
8
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"canonical": {
|
|
12
|
+
"mark": "bar",
|
|
13
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
14
|
+
"encoding": {
|
|
15
|
+
"x": { "field": "cat", "type": "nominal", "axis": false },
|
|
16
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "bar",
|
|
5
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
6
|
+
"encoding": {
|
|
7
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
8
|
+
"y": { "field": "value", "type": "quantitative" },
|
|
9
|
+
"color": { "value": "#1b7fa3" }
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"canonical": {
|
|
13
|
+
"mark": { "type": "bar", "fill": "#1b7fa3" },
|
|
14
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
15
|
+
"encoding": {
|
|
16
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
17
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "bar",
|
|
5
|
+
"data": [{ "cat": "A", "v": 1 }, { "cat": "A", "v": 2 }, { "cat": "B", "v": 3 }],
|
|
6
|
+
"encoding": {
|
|
7
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
8
|
+
"y": { "aggregate": "count" }
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"canonical": {
|
|
12
|
+
"mark": "bar",
|
|
13
|
+
"data": [{ "cat": "A", "v": 1 }, { "cat": "A", "v": 2 }, { "cat": "B", "v": 3 }],
|
|
14
|
+
"transform": [
|
|
15
|
+
{ "aggregate": [{ "op": "count", "field": "__count", "as": "__count" }], "groupby": ["cat"] }
|
|
16
|
+
],
|
|
17
|
+
"encoding": {
|
|
18
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
19
|
+
"y": { "field": "__count", "type": "quantitative", "title": "Count" }
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "bar",
|
|
5
|
+
"data": { "values": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }] },
|
|
6
|
+
"encoding": {
|
|
7
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
8
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"canonical": {
|
|
12
|
+
"mark": "bar",
|
|
13
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
14
|
+
"encoding": {
|
|
15
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
16
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
6
|
+
"encoding": { "x": { "field": "cat", "type": "nominal", "axis": null } },
|
|
7
|
+
"layer": [{ "mark": "bar", "encoding": { "y": { "field": "value", "type": "quantitative" } } }]
|
|
8
|
+
},
|
|
9
|
+
"canonical": {
|
|
10
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
11
|
+
"encoding": { "x": { "field": "cat", "type": "nominal", "axis": false } },
|
|
12
|
+
"layer": [{ "mark": "bar", "encoding": { "y": { "field": "value", "type": "quantitative" } } }]
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": [{ "cat": "A", "v": 1 }, { "cat": "A", "v": 2 }, { "cat": "B", "v": 3 }],
|
|
6
|
+
"layer": [
|
|
7
|
+
{
|
|
8
|
+
"mark": "bar",
|
|
9
|
+
"encoding": {
|
|
10
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
11
|
+
"y": { "aggregate": "count" }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"canonical": {
|
|
17
|
+
"data": [{ "cat": "A", "v": 1 }, { "cat": "A", "v": 2 }, { "cat": "B", "v": 3 }],
|
|
18
|
+
"layer": [
|
|
19
|
+
{
|
|
20
|
+
"mark": "bar",
|
|
21
|
+
"transform": [
|
|
22
|
+
{
|
|
23
|
+
"aggregate": [{ "op": "count", "field": "__count", "as": "__count" }],
|
|
24
|
+
"groupby": ["cat"]
|
|
25
|
+
}
|
|
26
|
+
],
|
|
27
|
+
"encoding": {
|
|
28
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
29
|
+
"y": { "field": "__count", "type": "quantitative", "title": "Count" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": {
|
|
6
|
+
"values": [{ "date": "2020-01-01", "a": 1, "b": 4 }, { "date": "2021-01-01", "a": 2, "b": 3 }]
|
|
7
|
+
},
|
|
8
|
+
"encoding": { "x": { "field": "date", "type": "temporal" } },
|
|
9
|
+
"layer": [
|
|
10
|
+
{ "mark": "line", "encoding": { "y": { "field": "a", "type": "quantitative" } } },
|
|
11
|
+
{ "mark": "line", "encoding": { "y": { "field": "b", "type": "quantitative" } } }
|
|
12
|
+
]
|
|
13
|
+
},
|
|
14
|
+
"canonical": {
|
|
15
|
+
"data": [{ "date": "2020-01-01", "a": 1, "b": 4 }, { "date": "2021-01-01", "a": 2, "b": 3 }],
|
|
16
|
+
"encoding": { "x": { "field": "date", "type": "temporal" } },
|
|
17
|
+
"layer": [
|
|
18
|
+
{ "mark": "line", "encoding": { "y": { "field": "a", "type": "quantitative" } } },
|
|
19
|
+
{ "mark": "line", "encoding": { "y": { "field": "b", "type": "quantitative" } } }
|
|
20
|
+
]
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": [
|
|
6
|
+
{ "date": "2020-01-01", "value": 1, "group": "A" },
|
|
7
|
+
{ "date": "2021-01-01", "value": 2, "group": "A" },
|
|
8
|
+
{ "date": "2020-01-01", "value": 3, "group": "B" },
|
|
9
|
+
{ "date": "2021-01-01", "value": 4, "group": "B" }
|
|
10
|
+
],
|
|
11
|
+
"encoding": { "color": { "field": "group", "type": "nominal", "legend": null } },
|
|
12
|
+
"layer": [
|
|
13
|
+
{
|
|
14
|
+
"mark": "line",
|
|
15
|
+
"encoding": {
|
|
16
|
+
"x": { "field": "date", "type": "temporal" },
|
|
17
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
"canonical": {
|
|
23
|
+
"legend": { "show": false },
|
|
24
|
+
"data": [
|
|
25
|
+
{ "date": "2020-01-01", "value": 1, "group": "A" },
|
|
26
|
+
{ "date": "2021-01-01", "value": 2, "group": "A" },
|
|
27
|
+
{ "date": "2020-01-01", "value": 3, "group": "B" },
|
|
28
|
+
{ "date": "2021-01-01", "value": 4, "group": "B" }
|
|
29
|
+
],
|
|
30
|
+
"encoding": { "color": { "field": "group", "type": "nominal" } },
|
|
31
|
+
"layer": [
|
|
32
|
+
{
|
|
33
|
+
"mark": "line",
|
|
34
|
+
"encoding": {
|
|
35
|
+
"x": { "field": "date", "type": "temporal" },
|
|
36
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }, { "cat": "C", "value": 30 }],
|
|
6
|
+
"encoding": {
|
|
7
|
+
"color": { "field": "value", "type": "quantitative", "scale": { "scheme": "blues" } }
|
|
8
|
+
},
|
|
9
|
+
"layer": [
|
|
10
|
+
{
|
|
11
|
+
"mark": "bar",
|
|
12
|
+
"encoding": {
|
|
13
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
14
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
},
|
|
19
|
+
"canonical": {
|
|
20
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }, { "cat": "C", "value": 30 }],
|
|
21
|
+
"encoding": {
|
|
22
|
+
"color": {
|
|
23
|
+
"field": "value",
|
|
24
|
+
"type": "quantitative",
|
|
25
|
+
"scale": { "range": ["#deebf7", "#c6dbef", "#9ecae1", "#6baed6", "#3182bd", "#08519c"] }
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"layer": [
|
|
29
|
+
{
|
|
30
|
+
"mark": "bar",
|
|
31
|
+
"encoding": {
|
|
32
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
33
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": [{ "cat": "A", "value": 20 }, { "cat": "B", "value": 50 }, { "cat": "C", "value": 10 }],
|
|
6
|
+
"layer": [
|
|
7
|
+
{
|
|
8
|
+
"mark": "bar",
|
|
9
|
+
"encoding": {
|
|
10
|
+
"x": { "field": "cat", "type": "nominal", "sort": "-y" },
|
|
11
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"canonical": {
|
|
17
|
+
"data": [{ "cat": "A", "value": 20 }, { "cat": "B", "value": 50 }, { "cat": "C", "value": 10 }],
|
|
18
|
+
"layer": [
|
|
19
|
+
{
|
|
20
|
+
"mark": "bar",
|
|
21
|
+
"encoding": {
|
|
22
|
+
"x": { "field": "cat", "type": "nominal", "scale": { "domain": ["B", "A", "C"] } },
|
|
23
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": [{ "category": "A", "amount": 30 }, { "category": "B", "amount": 70 }],
|
|
6
|
+
"layer": [
|
|
7
|
+
{
|
|
8
|
+
"mark": "arc",
|
|
9
|
+
"encoding": {
|
|
10
|
+
"theta": { "field": "amount", "type": "quantitative" },
|
|
11
|
+
"color": { "field": "category", "type": "nominal" }
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
]
|
|
15
|
+
},
|
|
16
|
+
"canonical": {
|
|
17
|
+
"data": [{ "category": "A", "amount": 30 }, { "category": "B", "amount": 70 }],
|
|
18
|
+
"layer": [
|
|
19
|
+
{
|
|
20
|
+
"mark": "arc",
|
|
21
|
+
"encoding": {
|
|
22
|
+
"y": { "field": "amount", "type": "quantitative" },
|
|
23
|
+
"color": { "field": "category", "type": "nominal" }
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"title": "Layered revenue",
|
|
6
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
7
|
+
"layer": [
|
|
8
|
+
{
|
|
9
|
+
"mark": "bar",
|
|
10
|
+
"encoding": {
|
|
11
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
12
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"canonical": {
|
|
18
|
+
"chrome": { "title": "Layered revenue" },
|
|
19
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
20
|
+
"layer": [
|
|
21
|
+
{
|
|
22
|
+
"mark": "bar",
|
|
23
|
+
"encoding": {
|
|
24
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
25
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"layered": true,
|
|
3
|
+
"options": { "width": 600, "height": 400 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
6
|
+
"layer": [
|
|
7
|
+
{
|
|
8
|
+
"mark": "bar",
|
|
9
|
+
"encoding": {
|
|
10
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
11
|
+
"y": { "field": "value", "type": "quantitative" },
|
|
12
|
+
"color": { "value": "#1b7fa3" }
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
]
|
|
16
|
+
},
|
|
17
|
+
"canonical": {
|
|
18
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
19
|
+
"layer": [
|
|
20
|
+
{
|
|
21
|
+
"mark": { "type": "bar", "fill": "#1b7fa3" },
|
|
22
|
+
"encoding": {
|
|
23
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
24
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "line",
|
|
5
|
+
"data": [
|
|
6
|
+
{ "date": "2020-01-01", "value": 1, "group": "A" },
|
|
7
|
+
{ "date": "2021-01-01", "value": 2, "group": "A" },
|
|
8
|
+
{ "date": "2020-01-01", "value": 3, "group": "B" },
|
|
9
|
+
{ "date": "2021-01-01", "value": 4, "group": "B" }
|
|
10
|
+
],
|
|
11
|
+
"encoding": {
|
|
12
|
+
"x": { "field": "date", "type": "temporal" },
|
|
13
|
+
"y": { "field": "value", "type": "quantitative" },
|
|
14
|
+
"color": { "field": "group", "type": "nominal", "legend": null }
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
"canonical": {
|
|
18
|
+
"mark": "line",
|
|
19
|
+
"legend": { "show": false },
|
|
20
|
+
"data": [
|
|
21
|
+
{ "date": "2020-01-01", "value": 1, "group": "A" },
|
|
22
|
+
{ "date": "2021-01-01", "value": 2, "group": "A" },
|
|
23
|
+
{ "date": "2020-01-01", "value": 3, "group": "B" },
|
|
24
|
+
{ "date": "2021-01-01", "value": 4, "group": "B" }
|
|
25
|
+
],
|
|
26
|
+
"encoding": {
|
|
27
|
+
"x": { "field": "date", "type": "temporal" },
|
|
28
|
+
"y": { "field": "value", "type": "quantitative" },
|
|
29
|
+
"color": { "field": "group", "type": "nominal" }
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "bar",
|
|
5
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }, { "cat": "C", "value": 30 }],
|
|
6
|
+
"encoding": {
|
|
7
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
8
|
+
"y": { "field": "value", "type": "quantitative" },
|
|
9
|
+
"color": { "field": "value", "type": "quantitative", "scale": { "scheme": "blues" } }
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"canonical": {
|
|
13
|
+
"mark": "bar",
|
|
14
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }, { "cat": "C", "value": 30 }],
|
|
15
|
+
"encoding": {
|
|
16
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
17
|
+
"y": { "field": "value", "type": "quantitative" },
|
|
18
|
+
"color": {
|
|
19
|
+
"field": "value",
|
|
20
|
+
"type": "quantitative",
|
|
21
|
+
"scale": { "range": ["#deebf7", "#c6dbef", "#9ecae1", "#6baed6", "#3182bd", "#08519c"] }
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "bar",
|
|
5
|
+
"data": [{ "cat": "A", "value": 20 }, { "cat": "B", "value": 50 }, { "cat": "C", "value": 10 }],
|
|
6
|
+
"encoding": {
|
|
7
|
+
"x": { "field": "cat", "type": "nominal", "sort": "-y" },
|
|
8
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"canonical": {
|
|
12
|
+
"mark": "bar",
|
|
13
|
+
"data": [{ "cat": "A", "value": 20 }, { "cat": "B", "value": 50 }, { "cat": "C", "value": 10 }],
|
|
14
|
+
"encoding": {
|
|
15
|
+
"x": { "field": "cat", "type": "nominal", "scale": { "domain": ["B", "A", "C"] } },
|
|
16
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "arc",
|
|
5
|
+
"data": [{ "category": "A", "amount": 30 }, { "category": "B", "amount": 70 }],
|
|
6
|
+
"encoding": {
|
|
7
|
+
"theta": { "field": "amount", "type": "quantitative" },
|
|
8
|
+
"color": { "field": "category", "type": "nominal" }
|
|
9
|
+
}
|
|
10
|
+
},
|
|
11
|
+
"canonical": {
|
|
12
|
+
"mark": "arc",
|
|
13
|
+
"data": [{ "category": "A", "amount": 30 }, { "category": "B", "amount": 70 }],
|
|
14
|
+
"encoding": {
|
|
15
|
+
"y": { "field": "amount", "type": "quantitative" },
|
|
16
|
+
"color": { "field": "category", "type": "nominal" }
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 600, "height": 400 },
|
|
3
|
+
"vl": {
|
|
4
|
+
"mark": "line",
|
|
5
|
+
"title": { "text": "Revenue", "subtitle": "By quarter" },
|
|
6
|
+
"data": [{ "date": "2020-01-01", "value": 1 }, { "date": "2021-01-01", "value": 2 }],
|
|
7
|
+
"encoding": {
|
|
8
|
+
"x": { "field": "date", "type": "temporal" },
|
|
9
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"canonical": {
|
|
13
|
+
"mark": "line",
|
|
14
|
+
"chrome": { "title": "Revenue", "subtitle": "By quarter" },
|
|
15
|
+
"data": [{ "date": "2020-01-01", "value": 1 }, { "date": "2021-01-01", "value": 2 }],
|
|
16
|
+
"encoding": {
|
|
17
|
+
"x": { "field": "date", "type": "temporal" },
|
|
18
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"options": { "width": 400, "height": 300 },
|
|
3
|
+
"vlOptions": { "width": 800, "height": 600 },
|
|
4
|
+
"vl": {
|
|
5
|
+
"mark": "bar",
|
|
6
|
+
"width": 400,
|
|
7
|
+
"height": 300,
|
|
8
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
9
|
+
"encoding": {
|
|
10
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
11
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"canonical": {
|
|
15
|
+
"mark": "bar",
|
|
16
|
+
"responsive": false,
|
|
17
|
+
"data": [{ "cat": "A", "value": 10 }, { "cat": "B", "value": 20 }],
|
|
18
|
+
"encoding": {
|
|
19
|
+
"x": { "field": "cat", "type": "nominal" },
|
|
20
|
+
"y": { "field": "value", "type": "quantitative" }
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|