@ac-kit/model-chart 0.1.0 → 0.3.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/CHANGELOG.md +217 -0
- package/README.md +141 -1
- package/dist/geographic/index.d.ts +2 -0
- package/dist/geographic/index.d.ts.map +1 -0
- package/dist/geographic/index.js +2 -0
- package/dist/geographic/index.js.map +1 -0
- package/dist/geographic/project-geographic-layer.d.ts +54 -0
- package/dist/geographic/project-geographic-layer.d.ts.map +1 -0
- package/dist/geographic/project-geographic-layer.js +214 -0
- package/dist/geographic/project-geographic-layer.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/layout/_fit.d.ts +12 -0
- package/dist/layout/_fit.d.ts.map +1 -0
- package/dist/layout/_fit.js +52 -0
- package/dist/layout/_fit.js.map +1 -0
- package/dist/layout/index.d.ts +4 -0
- package/dist/layout/index.d.ts.map +1 -0
- package/dist/layout/index.js +4 -0
- package/dist/layout/index.js.map +1 -0
- package/dist/layout/layout-hierarchy.d.ts +35 -0
- package/dist/layout/layout-hierarchy.d.ts.map +1 -0
- package/dist/layout/layout-hierarchy.js +98 -0
- package/dist/layout/layout-hierarchy.js.map +1 -0
- package/dist/layout/layout-network.d.ts +45 -0
- package/dist/layout/layout-network.d.ts.map +1 -0
- package/dist/layout/layout-network.js +197 -0
- package/dist/layout/layout-network.js.map +1 -0
- package/dist/layout/options.d.ts +29 -0
- package/dist/layout/options.d.ts.map +1 -0
- package/dist/layout/options.js +2 -0
- package/dist/layout/options.js.map +1 -0
- package/dist/render/_fallback-chain.d.ts +13 -0
- package/dist/render/_fallback-chain.d.ts.map +1 -0
- package/dist/render/_fallback-chain.js +41 -0
- package/dist/render/_fallback-chain.js.map +1 -0
- package/dist/render/capabilities.d.ts +23 -1
- package/dist/render/capabilities.d.ts.map +1 -1
- package/dist/render/capabilities.js +56 -10
- package/dist/render/capabilities.js.map +1 -1
- package/dist/resolve/_calendar-interval.d.ts +10 -0
- package/dist/resolve/_calendar-interval.d.ts.map +1 -0
- package/dist/resolve/_calendar-interval.js +27 -0
- package/dist/resolve/_calendar-interval.js.map +1 -0
- package/dist/resolve/_coords.d.ts +35 -0
- package/dist/resolve/_coords.d.ts.map +1 -0
- package/dist/resolve/_coords.js +354 -0
- package/dist/resolve/_coords.js.map +1 -0
- package/dist/resolve/_grid-field.d.ts +16 -0
- package/dist/resolve/_grid-field.d.ts.map +1 -0
- package/dist/resolve/_grid-field.js +23 -0
- package/dist/resolve/_grid-field.js.map +1 -0
- package/dist/resolve/_guides.d.ts +16 -0
- package/dist/resolve/_guides.d.ts.map +1 -0
- package/dist/resolve/_guides.js +66 -0
- package/dist/resolve/_guides.js.map +1 -0
- package/dist/resolve/_options.d.ts +17 -0
- package/dist/resolve/_options.d.ts.map +1 -0
- package/dist/resolve/_options.js +38 -0
- package/dist/resolve/_options.js.map +1 -0
- package/dist/resolve/errors.d.ts +63 -0
- package/dist/resolve/errors.d.ts.map +1 -0
- package/dist/resolve/errors.js +91 -0
- package/dist/resolve/errors.js.map +1 -0
- package/dist/resolve/options.d.ts +30 -0
- package/dist/resolve/options.d.ts.map +1 -0
- package/dist/resolve/options.js +2 -0
- package/dist/resolve/options.js.map +1 -0
- package/dist/resolve/scale-ticks.d.ts +91 -0
- package/dist/resolve/scale-ticks.d.ts.map +1 -0
- package/dist/resolve/scale-ticks.js +231 -0
- package/dist/resolve/scale-ticks.js.map +1 -0
- package/dist/resolve/scale-transform.d.ts +102 -0
- package/dist/resolve/scale-transform.d.ts.map +1 -0
- package/dist/resolve/scale-transform.js +466 -0
- package/dist/resolve/scale-transform.js.map +1 -0
- package/dist/resolve/scale.d.ts +139 -0
- package/dist/resolve/scale.d.ts.map +1 -0
- package/dist/resolve/scale.js +710 -0
- package/dist/resolve/scale.js.map +1 -0
- package/dist/resolve/series.d.ts +26 -0
- package/dist/resolve/series.d.ts.map +1 -0
- package/dist/resolve/series.js +105 -0
- package/dist/resolve/series.js.map +1 -0
- package/dist/resolve/view-types.d.ts +223 -0
- package/dist/resolve/view-types.d.ts.map +1 -0
- package/dist/resolve/view-types.js +2 -0
- package/dist/resolve/view-types.js.map +1 -0
- package/dist/resolve/view.d.ts +43 -0
- package/dist/resolve/view.d.ts.map +1 -0
- package/dist/resolve/view.js +621 -0
- package/dist/resolve/view.js.map +1 -0
- package/dist/spec/channel.d.ts +3 -1
- package/dist/spec/channel.d.ts.map +1 -1
- package/dist/spec/channel.js.map +1 -1
- package/dist/spec/coord.d.ts +22 -0
- package/dist/spec/coord.d.ts.map +1 -1
- package/dist/spec/data-sources.d.ts +47 -0
- package/dist/spec/data-sources.d.ts.map +1 -0
- package/dist/spec/data-sources.js +112 -0
- package/dist/spec/data-sources.js.map +1 -0
- package/dist/spec/mark.d.ts +6 -1
- package/dist/spec/mark.d.ts.map +1 -1
- package/dist/spec/plot.d.ts +5 -0
- package/dist/spec/plot.d.ts.map +1 -1
- package/dist/spec/scale.d.ts +21 -2
- package/dist/spec/scale.d.ts.map +1 -1
- package/dist/spec/transform.d.ts +32 -6
- package/dist/spec/transform.d.ts.map +1 -1
- package/dist/transform/aggregate.d.ts +28 -0
- package/dist/transform/aggregate.d.ts.map +1 -0
- package/dist/transform/aggregate.js +463 -0
- package/dist/transform/aggregate.js.map +1 -0
- package/dist/transform/apply-transforms.d.ts +26 -0
- package/dist/transform/apply-transforms.d.ts.map +1 -0
- package/dist/transform/apply-transforms.js +66 -0
- package/dist/transform/apply-transforms.js.map +1 -0
- package/dist/transform/bin.d.ts +30 -0
- package/dist/transform/bin.d.ts.map +1 -0
- package/dist/transform/bin.js +169 -0
- package/dist/transform/bin.js.map +1 -0
- package/dist/transform/columns.d.ts +24 -0
- package/dist/transform/columns.d.ts.map +1 -0
- package/dist/transform/columns.js +77 -0
- package/dist/transform/columns.js.map +1 -0
- package/dist/transform/filter.d.ts +11 -0
- package/dist/transform/filter.d.ts.map +1 -0
- package/dist/transform/filter.js +64 -0
- package/dist/transform/filter.js.map +1 -0
- package/dist/transform/group-rows.d.ts +25 -0
- package/dist/transform/group-rows.d.ts.map +1 -0
- package/dist/transform/group-rows.js +52 -0
- package/dist/transform/group-rows.js.map +1 -0
- package/dist/transform/sort.d.ts +10 -0
- package/dist/transform/sort.d.ts.map +1 -0
- package/dist/transform/sort.js +63 -0
- package/dist/transform/sort.js.map +1 -0
- package/dist/transform/stack.d.ts +37 -0
- package/dist/transform/stack.d.ts.map +1 -0
- package/dist/transform/stack.js +218 -0
- package/dist/transform/stack.js.map +1 -0
- package/package.json +28 -9
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
# @ac-kit/model-chart
|
|
2
|
+
|
|
3
|
+
## 0.3.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 0b4fe43: `applyTransforms(transforms, frame, options)` runs a spec's `filter`, `sort`,
|
|
8
|
+
`aggregate`, `bin` and `stack` transforms in order and never mutates the frame;
|
|
9
|
+
untouched columns are shared and new numeric columns are `Float64Array` when
|
|
10
|
+
complete. `null` and `NaN` fail every `filter` comparison and come last in a
|
|
11
|
+
`sort`. `aggregate` outputs groups in first-appearance order (one row for an
|
|
12
|
+
empty `groupBy`), skips missing cells, and gives `null` for an empty group or a
|
|
13
|
+
`variance` of fewer than two values. `distinct` counts the non-`null` cells by
|
|
14
|
+
SameValueZero, as a `Set` would: `NaN` once, `0` and `-0` as one, `1n` and `1`
|
|
15
|
+
as two, and geometries by identity; unlike Vega, `null` is not counted.
|
|
16
|
+
An `aggregate` allocates its output columns and nothing per group or per row,
|
|
17
|
+
whatever the source column holds: a numeric field in a boxed or `Int32Array`
|
|
18
|
+
column is read group by group, not converted whole.
|
|
19
|
+
`bin` takes math-stats `histogramEdges`' nice edges: the width of its `rule`
|
|
20
|
+
(any `HistogramBinRule`, `"freedman-diaconis"` by default, Sturges' where the
|
|
21
|
+
rule finds none) rounded up to 1, 2 or 5 times a power of ten within `maxBins`,
|
|
22
|
+
edges on its multiples (calendar edges in `options.timeZone` for temporal
|
|
23
|
+
fields), the last bin closed; a temporal field's `step` may be a calendar
|
|
24
|
+
interval (`"month"`, `{ unit: "day", step: 7 }`), whose boundaries in the zone
|
|
25
|
+
are the edges. Edges that would leave the double range throw
|
|
26
|
+
`InvalidTransformError`, math-stats' `RangeError` as its `cause`
|
|
27
|
+
(`InvalidTransformError` takes `ErrorOptions`).
|
|
28
|
+
A `null` or `NaN` value adds nothing to its stack and gets `null` edges, so no
|
|
29
|
+
segment is drawn for it (Vega-Lite's default `invalid: "filter"`).
|
|
30
|
+
`stack` offsets are `zero`, `normalize`, `center` (every stack centred on the
|
|
31
|
+
tallest one's middle, as Vega's `center`), `silhouette` (each stack centred on
|
|
32
|
+
0, as d3's) and `wiggle` (the streamgraph baseline that minimises the layers'
|
|
33
|
+
weighted wiggle, Byron and Wattenberg 2008, as d3's). `stack`'s `series`
|
|
34
|
+
fields name each row's layer: every offset then matches layers by key, stacks
|
|
35
|
+
them bottom up in the order their keys first appear and counts a layer missing
|
|
36
|
+
from a stack as zero; `wiggle` requires it.
|
|
37
|
+
Other kinds throw `InvalidTransformError`; `RESOLVABLE_TRANSFORMS` lists the
|
|
38
|
+
supported ones.
|
|
39
|
+
- 0b4fe43: `resolveScale(inputs, options)` resolves the scale every input of one scale
|
|
40
|
+
channel shares, by Vega-Lite's documented defaults: kind from the field and the
|
|
41
|
+
mark (`band` for bars, rects and surfaces, `point` otherwise, `ordinal` off the
|
|
42
|
+
position channels), `zero` for linear, pow and symlog position and size scales,
|
|
43
|
+
`nice` for linear, pow, symlog and log x, y and z scales (an angle or a radius
|
|
44
|
+
keeps its extent, so a pie closes at its total), band and point paddings, and
|
|
45
|
+
the `sort` order of categories. `ScaleSpec.nice` takes `true`, a tick count, or
|
|
46
|
+
a calendar interval for a time scale (`"month"`, `{ unit: "month", step: 3 }`,
|
|
47
|
+
Vega-Lite's `TimeInterval`), whose boundaries in the chart's time zone the
|
|
48
|
+
domain is widened to. Continuous domains are the union of the finite
|
|
49
|
+
extents (log keeps one sign), widened by `include` (annotation positions) and a
|
|
50
|
+
diverging midpoint, and a single value stays `[v, v]`. An explicit domain is
|
|
51
|
+
final. Binned or stacked inputs are flagged with `ScaleInput.binned` and
|
|
52
|
+
`stacked`. Data grids give lattice domains (cell edges for `rect`, centres
|
|
53
|
+
otherwise). `scaleChannelOf` folds `x2`, `y2`, `theta2` and `radius2` onto their
|
|
54
|
+
scale channel, and `ResolveOptions` carries the time zone (default `"UTC"`),
|
|
55
|
+
week start, tick, bin and class counts. Scales a spec makes impossible throw
|
|
56
|
+
`InvalidScaleError`.
|
|
57
|
+
- 0b4fe43: The spec grows the vocabulary the resolver needs. `Mark` gains `"surface"` (a
|
|
58
|
+
surface over a data grid, height `z`) and `Channel` gains `"parent"` (a
|
|
59
|
+
hierarchy row's parent key, `null` for the root). `CoordSpec` gains
|
|
60
|
+
`parallel.axes` (one `FieldEncoding` per axis, in order) and `hierarchy.radial`
|
|
61
|
+
(x → angle, y → radius). Polar angles are radians, clockwise from 12 o'clock,
|
|
62
|
+
and `innerRadius` is a fraction of the outer radius in [0, 1).
|
|
63
|
+
`RESOLVER_SUPPORT` lists the transforms, projections and layouts model-chart
|
|
64
|
+
itself can resolve, and the `Invalid…Error` classes (`InvalidScaleError`,
|
|
65
|
+
`InvalidTransformError`, `InvalidEncodingError`, `InvalidCoordError`,
|
|
66
|
+
`InvalidLayerSourceError`, `InvalidHierarchyError`, `InvalidNetworkError`) are
|
|
67
|
+
exported. `resolvePlot` gives a `surface` that nothing in its fallback chain can
|
|
68
|
+
draw one last candidate: a `rect` over the same grid, coloured by
|
|
69
|
+
`color ?? z`.
|
|
70
|
+
|
|
71
|
+
Migration: the `Mark` and `Channel` unions are widened, so an exhaustive
|
|
72
|
+
`switch` (or a `Record<Mark, …>` / `Record<Channel, …>`) over either needs a
|
|
73
|
+
case for `"surface"` and `"parent"`. A `{ kind: "parallel" }` and a
|
|
74
|
+
`{ kind: "hierarchy", layout }` coordinate system stay valid. `ScaleSpec.nice`
|
|
75
|
+
widens from `boolean` to `boolean | number | CalendarIntervalSpec` and
|
|
76
|
+
`BinTransform.step` from `number` to `number | CalendarIntervalSpec`
|
|
77
|
+
(`CalendarIntervalSpec` is a calendar unit or `{ unit, step? }`): code that
|
|
78
|
+
reads either from a spec must handle the new forms.
|
|
79
|
+
- 0b4fe43: `resolveView(spec, data, capabilities, options)` resolves a whole view for a
|
|
80
|
+
renderer: each plot through its fallback chain against the renderer's
|
|
81
|
+
capabilities and what model-chart can resolve (`RESOLVER_SUPPORT`), with the
|
|
82
|
+
inherited coordinate system, `maxMarks` checked after transforms
|
|
83
|
+
(`mark count N (limit M)`) and a `crs` other than WGS 84 declined
|
|
84
|
+
(`crs X`); transforms applied; scales shared across a layer composition and,
|
|
85
|
+
unless `sharedScales` is false, across a facet's cells; guides (axes and
|
|
86
|
+
legends with their titles, gridlines and tick settings); and the coordinate
|
|
87
|
+
system (`cartesian` with its dimension, `polar` angles, the checked
|
|
88
|
+
`geographic` projection, `parallel` axes with their own scales, `hierarchy`
|
|
89
|
+
parent rows and `network` node and link index tables). The result is a tree of
|
|
90
|
+
`panel`, `facet`, `concat` and `table` nodes, plus every panel depth-first; a
|
|
91
|
+
root it cannot draw gives `kind: "table"` with the reasons and the frames, and
|
|
92
|
+
an undrawable concatenated view becomes a `table` node. A plot encoding `row`
|
|
93
|
+
or `column` is faceted by those fields; an `arc` with `theta` and no `theta2`
|
|
94
|
+
in polar coordinates stacks `theta` (the pie); annotations widen continuous
|
|
95
|
+
domains. `layerSeries(layer, panel)` gives a line or area layer's paths.
|
|
96
|
+
|
|
97
|
+
Two subpaths keep their dependencies away from the root:
|
|
98
|
+
`@ac-kit/model-chart/layout` lays hierarchy and network panels out in the
|
|
99
|
+
plot's unit square with `@ac-kit/math-graph` (`layoutHierarchy`,
|
|
100
|
+
`layoutNetwork`, `layoutNetworkAsync`, which takes an `AbortSignal`), and
|
|
101
|
+
`@ac-kit/model-chart/geographic` projects a map layer's points and GeoJSON
|
|
102
|
+
geometries with `@ac-kit/math-map-projection` (`projectGeographicLayer`), cut
|
|
103
|
+
at the map's edge, with the bounds a renderer fits. `RESOLVER_SUPPORT`
|
|
104
|
+
includes the `transverse-mercator` projection.
|
|
105
|
+
|
|
106
|
+
Migration: `resolvePlot` is unchanged; a renderer that resolved scales itself
|
|
107
|
+
can call `resolveView` instead.
|
|
108
|
+
- 0b4fe43: Resolved scales come with allocation-free kernels. `scaleTransform` and
|
|
109
|
+
`scaleInvertTransform` map a value into and out of the space where a position
|
|
110
|
+
scale is affine (identity for linear and time, `log_b`, signed power, signed
|
|
111
|
+
`log1p`); a value outside the transform's domain gives NaN and nothing throws.
|
|
112
|
+
`scaleNormalize` gives the `[0, 1]` position, piecewise about a diverging
|
|
113
|
+
midpoint, clamped in data space like d3, mirrored by `reverse`, and ½ for a zero
|
|
114
|
+
span. The array forms (`scaleTransformArray`, `scaleNormalizeArray`,
|
|
115
|
+
`scaleDiscreteIndexArray`, `scaleClassIndexArray`) take `out` first, accept
|
|
116
|
+
`out` as the input for in-place use, and throw `RangeError` on unequal lengths.
|
|
117
|
+
They allocate nothing per pass, whatever mix of scale kinds a caller
|
|
118
|
+
alternates: the first call for a scale object caches its constants (resolved
|
|
119
|
+
scales are immutable records). `scaleBandGeometry` gives the start, step and
|
|
120
|
+
bandwidth of band and point scales. All match d3-scale's log, pow, symlog, band, point, quantile, quantize
|
|
121
|
+
and threshold scales.
|
|
122
|
+
- 0b4fe43: `scaleTicks(scale, { count, visible, values })` gives a resolved scale's axis
|
|
123
|
+
ticks, each with its value, transformed-space position and whether it is major.
|
|
124
|
+
Linear and pow scales give d3's `ticks` with the decimal `precision` to format
|
|
125
|
+
them; symlog scales give `symlogTicks` with the scale's constant (decades
|
|
126
|
+
beyond `±constant`, linear ticks inside) and the `precision` that prints every
|
|
127
|
+
tick exactly; log scales give `logTicks` (a tick is major exactly when it is a
|
|
128
|
+
whole power of the base, with no tolerance); time
|
|
129
|
+
scales give calendar ticks in the scale's time zone and week start, with their
|
|
130
|
+
`unit` and `step`; discrete scales give the band indices and binning scales
|
|
131
|
+
their thresholds; identity gives `{ kind: "none" }`. `visible` (a zoomed range
|
|
132
|
+
in transformed space, ends in either order) restricts the ticks to those whose
|
|
133
|
+
transformed position lies in it, without rounding through the inverse
|
|
134
|
+
transform: a `visible` equal to the transformed domain gives exactly the
|
|
135
|
+
domain's ticks. `values` replaces them with exactly those inside `visible`,
|
|
136
|
+
with the `precision` that prints each one returned exactly. A
|
|
137
|
+
non-positive `count` throws `RangeError`.
|
|
138
|
+
|
|
139
|
+
### Patch Changes
|
|
140
|
+
|
|
141
|
+
- Updated dependencies [0b4fe43]
|
|
142
|
+
- Updated dependencies [0b4fe43]
|
|
143
|
+
- Updated dependencies [0b4fe43]
|
|
144
|
+
- Updated dependencies [0b4fe43]
|
|
145
|
+
- Updated dependencies [0b4fe43]
|
|
146
|
+
- Updated dependencies [0b4fe43]
|
|
147
|
+
- Updated dependencies [0b4fe43]
|
|
148
|
+
- Updated dependencies [0b4fe43]
|
|
149
|
+
- Updated dependencies [0b4fe43]
|
|
150
|
+
- Updated dependencies [0b4fe43]
|
|
151
|
+
- Updated dependencies [0b4fe43]
|
|
152
|
+
- Updated dependencies [0b4fe43]
|
|
153
|
+
- Updated dependencies [0b4fe43]
|
|
154
|
+
- Updated dependencies [0b4fe43]
|
|
155
|
+
- Updated dependencies [0b4fe43]
|
|
156
|
+
- Updated dependencies [0b4fe43]
|
|
157
|
+
- Updated dependencies [0b4fe43]
|
|
158
|
+
- Updated dependencies [0b4fe43]
|
|
159
|
+
- Updated dependencies [0b4fe43]
|
|
160
|
+
- Updated dependencies [0b4fe43]
|
|
161
|
+
- Updated dependencies [0b4fe43]
|
|
162
|
+
- Updated dependencies [0b4fe43]
|
|
163
|
+
- Updated dependencies [0b4fe43]
|
|
164
|
+
- Updated dependencies [0b4fe43]
|
|
165
|
+
- Updated dependencies [0b4fe43]
|
|
166
|
+
- Updated dependencies [0b4fe43]
|
|
167
|
+
- Updated dependencies [0b4fe43]
|
|
168
|
+
- Updated dependencies [0b4fe43]
|
|
169
|
+
- Updated dependencies [0b4fe43]
|
|
170
|
+
- Updated dependencies [0b4fe43]
|
|
171
|
+
- Updated dependencies [0b4fe43]
|
|
172
|
+
- Updated dependencies [0b4fe43]
|
|
173
|
+
- Updated dependencies [0b4fe43]
|
|
174
|
+
- Updated dependencies [0b4fe43]
|
|
175
|
+
- Updated dependencies [0b4fe43]
|
|
176
|
+
- Updated dependencies [0b4fe43]
|
|
177
|
+
- Updated dependencies [0b4fe43]
|
|
178
|
+
- Updated dependencies [0b4fe43]
|
|
179
|
+
- Updated dependencies [0b4fe43]
|
|
180
|
+
- Updated dependencies [0b4fe43]
|
|
181
|
+
- Updated dependencies [0b4fe43]
|
|
182
|
+
- Updated dependencies [0b4fe43]
|
|
183
|
+
- Updated dependencies [0b4fe43]
|
|
184
|
+
- Updated dependencies [0b4fe43]
|
|
185
|
+
- Updated dependencies [0b4fe43]
|
|
186
|
+
- Updated dependencies [0b4fe43]
|
|
187
|
+
- @ac-kit/algo@0.6.0
|
|
188
|
+
- @ac-kit/core@0.13.0
|
|
189
|
+
- @ac-kit/math-geometry@0.4.0
|
|
190
|
+
- @ac-kit/math-graph@0.2.0
|
|
191
|
+
- @ac-kit/math-linear@0.4.0
|
|
192
|
+
- @ac-kit/math-map-projection@0.2.0
|
|
193
|
+
- @ac-kit/math-scalar@0.4.0
|
|
194
|
+
- @ac-kit/math-stats@0.6.0
|
|
195
|
+
- @ac-kit/model-dataset@0.3.0
|
|
196
|
+
|
|
197
|
+
## 0.2.0
|
|
198
|
+
|
|
199
|
+
### Minor Changes
|
|
200
|
+
|
|
201
|
+
- 34e8cfa: A chart can read several named sources. `DataSources` maps names to frames and
|
|
202
|
+
`DataGrid`s; `PlotSpec.data` names the one a layer reads (absent: the only
|
|
203
|
+
source, or `"default"`); a network's `nodes` names the frame of node rows keyed
|
|
204
|
+
by `id`. `resolveDataSource` and `assertDataReferences` throw
|
|
205
|
+
`UnknownDataSourceError` for a layer, fallback or `nodes` naming a missing
|
|
206
|
+
source, and `InvalidNodeSourceError` for a `nodes` source that is a grid or has
|
|
207
|
+
no `id` field, including a `nodes` inherited from an enclosing layer
|
|
208
|
+
composition. `RendererCapabilities` gains optional `dimensions`, `projections`
|
|
209
|
+
and `layouts`; absent means no restriction, and `unsupportedFeatures` reports
|
|
210
|
+
`dimension 2`, `dimension 3`, `projection albers-usa` or `layout pack` when a
|
|
211
|
+
declared set lacks what a spec needs.
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- Updated dependencies [34e8cfa]
|
|
216
|
+
- Updated dependencies [34e8cfa]
|
|
217
|
+
- @ac-kit/model-dataset@0.2.0
|
package/README.md
CHANGED
|
@@ -40,8 +40,14 @@ not a new type someone has to add.
|
|
|
40
40
|
| Transforms | `TransformSpec` and its ten members (`bin`, `aggregate`, `stack`, `density`, …) |
|
|
41
41
|
| Coordinates | `CoordSpec`, `CoordKind`, `ProjectionSpec`, `ProjectionKind`, `HierarchyLayout`, `NetworkLayout` |
|
|
42
42
|
| Composition | `PlotSpec`, `ViewSpec`, `LayerSpec`, `FacetSpec`, `ConcatSpec`, `Interpolation` |
|
|
43
|
+
| Data | `DataSources`, `resolveDataSource`, `assertDataReferences`, `UnknownDataSourceError`, `InvalidNodeSourceError` |
|
|
43
44
|
| Annotations | `AnnotationSpec` |
|
|
44
45
|
| Rendering | `RendererCapabilities`, `canRender`, `resolvePlot`, `unsupportedFeatures` |
|
|
46
|
+
| Resolve | `resolveScale`, `scaleChannelOf`, `ScaleInput`, `ResolvedScale` and its kinds, `ResolveOptions`; the scale kernels `scaleTransform`, `scaleNormalizeArray`, `scaleDiscreteIndexArray`, `scaleClassIndexArray`, `scaleBandGeometry`; the ticks `scaleTicks`, `ScaleTicks`, `ScaleTick`, `ScaleTicksOptions` |
|
|
47
|
+
| View | `resolveView`, `ResolveViewResult`, `ResolvedView`, `ResolvedNode`, `ResolvedPanel`, `ResolvedLayer`, `ResolvedChannel`, `ResolvedGuide`, `ResolvedCoord`, `ResolvedTable`; `layerSeries`, `LayerSeries` |
|
|
48
|
+
| Transforms (run) | `applyTransforms`, `ApplyTransformsOptions`, `RESOLVABLE_TRANSFORMS` |
|
|
49
|
+
| `./layout` | `layoutHierarchy`, `layoutNetwork`, `layoutNetworkAsync`, `ChartLayoutOptions` |
|
|
50
|
+
| `./geographic` | `projectGeographicLayer`, `GeographicLayerProjection`, `GeographicShape` |
|
|
45
51
|
|
|
46
52
|
## Nothing here is in output units
|
|
47
53
|
|
|
@@ -63,6 +69,39 @@ result is the signal to apply the universal fallback and render the underlying
|
|
|
63
69
|
frame as a table. Every spec carries a `description` so a renderer that declines
|
|
64
70
|
still has something to say.
|
|
65
71
|
|
|
72
|
+
`dimensions`, `projections` and `layouts` are optional: absent means no
|
|
73
|
+
restriction, so a renderer that predates them is unaffected. Declared, they make
|
|
74
|
+
`unsupportedFeatures` report `dimension 3`, `projection albers-usa` or
|
|
75
|
+
`layout pack` for a spec that needs what the renderer lacks.
|
|
76
|
+
|
|
77
|
+
## Named data sources
|
|
78
|
+
|
|
79
|
+
`PlotSpec.data` names the source a layer reads among the `DataSources` a chart
|
|
80
|
+
is given — frames and `DataGrid`s by name. Absent, it reads the only source, or
|
|
81
|
+
the one called `"default"`. A network's `nodes` names the frame of node rows,
|
|
82
|
+
keyed by `id`. `assertDataReferences` checks a whole view, fallbacks included,
|
|
83
|
+
before anything is resolved.
|
|
84
|
+
|
|
85
|
+
```ts
|
|
86
|
+
import { dataFrameFromColumns } from "@ac-kit/model-dataset";
|
|
87
|
+
import { assertDataReferences, type DataSources } from "@ac-kit/model-chart";
|
|
88
|
+
|
|
89
|
+
const sources: DataSources = new Map([
|
|
90
|
+
["links", dataFrameFromColumns([{ name: "source", kind: "nominal" }], [["a"]])],
|
|
91
|
+
["people", dataFrameFromColumns([{ name: "id", kind: "identifier" }], [["a"]])],
|
|
92
|
+
]);
|
|
93
|
+
|
|
94
|
+
assertDataReferences(
|
|
95
|
+
{
|
|
96
|
+
mark: "link",
|
|
97
|
+
data: "links",
|
|
98
|
+
encoding: {},
|
|
99
|
+
coord: { kind: "network", layout: "force", nodes: "people" },
|
|
100
|
+
},
|
|
101
|
+
sources,
|
|
102
|
+
);
|
|
103
|
+
```
|
|
104
|
+
|
|
66
105
|
## Transforms are declared here, computed elsewhere
|
|
67
106
|
|
|
68
107
|
`bin`, `density`, `regression` and `contour` are named operations with real
|
|
@@ -71,5 +110,106 @@ implementations, and those belong where the mathematics lives —
|
|
|
71
110
|
which one to apply, not how.
|
|
72
111
|
|
|
73
112
|
See the
|
|
74
|
-
[generated API docs](https://anthochamp.
|
|
113
|
+
[generated API docs](https://anthochamp.pages.grenadine.io/node-essentials/api/model-chart/)
|
|
75
114
|
for the full reference.
|
|
115
|
+
|
|
116
|
+
## Resolving a view
|
|
117
|
+
|
|
118
|
+
`resolveView(spec, data, capabilities, options)` does what every renderer would
|
|
119
|
+
otherwise repeat: it walks each plot's fallback chain against the renderer's
|
|
120
|
+
capabilities and what model-chart can resolve (`RESOLVER_SUPPORT`), applies the
|
|
121
|
+
transforms, resolves the scales (shared across a layer composition, and across
|
|
122
|
+
a facet's cells unless `sharedScales` is false), the guides and the coordinate
|
|
123
|
+
system, and returns a tree of panels. A root it cannot draw comes back as
|
|
124
|
+
`kind: "table"` with the reasons and the frames to show instead; inside a
|
|
125
|
+
concatenation, an undrawable view becomes a `table` node. Spec and data errors
|
|
126
|
+
throw; renderer limits decline.
|
|
127
|
+
|
|
128
|
+
```ts
|
|
129
|
+
import { dataFrameFromColumns } from "@ac-kit/model-dataset";
|
|
130
|
+
import { resolveView, scaleNormalizeArray } from "@ac-kit/model-chart";
|
|
131
|
+
|
|
132
|
+
const frame = dataFrameFromColumns(
|
|
133
|
+
[
|
|
134
|
+
{ name: "speed", kind: "quantitative" },
|
|
135
|
+
{ name: "cost", kind: "quantitative" },
|
|
136
|
+
],
|
|
137
|
+
[Float64Array.of(6, 18, 48), Float64Array.of(1.5, 9, 4)],
|
|
138
|
+
);
|
|
139
|
+
const result = resolveView(
|
|
140
|
+
{ mark: "point", encoding: { x: { field: "speed" }, y: { field: "cost" } } },
|
|
141
|
+
frame,
|
|
142
|
+
{
|
|
143
|
+
marks: new Set(["point"]),
|
|
144
|
+
coords: new Set(["cartesian"]),
|
|
145
|
+
channels: new Set(["x", "y"]),
|
|
146
|
+
transforms: new Set(),
|
|
147
|
+
colorDepth: 24,
|
|
148
|
+
continuous: true,
|
|
149
|
+
},
|
|
150
|
+
);
|
|
151
|
+
if (result.kind === "chart") {
|
|
152
|
+
const [panel] = result.view.panels;
|
|
153
|
+
const x = panel!.scales.get("x")!; // linear, domain [0, 50]: zero and nice
|
|
154
|
+
if (x.kind === "linear") {
|
|
155
|
+
// [0.12, 0.36, 0.96], ready for any output's own units.
|
|
156
|
+
scaleNormalizeArray(new Float64Array(3), Float64Array.of(6, 18, 48), x);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### Normalised positions
|
|
162
|
+
|
|
163
|
+
Scales declare domains, never ranges. A renderer maps a value to `[0, 1]` with
|
|
164
|
+
`scaleNormalize` or, for a whole column, `scaleNormalizeArray` into a buffer it
|
|
165
|
+
owns (0 B per pass), then to pixels, cells or radians itself; band and point
|
|
166
|
+
scales give `scaleBandGeometry`, binning scales `scaleClassIndexArray`, and
|
|
167
|
+
`scaleTicks` the ticks of an axis, including those of a zoomed range.
|
|
168
|
+
|
|
169
|
+
### Time zones
|
|
170
|
+
|
|
171
|
+
Domains are epoch milliseconds and never depend on a zone. The zone
|
|
172
|
+
(`options.timeZone`, default `"UTC"`) and week start are fixed once on each time
|
|
173
|
+
scale; they decide only calendar ticks, a time scale's `nice` and temporal
|
|
174
|
+
bins. `nice` takes `true`, a tick count, or a calendar interval (`"month"`,
|
|
175
|
+
`{ unit: "month", step: 3 }`), and a temporal `bin` takes a calendar `step`
|
|
176
|
+
the same way, as Vega-Lite's `TimeInterval`.
|
|
177
|
+
|
|
178
|
+
### Grids
|
|
179
|
+
|
|
180
|
+
A layer may read a `DataGrid` (`@ac-kit/model-dataset`): its x and y fields are
|
|
181
|
+
continuous lattice axes (cell edges for `rect`, centres otherwise) and its value
|
|
182
|
+
field feeds `z`, `color` or any other channel. `rect`, `surface`, `point` and
|
|
183
|
+
`text` read grids; a `surface` that a 2D renderer cannot draw falls back to a
|
|
184
|
+
`rect` coloured by its height.
|
|
185
|
+
|
|
186
|
+
### Layouts and maps
|
|
187
|
+
|
|
188
|
+
Hierarchy and network panels carry index tables (parent rows, node keys, link
|
|
189
|
+
ends); `@ac-kit/model-chart/layout` turns them into positions in the plot's
|
|
190
|
+
unit square with `@ac-kit/math-graph`'s layouts (`layoutHierarchy`,
|
|
191
|
+
`layoutNetwork` and its cancellable `layoutNetworkAsync`).
|
|
192
|
+
`@ac-kit/model-chart/geographic` projects a map layer's points and GeoJSON
|
|
193
|
+
geometries with `@ac-kit/math-map-projection` (`projectGeographicLayer`), cut
|
|
194
|
+
at the map's edge. Both are subpaths, so terminal and SVG renderers that need
|
|
195
|
+
neither don't load them.
|
|
196
|
+
|
|
197
|
+
### Stack offsets
|
|
198
|
+
|
|
199
|
+
`applyTransforms` runs `stack` with five offsets. `zero` stacks positives up
|
|
200
|
+
and negatives down from 0, and `normalize` divides each stack by its total.
|
|
201
|
+
The three others stack magnitudes and differ only in where each stack sits:
|
|
202
|
+
|
|
203
|
+
| Offset | Baseline of each stack | As |
|
|
204
|
+
| ------------ | -------------------------------------------------------- | ------------------------------- |
|
|
205
|
+
| `center` | half of what it lacks to match the tallest stack | Vega's `center` |
|
|
206
|
+
| `silhouette` | −total/2, so every stack centres on 0 | d3's `stackOffsetSilhouette` |
|
|
207
|
+
| `wiggle` | the one minimising the layers' thickness-weighted wiggle | d3's `stackOffsetWiggle` |
|
|
208
|
+
|
|
209
|
+
`wiggle` is Byron and Wattenberg's streamgraph baseline ("Stacked Graphs –
|
|
210
|
+
Geometry & Aesthetics", 2008). It reads the stacks in the order their groups
|
|
211
|
+
first appear, so sort by the position field first. It needs `series`, the
|
|
212
|
+
fields naming each row's layer. With `series`, every offset matches layers by
|
|
213
|
+
key, so a layer sits at the same height in every stack and counts as zero
|
|
214
|
+
where it has no row. Layers stack bottom up in the order their keys first
|
|
215
|
+
appear.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/geographic/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/geographic/index.ts"],"names":[],"mappings":"AAAA,cAAc,+BAA+B,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { type GeometryOptions, type Projection, type VertexRuns } from "@ac-kit/math-map-projection";
|
|
2
|
+
import type { ResolvedGeographicCoord, ResolvedLayer } from "../resolve/view-types.js";
|
|
3
|
+
/**
|
|
4
|
+
* One row's geometry in the plane, by the way it is drawn: points (2 numbers
|
|
5
|
+
* each), polylines to stroke and polygon rings to fill with the non-zero
|
|
6
|
+
* winding rule. A collection fills all three; a ring or a line cut by the map's
|
|
7
|
+
* edge comes back as several runs.
|
|
8
|
+
*/
|
|
9
|
+
export type GeographicShape = {
|
|
10
|
+
readonly points: Float64Array;
|
|
11
|
+
readonly lines: VertexRuns;
|
|
12
|
+
readonly polygons: VertexRuns;
|
|
13
|
+
};
|
|
14
|
+
/** A geographic layer projected onto its map's plane (x east, y north). */
|
|
15
|
+
export type GeographicLayerProjection = {
|
|
16
|
+
readonly projection: Projection;
|
|
17
|
+
/**
|
|
18
|
+
* 2 per row from the `longitude` and `latitude` channels (degrees); NaN for a
|
|
19
|
+
* missing coordinate or a point off the map (outside the projection's domain
|
|
20
|
+
* or beyond an azimuthal projection's clip angle). `undefined` without them.
|
|
21
|
+
*/
|
|
22
|
+
readonly positions: Float64Array | undefined;
|
|
23
|
+
/** Per row of a `geometry` channel; `undefined` for a missing geometry. */
|
|
24
|
+
readonly shapes: readonly (GeographicShape | undefined)[] | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* `[minX, minY, maxX, maxY]` of every finite point projected, the box a
|
|
27
|
+
* renderer fits; `[∞, ∞, −∞, −∞]` when nothing landed on the map.
|
|
28
|
+
*/
|
|
29
|
+
readonly bounds: Float64Array;
|
|
30
|
+
};
|
|
31
|
+
/** Options of {@link projectGeographicLayer}. */
|
|
32
|
+
export type ProjectGeographicLayerOptions = GeometryOptions & {
|
|
33
|
+
/**
|
|
34
|
+
* Angular radius, radians, of an azimuthal projection's map (its default
|
|
35
|
+
* otherwise); see math-map-projection's `ProjectionOptions`.
|
|
36
|
+
*/
|
|
37
|
+
readonly clipAngle?: number;
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Projects a layer of a geographic panel: `projectionCreate` of the panel's
|
|
41
|
+
* projection, then the `longitude`/`latitude` channels as points (degrees, as
|
|
42
|
+
* GeoJSON) and each row of the `geometry` channel cut at the map's edge and
|
|
43
|
+
* resampled (`projectionPolylineProject`, `projectionPolygonProject`; GeoJSON
|
|
44
|
+
* positions in degrees, closed rings with their repeated last position, RFC
|
|
45
|
+
* 7946 winding).
|
|
46
|
+
*
|
|
47
|
+
* O(points + vertices × samples per arc).
|
|
48
|
+
*
|
|
49
|
+
* @throws {RangeError} From `projectionCreate` or the geometry functions (bad
|
|
50
|
+
* options, too many vertices); `UnsupportedError` for a projection not
|
|
51
|
+
* built.
|
|
52
|
+
*/
|
|
53
|
+
export declare function projectGeographicLayer(layer: ResolvedLayer, coord: ResolvedGeographicCoord, options?: ProjectGeographicLayerOptions): GeographicLayerProjection;
|
|
54
|
+
//# sourceMappingURL=project-geographic-layer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"project-geographic-layer.d.ts","sourceRoot":"","sources":["../../src/geographic/project-geographic-layer.ts"],"names":[],"mappings":"AAKA,OAAO,EACN,KAAK,eAAe,EACpB,KAAK,UAAU,EAIf,KAAK,UAAU,EACf,MAAM,6BAA6B,CAAC;AAUrC,OAAO,KAAK,EACX,uBAAuB,EACvB,aAAa,EACb,MAAM,0BAA0B,CAAC;AAElC;;;;;GAKG;AACH,MAAM,MAAM,eAAe,GAAG;IAC7B,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;IAC9B,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,QAAQ,EAAE,UAAU,CAAC;CAC9B,CAAC;AAEF,2EAA2E;AAC3E,MAAM,MAAM,yBAAyB,GAAG;IACvC,QAAQ,CAAC,UAAU,EAAE,UAAU,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,YAAY,GAAG,SAAS,CAAC;IAC7C,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,GAAG,SAAS,CAAC,EAAE,GAAG,SAAS,CAAC;IACtE;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,YAAY,CAAC;CAC9B,CAAC;AAEF,iDAAiD;AACjD,MAAM,MAAM,6BAA6B,GAAG,eAAe,GAAG;IAC7D;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC5B,CAAC;AA6GF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CACrC,KAAK,EAAE,aAAa,EACpB,KAAK,EAAE,uBAAuB,EAC9B,OAAO,GAAE,6BAAkC,GACzC,yBAAyB,CA8D3B"}
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { longitudeLatitudeCreate, vec3FromLongitudeLatitude, } from "@ac-kit/math-geometry";
|
|
2
|
+
import { vec3Create, vec3TransformMat3x3 } from "@ac-kit/math-linear";
|
|
3
|
+
import { projectionCreate, projectionPolygonProject, projectionPolylineProject, } from "@ac-kit/math-map-projection";
|
|
4
|
+
import { DEG_TO_RAD } from "@ac-kit/math-scalar";
|
|
5
|
+
import { columnToFloat64Array } from "@ac-kit/model-dataset";
|
|
6
|
+
const EMPTY_RUNS_ = {
|
|
7
|
+
vertices: new Float64Array(0),
|
|
8
|
+
offsets: Uint32Array.of(0),
|
|
9
|
+
};
|
|
10
|
+
function radians_(position) {
|
|
11
|
+
return [position[0] * DEG_TO_RAD, position[1] * DEG_TO_RAD];
|
|
12
|
+
}
|
|
13
|
+
function runsOf_(rings) {
|
|
14
|
+
let total = 0;
|
|
15
|
+
for (const ring of rings) {
|
|
16
|
+
total += ring.length;
|
|
17
|
+
}
|
|
18
|
+
const vertices = new Float64Array(total * 2);
|
|
19
|
+
const offsets = new Uint32Array(rings.length + 1);
|
|
20
|
+
let at = 0;
|
|
21
|
+
for (const [index, ring] of rings.entries()) {
|
|
22
|
+
for (const position of ring) {
|
|
23
|
+
const [longitude, latitude] = radians_(position);
|
|
24
|
+
vertices[2 * at] = longitude;
|
|
25
|
+
vertices[2 * at + 1] = latitude;
|
|
26
|
+
at++;
|
|
27
|
+
}
|
|
28
|
+
offsets[index + 1] = at;
|
|
29
|
+
}
|
|
30
|
+
return { vertices, offsets };
|
|
31
|
+
}
|
|
32
|
+
// GeoJSON rings repeat their first position last; math-map-projection's do not.
|
|
33
|
+
function openRing_(ring) {
|
|
34
|
+
const first = ring[0];
|
|
35
|
+
const last = ring.at(-1);
|
|
36
|
+
return ring.length > 1 &&
|
|
37
|
+
first !== undefined &&
|
|
38
|
+
last !== undefined &&
|
|
39
|
+
first[0] === last[0] &&
|
|
40
|
+
first[1] === last[1]
|
|
41
|
+
? ring.slice(0, -1)
|
|
42
|
+
: ring;
|
|
43
|
+
}
|
|
44
|
+
function collect_(geometry, parts) {
|
|
45
|
+
switch (geometry.type) {
|
|
46
|
+
case "Point":
|
|
47
|
+
parts.points.push(...radians_(geometry.coordinates));
|
|
48
|
+
return;
|
|
49
|
+
case "MultiPoint":
|
|
50
|
+
for (const position of geometry.coordinates) {
|
|
51
|
+
parts.points.push(...radians_(position));
|
|
52
|
+
}
|
|
53
|
+
return;
|
|
54
|
+
case "LineString":
|
|
55
|
+
parts.lines.push(geometry.coordinates);
|
|
56
|
+
return;
|
|
57
|
+
case "MultiLineString":
|
|
58
|
+
parts.lines.push(...geometry.coordinates);
|
|
59
|
+
return;
|
|
60
|
+
case "Polygon":
|
|
61
|
+
parts.polygons.push(runsOf_(geometry.coordinates.map(openRing_)));
|
|
62
|
+
return;
|
|
63
|
+
case "MultiPolygon":
|
|
64
|
+
for (const polygon of geometry.coordinates) {
|
|
65
|
+
parts.polygons.push(runsOf_(polygon.map(openRing_)));
|
|
66
|
+
}
|
|
67
|
+
return;
|
|
68
|
+
case "GeometryCollection":
|
|
69
|
+
for (const member of geometry.geometries) {
|
|
70
|
+
collect_(member, parts);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function concatenate_(runs) {
|
|
75
|
+
if (runs.length === 0) {
|
|
76
|
+
return EMPTY_RUNS_;
|
|
77
|
+
}
|
|
78
|
+
let vertexCount = 0;
|
|
79
|
+
let runCount = 0;
|
|
80
|
+
for (const item of runs) {
|
|
81
|
+
vertexCount += item.vertices.length;
|
|
82
|
+
runCount += item.offsets.length - 1;
|
|
83
|
+
}
|
|
84
|
+
const vertices = new Float64Array(vertexCount);
|
|
85
|
+
const offsets = new Uint32Array(runCount + 1);
|
|
86
|
+
let vertexAt = 0;
|
|
87
|
+
let runAt = 0;
|
|
88
|
+
for (const item of runs) {
|
|
89
|
+
vertices.set(item.vertices, vertexAt);
|
|
90
|
+
for (let index = 1; index < item.offsets.length; index++) {
|
|
91
|
+
offsets[++runAt] = vertexAt / 2 + item.offsets[index];
|
|
92
|
+
}
|
|
93
|
+
vertexAt += item.vertices.length;
|
|
94
|
+
}
|
|
95
|
+
return { vertices, offsets };
|
|
96
|
+
}
|
|
97
|
+
function isGeometry_(value) {
|
|
98
|
+
return typeof value === "object" && value !== null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Projects a layer of a geographic panel: `projectionCreate` of the panel's
|
|
102
|
+
* projection, then the `longitude`/`latitude` channels as points (degrees, as
|
|
103
|
+
* GeoJSON) and each row of the `geometry` channel cut at the map's edge and
|
|
104
|
+
* resampled (`projectionPolylineProject`, `projectionPolygonProject`; GeoJSON
|
|
105
|
+
* positions in degrees, closed rings with their repeated last position, RFC
|
|
106
|
+
* 7946 winding).
|
|
107
|
+
*
|
|
108
|
+
* O(points + vertices × samples per arc).
|
|
109
|
+
*
|
|
110
|
+
* @throws {RangeError} From `projectionCreate` or the geometry functions (bad
|
|
111
|
+
* options, too many vertices); `UnsupportedError` for a projection not
|
|
112
|
+
* built.
|
|
113
|
+
*/
|
|
114
|
+
export function projectGeographicLayer(layer, coord, options = {}) {
|
|
115
|
+
const { clipAngle, ...geometryOptions } = options;
|
|
116
|
+
const projection = projectionCreate(coord.projection, clipAngle === undefined ? {} : { clipAngle });
|
|
117
|
+
const bounds = Float64Array.of(Infinity, Infinity, -Infinity, -Infinity);
|
|
118
|
+
const extend = (x, y) => {
|
|
119
|
+
if (x - x === 0 && y - y === 0) {
|
|
120
|
+
bounds[0] = Math.min(bounds[0], x);
|
|
121
|
+
bounds[1] = Math.min(bounds[1], y);
|
|
122
|
+
bounds[2] = Math.max(bounds[2], x);
|
|
123
|
+
bounds[3] = Math.max(bounds[3], y);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const visible = visibility_(projection);
|
|
127
|
+
const longitude = layer.channels.get("longitude");
|
|
128
|
+
const latitude = layer.channels.get("latitude");
|
|
129
|
+
let positions;
|
|
130
|
+
if (longitude?.kind === "field" && latitude?.kind === "field") {
|
|
131
|
+
positions = pointsOf_(longitude.column, latitude.column);
|
|
132
|
+
projectPoints_(projection, positions, visible);
|
|
133
|
+
for (let index = 0; index < positions.length; index += 2) {
|
|
134
|
+
extend(positions[index], positions[index + 1]);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
const geometry = layer.channels.get("geometry");
|
|
138
|
+
let shapes;
|
|
139
|
+
if (geometry?.kind === "field") {
|
|
140
|
+
shapes = Array.from({ length: geometry.column.length }, (_, row) => {
|
|
141
|
+
const value = geometry.column[row] ?? null;
|
|
142
|
+
if (!isGeometry_(value)) {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const parts = { points: [], lines: [], polygons: [] };
|
|
146
|
+
collect_(value, parts);
|
|
147
|
+
const points = Float64Array.from(parts.points);
|
|
148
|
+
projectPoints_(projection, points, visible);
|
|
149
|
+
const lines = parts.lines.length === 0
|
|
150
|
+
? EMPTY_RUNS_
|
|
151
|
+
: projectionPolylineProject(projection, runsOf_(parts.lines), geometryOptions);
|
|
152
|
+
const polygons = concatenate_(parts.polygons.map((rings) => projectionPolygonProject(projection, rings, geometryOptions)));
|
|
153
|
+
for (const values of [points, lines.vertices, polygons.vertices]) {
|
|
154
|
+
for (let index = 0; index < values.length; index += 2) {
|
|
155
|
+
extend(values[index], values[index + 1]);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return { points, lines, polygons };
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return { projection, positions, shapes, bounds };
|
|
162
|
+
}
|
|
163
|
+
function pointsOf_(longitudes, latitudes) {
|
|
164
|
+
const count = longitudes.length;
|
|
165
|
+
const lon = columnToFloat64Array(new Float64Array(count), longitudes);
|
|
166
|
+
const lat = columnToFloat64Array(new Float64Array(count), latitudes);
|
|
167
|
+
const pairs = new Float64Array(2 * count);
|
|
168
|
+
for (let row = 0; row < count; row++) {
|
|
169
|
+
pairs[2 * row] = lon[row] * DEG_TO_RAD;
|
|
170
|
+
pairs[2 * row + 1] = lat[row] * DEG_TO_RAD;
|
|
171
|
+
}
|
|
172
|
+
return pairs;
|
|
173
|
+
}
|
|
174
|
+
// Whether a longitude–latitude (radians) lies on the map: within an azimuthal
|
|
175
|
+
// projection's cap, whose centre the rotation takes to +X.
|
|
176
|
+
function visibility_(projection) {
|
|
177
|
+
if (projection.family !== "azimuthal") {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
const coords = longitudeLatitudeCreate();
|
|
181
|
+
const unit = vec3Create();
|
|
182
|
+
const cosine = Math.cos(projection.clipAngle);
|
|
183
|
+
return (longitude, latitude) => {
|
|
184
|
+
coords[0] = longitude;
|
|
185
|
+
coords[1] = latitude;
|
|
186
|
+
vec3FromLongitudeLatitude(unit, coords);
|
|
187
|
+
vec3TransformMat3x3(unit, unit, projection.rotation);
|
|
188
|
+
return unit[0] >= cosine;
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
// Longitude–latitude pairs (radians) to plane points in place, NaN off the map.
|
|
192
|
+
function projectPoints_(projection, pairs, visible) {
|
|
193
|
+
const hidden = new Uint8Array(pairs.length / 2);
|
|
194
|
+
if (visible !== undefined) {
|
|
195
|
+
for (let index = 0; index < hidden.length; index++) {
|
|
196
|
+
const longitude = pairs[2 * index];
|
|
197
|
+
const latitude = pairs[2 * index + 1];
|
|
198
|
+
hidden[index] =
|
|
199
|
+
longitude - longitude === 0 &&
|
|
200
|
+
latitude - latitude === 0 &&
|
|
201
|
+
visible(longitude, latitude)
|
|
202
|
+
? 0
|
|
203
|
+
: 1;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
projection.projectArray(pairs, pairs);
|
|
207
|
+
for (let index = 0; index < hidden.length; index++) {
|
|
208
|
+
if (hidden[index] === 1) {
|
|
209
|
+
pairs[2 * index] = Number.NaN;
|
|
210
|
+
pairs[2 * index + 1] = Number.NaN;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=project-geographic-layer.js.map
|