@opendata-ai/openchart-engine 6.11.0 → 6.13.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 (45) hide show
  1. package/dist/index.d.ts +7 -0
  2. package/dist/index.js +944 -629
  3. package/dist/index.js.map +1 -1
  4. package/package.json +2 -2
  5. package/src/__test-fixtures__/specs.ts +3 -0
  6. package/src/__tests__/axes.test.ts +12 -30
  7. package/src/__tests__/compile-chart.test.ts +4 -4
  8. package/src/__tests__/dimensions.test.ts +2 -2
  9. package/src/__tests__/encoding-sugar.test.ts +389 -0
  10. package/src/annotations/collisions.ts +268 -0
  11. package/src/annotations/compute.ts +9 -912
  12. package/src/annotations/constants.ts +32 -0
  13. package/src/annotations/geometry.ts +167 -0
  14. package/src/annotations/position.ts +95 -0
  15. package/src/annotations/resolve-range.ts +98 -0
  16. package/src/annotations/resolve-refline.ts +148 -0
  17. package/src/annotations/resolve-text.ts +134 -0
  18. package/src/charts/__tests__/post-process.test.ts +258 -0
  19. package/src/charts/bar/__tests__/labels.test.ts +31 -0
  20. package/src/charts/bar/compute.ts +27 -6
  21. package/src/charts/bar/labels.ts +7 -1
  22. package/src/charts/column/__tests__/compute.test.ts +99 -0
  23. package/src/charts/column/compute.ts +27 -6
  24. package/src/charts/line/area.ts +19 -2
  25. package/src/charts/post-process.ts +215 -0
  26. package/src/compile.ts +113 -169
  27. package/src/compiler/__tests__/normalize.test.ts +110 -0
  28. package/src/compiler/normalize.ts +22 -3
  29. package/src/compiler/types.ts +4 -0
  30. package/src/graphs/compile-graph.ts +8 -0
  31. package/src/graphs/types.ts +2 -0
  32. package/src/layout/axes.ts +10 -13
  33. package/src/layout/dimensions.ts +6 -3
  34. package/src/layout/scales.ts +106 -29
  35. package/src/legend/compute.ts +3 -1
  36. package/src/sankey/compile-sankey.ts +12 -2
  37. package/src/sankey/types.ts +1 -0
  38. package/src/tables/compile-table.ts +5 -0
  39. package/src/tooltips/__tests__/compute.test.ts +188 -0
  40. package/src/tooltips/compute.ts +25 -11
  41. package/src/transforms/__tests__/aggregate.test.ts +159 -0
  42. package/src/transforms/__tests__/fold.test.ts +79 -0
  43. package/src/transforms/aggregate.ts +130 -0
  44. package/src/transforms/fold.ts +49 -0
  45. package/src/transforms/index.ts +8 -0
@@ -0,0 +1,49 @@
1
+ /**
2
+ * Fold transform: unpivots wide-format data into long format.
3
+ *
4
+ * Follows Vega-Lite fold transform conventions.
5
+ * For each input row, creates N new rows (one per fold field),
6
+ * copying all non-fold fields and adding key/value columns.
7
+ */
8
+
9
+ import type { DataRow, FoldTransform } from '@opendata-ai/openchart-core';
10
+
11
+ /**
12
+ * Apply a fold transform to data rows.
13
+ *
14
+ * For each input row, creates one output row per fold field. Each output
15
+ * row contains all fields from the original row (except the fold fields),
16
+ * plus a key field (the fold field name) and a value field (the fold field value).
17
+ *
18
+ * @param data - Input rows.
19
+ * @param transform - Fold transform definition.
20
+ * @returns Folded rows (N rows per input row, where N = fold fields count).
21
+ */
22
+ export function runFold(data: DataRow[], transform: FoldTransform): DataRow[] {
23
+ const { fold } = transform;
24
+ const [keyAs, valueAs] = transform.as ?? ['key', 'value'];
25
+ const foldSet = new Set(fold);
26
+
27
+ const result: DataRow[] = [];
28
+
29
+ for (const row of data) {
30
+ // Copy all non-fold fields
31
+ const base: DataRow = {};
32
+ for (const [k, v] of Object.entries(row)) {
33
+ if (!foldSet.has(k)) {
34
+ base[k] = v;
35
+ }
36
+ }
37
+
38
+ // Create one row per fold field
39
+ for (const field of fold) {
40
+ result.push({
41
+ ...base,
42
+ [keyAs]: field,
43
+ [valueAs]: row[field],
44
+ });
45
+ }
46
+ }
47
+
48
+ return result;
49
+ }
@@ -7,15 +7,19 @@
7
7
  */
8
8
 
9
9
  import type { DataRow, Transform } from '@opendata-ai/openchart-core';
10
+ import { runAggregate } from './aggregate';
10
11
  import { runBin } from './bin';
11
12
  import { runCalculate } from './calculate';
12
13
  import { runFilter } from './filter';
14
+ import { runFold } from './fold';
13
15
  import { runTimeUnit } from './timeunit';
14
16
 
17
+ export { runAggregate } from './aggregate';
15
18
  export { runBin } from './bin';
16
19
  export { runCalculate } from './calculate';
17
20
  export { isConditionalValueDef, resolveConditionalValue } from './conditional';
18
21
  export { runFilter } from './filter';
22
+ export { runFold } from './fold';
19
23
  export { evaluatePredicate } from './predicates';
20
24
  export { runTimeUnit } from './timeunit';
21
25
 
@@ -41,6 +45,10 @@ export function runTransforms(data: DataRow[], transforms: Transform[]): DataRow
41
45
  result = runCalculate(result, transform);
42
46
  } else if ('timeUnit' in transform) {
43
47
  result = runTimeUnit(result, transform);
48
+ } else if ('aggregate' in transform) {
49
+ result = runAggregate(result, transform);
50
+ } else if ('fold' in transform) {
51
+ result = runFold(result, transform);
44
52
  }
45
53
  }
46
54