@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.
Files changed (271) hide show
  1. package/dist/index.d.ts +149 -12
  2. package/dist/index.js +804 -155
  3. package/dist/index.js.map +1 -1
  4. package/package.json +3 -4
  5. package/src/__test-fixtures__/specs.ts +0 -182
  6. package/src/__tests__/__snapshots__/compile-snapshot.test.ts.snap +0 -2401
  7. package/src/__tests__/annotation-behavior.test.ts +0 -852
  8. package/src/__tests__/axes.test.ts +0 -1579
  9. package/src/__tests__/compile-animation.test.ts +0 -161
  10. package/src/__tests__/compile-chart.test.ts +0 -1303
  11. package/src/__tests__/compile-footnotes.test.ts +0 -277
  12. package/src/__tests__/compile-layer.test.ts +0 -969
  13. package/src/__tests__/compile-snapshot.test.ts +0 -156
  14. package/src/__tests__/compound-labels.test.ts +0 -147
  15. package/src/__tests__/dimensions.test.ts +0 -918
  16. package/src/__tests__/encoding-sugar.test.ts +0 -390
  17. package/src/__tests__/facet.test.ts +0 -215
  18. package/src/__tests__/helpers/invariants.ts +0 -299
  19. package/src/__tests__/known-bugs.test.ts +0 -566
  20. package/src/__tests__/layout-fuzz.test.ts +0 -358
  21. package/src/__tests__/layout-invariants.test.ts +0 -535
  22. package/src/__tests__/legend.test.ts +0 -721
  23. package/src/__tests__/mark-keys.test.ts +0 -294
  24. package/src/__tests__/ranking-recipes.test.ts +0 -260
  25. package/src/__tests__/rotation.test.ts +0 -83
  26. package/src/__tests__/scales.test.ts +0 -323
  27. package/src/__tests__/series-search.test.ts +0 -92
  28. package/src/__tests__/spec-sugar.test.ts +0 -801
  29. package/src/__tests__/you-draw-it.test.ts +0 -160
  30. package/src/annotations/__tests__/compute.test.ts +0 -1672
  31. package/src/annotations/__tests__/geometry.test.ts +0 -66
  32. package/src/annotations/__tests__/placement-fuzz.test.ts +0 -256
  33. package/src/annotations/__tests__/placement-invariants.test.ts +0 -345
  34. package/src/annotations/__tests__/placement.test.ts +0 -316
  35. package/src/annotations/__tests__/resolve-text.test.ts +0 -788
  36. package/src/annotations/__tests__/rich-text.test.ts +0 -91
  37. package/src/annotations/__tests__/thinning.test.ts +0 -285
  38. package/src/annotations/collisions.ts +0 -326
  39. package/src/annotations/compute.ts +0 -333
  40. package/src/annotations/constants.ts +0 -162
  41. package/src/annotations/geometry.ts +0 -376
  42. package/src/annotations/move.ts +0 -135
  43. package/src/annotations/placement.ts +0 -636
  44. package/src/annotations/position.ts +0 -131
  45. package/src/annotations/resolve-range.ts +0 -117
  46. package/src/annotations/resolve-refline.ts +0 -157
  47. package/src/annotations/resolve-text.ts +0 -545
  48. package/src/annotations/rich-text.ts +0 -65
  49. package/src/annotations/thinning.ts +0 -190
  50. package/src/barlist/__tests__/compile-barlist.test.ts +0 -200
  51. package/src/barlist/compile-barlist.ts +0 -391
  52. package/src/barlist/types.ts +0 -28
  53. package/src/charts/__tests__/post-process.test.ts +0 -237
  54. package/src/charts/__tests__/registry.test.ts +0 -116
  55. package/src/charts/__tests__/utils.test.ts +0 -195
  56. package/src/charts/_shared/__tests__/density-filter.test.ts +0 -32
  57. package/src/charts/_shared/density-filter.ts +0 -26
  58. package/src/charts/_shared/format-label-value.ts +0 -16
  59. package/src/charts/bar/__tests__/compute.test.ts +0 -934
  60. package/src/charts/bar/__tests__/gradient-orient.test.ts +0 -127
  61. package/src/charts/bar/__tests__/labels.test.ts +0 -292
  62. package/src/charts/bar/compute.ts +0 -539
  63. package/src/charts/bar/index.ts +0 -60
  64. package/src/charts/bar/labels.ts +0 -311
  65. package/src/charts/beeswarm/__tests__/compute.test.ts +0 -280
  66. package/src/charts/beeswarm/__tests__/dodge.test.ts +0 -148
  67. package/src/charts/beeswarm/compute.ts +0 -203
  68. package/src/charts/beeswarm/dodge.ts +0 -155
  69. package/src/charts/beeswarm/index.ts +0 -32
  70. package/src/charts/builtin.ts +0 -75
  71. package/src/charts/calendar/__tests__/compute.test.ts +0 -417
  72. package/src/charts/calendar/compute.ts +0 -319
  73. package/src/charts/calendar/index.ts +0 -32
  74. package/src/charts/column/__tests__/compute.test.ts +0 -540
  75. package/src/charts/column/__tests__/labels.test.ts +0 -179
  76. package/src/charts/column/compute.ts +0 -493
  77. package/src/charts/column/index.ts +0 -53
  78. package/src/charts/column/labels.ts +0 -229
  79. package/src/charts/dot/__tests__/compute.test.ts +0 -380
  80. package/src/charts/dot/__tests__/labels.test.ts +0 -98
  81. package/src/charts/dot/compute.ts +0 -285
  82. package/src/charts/dot/index.ts +0 -62
  83. package/src/charts/dot/labels.ts +0 -121
  84. package/src/charts/line/__tests__/compute.test.ts +0 -1194
  85. package/src/charts/line/__tests__/curves.test.ts +0 -51
  86. package/src/charts/line/__tests__/labels.test.ts +0 -94
  87. package/src/charts/line/__tests__/mark-options.test.ts +0 -175
  88. package/src/charts/line/area.ts +0 -484
  89. package/src/charts/line/compute.ts +0 -356
  90. package/src/charts/line/curves.ts +0 -85
  91. package/src/charts/line/index.ts +0 -176
  92. package/src/charts/line/labels.ts +0 -177
  93. package/src/charts/parliament/__tests__/compute.test.ts +0 -411
  94. package/src/charts/parliament/compute.ts +0 -313
  95. package/src/charts/parliament/index.ts +0 -32
  96. package/src/charts/pie/__tests__/compute.test.ts +0 -384
  97. package/src/charts/pie/__tests__/labels.test.ts +0 -132
  98. package/src/charts/pie/compute.ts +0 -324
  99. package/src/charts/pie/index.ts +0 -49
  100. package/src/charts/pie/labels.ts +0 -143
  101. package/src/charts/post-process.ts +0 -229
  102. package/src/charts/range/__tests__/compute.test.ts +0 -486
  103. package/src/charts/range/compute.ts +0 -273
  104. package/src/charts/range/index.ts +0 -82
  105. package/src/charts/range/labels.ts +0 -169
  106. package/src/charts/rect/__tests__/compute.test.ts +0 -120
  107. package/src/charts/rect/index.ts +0 -127
  108. package/src/charts/registry.ts +0 -72
  109. package/src/charts/rule/index.ts +0 -139
  110. package/src/charts/scatter/__tests__/compute.test.ts +0 -488
  111. package/src/charts/scatter/__tests__/trendline.test.ts +0 -191
  112. package/src/charts/scatter/compute.ts +0 -192
  113. package/src/charts/scatter/index.ts +0 -46
  114. package/src/charts/scatter/trendline.ts +0 -100
  115. package/src/charts/text/__tests__/compute.test.ts +0 -307
  116. package/src/charts/text/index.ts +0 -141
  117. package/src/charts/tick/__tests__/compute.test.ts +0 -75
  118. package/src/charts/tick/index.ts +0 -99
  119. package/src/charts/utils.ts +0 -170
  120. package/src/charts/waffle/__tests__/compute.test.ts +0 -305
  121. package/src/charts/waffle/compute.ts +0 -197
  122. package/src/charts/waffle/index.ts +0 -31
  123. package/src/compile/__tests__/color-scale-range.test.ts +0 -158
  124. package/src/compile/__tests__/color-scale-reverse.test.ts +0 -89
  125. package/src/compile/__tests__/data-clip.test.ts +0 -127
  126. package/src/compile/__tests__/fill-patterns.test.ts +0 -154
  127. package/src/compile/__tests__/size-scale.test.ts +0 -108
  128. package/src/compile/__tests__/watermark-obstacle.test.ts +0 -93
  129. package/src/compile/color-scale-range.ts +0 -101
  130. package/src/compile/data-clip.ts +0 -48
  131. package/src/compile/fill-patterns.ts +0 -74
  132. package/src/compile/layer.ts +0 -630
  133. package/src/compile/size-scale.ts +0 -141
  134. package/src/compile/spec-sugar.ts +0 -758
  135. package/src/compile/watermark-obstacle.ts +0 -54
  136. package/src/compile/you-draw-it.ts +0 -123
  137. package/src/compile.ts +0 -1503
  138. package/src/compiler/__tests__/a11y-warnings.test.ts +0 -148
  139. package/src/compiler/__tests__/animation.test.ts +0 -177
  140. package/src/compiler/__tests__/compile.test.ts +0 -87
  141. package/src/compiler/__tests__/fixtures/vl-parity/axis-null.json +0 -19
  142. package/src/compiler/__tests__/fixtures/vl-parity/color-value.json +0 -20
  143. package/src/compiler/__tests__/fixtures/vl-parity/count-aggregate.json +0 -22
  144. package/src/compiler/__tests__/fixtures/vl-parity/data-values.json +0 -19
  145. package/src/compiler/__tests__/fixtures/vl-parity/layer-axis-null.json +0 -14
  146. package/src/compiler/__tests__/fixtures/vl-parity/layer-count.json +0 -34
  147. package/src/compiler/__tests__/fixtures/vl-parity/layer-data-values.json +0 -22
  148. package/src/compiler/__tests__/fixtures/vl-parity/layer-legend-null.json +0 -41
  149. package/src/compiler/__tests__/fixtures/vl-parity/layer-scheme.json +0 -38
  150. package/src/compiler/__tests__/fixtures/vl-parity/layer-sort.json +0 -28
  151. package/src/compiler/__tests__/fixtures/vl-parity/layer-theta.json +0 -28
  152. package/src/compiler/__tests__/fixtures/vl-parity/layer-title.json +0 -30
  153. package/src/compiler/__tests__/fixtures/vl-parity/layer-value-def.json +0 -29
  154. package/src/compiler/__tests__/fixtures/vl-parity/legend-null.json +0 -32
  155. package/src/compiler/__tests__/fixtures/vl-parity/scheme.json +0 -25
  156. package/src/compiler/__tests__/fixtures/vl-parity/sort-by-value.json +0 -19
  157. package/src/compiler/__tests__/fixtures/vl-parity/theta-arc.json +0 -19
  158. package/src/compiler/__tests__/fixtures/vl-parity/title-subtitle.json +0 -21
  159. package/src/compiler/__tests__/fixtures/vl-parity/width-height.json +0 -23
  160. package/src/compiler/__tests__/keys.test.ts +0 -83
  161. package/src/compiler/__tests__/normalize-highlight.test.ts +0 -103
  162. package/src/compiler/__tests__/normalize.test.ts +0 -399
  163. package/src/compiler/__tests__/sparkline-defaults.test.ts +0 -153
  164. package/src/compiler/__tests__/validate-did-you-mean.test.ts +0 -170
  165. package/src/compiler/__tests__/validate-highlight.test.ts +0 -112
  166. package/src/compiler/__tests__/validate-near-miss.test.ts +0 -251
  167. package/src/compiler/__tests__/validate.test.ts +0 -629
  168. package/src/compiler/__tests__/vl-parity.test.ts +0 -68
  169. package/src/compiler/a11y-warnings.ts +0 -110
  170. package/src/compiler/animation.ts +0 -142
  171. package/src/compiler/index.ts +0 -47
  172. package/src/compiler/keys.ts +0 -55
  173. package/src/compiler/normalize.ts +0 -734
  174. package/src/compiler/sparkline-defaults.ts +0 -138
  175. package/src/compiler/types.ts +0 -241
  176. package/src/compiler/validate.ts +0 -2041
  177. package/src/endpoint-labels/__tests__/compute.test.ts +0 -587
  178. package/src/endpoint-labels/compute.ts +0 -621
  179. package/src/endpoint-labels/constants.ts +0 -54
  180. package/src/endpoint-labels/format.ts +0 -60
  181. package/src/endpoint-labels/predict.ts +0 -139
  182. package/src/format/__tests__/field-format.test.ts +0 -164
  183. package/src/format/field-format.ts +0 -27
  184. package/src/geo/__tests__/compile-map.test.ts +0 -1128
  185. package/src/geo/compile-map.ts +0 -1376
  186. package/src/geo/join.ts +0 -115
  187. package/src/geo/projections.ts +0 -65
  188. package/src/geo/types.ts +0 -26
  189. package/src/graphs/__tests__/community.test.ts +0 -228
  190. package/src/graphs/__tests__/compile-graph.test.ts +0 -396
  191. package/src/graphs/__tests__/encoding.test.ts +0 -415
  192. package/src/graphs/community.ts +0 -92
  193. package/src/graphs/compile-graph.ts +0 -329
  194. package/src/graphs/encoding.ts +0 -356
  195. package/src/graphs/types.ts +0 -106
  196. package/src/index.ts +0 -177
  197. package/src/layout/__tests__/metrics.test.ts +0 -97
  198. package/src/layout/__tests__/scales-highlight.test.ts +0 -192
  199. package/src/layout/axes/rotation.ts +0 -152
  200. package/src/layout/axes/thinning.ts +0 -98
  201. package/src/layout/axes/ticks.ts +0 -409
  202. package/src/layout/axes.ts +0 -757
  203. package/src/layout/dimensions.ts +0 -912
  204. package/src/layout/facet.ts +0 -91
  205. package/src/layout/gridlines.ts +0 -84
  206. package/src/layout/metrics.ts +0 -132
  207. package/src/layout/plan.ts +0 -631
  208. package/src/layout/scales.ts +0 -1053
  209. package/src/layout/shared.ts +0 -44
  210. package/src/legend/__tests__/continuous.test.ts +0 -318
  211. package/src/legend/__tests__/redundancy.test.ts +0 -108
  212. package/src/legend/__tests__/size.test.ts +0 -348
  213. package/src/legend/__tests__/suppression.test.ts +0 -382
  214. package/src/legend/compute.ts +0 -748
  215. package/src/legend/continuous.ts +0 -327
  216. package/src/legend/size.ts +0 -407
  217. package/src/legend/suppression.ts +0 -226
  218. package/src/legend/wrap.ts +0 -117
  219. package/src/sankey/__tests__/compile-sankey.test.ts +0 -458
  220. package/src/sankey/__tests__/layout.test.ts +0 -165
  221. package/src/sankey/__tests__/node-label-wrap.test.ts +0 -114
  222. package/src/sankey/__tests__/node-sort.test.ts +0 -45
  223. package/src/sankey/compile-sankey.ts +0 -706
  224. package/src/sankey/layout.ts +0 -184
  225. package/src/sankey/types.ts +0 -41
  226. package/src/tables/__tests__/bar-column.test.ts +0 -147
  227. package/src/tables/__tests__/category-colors.test.ts +0 -230
  228. package/src/tables/__tests__/compile-table.test.ts +0 -236
  229. package/src/tables/__tests__/format-cells.test.ts +0 -143
  230. package/src/tables/__tests__/heatmap.test.ts +0 -148
  231. package/src/tables/__tests__/pagination.test.ts +0 -78
  232. package/src/tables/__tests__/search.test.ts +0 -94
  233. package/src/tables/__tests__/sort.test.ts +0 -107
  234. package/src/tables/__tests__/sparkline.test.ts +0 -122
  235. package/src/tables/bar-column.ts +0 -94
  236. package/src/tables/category-colors.ts +0 -78
  237. package/src/tables/compile-table.ts +0 -427
  238. package/src/tables/format-cells.ts +0 -115
  239. package/src/tables/heatmap.ts +0 -141
  240. package/src/tables/pagination.ts +0 -46
  241. package/src/tables/search.ts +0 -66
  242. package/src/tables/sort.ts +0 -69
  243. package/src/tables/sparkline.ts +0 -113
  244. package/src/tables/utils.ts +0 -16
  245. package/src/tilemap/__tests__/compile-tilemap.test.ts +0 -576
  246. package/src/tilemap/compile-tilemap.ts +0 -755
  247. package/src/tilemap/layout.ts +0 -172
  248. package/src/tilemap/types.ts +0 -33
  249. package/src/tooltips/__tests__/compute.test.ts +0 -582
  250. package/src/tooltips/compute.ts +0 -700
  251. package/src/transforms/__tests__/aggregate.test.ts +0 -159
  252. package/src/transforms/__tests__/bin.test.ts +0 -88
  253. package/src/transforms/__tests__/calculate.test.ts +0 -146
  254. package/src/transforms/__tests__/conditional.test.ts +0 -127
  255. package/src/transforms/__tests__/filter-relative.test.ts +0 -202
  256. package/src/transforms/__tests__/filter.test.ts +0 -59
  257. package/src/transforms/__tests__/fold.test.ts +0 -79
  258. package/src/transforms/__tests__/index.test.ts +0 -93
  259. package/src/transforms/__tests__/predicates.test.ts +0 -193
  260. package/src/transforms/__tests__/timeunit.test.ts +0 -129
  261. package/src/transforms/__tests__/window.test.ts +0 -286
  262. package/src/transforms/aggregate.ts +0 -131
  263. package/src/transforms/bin.ts +0 -87
  264. package/src/transforms/calculate.ts +0 -60
  265. package/src/transforms/conditional.ts +0 -46
  266. package/src/transforms/filter.ts +0 -122
  267. package/src/transforms/fold.ts +0 -49
  268. package/src/transforms/index.ts +0 -60
  269. package/src/transforms/predicates.ts +0 -123
  270. package/src/transforms/timeunit.ts +0 -88
  271. package/src/transforms/window.ts +0 -185
