@ac-kit/model-chart 0.3.0 → 0.4.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 (50) hide show
  1. package/CHANGELOG.md +117 -0
  2. package/README.md +68 -4
  3. package/dist/index.d.ts +3 -0
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +3 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/render/capabilities.d.ts +13 -0
  8. package/dist/render/capabilities.d.ts.map +1 -1
  9. package/dist/render/capabilities.js +8 -0
  10. package/dist/render/capabilities.js.map +1 -1
  11. package/dist/resolve/__fixtures__/vega-lite-views.json +4727 -0
  12. package/dist/resolve/_guides.d.ts +4 -1
  13. package/dist/resolve/_guides.d.ts.map +1 -1
  14. package/dist/resolve/_guides.js +12 -3
  15. package/dist/resolve/_guides.js.map +1 -1
  16. package/dist/resolve/color-scheme.d.ts +21 -0
  17. package/dist/resolve/color-scheme.d.ts.map +1 -0
  18. package/dist/resolve/color-scheme.js +42 -0
  19. package/dist/resolve/color-scheme.js.map +1 -0
  20. package/dist/resolve/mark-geometry.d.ts +154 -0
  21. package/dist/resolve/mark-geometry.d.ts.map +1 -0
  22. package/dist/resolve/mark-geometry.js +517 -0
  23. package/dist/resolve/mark-geometry.js.map +1 -0
  24. package/dist/resolve/scale-tick-labels.d.ts +39 -0
  25. package/dist/resolve/scale-tick-labels.d.ts.map +1 -0
  26. package/dist/resolve/scale-tick-labels.js +158 -0
  27. package/dist/resolve/scale-tick-labels.js.map +1 -0
  28. package/dist/resolve/scale.d.ts +10 -2
  29. package/dist/resolve/scale.d.ts.map +1 -1
  30. package/dist/resolve/scale.js +24 -4
  31. package/dist/resolve/scale.js.map +1 -1
  32. package/dist/resolve/view-types.d.ts +6 -3
  33. package/dist/resolve/view-types.d.ts.map +1 -1
  34. package/dist/resolve/view.d.ts.map +1 -1
  35. package/dist/resolve/view.js +88 -0
  36. package/dist/resolve/view.js.map +1 -1
  37. package/dist/spec/channel.d.ts +1 -1
  38. package/dist/spec/channel.d.ts.map +1 -1
  39. package/dist/spec/channel.js +2 -0
  40. package/dist/spec/channel.js.map +1 -1
  41. package/dist/testing/__fixtures__/vega-geometry.json +1434 -0
  42. package/dist/testing/index.d.ts +2 -0
  43. package/dist/testing/index.d.ts.map +1 -0
  44. package/dist/testing/index.js +2 -0
  45. package/dist/testing/index.js.map +1 -0
  46. package/dist/testing/vega-lite-cases.d.ts +164 -0
  47. package/dist/testing/vega-lite-cases.d.ts.map +1 -0
  48. package/dist/testing/vega-lite-cases.js +143 -0
  49. package/dist/testing/vega-lite-cases.js.map +1 -0
  50. package/package.json +18 -15
