@opendata-ai/openchart-engine 8.0.0-rc.9 → 8.0.0
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 +149 -12
- package/dist/index.js +804 -155
- 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 -215
- 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 -758
- package/src/compile/watermark-obstacle.ts +0 -54
- package/src/compile/you-draw-it.ts +0 -123
- package/src/compile.ts +0 -1503
- 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 -629
- 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 -2041
- 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,587 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Tests for the endpoint-labels compute module.
|
|
3
|
-
*
|
|
4
|
-
* Covers:
|
|
5
|
-
* - Multi-series produces N entries
|
|
6
|
-
* - Long labels wrap to multiple lines
|
|
7
|
-
* - `endpointLabels: false` returns an empty layout
|
|
8
|
-
* - Bidirectional collision sweep displaces overlapping entries
|
|
9
|
-
* - `showLeader: true` when an entry is displaced past the threshold
|
|
10
|
-
* - Entries clamp at the chart top/bottom edges
|
|
11
|
-
* - Marker positions are correct (right edge of chart area, on the line)
|
|
12
|
-
* - Single-series produces an empty layout
|
|
13
|
-
* - Compact strategy returns empty
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
import type { AreaMark, LineMark, Mark, Rect, ResolvedTheme } from '@opendata-ai/openchart-core';
|
|
17
|
-
import { resolveTheme } from '@opendata-ai/openchart-core';
|
|
18
|
-
import { describe, expect, it } from 'vitest';
|
|
19
|
-
|
|
20
|
-
import type { NormalizedChartSpec } from '../../compiler/types';
|
|
21
|
-
import { bidirectionalSweep, computeEndpointLabels } from '../compute';
|
|
22
|
-
import { ENDPOINT_MARKER_RADIUS } from '../constants';
|
|
23
|
-
|
|
24
|
-
// ---------------------------------------------------------------------------
|
|
25
|
-
// Fixtures
|
|
26
|
-
// ---------------------------------------------------------------------------
|
|
27
|
-
|
|
28
|
-
const chartArea: Rect = { x: 50, y: 20, width: 500, height: 300 };
|
|
29
|
-
const theme: ResolvedTheme = resolveTheme();
|
|
30
|
-
|
|
31
|
-
function makeSpec(overrides: Partial<NormalizedChartSpec> = {}): NormalizedChartSpec {
|
|
32
|
-
return {
|
|
33
|
-
markType: 'line',
|
|
34
|
-
markDef: { type: 'line' },
|
|
35
|
-
data: [
|
|
36
|
-
{ date: '2020', value: 10, country: 'US' },
|
|
37
|
-
{ date: '2021', value: 40, country: 'US' },
|
|
38
|
-
{ date: '2020', value: 5, country: 'UK' },
|
|
39
|
-
{ date: '2021', value: 35, country: 'UK' },
|
|
40
|
-
],
|
|
41
|
-
encoding: {
|
|
42
|
-
x: { field: 'date', type: 'temporal' },
|
|
43
|
-
y: { field: 'value', type: 'quantitative' },
|
|
44
|
-
color: { field: 'country', type: 'nominal' },
|
|
45
|
-
},
|
|
46
|
-
chrome: {},
|
|
47
|
-
annotations: [],
|
|
48
|
-
responsive: true,
|
|
49
|
-
theme: {},
|
|
50
|
-
darkMode: 'off',
|
|
51
|
-
labels: { density: 'auto', format: '', prefix: '' },
|
|
52
|
-
hiddenSeries: [],
|
|
53
|
-
seriesStyles: {},
|
|
54
|
-
watermark: true,
|
|
55
|
-
display: 'full',
|
|
56
|
-
userExplicit: {
|
|
57
|
-
chrome: false,
|
|
58
|
-
legend: false,
|
|
59
|
-
endpointLabels: false,
|
|
60
|
-
xAxis: false,
|
|
61
|
-
yAxis: false,
|
|
62
|
-
labels: false,
|
|
63
|
-
animation: false,
|
|
64
|
-
watermark: false,
|
|
65
|
-
crosshair: false,
|
|
66
|
-
},
|
|
67
|
-
...overrides,
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function makeLineMark(
|
|
72
|
-
seriesKey: string,
|
|
73
|
-
lastY: number,
|
|
74
|
-
value: number,
|
|
75
|
-
stroke = '#3366cc',
|
|
76
|
-
): LineMark {
|
|
77
|
-
const lastX = chartArea.x + chartArea.width;
|
|
78
|
-
return {
|
|
79
|
-
type: 'line',
|
|
80
|
-
points: [
|
|
81
|
-
{ x: chartArea.x, y: lastY + 20 },
|
|
82
|
-
{ x: lastX, y: lastY },
|
|
83
|
-
],
|
|
84
|
-
stroke,
|
|
85
|
-
strokeWidth: 2,
|
|
86
|
-
seriesKey,
|
|
87
|
-
data: [
|
|
88
|
-
{ date: '2020', value: value - 5, country: seriesKey },
|
|
89
|
-
{ date: '2021', value, country: seriesKey },
|
|
90
|
-
],
|
|
91
|
-
dataPoints: [
|
|
92
|
-
{
|
|
93
|
-
x: chartArea.x,
|
|
94
|
-
y: lastY + 20,
|
|
95
|
-
datum: { date: '2020', value: value - 5, country: seriesKey },
|
|
96
|
-
},
|
|
97
|
-
{ x: lastX, y: lastY, datum: { date: '2021', value, country: seriesKey } },
|
|
98
|
-
],
|
|
99
|
-
aria: { label: seriesKey },
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function makeAreaMark(seriesKey: string, lastY: number, value: number, fill = '#3366cc'): AreaMark {
|
|
104
|
-
const lastX = chartArea.x + chartArea.width;
|
|
105
|
-
return {
|
|
106
|
-
type: 'area',
|
|
107
|
-
topPoints: [
|
|
108
|
-
{ x: chartArea.x, y: lastY + 20 },
|
|
109
|
-
{ x: lastX, y: lastY },
|
|
110
|
-
],
|
|
111
|
-
bottomPoints: [
|
|
112
|
-
{ x: chartArea.x, y: chartArea.y + chartArea.height },
|
|
113
|
-
{ x: lastX, y: chartArea.y + chartArea.height },
|
|
114
|
-
],
|
|
115
|
-
path: '',
|
|
116
|
-
topPath: '',
|
|
117
|
-
fill,
|
|
118
|
-
fillOpacity: 0.3,
|
|
119
|
-
stroke: fill,
|
|
120
|
-
strokeWidth: 2,
|
|
121
|
-
seriesKey,
|
|
122
|
-
data: [
|
|
123
|
-
{ date: '2020', value: value - 5, country: seriesKey },
|
|
124
|
-
{ date: '2021', value, country: seriesKey },
|
|
125
|
-
],
|
|
126
|
-
dataPoints: [
|
|
127
|
-
{
|
|
128
|
-
x: chartArea.x,
|
|
129
|
-
y: lastY + 20,
|
|
130
|
-
datum: { date: '2020', value: value - 5, country: seriesKey },
|
|
131
|
-
},
|
|
132
|
-
{ x: lastX, y: lastY, datum: { date: '2021', value, country: seriesKey } },
|
|
133
|
-
],
|
|
134
|
-
aria: { label: seriesKey },
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// ---------------------------------------------------------------------------
|
|
139
|
-
// Tests
|
|
140
|
-
// ---------------------------------------------------------------------------
|
|
141
|
-
|
|
142
|
-
describe('computeEndpointLabels', () => {
|
|
143
|
-
it('produces one entry per series for a multi-series line chart', () => {
|
|
144
|
-
const spec = makeSpec();
|
|
145
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
146
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
147
|
-
|
|
148
|
-
expect(layout.entries).toHaveLength(2);
|
|
149
|
-
const keys = layout.entries.map((e) => e.seriesKey).sort();
|
|
150
|
-
expect(keys).toEqual(['UK', 'US']);
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
it('returns an empty layout when endpointLabels: false', () => {
|
|
154
|
-
const spec = makeSpec({ endpointLabels: false });
|
|
155
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35)];
|
|
156
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
157
|
-
|
|
158
|
-
expect(layout.entries).toHaveLength(0);
|
|
159
|
-
expect(layout.bounds.width).toBe(0);
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
it('returns an empty layout for a single-series chart', () => {
|
|
163
|
-
const spec = makeSpec();
|
|
164
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40)];
|
|
165
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
166
|
-
|
|
167
|
-
expect(layout.entries).toHaveLength(0);
|
|
168
|
-
});
|
|
169
|
-
|
|
170
|
-
it('returns an empty layout when strategy.labelMode is "none" (compact breakpoint)', () => {
|
|
171
|
-
const spec = makeSpec();
|
|
172
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35)];
|
|
173
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea, {
|
|
174
|
-
labelMode: 'none',
|
|
175
|
-
legendPosition: 'top',
|
|
176
|
-
annotationPosition: 'tooltip-only',
|
|
177
|
-
axisLabelDensity: 'minimal',
|
|
178
|
-
chromeMode: 'full',
|
|
179
|
-
legendMaxHeight: -1,
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
expect(layout.entries).toHaveLength(0);
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
it('wraps long series names to multiple lines', () => {
|
|
186
|
-
const longName = 'A really long multi-word series name that should wrap';
|
|
187
|
-
const spec = makeSpec({
|
|
188
|
-
data: [
|
|
189
|
-
{ date: '2020', value: 10, country: longName },
|
|
190
|
-
{ date: '2021', value: 40, country: longName },
|
|
191
|
-
{ date: '2020', value: 5, country: 'UK' },
|
|
192
|
-
{ date: '2021', value: 35, country: 'UK' },
|
|
193
|
-
],
|
|
194
|
-
endpointLabels: { width: 80 },
|
|
195
|
-
});
|
|
196
|
-
const marks: Mark[] = [makeLineMark(longName, 100, 40), makeLineMark('UK', 200, 35)];
|
|
197
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
198
|
-
|
|
199
|
-
const longEntry = layout.entries.find((e) => e.seriesKey === longName);
|
|
200
|
-
expect(longEntry).toBeDefined();
|
|
201
|
-
expect(longEntry!.labelLines.length).toBeGreaterThan(1);
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it('displaces overlapping entries via the bidirectional collision sweep', () => {
|
|
205
|
-
// Two series whose last data points are very close together (same y).
|
|
206
|
-
const spec = makeSpec();
|
|
207
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 102, 35, '#cc6633')];
|
|
208
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
209
|
-
|
|
210
|
-
expect(layout.entries).toHaveLength(2);
|
|
211
|
-
const [a, b] = layout.entries;
|
|
212
|
-
// Their labelY values should be separated by at least their height (no overlap).
|
|
213
|
-
const distance = Math.abs(a.labelY - b.labelY);
|
|
214
|
-
// Each entry has at least one line of label height.
|
|
215
|
-
expect(distance).toBeGreaterThanOrEqual(11 * 1.25 - 0.5);
|
|
216
|
-
});
|
|
217
|
-
|
|
218
|
-
it('marks displaced entries with showLeader: true when opted in', () => {
|
|
219
|
-
// Leaders are off by default; opt in via endpointLabels.showLeader.
|
|
220
|
-
const spec = makeSpec({ endpointLabels: { showLeader: true } });
|
|
221
|
-
// Force overlap at the same y to guarantee displacement.
|
|
222
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 100, 35, '#cc6633')];
|
|
223
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
224
|
-
|
|
225
|
-
const anyDisplaced = layout.entries.some((e) => e.showLeader);
|
|
226
|
-
expect(anyDisplaced).toBe(true);
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('keeps showLeader off by default even when displaced', () => {
|
|
230
|
-
// Default (no showLeader config): displacement does not produce a leader.
|
|
231
|
-
const spec = makeSpec();
|
|
232
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 100, 35, '#cc6633')];
|
|
233
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
234
|
-
|
|
235
|
-
expect(layout.entries.every((e) => !e.showLeader)).toBe(true);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it('does not flag undisplaced entries with showLeader', () => {
|
|
239
|
-
// Two series far apart vertically — no collision, no leader, even when opted in.
|
|
240
|
-
const spec = makeSpec({ endpointLabels: { showLeader: true } });
|
|
241
|
-
const marks: Mark[] = [makeLineMark('US', 50, 40), makeLineMark('UK', 280, 35, '#cc6633')];
|
|
242
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
243
|
-
|
|
244
|
-
expect(layout.entries.every((e) => !e.showLeader)).toBe(true);
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
it('clamps entries inside the chart area at the top edge', () => {
|
|
248
|
-
const spec = makeSpec();
|
|
249
|
-
// Series whose last point is at the very top of the chart area.
|
|
250
|
-
const marks: Mark[] = [
|
|
251
|
-
makeLineMark('US', chartArea.y, 40),
|
|
252
|
-
makeLineMark('UK', chartArea.y + 5, 35, '#cc6633'),
|
|
253
|
-
];
|
|
254
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
255
|
-
|
|
256
|
-
for (const entry of layout.entries) {
|
|
257
|
-
expect(entry.labelY).toBeGreaterThanOrEqual(chartArea.y - 0.0001);
|
|
258
|
-
}
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('clamps entries inside the chart area at the bottom edge', () => {
|
|
262
|
-
const spec = makeSpec();
|
|
263
|
-
const bottomY = chartArea.y + chartArea.height;
|
|
264
|
-
const marks: Mark[] = [
|
|
265
|
-
makeLineMark('US', bottomY, 40),
|
|
266
|
-
makeLineMark('UK', bottomY - 5, 35, '#cc6633'),
|
|
267
|
-
];
|
|
268
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
269
|
-
|
|
270
|
-
// Some line height; height = 11 * 1.25 ≈ 13.75
|
|
271
|
-
const labelLineHeight = 11 * 1.25;
|
|
272
|
-
for (const entry of layout.entries) {
|
|
273
|
-
expect(entry.labelY + labelLineHeight).toBeLessThanOrEqual(bottomY + 0.5);
|
|
274
|
-
}
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
it('attaches a marker on the line at the chart right edge', () => {
|
|
278
|
-
const spec = makeSpec();
|
|
279
|
-
const lastX = chartArea.x + chartArea.width;
|
|
280
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
281
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
282
|
-
|
|
283
|
-
for (const entry of layout.entries) {
|
|
284
|
-
expect(entry.marker).toBeDefined();
|
|
285
|
-
// dataX is the original line endpoint; x is offset right by radius so the
|
|
286
|
-
// line terminates at the circle edge rather than its center.
|
|
287
|
-
expect(entry.marker!.dataX).toBe(lastX);
|
|
288
|
-
expect(entry.marker!.x).toBe(lastX + ENDPOINT_MARKER_RADIUS);
|
|
289
|
-
// Marker y is at the actual data point (not displaced labelY).
|
|
290
|
-
expect(entry.marker!.y).toBe(entry.dataY);
|
|
291
|
-
// Open-circle convention: fill = background, stroke = series color.
|
|
292
|
-
expect(entry.marker!.stroke).toBe(entry.color);
|
|
293
|
-
}
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it('omits the marker when showMarker is explicitly false', () => {
|
|
297
|
-
const spec = makeSpec({ endpointLabels: { showMarker: false } });
|
|
298
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
299
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
300
|
-
|
|
301
|
-
for (const entry of layout.entries) {
|
|
302
|
-
expect(entry.marker).toBeUndefined();
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
|
|
306
|
-
it('formats values via the spec format string', () => {
|
|
307
|
-
const spec = makeSpec({ endpointLabels: { format: '$.2f' } });
|
|
308
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
309
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
310
|
-
|
|
311
|
-
for (const entry of layout.entries) {
|
|
312
|
-
expect(entry.value.startsWith('$')).toBe(true);
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
it('positions the column to the right of the chart area', () => {
|
|
317
|
-
const spec = makeSpec();
|
|
318
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
319
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
320
|
-
|
|
321
|
-
expect(layout.bounds.x).toBeGreaterThanOrEqual(chartArea.x + chartArea.width);
|
|
322
|
-
expect(layout.bounds.width).toBeGreaterThan(0);
|
|
323
|
-
});
|
|
324
|
-
|
|
325
|
-
it('handles area marks (overlap, not stacked)', () => {
|
|
326
|
-
// v8: area stacks by default, and stacked areas suppress the endpoint
|
|
327
|
-
// column in favor of the traditional legend. Stamp stack: null to
|
|
328
|
-
// exercise the overlap path this test targets.
|
|
329
|
-
const spec = makeSpec({
|
|
330
|
-
markType: 'area',
|
|
331
|
-
markDef: { type: 'area' },
|
|
332
|
-
encoding: {
|
|
333
|
-
x: { field: 'date', type: 'temporal' },
|
|
334
|
-
y: { field: 'value', type: 'quantitative', stack: null },
|
|
335
|
-
color: { field: 'country', type: 'nominal' },
|
|
336
|
-
},
|
|
337
|
-
});
|
|
338
|
-
const marks: Mark[] = [makeAreaMark('US', 100, 40), makeAreaMark('UK', 200, 35, '#cc6633')];
|
|
339
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
340
|
-
|
|
341
|
-
expect(layout.entries).toHaveLength(2);
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it('dedupes by seriesKey when both an area and a derived line exist for a series', () => {
|
|
345
|
-
// Defect-1 regression: the area renderer emits BOTH an AreaMark AND a
|
|
346
|
-
// derived LineMark per series (see linesFromAreas in
|
|
347
|
-
// packages/engine/src/charts/line/index.ts). Without dedupe, each series
|
|
348
|
-
// produces two endpoint entries.
|
|
349
|
-
// v8: stamp stack: null so this overlap-mode fixture still shows the
|
|
350
|
-
// endpoint column (stacked areas suppress it in favor of the legend).
|
|
351
|
-
const spec = makeSpec({
|
|
352
|
-
markType: 'area',
|
|
353
|
-
markDef: { type: 'area' },
|
|
354
|
-
encoding: {
|
|
355
|
-
x: { field: 'date', type: 'temporal' },
|
|
356
|
-
y: { field: 'value', type: 'quantitative', stack: null },
|
|
357
|
-
color: { field: 'country', type: 'nominal' },
|
|
358
|
-
},
|
|
359
|
-
});
|
|
360
|
-
const lineColor = '#3366cc';
|
|
361
|
-
const areaColor = '#ddee99'; // fake gradient-derived color, distinct from the line stroke
|
|
362
|
-
const marks: Mark[] = [
|
|
363
|
-
makeAreaMark('US', 100, 40, areaColor),
|
|
364
|
-
makeAreaMark('UK', 200, 35, areaColor),
|
|
365
|
-
makeLineMark('US', 100, 40, lineColor),
|
|
366
|
-
makeLineMark('UK', 200, 35, lineColor),
|
|
367
|
-
];
|
|
368
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
369
|
-
|
|
370
|
-
// Single entry per series.
|
|
371
|
-
expect(layout.entries).toHaveLength(2);
|
|
372
|
-
const keys = layout.entries.map((e) => e.seriesKey).sort();
|
|
373
|
-
expect(keys).toEqual(['UK', 'US']);
|
|
374
|
-
|
|
375
|
-
// Line marks win — entry color should match the line stroke, not the
|
|
376
|
-
// area-derived gradient color.
|
|
377
|
-
for (const entry of layout.entries) {
|
|
378
|
-
expect(entry.color).toBe(lineColor);
|
|
379
|
-
}
|
|
380
|
-
});
|
|
381
|
-
|
|
382
|
-
it('bidirectional sweep produces non-overlapping tops when stack fits in area (deterministic fuzz)', () => {
|
|
383
|
-
// Seeded LCG so the fuzz is reproducible without dragging in a dep.
|
|
384
|
-
const rand = (() => {
|
|
385
|
-
let s = 0x12345678 >>> 0;
|
|
386
|
-
return () => {
|
|
387
|
-
s = (Math.imul(s, 1664525) + 1013904223) >>> 0;
|
|
388
|
-
return s / 0x100000000;
|
|
389
|
-
};
|
|
390
|
-
})();
|
|
391
|
-
|
|
392
|
-
const areaTop = 0;
|
|
393
|
-
const areaBottom = 600;
|
|
394
|
-
const areaHeight = areaBottom - areaTop;
|
|
395
|
-
|
|
396
|
-
for (let trial = 0; trial < 200; trial++) {
|
|
397
|
-
const n = 2 + Math.floor(rand() * 9); // 2..10 entries
|
|
398
|
-
const heights: number[] = [];
|
|
399
|
-
let totalHeight = 0;
|
|
400
|
-
for (let i = 0; i < n; i++) {
|
|
401
|
-
const h = 12 + Math.floor(rand() * 30); // 12..41
|
|
402
|
-
heights.push(h);
|
|
403
|
-
totalHeight += h;
|
|
404
|
-
}
|
|
405
|
-
// Skip trials whose stack can't fit — the algorithm explicitly cannot
|
|
406
|
-
// promise non-overlap when the chart is too short for the entries.
|
|
407
|
-
if (totalHeight > areaHeight) continue;
|
|
408
|
-
|
|
409
|
-
const sweepEntries = heights.map((h, idx) => ({
|
|
410
|
-
naturalTop: areaTop + rand() * (areaBottom - h),
|
|
411
|
-
height: h,
|
|
412
|
-
index: idx,
|
|
413
|
-
}));
|
|
414
|
-
const tops = bidirectionalSweep(sweepEntries, areaTop, areaBottom);
|
|
415
|
-
|
|
416
|
-
// Resort by final top to validate the sorted-stack invariant the
|
|
417
|
-
// algorithm guarantees: every entry sits inside [areaTop, areaBottom-h]
|
|
418
|
-
// and adjacent entries never overlap.
|
|
419
|
-
const sortedFinals = sweepEntries
|
|
420
|
-
.map((e) => ({ top: tops[e.index], height: e.height }))
|
|
421
|
-
.sort((a, b) => a.top - b.top);
|
|
422
|
-
|
|
423
|
-
for (let i = 0; i < sortedFinals.length; i++) {
|
|
424
|
-
const { top, height } = sortedFinals[i];
|
|
425
|
-
expect(top).toBeGreaterThanOrEqual(areaTop - 1e-6);
|
|
426
|
-
expect(top + height).toBeLessThanOrEqual(areaBottom + 1e-6);
|
|
427
|
-
if (i + 1 < sortedFinals.length) {
|
|
428
|
-
const next = sortedFinals[i + 1];
|
|
429
|
-
expect(top + height).toBeLessThanOrEqual(next.top + 1e-6);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
it('dedupe prefers line mark even when area appears later in the marks array', () => {
|
|
436
|
-
// Defect-1 regression: area marks listed AFTER line marks should not
|
|
437
|
-
// overwrite the line's canonical stroke color in the endpoint entry.
|
|
438
|
-
// v8: stamp stack: null so this overlap-mode fixture still shows the
|
|
439
|
-
// endpoint column (stacked areas suppress it in favor of the legend).
|
|
440
|
-
const spec = makeSpec({
|
|
441
|
-
markType: 'area',
|
|
442
|
-
markDef: { type: 'area' },
|
|
443
|
-
encoding: {
|
|
444
|
-
x: { field: 'date', type: 'temporal' },
|
|
445
|
-
y: { field: 'value', type: 'quantitative', stack: null },
|
|
446
|
-
color: { field: 'country', type: 'nominal' },
|
|
447
|
-
},
|
|
448
|
-
});
|
|
449
|
-
const lineColor = '#3366cc';
|
|
450
|
-
const areaColor = '#ddee99';
|
|
451
|
-
const marks: Mark[] = [
|
|
452
|
-
makeLineMark('US', 100, 40, lineColor),
|
|
453
|
-
makeLineMark('UK', 200, 35, lineColor),
|
|
454
|
-
makeAreaMark('US', 100, 40, areaColor),
|
|
455
|
-
makeAreaMark('UK', 200, 35, areaColor),
|
|
456
|
-
];
|
|
457
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
458
|
-
|
|
459
|
-
expect(layout.entries).toHaveLength(2);
|
|
460
|
-
for (const entry of layout.entries) {
|
|
461
|
-
expect(entry.color).toBe(lineColor);
|
|
462
|
-
}
|
|
463
|
-
});
|
|
464
|
-
|
|
465
|
-
it('produces leading entries when ends: "both"', () => {
|
|
466
|
-
const spec = makeSpec({ endpointLabels: { ends: 'both' } });
|
|
467
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
468
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
469
|
-
|
|
470
|
-
expect(layout.entries).toHaveLength(2);
|
|
471
|
-
expect(layout.leading).toBeDefined();
|
|
472
|
-
expect(layout.leading).toHaveLength(2);
|
|
473
|
-
const leadingKeys = layout.leading!.map((e) => e.seriesKey).sort();
|
|
474
|
-
expect(leadingKeys).toEqual(['UK', 'US']);
|
|
475
|
-
});
|
|
476
|
-
|
|
477
|
-
it('positions leading column to the left of the chart area', () => {
|
|
478
|
-
const spec = makeSpec({ endpointLabels: { ends: 'both' } });
|
|
479
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
480
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
481
|
-
|
|
482
|
-
expect(layout.leadingBounds).toBeDefined();
|
|
483
|
-
expect(layout.leadingBounds!.x + layout.leadingBounds!.width).toBeLessThanOrEqual(chartArea.x);
|
|
484
|
-
expect(layout.leadingBounds!.width).toBeGreaterThan(0);
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
it('leading entries use the first data point value', () => {
|
|
488
|
-
const spec = makeSpec({ endpointLabels: { ends: 'both' } });
|
|
489
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
490
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
491
|
-
|
|
492
|
-
const usTrailing = layout.entries.find((e) => e.seriesKey === 'US');
|
|
493
|
-
const usLeading = layout.leading!.find((e) => e.seriesKey === 'US');
|
|
494
|
-
expect(usTrailing).toBeDefined();
|
|
495
|
-
expect(usLeading).toBeDefined();
|
|
496
|
-
// The first data point has value - 5 (35 for US), the last has the full value (40).
|
|
497
|
-
expect(usLeading!.value).not.toBe(usTrailing!.value);
|
|
498
|
-
});
|
|
499
|
-
|
|
500
|
-
it('does not produce leading entries when ends is unset (default)', () => {
|
|
501
|
-
const spec = makeSpec();
|
|
502
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
503
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
504
|
-
|
|
505
|
-
expect(layout.leading).toBeUndefined();
|
|
506
|
-
expect(layout.leadingBounds).toBeUndefined();
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
it('leading entries get markers at the first data point', () => {
|
|
510
|
-
const spec = makeSpec({ endpointLabels: { ends: 'both' } });
|
|
511
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
512
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
513
|
-
|
|
514
|
-
for (const entry of layout.leading!) {
|
|
515
|
-
expect(entry.marker).toBeDefined();
|
|
516
|
-
expect(entry.marker!.dataX).toBe(chartArea.x);
|
|
517
|
-
// Leading marker offset: x = dataX - radius (left side).
|
|
518
|
-
expect(entry.marker!.x).toBe(chartArea.x - ENDPOINT_MARKER_RADIUS);
|
|
519
|
-
}
|
|
520
|
-
});
|
|
521
|
-
|
|
522
|
-
it("content: 'label value' joins name and value on one line and drops the value line", () => {
|
|
523
|
-
const spec = makeSpec({ endpointLabels: { content: 'label value' } });
|
|
524
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
525
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
526
|
-
|
|
527
|
-
const us = layout.entries.find((e) => e.seriesKey === 'US');
|
|
528
|
-
expect(us!.labelLines[0]).toBe('US 40');
|
|
529
|
-
expect(us!.value).toBe('');
|
|
530
|
-
});
|
|
531
|
-
|
|
532
|
-
it("content: 'value' renders the formatted value alone", () => {
|
|
533
|
-
const spec = makeSpec({ endpointLabels: { content: 'value' } });
|
|
534
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
535
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
536
|
-
|
|
537
|
-
const us = layout.entries.find((e) => e.seriesKey === 'US');
|
|
538
|
-
expect(us!.labelLines).toEqual(['40']);
|
|
539
|
-
expect(us!.value).toBe('');
|
|
540
|
-
});
|
|
541
|
-
|
|
542
|
-
it("content: 'label' renders the series name alone", () => {
|
|
543
|
-
const spec = makeSpec({ endpointLabels: { content: 'label' } });
|
|
544
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
545
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
546
|
-
|
|
547
|
-
const us = layout.entries.find((e) => e.seriesKey === 'US');
|
|
548
|
-
expect(us!.labelLines).toEqual(['US']);
|
|
549
|
-
expect(us!.value).toBe('');
|
|
550
|
-
});
|
|
551
|
-
|
|
552
|
-
it('per-side content object resolves leading and trailing independently', () => {
|
|
553
|
-
const spec = makeSpec({
|
|
554
|
-
endpointLabels: {
|
|
555
|
-
ends: 'both',
|
|
556
|
-
content: { leading: 'label value', trailing: 'value' },
|
|
557
|
-
},
|
|
558
|
-
});
|
|
559
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
560
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea);
|
|
561
|
-
|
|
562
|
-
// Leading: first data point value (value - 5) joined with the name.
|
|
563
|
-
const usLeading = layout.leading!.find((e) => e.seriesKey === 'US');
|
|
564
|
-
expect(usLeading!.labelLines[0]).toBe('US 35');
|
|
565
|
-
// Trailing: last value alone.
|
|
566
|
-
const usTrailing = layout.entries.find((e) => e.seriesKey === 'US');
|
|
567
|
-
expect(usTrailing!.labelLines).toEqual(['40']);
|
|
568
|
-
});
|
|
569
|
-
|
|
570
|
-
it('keeps the column at compact breakpoints when endpoint labels are explicitly on', () => {
|
|
571
|
-
// Slope/bump recipes carry their values on the labels: explicit user
|
|
572
|
-
// config must survive the compact strategy strip (labelMode: 'none').
|
|
573
|
-
const spec = makeSpec({ endpointLabels: { ends: 'both', content: 'label value' } });
|
|
574
|
-
const marks: Mark[] = [makeLineMark('US', 100, 40), makeLineMark('UK', 200, 35, '#cc6633')];
|
|
575
|
-
const layout = computeEndpointLabels(spec, marks, theme, chartArea, {
|
|
576
|
-
labelMode: 'none',
|
|
577
|
-
legendPosition: 'top',
|
|
578
|
-
annotationPosition: 'tooltip-only',
|
|
579
|
-
axisLabelDensity: 'minimal',
|
|
580
|
-
chromeMode: 'full',
|
|
581
|
-
legendMaxHeight: -1,
|
|
582
|
-
});
|
|
583
|
-
|
|
584
|
-
expect(layout.entries).toHaveLength(2);
|
|
585
|
-
expect(layout.leading).toHaveLength(2);
|
|
586
|
-
});
|
|
587
|
-
});
|