@@ -1,294 +0,0 @@
1
- /**
2
- * Integration tests for mark key stamping across chart types.
3
- *
4
- * Verifies that compileChart() stamps stable `key` fields on marks
5
- * for data-update transitions. Each chart type has its own keying
6
- * strategy; these tests verify the end-to-end pipeline.
7
- */
8
-
9
- import type { ChartSpec } from '@opendata-ai/openchart-core';
10
- import { describe, expect, it } from 'vitest';
11
- import { compileChart } from '../compile';
12
-
13
- const dims = { width: 600, height: 400 };
14
-
15
- // ---------------------------------------------------------------------------
16
- // Column chart keys
17
- // ---------------------------------------------------------------------------
18
-
19
- describe('column chart mark keys', () => {
20
- it('stamps unique keys on simple column marks', () => {
21
- const spec: ChartSpec = {
22
- mark: 'bar',
23
- data: [
24
- { category: 'A', value: 10 },
25
- { category: 'B', value: 20 },
26
- { category: 'C', value: 30 },
27
- ],
28
- encoding: {
29
- x: { field: 'category', type: 'nominal' },
30
- y: { field: 'value', type: 'quantitative' },
31
- },
32
- };
33
- const layout = compileChart(spec, dims);
34
- const rects = layout.marks.filter((m) => m.type === 'rect');
35
- expect(rects.length).toBe(3);
36
-
37
- for (const m of rects) {
38
- expect((m as { key?: string }).key).toBeDefined();
39
- }
40
-
41
- const keys = rects.map((m) => (m as { key?: string }).key);
42
- expect(new Set(keys).size).toBe(3);
43
- });
44
-
45
- it('deduplicates keys for duplicate category values', () => {
46
- const spec: ChartSpec = {
47
- mark: 'bar',
48
- data: [
49
- { category: 'A', value: 10 },
50
- { category: 'A', value: 20 },
51
- { category: 'B', value: 30 },
52
- ],
53
- encoding: {
54
- x: { field: 'category', type: 'nominal' },
55
- y: { field: 'value', type: 'quantitative' },
56
- },
57
- };
58
- const layout = compileChart(spec, dims);
59
- const rects = layout.marks.filter((m) => m.type === 'rect');
60
- const keys = rects.map((m) => (m as { key?: string }).key);
61
- // All keys must be unique even with duplicate categories
62
- expect(new Set(keys).size).toBe(keys.length);
63
- });
64
-
65
- it('stamps keys on grouped columns', () => {
66
- const spec: ChartSpec = {
67
- mark: 'bar',
68
- data: [
69
- { category: 'Q1', series: 'Revenue', value: 100 },
70
- { category: 'Q1', series: 'Cost', value: 60 },
71
- { category: 'Q2', series: 'Revenue', value: 150 },
72
- { category: 'Q2', series: 'Cost', value: 90 },
73
- ],
74
- encoding: {
75
- x: { field: 'category', type: 'nominal' },
76
- y: { field: 'value', type: 'quantitative' },
77
- color: { field: 'series', type: 'nominal' },
78
- },
79
- };
80
- const layout = compileChart(spec, dims);
81
- const rects = layout.marks.filter((m) => m.type === 'rect');
82
- expect(rects.length).toBeGreaterThanOrEqual(4);
83
-
84
- const keys = rects.map((m) => (m as { key?: string }).key);
85
- for (const k of keys) {
86
- expect(k).toBeDefined();
87
- }
88
- expect(new Set(keys).size).toBe(keys.length);
89
- });
90
- });
91
-
92
- // ---------------------------------------------------------------------------
93
- // Bar chart keys
94
- // ---------------------------------------------------------------------------
95
-
96
- describe('bar chart mark keys', () => {
97
- it('stamps unique keys on horizontal bar marks', () => {
98
- const spec: ChartSpec = {
99
- mark: 'bar',
100
- data: [
101
- { name: 'Alpha', value: 10 },
102
- { name: 'Beta', value: 30 },
103
- { name: 'Gamma', value: 20 },
104
- ],
105
- encoding: {
106
- x: { field: 'value', type: 'quantitative' },
107
- y: { field: 'name', type: 'nominal' },
108
- },
109
- };
110
- const layout = compileChart(spec, dims);
111
- const rects = layout.marks.filter((m) => m.type === 'rect');
112
- const keys = rects.map((m) => (m as { key?: string }).key);
113
- for (const k of keys) {
114
- expect(k).toBeDefined();
115
- }
116
- expect(new Set(keys).size).toBe(keys.length);
117
- });
118
- });
119
-
120
- // ---------------------------------------------------------------------------
121
- // Line chart keys
122
- // ---------------------------------------------------------------------------
123
-
124
- describe('line chart mark keys', () => {
125
- it('stamps key on line marks for multi-series', () => {
126
- const spec: ChartSpec = {
127
- mark: 'line',
128
- data: [
129
- { date: '2020-01-01', value: 10, country: 'US' },
130
- { date: '2021-01-01', value: 40, country: 'US' },
131
- { date: '2020-01-01', value: 15, country: 'UK' },
132
- { date: '2021-01-01', value: 35, country: 'UK' },
133
- ],
134
- encoding: {
135
- x: { field: 'date', type: 'temporal' },
136
- y: { field: 'value', type: 'quantitative' },
137
- color: { field: 'country', type: 'nominal' },
138
- },
139
- };
140
- const layout = compileChart(spec, dims);
141
- const lines = layout.marks.filter((m) => m.type === 'line');
142
- expect(lines.length).toBe(2);
143
-
144
- const keys = lines.map((m) => (m as { key?: string }).key);
145
- for (const k of keys) {
146
- expect(k).toBeDefined();
147
- }
148
- expect(new Set(keys).size).toBe(2);
149
- });
150
-
151
- it('stamps pointKeys on line marks with temporal x', () => {
152
- const spec: ChartSpec = {
153
- mark: 'line',
154
- data: [
155
- { date: '2020-01-01', value: 10 },
156
- { date: '2021-01-01', value: 40 },
157
- { date: '2022-01-01', value: 25 },
158
- ],
159
- encoding: {
160
- x: { field: 'date', type: 'temporal' },
161
- y: { field: 'value', type: 'quantitative' },
162
- },
163
- };
164
- const layout = compileChart(spec, dims);
165
- const lines = layout.marks.filter((m) => m.type === 'line');
166
- expect(lines.length).toBe(1);
167
-
168
- const line = lines[0] as { pointKeys?: string[] };
169
- expect(line.pointKeys).toBeDefined();
170
- expect(line.pointKeys!.length).toBe(3);
171
-
172
- // Each point key should be a unique, defined string
173
- for (const pk of line.pointKeys!) {
174
- expect(pk).toBeDefined();
175
- expect(typeof pk).toBe('string');
176
- }
177
- expect(new Set(line.pointKeys!).size).toBe(3);
178
- });
179
- });
180
-
181
- // ---------------------------------------------------------------------------
182
- // Scatter chart keys
183
- // ---------------------------------------------------------------------------
184
-
185
- describe('scatter chart mark keys', () => {
186
- it('stamps keys on scatter point marks', () => {
187
- const spec: ChartSpec = {
188
- mark: 'point',
189
- data: [
190
- { x: 10, y: 20, label: 'A' },
191
- { x: 30, y: 40, label: 'B' },
192
- { x: 50, y: 60, label: 'C' },
193
- ],
194
- encoding: {
195
- x: { field: 'x', type: 'quantitative' },
196
- y: { field: 'y', type: 'quantitative' },
197
- },
198
- };
199
- const layout = compileChart(spec, dims);
200
- const points = layout.marks.filter((m) => m.type === 'point');
201
- expect(points.length).toBe(3);
202
-
203
- const keys = points.map((m) => (m as { key?: string }).key);
204
- for (const k of keys) {
205
- expect(k).toBeDefined();
206
- }
207
- expect(new Set(keys).size).toBe(3);
208
- });
209
-
210
- it('uses encoding.key field when specified', () => {
211
- const spec: ChartSpec = {
212
- mark: 'point',
213
- data: [
214
- { x: 10, y: 20, id: 'item-1' },
215
- { x: 30, y: 40, id: 'item-2' },
216
- { x: 50, y: 60, id: 'item-3' },
217
- ],
218
- encoding: {
219
- x: { field: 'x', type: 'quantitative' },
220
- y: { field: 'y', type: 'quantitative' },
221
- key: { field: 'id' },
222
- },
223
- };
224
- const layout = compileChart(spec, dims);
225
- const points = layout.marks.filter((m) => m.type === 'point');
226
- const keys = points.map((m) => (m as { key?: string }).key);
227
-
228
- expect(keys).toContain('item-1');
229
- expect(keys).toContain('item-2');
230
- expect(keys).toContain('item-3');
231
- });
232
- });
233
-
234
- // ---------------------------------------------------------------------------
235
- // Pie chart keys
236
- // ---------------------------------------------------------------------------
237
-
238
- describe('pie chart mark keys', () => {
239
- it('stamps keys on arc marks', () => {
240
- const spec: ChartSpec = {
241
- mark: 'arc',
242
- data: [
243
- { category: 'Desktop', share: 60 },
244
- { category: 'Mobile', share: 30 },
245
- { category: 'Tablet', share: 10 },
246
- ],
247
- encoding: {
248
- y: { field: 'share', type: 'quantitative' },
249
- color: { field: 'category', type: 'nominal' },
250
- },
251
- };
252
- const layout = compileChart(spec, dims);
253
- const arcs = layout.marks.filter((m) => m.type === 'arc');
254
- expect(arcs.length).toBe(3);
255
-
256
- const keys = arcs.map((m) => (m as { key?: string }).key);
257
- for (const k of keys) {
258
- expect(k).toBeDefined();
259
- }
260
- expect(new Set(keys).size).toBe(3);
261
- });
262
- });
263
-
264
- // ---------------------------------------------------------------------------
265
- // Area chart keys
266
- // ---------------------------------------------------------------------------
267
-
268
- describe('area chart mark keys', () => {
269
- it('stamps key on area marks', () => {
270
- const spec: ChartSpec = {
271
- mark: 'area',
272
- data: [
273
- { date: '2020-01-01', value: 10, series: 'A' },
274
- { date: '2021-01-01', value: 40, series: 'A' },
275
- { date: '2020-01-01', value: 15, series: 'B' },
276
- { date: '2021-01-01', value: 35, series: 'B' },
277
- ],
278
- encoding: {
279
- x: { field: 'date', type: 'temporal' },
280
- y: { field: 'value', type: 'quantitative' },
281
- color: { field: 'series', type: 'nominal' },
282
- },
283
- };
284
- const layout = compileChart(spec, dims);
285
- const areas = layout.marks.filter((m) => m.type === 'area');
286
- expect(areas.length).toBe(2);
287
-
288
- const keys = areas.map((m) => (m as { key?: string }).key);
289
- for (const k of keys) {
290
- expect(k).toBeDefined();
291
- }
292
- expect(new Set(keys).size).toBe(2);
293
- });
294
- });
@@ -1,260 +0,0 @@
1
- /**
2
- * Integration tests for the slope + bump chart recipes (plan 14).
3
- *
4
- * These are the exact specs published on docs/ranking-and-change.md and
5
- * pinned as visual fixtures in examples/src/testing/fixtures-ranking.stories.tsx.
6
- * They use only public spec surface: if a test here needs a private flag to
7
- * pass, the recipe is broken.
8
- */
9
-
10
- import type { ChartSpec, LineMark, PointMark } from '@opendata-ai/openchart-core';
11
- import { describe, expect, it } from 'vitest';
12
-
13
- import { compileChart } from '../compile';
14
-
15
- // ---------------------------------------------------------------------------
16
- // Recipe specs (keep byte-identical to docs/ranking-and-change.md)
17
- // ---------------------------------------------------------------------------
18
-
19
- const slopeMarketShareSpec: ChartSpec = {
20
- mark: 'line',
21
- data: [
22
- { year: '2019', brand: 'Samsung', share: 0.216 },
23
- { year: '2024', brand: 'Samsung', share: 0.19 },
24
- { year: '2019', brand: 'Huawei', share: 0.176 },
25
- { year: '2024', brand: 'Huawei', share: 0.043 },
26
- { year: '2019', brand: 'Apple', share: 0.139 },
27
- { year: '2024', brand: 'Apple', share: 0.187 },
28
- { year: '2019', brand: 'Xiaomi', share: 0.092 },
29
- { year: '2024', brand: 'Xiaomi', share: 0.136 },
30
- { year: '2019', brand: 'Oppo', share: 0.083 },
31
- { year: '2024', brand: 'Oppo', share: 0.087 },
32
- ],
33
- encoding: {
34
- x: { field: 'year', type: 'ordinal' },
35
- y: {
36
- field: 'share',
37
- type: 'quantitative',
38
- axis: false,
39
- scale: { zero: false },
40
- },
41
- color: { field: 'brand', type: 'nominal' },
42
- },
43
- endpointLabels: {
44
- ends: 'both',
45
- content: 'label value',
46
- format: '.0%',
47
- },
48
- legend: { show: false },
49
- chrome: {
50
- title: 'Apple and Xiaomi Split What Huawei Lost',
51
- subtitle: 'Share of global smartphone shipments, 2019 vs 2024',
52
- source: 'Source: IDC Worldwide Quarterly Mobile Phone Tracker',
53
- },
54
- };
55
-
56
- const bumpConstructorsSpec: ChartSpec = {
57
- mark: { type: 'line', interpolate: 'monotone', point: true },
58
- data: [
59
- { season: '2019', team: 'Mercedes', position: 1 },
60
- { season: '2020', team: 'Mercedes', position: 1 },
61
- { season: '2021', team: 'Mercedes', position: 1 },
62
- { season: '2022', team: 'Mercedes', position: 3 },
63
- { season: '2023', team: 'Mercedes', position: 2 },
64
- { season: '2024', team: 'Mercedes', position: 4 },
65
- { season: '2019', team: 'Red Bull', position: 3 },
66
- { season: '2020', team: 'Red Bull', position: 2 },
67
- { season: '2021', team: 'Red Bull', position: 2 },
68
- { season: '2022', team: 'Red Bull', position: 1 },
69
- { season: '2023', team: 'Red Bull', position: 1 },
70
- { season: '2024', team: 'Red Bull', position: 3 },
71
- { season: '2019', team: 'Ferrari', position: 2 },
72
- { season: '2020', team: 'Ferrari', position: 6 },
73
- { season: '2021', team: 'Ferrari', position: 3 },
74
- { season: '2022', team: 'Ferrari', position: 2 },
75
- { season: '2023', team: 'Ferrari', position: 3 },
76
- { season: '2024', team: 'Ferrari', position: 2 },
77
- { season: '2019', team: 'McLaren', position: 4 },
78
- { season: '2020', team: 'McLaren', position: 3 },
79
- { season: '2021', team: 'McLaren', position: 4 },
80
- { season: '2022', team: 'McLaren', position: 5 },
81
- { season: '2023', team: 'McLaren', position: 4 },
82
- { season: '2024', team: 'McLaren', position: 1 },
83
- { season: '2019', team: 'Alpine', position: 5 },
84
- { season: '2020', team: 'Alpine', position: 5 },
85
- { season: '2021', team: 'Alpine', position: 5 },
86
- { season: '2022', team: 'Alpine', position: 4 },
87
- { season: '2023', team: 'Alpine', position: 6 },
88
- { season: '2024', team: 'Alpine', position: 6 },
89
- ],
90
- encoding: {
91
- x: { field: 'season', type: 'ordinal' },
92
- y: {
93
- field: 'position',
94
- type: 'quantitative',
95
- scale: { reverse: true, zero: false },
96
- axis: { values: [1, 2, 3, 4, 5, 6], format: 'ordinal' },
97
- },
98
- color: { field: 'team', type: 'nominal' },
99
- },
100
- endpointLabels: {
101
- ends: 'both',
102
- content: 'label',
103
- showMarker: false,
104
- },
105
- legend: { show: false },
106
- chrome: {
107
- title: 'McLaren Went From Midfield to Champions',
108
- subtitle: 'Formula 1 constructors championship, final position by season',
109
- source: 'Source: FIA official standings',
110
- },
111
- };
112
-
113
- // ---------------------------------------------------------------------------
114
- // Slope recipe
115
- // ---------------------------------------------------------------------------
116
-
117
- describe('slope chart recipe', () => {
118
- it('renders both-end labels for all five series', () => {
119
- const layout = compileChart(slopeMarketShareSpec, { width: 640, height: 420 });
120
-
121
- expect(layout.endpointLabels?.entries).toHaveLength(5);
122
- expect(layout.endpointLabels?.leading).toHaveLength(5);
123
- });
124
-
125
- it("composes 'name value' on one line at both ends", () => {
126
- const layout = compileChart(slopeMarketShareSpec, { width: 640, height: 420 });
127
-
128
- const left = layout.endpointLabels!.leading!.find((e) => e.seriesKey === 'Samsung');
129
- expect(left!.labelLines[0]).toBe('Samsung 22%');
130
- expect(left!.value).toBe('');
131
-
132
- const right = layout.endpointLabels!.entries.find((e) => e.seriesKey === 'Samsung');
133
- expect(right!.labelLines[0]).toBe('Samsung 19%');
134
- expect(right!.value).toBe('');
135
- });
136
-
137
- it('renders no y axis and no gridlines', () => {
138
- const layout = compileChart(slopeMarketShareSpec, { width: 640, height: 420 });
139
-
140
- expect(layout.axes.y).toBeUndefined();
141
- });
142
-
143
- it('orders labels by value at each end (Huawei falls from 2nd to last)', () => {
144
- const layout = compileChart(slopeMarketShareSpec, { width: 640, height: 420 });
145
-
146
- const byY = (a: { labelY: number }, b: { labelY: number }) => a.labelY - b.labelY;
147
- const leftOrder = [...layout.endpointLabels!.leading!].sort(byY).map((e) => e.seriesKey);
148
- expect(leftOrder).toEqual(['Samsung', 'Huawei', 'Apple', 'Xiaomi', 'Oppo']);
149
-
150
- const rightOrder = [...layout.endpointLabels!.entries].sort(byY).map((e) => e.seriesKey);
151
- expect(rightOrder).toEqual(['Samsung', 'Apple', 'Xiaomi', 'Oppo', 'Huawei']);
152
- });
153
-
154
- it('keeps both-end labels and a positive plot area at 320px (compact breakpoint)', () => {
155
- const layout = compileChart(slopeMarketShareSpec, { width: 320, height: 360 });
156
-
157
- expect(layout.endpointLabels?.entries).toHaveLength(5);
158
- expect(layout.endpointLabels?.leading).toHaveLength(5);
159
- expect(layout.area.width).toBeGreaterThan(0);
160
- // Both label columns fit inside the 320px canvas.
161
- expect(layout.endpointLabels!.leadingBounds!.x).toBeGreaterThanOrEqual(0);
162
- expect(
163
- layout.endpointLabels!.bounds.x + layout.endpointLabels!.bounds.width,
164
- ).toBeLessThanOrEqual(320);
165
- });
166
- });
167
-
168
- // ---------------------------------------------------------------------------
169
- // Bump recipe
170
- // ---------------------------------------------------------------------------
171
-
172
- describe('bump chart recipe', () => {
173
- it('puts rank 1 at the top via scale.reverse', () => {
174
- const layout = compileChart(bumpConstructorsSpec, { width: 640, height: 460 });
175
-
176
- const ticks = layout.axes.y!.ticks;
177
- const first = ticks.find((t) => t.value === 1);
178
- const last = ticks.find((t) => t.value === 6);
179
- expect(first).toBeDefined();
180
- expect(last).toBeDefined();
181
- expect(first!.position).toBeLessThan(last!.position);
182
- });
183
-
184
- it('labels rank ticks as ordinals, 1st through 6th top to bottom', () => {
185
- const layout = compileChart(bumpConstructorsSpec, { width: 640, height: 460 });
186
-
187
- const labels = [...layout.axes.y!.ticks]
188
- .sort((a, b) => a.position - b.position)
189
- .map((t) => t.label);
190
- expect(labels).toEqual(['1st', '2nd', '3rd', '4th', '5th', '6th']);
191
- });
192
-
193
- it('draws a point marker at every step of every series', () => {
194
- const layout = compileChart(bumpConstructorsSpec, { width: 640, height: 460 });
195
-
196
- const points = layout.marks.filter(
197
- (m): m is PointMark => m.type === 'point' && m.opacity !== 0,
198
- );
199
- // 5 teams x 6 seasons.
200
- expect(points).toHaveLength(30);
201
- });
202
-
203
- it('orders both-end name labels by rank at each end', () => {
204
- const layout = compileChart(bumpConstructorsSpec, { width: 640, height: 460 });
205
-
206
- const byY = (a: { labelY: number }, b: { labelY: number }) => a.labelY - b.labelY;
207
- // 2019: Mercedes 1st, Ferrari 2nd, Red Bull 3rd, McLaren 4th, Alpine 5th.
208
- const leftOrder = [...layout.endpointLabels!.leading!].sort(byY).map((e) => e.seriesKey);
209
- expect(leftOrder).toEqual(['Mercedes', 'Ferrari', 'Red Bull', 'McLaren', 'Alpine']);
210
- // 2024: McLaren 1st, Ferrari 2nd, Red Bull 3rd, Mercedes 4th, Alpine 6th.
211
- const rightOrder = [...layout.endpointLabels!.entries].sort(byY).map((e) => e.seriesKey);
212
- expect(rightOrder).toEqual(['McLaren', 'Ferrari', 'Red Bull', 'Mercedes', 'Alpine']);
213
- });
214
-
215
- it('renders name-only labels (no value line)', () => {
216
- const layout = compileChart(bumpConstructorsSpec, { width: 640, height: 460 });
217
-
218
- for (const entry of layout.endpointLabels!.entries) {
219
- expect(entry.labelLines).toEqual([entry.seriesKey]);
220
- expect(entry.value).toBe('');
221
- }
222
- });
223
-
224
- it('maps tied ranks to the same y (ties share a row)', () => {
225
- const tieSpec: ChartSpec = {
226
- ...bumpConstructorsSpec,
227
- data: [
228
- { season: '2023', team: 'A', position: 1 },
229
- { season: '2024', team: 'A', position: 2 },
230
- { season: '2023', team: 'B', position: 2 },
231
- { season: '2024', team: 'B', position: 2 },
232
- { season: '2023', team: 'C', position: 3 },
233
- { season: '2024', team: 'C', position: 1 },
234
- ],
235
- encoding: {
236
- ...bumpConstructorsSpec.encoding,
237
- y: {
238
- field: 'position',
239
- type: 'quantitative',
240
- scale: { reverse: true, zero: false },
241
- axis: { values: [1, 2, 3], format: 'ordinal' },
242
- },
243
- },
244
- };
245
- const layout = compileChart(tieSpec, { width: 640, height: 400 });
246
-
247
- const lines = layout.marks.filter(
248
- (m): m is LineMark => m.type === 'line' && m.seriesKey != null,
249
- );
250
- const lastY = (key: string) => {
251
- const mark = lines.find((m) => m.seriesKey === key)!;
252
- const pts = mark.dataPoints ?? [];
253
- return pts[pts.length - 1]!.y;
254
- };
255
- // A and B tie for 2nd in 2024: identical y.
256
- expect(lastY('A')).toBeCloseTo(lastY('B'), 6);
257
- // C is 1st, above the tied pair (smaller y = higher rank).
258
- expect(lastY('C')).toBeLessThan(lastY('A'));
259
- });
260
- });
@@ -1,83 +0,0 @@
1
- import { describe, expect, it } from 'vitest';
2
- import { bandLabelStride, resolveBandTickAngle } from '../layout/axes/rotation';
3
-
4
- // Geometry cheat sheet at the default 11px tick font:
5
- // - ribbon thickness = 11 * 1.2 + 4 = 17.2px (perpendicular room one label needs)
6
- // - at -45°, ribbon separation = spacing * 0.707, so the -45 → -90 flip sits
7
- // near spacing ≈ 24.3px
8
- // - at -90°, separation = spacing, so the stride safety net starts below
9
- // spacing ≈ 17.2px
10
-
11
- describe('resolveBandTickAngle', () => {
12
- it('returns the explicit angle untouched', () => {
13
- expect(resolveBandTickAngle(-30, 100, 20, 5, 50, 11)).toBe(-30);
14
- expect(resolveBandTickAngle(0, 100, 20, 5, 50, 11)).toBe(0);
15
- });
16
-
17
- it('never rotates a single label', () => {
18
- expect(resolveBandTickAngle(undefined, 100, 20, 1, 50, 11)).toBeUndefined();
19
- });
20
-
21
- it('stays flat when the widest label fits its band', () => {
22
- expect(resolveBandTickAngle(undefined, 17, 20, 5, 30, 11)).toBeUndefined();
23
- });
24
-
25
- it('picks -45 when diagonal ribbons clear one line height', () => {
26
- // separation = 25 * sin45 ≈ 17.7 >= 17.2
27
- expect(resolveBandTickAngle(undefined, 40, 20, 5, 25, 11)).toBe(-45);
28
- });
29
-
30
- it('escalates to -90 when diagonal ribbons would touch', () => {
31
- // separation = 24 * sin45 ≈ 17.0 < 17.2, and 24px along-text clearance
32
- // cannot fit a 40px label; vertical separation 24 >= 17.2 fits.
33
- expect(resolveBandTickAngle(undefined, 40, 20, 5, 24, 11)).toBe(-90);
34
- });
35
-
36
- it('keeps -45 for short labels that clear end-to-end along the text direction', () => {
37
- // Ribbons touch (24 * sin45 < 17.2) but a 10px label clears via the
38
- // 17px along-text offset — finite segments slide past each other.
39
- expect(resolveBandTickAngle(undefined, 10, 8, 5, 24, 11)).toBe(-45);
40
- });
41
-
42
- it('refuses -90 for labels longer than the rotated-extent cap', () => {
43
- // A 150px label projected vertically exceeds the 120px reservation cap
44
- // and would clip into the source line; stay at -45 and let the stride
45
- // safety net thin instead.
46
- expect(resolveBandTickAngle(undefined, 150, 20, 5, 20, 11)).toBe(-45);
47
- });
48
- });
49
-
50
- describe('bandLabelStride', () => {
51
- it('returns 1 for degenerate spacing', () => {
52
- expect(bandLabelStride(50, -45, 11, 0)).toBe(1);
53
- expect(bandLabelStride(50, -45, 11, -5)).toBe(1);
54
- });
55
-
56
- it('drives the flat stride by label width', () => {
57
- // (50 + 4) / 20 → every 3rd label
58
- expect(bandLabelStride(50, undefined, 11, 20)).toBe(3);
59
- expect(bandLabelStride(10, undefined, 11, 20)).toBe(1);
60
- });
61
-
62
- it('keeps every label when vertical separation fits', () => {
63
- expect(bandLabelStride(50, -90, 11, 20)).toBe(1);
64
- });
65
-
66
- it('thins vertical labels only at tiny steps', () => {
67
- // separation 7 < 17.2 → ceil(17.2 / 7) = 3
68
- expect(bandLabelStride(50, -90, 11, 7)).toBe(3);
69
- });
70
-
71
- it('does not thin a shallow explicit angle whose labels clear end-to-end', () => {
72
- // labelAngle -20 at 50px spacing: ribbon separation 17.1 barely misses
73
- // one line height, but the 47px along-text offset clears a 30px label.
74
- // The old span model dropped every other label here.
75
- expect(bandLabelStride(30, -20, 11, 50)).toBe(1);
76
- });
77
-
78
- it('thins a shallow explicit angle when labels overlap by both routes', () => {
79
- // labelAngle -20 at 30px spacing with 60px labels: separation 10.3 needs
80
- // stride 2, along-text clearance 28.2 needs stride 3 → ribbons win.
81
- expect(bandLabelStride(60, -20, 11, 30)).toBe(2);
82
- });
83
- });