@@ -0,0 +1,2 @@
1
+ export * from "./vega-lite-cases.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from "./vega-lite-cases.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC"}
@@ -0,0 +1,164 @@
1
+ import { type DataFrame, type Geometry, type Value } from "@ac-kit/model-dataset";
2
+ /** The examples recorded from Vega-Lite, by name. */
3
+ export type VegaLiteCaseName = "bar" | "bar-sorted" | "scatter" | "stacked" | "histogram" | "heatmap" | "line" | "pie" | "donut" | "radial" | "facet" | "layer" | "concat";
4
+ /**
5
+ * One sector Vega drew: its angles in radians, clockwise from 12 o'clock (a
6
+ * stacked sector may run from its end back to its start), and its radii as
7
+ * fractions of the plot's outer radius (half the smaller of its sides).
8
+ */
9
+ export type VegaLiteArc = {
10
+ /** The value of the field the case names its sectors by. */
11
+ readonly key: Value;
12
+ readonly startAngle: number;
13
+ readonly endAngle: number;
14
+ readonly innerRadius: number;
15
+ readonly outerRadius: number;
16
+ };
17
+ /**
18
+ * One Vega-Lite example: its spec, its rows, and the scale domains Vega
19
+ * computed for it.
20
+ */
21
+ export type VegaLiteCase = {
22
+ /** The Vega-Lite spec as written, inline `data.values` included. */
23
+ readonly spec: Readonly<Record<string, unknown>>;
24
+ readonly rows: readonly Readonly<Record<string, Value>>[];
25
+ /**
26
+ * Domains by scale name (`x`, `y`, `color`, `size`, `theta`, `radius`;
27
+ * `concat_0_x` and so on for a concatenation): categories in order, or the
28
+ * two ends of a continuous domain (temporal ends as ISO 8601 strings).
29
+ */
30
+ readonly scales: Readonly<Record<string, readonly (string | number)[]>>;
31
+ /**
32
+ * The sectors Vega drew, in row order, for the polar cases (`donut`,
33
+ * `radial`, keyed by `k`); `undefined` for the others.
34
+ */
35
+ readonly arcs: readonly VegaLiteArc[] | undefined;
36
+ };
37
+ /**
38
+ * Vega-Lite's examples as Vega-Lite 5.23 compiled them and Vega 5.33 ran them
39
+ * (BSD-3-Clause; specs, domains and sector geometry only, no code), for a
40
+ * renderer of model-chart to check what it draws against: each case's spec, its
41
+ * rows, the scale domains Vega computed and, for the polar cases, the sectors
42
+ * it drew. Frozen.
43
+ */
44
+ export declare const VEGA_LITE_CASES: Readonly<Record<VegaLiteCaseName, VegaLiteCase>>;
45
+ /** The hierarchy layouts recorded from Vega, by its transform's method. */
46
+ export type VegaHierarchyCaseName = "treemap" | "partition" | "tidy" | "cluster";
47
+ /**
48
+ * One node Vega laid out, as fractions of the layout's width (x) and height (y,
49
+ * down from the root): a box for `treemap` and `partition`, a point for `tidy`
50
+ * and `cluster`.
51
+ */
52
+ export type VegaHierarchyNode = {
53
+ readonly id: string;
54
+ readonly x0: number;
55
+ readonly y0: number;
56
+ readonly x1: number;
57
+ readonly y1: number;
58
+ } | {
59
+ readonly id: string;
60
+ readonly x: number;
61
+ readonly y: number;
62
+ };
63
+ /** One Vega hierarchy transform over {@link VEGA_HIERARCHY_CASES}' rows. */
64
+ export type VegaHierarchyCase = {
65
+ /** The Vega transform as written (after a `stratify` by `id` and `parent`). */
66
+ readonly transform: Readonly<Record<string, unknown>>;
67
+ /** In row order. */
68
+ readonly nodes: readonly VegaHierarchyNode[];
69
+ };
70
+ /**
71
+ * Vega 5.33's hierarchy transforms (`treemap` squarified, `partition`, `tree`
72
+ * tidy and cluster; BSD-3-Clause, layouts only, no code) run over one tree of
73
+ * 13 rows (`id`, `parent`, `size` on the leaves) in a box `aspectRatio` wide
74
+ * and 1 high, for a renderer of model-chart's hierarchies to check its nodes
75
+ * against. Frozen.
76
+ */
77
+ export declare const VEGA_HIERARCHY_CASES: Readonly<{
78
+ readonly rows: readonly Readonly<Record<string, Value>>[];
79
+ readonly aspectRatio: number;
80
+ readonly cases: Readonly<Record<VegaHierarchyCaseName, VegaHierarchyCase>>;
81
+ }>;
82
+ /**
83
+ * The rows of {@link VEGA_HIERARCHY_CASES} as a frame: `id` and `parent`
84
+ * nominal, `size` quantitative.
85
+ */
86
+ export declare function vegaHierarchyFrame(): DataFrame;
87
+ /**
88
+ * The rows of a case as a frame: each field of the kind its Vega-Lite encoding
89
+ * gives it, else quantitative for numbers and nominal for strings, in the order
90
+ * the rows first name them.
91
+ */
92
+ export declare function vegaLiteCaseFrame(name: VegaLiteCaseName): DataFrame;
93
+ /** The maps recorded from Vega-Lite, by projection. */
94
+ export type VegaLiteMapCaseName = "equalEarth" | "mercator" | "naturalEarth" | "equirectangularRotated" | "conicConformal" | "albers" | "orthographic" | "stereographic";
95
+ /**
96
+ * A place or a shape's bounds as Vega-Lite drew it, as fractions of the box of
97
+ * everything the case drew (x right, y up).
98
+ */
99
+ export type VegaLiteMapPoint = {
100
+ readonly name: string;
101
+ readonly x: number;
102
+ readonly y: number;
103
+ };
104
+ /** See {@link VegaLiteMapPoint}. */
105
+ export type VegaLiteMapBounds = {
106
+ readonly name: string;
107
+ readonly x0: number;
108
+ readonly y0: number;
109
+ readonly x1: number;
110
+ readonly y1: number;
111
+ };
112
+ /**
113
+ * One map: a `geoshape` layer of {@link VEGA_LITE_MAPS}' regions and a `circle`
114
+ * layer of its cities by longitude and latitude, with the projection Vega-Lite
115
+ * fitted to both.
116
+ */
117
+ export type VegaLiteMapCase = {
118
+ /**
119
+ * Vega-Lite's projection as written (its `type` name, and `rotate` and
120
+ * `parallels` in degrees).
121
+ */
122
+ readonly projection: Readonly<Record<string, unknown>>;
123
+ /** Width to height of the box of everything drawn. */
124
+ readonly aspectRatio: number;
125
+ /** The cities in the case (those on the visible side of a globe). */
126
+ readonly cities: readonly string[];
127
+ readonly regions: readonly string[];
128
+ readonly points: readonly VegaLiteMapPoint[];
129
+ readonly shapes: readonly VegaLiteMapBounds[];
130
+ };
131
+ /** A region of {@link VEGA_LITE_MAPS}: RFC 7946 winding. */
132
+ export type VegaLiteMapRegion = {
133
+ readonly name: string;
134
+ readonly value: number;
135
+ readonly geometry: Geometry;
136
+ };
137
+ /**
138
+ * Maps as Vega-Lite 5.23 compiled them and Vega 5.33 ran them (BSD-3-Clause;
139
+ * specs and mark geometry only, no code) on a 400 × 300 view: eight cities and
140
+ * three regions (a square in Europe, a rectangle across the antimeridian, a
141
+ * rectangle with a hole) through Equal Earth, Mercator, Natural Earth, a
142
+ * rotated equirectangular, a conformal conic, Albers, and orthographic and
143
+ * stereographic globes, each fitted to its data. Frozen.
144
+ */
145
+ export declare const VEGA_LITE_MAPS: Readonly<{
146
+ readonly cities: readonly Readonly<{
147
+ name: string;
148
+ lon: number;
149
+ lat: number;
150
+ }>[];
151
+ readonly regions: readonly VegaLiteMapRegion[];
152
+ readonly cases: Readonly<Record<VegaLiteMapCaseName, VegaLiteMapCase>>;
153
+ }>;
154
+ /**
155
+ * The cities of a map case as a frame: `name` nominal, `lon` and `lat`
156
+ * quantitative (degrees).
157
+ */
158
+ export declare function vegaLiteMapCitiesFrame(name: VegaLiteMapCaseName): DataFrame;
159
+ /**
160
+ * The regions of a map case as a frame: `name` nominal, `value` quantitative,
161
+ * `geometry` a geometry field.
162
+ */
163
+ export declare function vegaLiteMapRegionsFrame(name: VegaLiteMapCaseName): DataFrame;
164
+ //# sourceMappingURL=vega-lite-cases.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vega-lite-cases.d.ts","sourceRoot":"","sources":["../../src/testing/vega-lite-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,SAAS,EAGd,KAAK,QAAQ,EACb,KAAK,KAAK,EACV,MAAM,uBAAuB,CAAC;AAK/B,qDAAqD;AACrD,MAAM,MAAM,gBAAgB,GACzB,KAAK,GACL,YAAY,GACZ,SAAS,GACT,SAAS,GACT,WAAW,GACX,SAAS,GACT,MAAM,GACN,KAAK,GACL,OAAO,GACP,QAAQ,GACR,OAAO,GACP,OAAO,GACP,QAAQ,CAAC;AAEZ;;;;GAIG;AACH,MAAM,MAAM,WAAW,GAAG;IACzB,4DAA4D;IAC5D,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC;IACpB,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IACjD,QAAQ,CAAC,IAAI,EAAE,SAAS,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;IAC1D;;;;OAIG;IACH,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IACxE;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,SAAS,WAAW,EAA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AC5D,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC5B,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC;IACrC,QAAQ,CAAC,MAAM,EAAE,SAAS,QAAQ,CAAC;QAClC,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,EAAE,MAAM,CAAC;QACZ,GAAG,EAAE,MAAM,CAAC;KACZ,CAAC,EAAE,CAAC;IACL,QAAQ,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,CAAC;IAC/C,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC,CAAC;CACvE,CAIC,CAAC;AAEH;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,mBAAmB,GAAG,SAAS,CAY3E;AAED;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,mBAAmB,GAAG,SAAS,CAY5E"}
@@ -0,0 +1,143 @@
1
+ import { dataFrameFromRows, } from "@ac-kit/model-dataset";
2
+ import fixture from "../resolve/__fixtures__/vega-lite-views.json" with { type: "json" };
3
+ import geometry from "./__fixtures__/vega-geometry.json" with { type: "json" };
4
+ /**
5
+ * Vega-Lite's examples as Vega-Lite 5.23 compiled them and Vega 5.33 ran them
6
+ * (BSD-3-Clause; specs, domains and sector geometry only, no code), for a
7
+ * renderer of model-chart to check what it draws against: each case's spec, its
8
+ * rows, the scale domains Vega computed and, for the polar cases, the sectors
9
+ * it drew. Frozen.
10
+ */
11
+ export const VEGA_LITE_CASES = Object.freeze(Object.fromEntries(Object.entries({
12
+ ...fixture.cases, // the recorder writes this shape
13
+ ...geometry.polar, // the recorder writes this shape
14
+ }).map(([name, recorded]) => [
15
+ name,
16
+ Object.freeze({
17
+ spec: recorded.spec,
18
+ rows: recorded.spec.data.values,
19
+ scales: recorded.scales,
20
+ arcs: recorded.marks?.arcs,
21
+ }),
22
+ ])));
23
+ /**
24
+ * Vega 5.33's hierarchy transforms (`treemap` squarified, `partition`, `tree`
25
+ * tidy and cluster; BSD-3-Clause, layouts only, no code) run over one tree of
26
+ * 13 rows (`id`, `parent`, `size` on the leaves) in a box `aspectRatio` wide
27
+ * and 1 high, for a renderer of model-chart's hierarchies to check its nodes
28
+ * against. Frozen.
29
+ */
30
+ export const VEGA_HIERARCHY_CASES = Object.freeze({
31
+ rows: geometry.hierarchies.rows,
32
+ aspectRatio: geometry.hierarchies.aspectRatio,
33
+ cases: geometry.hierarchies.cases,
34
+ });
35
+ /**
36
+ * The rows of {@link VEGA_HIERARCHY_CASES} as a frame: `id` and `parent`
37
+ * nominal, `size` quantitative.
38
+ */
39
+ export function vegaHierarchyFrame() {
40
+ const names = ["id", "parent", "size"];
41
+ return dataFrameFromRows([
42
+ { name: "id", kind: "nominal" },
43
+ { name: "parent", kind: "nominal" },
44
+ { name: "size", kind: "quantitative" },
45
+ ], VEGA_HIERARCHY_CASES.rows.map((row) => names.map((field) => row[field] ?? null)));
46
+ }
47
+ const KINDS_ = {
48
+ nominal: "nominal",
49
+ ordinal: "ordinal",
50
+ quantitative: "quantitative",
51
+ temporal: "temporal",
52
+ };
53
+ // The `type` each field is encoded with, anywhere in the spec (layers and concatenations included).
54
+ function encodedKinds_(spec, out) {
55
+ if (Array.isArray(spec)) {
56
+ for (const item of spec) {
57
+ encodedKinds_(item, out);
58
+ }
59
+ return;
60
+ }
61
+ if (typeof spec !== "object" || spec === null) {
62
+ return;
63
+ }
64
+ const record = spec;
65
+ const { field, type } = record;
66
+ if (typeof field === "string" &&
67
+ typeof type === "string" &&
68
+ KINDS_[type] !== undefined) {
69
+ out.set(field, KINDS_[type]);
70
+ }
71
+ for (const [key, value] of Object.entries(record)) {
72
+ if (key !== "data") {
73
+ encodedKinds_(value, out);
74
+ }
75
+ }
76
+ }
77
+ /**
78
+ * The rows of a case as a frame: each field of the kind its Vega-Lite encoding
79
+ * gives it, else quantitative for numbers and nominal for strings, in the order
80
+ * the rows first name them.
81
+ */
82
+ export function vegaLiteCaseFrame(name) {
83
+ const example = VEGA_LITE_CASES[name];
84
+ const kinds = new Map();
85
+ encodedKinds_(example.spec, kinds);
86
+ const names = [];
87
+ for (const row of example.rows) {
88
+ for (const key of Object.keys(row)) {
89
+ if (!names.includes(key)) {
90
+ names.push(key);
91
+ }
92
+ }
93
+ }
94
+ const fields = names.map((field) => {
95
+ const sample = example.rows.find((row) => row[field] !== null && row[field] !== undefined)?.[field];
96
+ const kind = kinds.get(field) ??
97
+ (typeof sample === "number" ? "quantitative" : "nominal");
98
+ return { name: field, kind }; // every kind takes a bare name
99
+ });
100
+ return dataFrameFromRows(fields, example.rows.map((row) => names.map((field) => row[field] ?? null)));
101
+ }
102
+ /**
103
+ * Maps as Vega-Lite 5.23 compiled them and Vega 5.33 ran them (BSD-3-Clause;
104
+ * specs and mark geometry only, no code) on a 400 × 300 view: eight cities and
105
+ * three regions (a square in Europe, a rectangle across the antimeridian, a
106
+ * rectangle with a hole) through Equal Earth, Mercator, Natural Earth, a
107
+ * rotated equirectangular, a conformal conic, Albers, and orthographic and
108
+ * stereographic globes, each fitted to its data. Frozen.
109
+ */
110
+ export const VEGA_LITE_MAPS = Object.freeze({
111
+ cities: geometry.maps.cities,
112
+ regions: geometry.maps.regions, // the recorder writes GeoJSON polygons
113
+ cases: geometry.maps.cases,
114
+ });
115
+ /**
116
+ * The cities of a map case as a frame: `name` nominal, `lon` and `lat`
117
+ * quantitative (degrees).
118
+ */
119
+ export function vegaLiteMapCitiesFrame(name) {
120
+ const kept = new Set(VEGA_LITE_MAPS.cases[name].cities);
121
+ return dataFrameFromRows([
122
+ { name: "name", kind: "nominal" },
123
+ { name: "lon", kind: "quantitative" },
124
+ { name: "lat", kind: "quantitative" },
125
+ ], VEGA_LITE_MAPS.cities
126
+ .filter((city) => kept.has(city.name))
127
+ .map((city) => [city.name, city.lon, city.lat]));
128
+ }
129
+ /**
130
+ * The regions of a map case as a frame: `name` nominal, `value` quantitative,
131
+ * `geometry` a geometry field.
132
+ */
133
+ export function vegaLiteMapRegionsFrame(name) {
134
+ const kept = new Set(VEGA_LITE_MAPS.cases[name].regions);
135
+ return dataFrameFromRows([
136
+ { name: "name", kind: "nominal" },
137
+ { name: "value", kind: "quantitative" },
138
+ { name: "geometry", kind: "geometry" },
139
+ ], VEGA_LITE_MAPS.regions
140
+ .filter((region) => kept.has(region.name))
141
+ .map((region) => [region.name, region.value, region.geometry]));
142
+ }
143
+ //# sourceMappingURL=vega-lite-cases.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vega-lite-cases.js","sourceRoot":"","sources":["../../src/testing/vega-lite-cases.ts"],"names":[],"mappings":"AAAA,OAAO,EAEN,iBAAiB,GAIjB,MAAM,uBAAuB,CAAC;AAE/B,OAAO,OAAO,MAAM,8CAA8C,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AACzF,OAAO,QAAQ,MAAM,mCAAmC,CAAC,OAAO,IAAI,EAAE,MAAM,EAAE,CAAC;AA6D/E;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,eAAe,GAC3B,MAAM,CAAC,MAAM,CACZ,MAAM,CAAC,WAAW,CACjB,MAAM,CAAC,OAAO,CAAC;IACd,GAAI,OAAO,CAAC,KAA8C,EAAE,iCAAiC;IAC7F,GAAI,QAAQ,CAAC,KAA8C,EAAE,iCAAiC;CAC9F,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,QAAQ,CAAC,EAAE,EAAE,CAAC;IAC5B,IAAI;IACJ,MAAM,CAAC,MAAM,CAAC;QACb,IAAI,EAAE,QAAQ,CAAC,IAAI;QACnB,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM;QAC/B,MAAM,EAAE,QAAQ,C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AAS,EAAE;QACjC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE;QACrC,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,cAAc,EAAE;KACrC,EACD,cAAc,CAAC,MAAM;SACnB,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;SACrC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAChD,CAAC;AACH,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,IAAyB;IAChE,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,cAAc,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,CAAC;IACzD,OAAO,iBAAiB,CACvB;QACC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE;QACjC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE;QACvC,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,UAAU,EAAE;KACtC,EACD,cAAc,CAAC,OAAO;SACpB,MAAM,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;SACzC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAC/D,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ac-kit/model-chart",
3
- "version": "0.3.0",
3
+ "version": "0.4.0",
4
4
  "description": "A description of a chart, independent of the medium it will be drawn in.",
5
5
  "keywords": [
6
6
  "chart",
@@ -28,14 +28,16 @@
28
28
  "exports": {
29
29
  ".": "./dist/index.js",
30
30
  "./geographic": "./dist/geographic/index.js",
31
- "./layout": "./dist/layout/index.js"
31
+ "./layout": "./dist/layout/index.js",
32
+ "./testing": "./dist/testing/index.js"
32
33
  },
33
34
  "publishConfig": {
34
35
  "main": "./dist/index.js",
35
36
  "exports": {
36
37
  ".": "./dist/index.js",
37
38
  "./geographic": "./dist/geographic/index.js",
38
- "./layout": "./dist/layout/index.js"
39
+ "./layout": "./dist/layout/index.js",
40
+ "./testing": "./dist/testing/index.js"
39
41
  },
40
42
  "access": "public"
41
43
  },
@@ -48,22 +50,23 @@
48
50
  "prepack": "yarn build"
49
51
  },
50
52
  "dependencies": {
51
- "@ac-kit/algo": "^0.6.0",
52
- "@ac-kit/core": "^0.13.0",
53
- "@ac-kit/math-geometry": "^0.4.0",
54
- "@ac-kit/math-graph": "^0.2.0",
55
- "@ac-kit/math-linear": "^0.4.0",
56
- "@ac-kit/math-map-projection": "^0.2.0",
57
- "@ac-kit/math-scalar": "^0.4.0",
58
- "@ac-kit/math-stats": "^0.6.0",
59
- "@ac-kit/model-dataset": "^0.3.0"
53
+ "@ac-kit/algo": "^0.7.0",
54
+ "@ac-kit/core": "^0.14.0",
55
+ "@ac-kit/math-color": "^0.4.0",
56
+ "@ac-kit/math-geometry": "^0.5.0",
57
+ "@ac-kit/math-graph": "^0.2.1",
58
+ "@ac-kit/math-linear": "^0.5.0",
59
+ "@ac-kit/math-map-projection": "^0.3.0",
60
+ "@ac-kit/math-scalar": "^0.5.0",
61
+ "@ac-kit/math-stats": "^0.7.0",
62
+ "@ac-kit/model-dataset": "^0.3.1"
60
63
  },
61
64
  "devDependencies": {
62
- "@ac-kit/math-random": "0.4.1",
63
- "@ac-kit/test-util": "0.5.0",
65
+ "@ac-kit/math-random": "0.4.2",
66
+ "@ac-kit/test-util": "0.5.1",
64
67
  "@ac-kit/tsconfig": "0.1.0",
65
68
  "@ac-kit/typedoc-config": "0.1.0",
66
- "@ac-kit/vitest-config": "0.2.0",
69
+ "@ac-kit/vitest-config": "0.3.0",
67
70
  "@types/d3-array": "3.2.2",
68
71
  "@types/d3-scale": "4.0.9",
69
72
  "@types/web": "^0.0.367",