@uwdata/vgplot 0.4.0 → 0.6.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 (65) hide show
  1. package/README.md +4 -2
  2. package/dist/vgplot.js +6677 -6503
  3. package/dist/vgplot.min.js +12 -33
  4. package/package.json +8 -10
  5. package/src/api.js +347 -0
  6. package/src/connect.js +14 -0
  7. package/src/context.js +20 -0
  8. package/src/index.js +14 -303
  9. package/src/inputs.js +24 -0
  10. package/src/{directives → plot}/attributes.js +32 -5
  11. package/src/{directives → plot}/interactors.js +8 -6
  12. package/src/{directives → plot}/legends.js +14 -6
  13. package/src/{directives → plot}/marks.js +18 -13
  14. package/src/plot/named-plots.js +49 -0
  15. package/src/plot/plot.js +9 -0
  16. package/src/directives/plot.js +0 -39
  17. package/src/interactors/Highlight.js +0 -101
  18. package/src/interactors/Interval1D.js +0 -90
  19. package/src/interactors/Interval2D.js +0 -102
  20. package/src/interactors/Nearest.js +0 -66
  21. package/src/interactors/PanZoom.js +0 -121
  22. package/src/interactors/Toggle.js +0 -111
  23. package/src/interactors/util/brush.js +0 -45
  24. package/src/interactors/util/close-to.js +0 -9
  25. package/src/interactors/util/get-field.js +0 -4
  26. package/src/interactors/util/invert.js +0 -3
  27. package/src/interactors/util/patchScreenCTM.js +0 -13
  28. package/src/interactors/util/sanitize-styles.js +0 -9
  29. package/src/interactors/util/to-kebab-case.js +0 -9
  30. package/src/layout/index.js +0 -2
  31. package/src/legend.js +0 -64
  32. package/src/marks/ConnectedMark.js +0 -63
  33. package/src/marks/ContourMark.js +0 -89
  34. package/src/marks/DenseLineMark.js +0 -146
  35. package/src/marks/Density1DMark.js +0 -104
  36. package/src/marks/Density2DMark.js +0 -69
  37. package/src/marks/Grid2DMark.js +0 -191
  38. package/src/marks/HexbinMark.js +0 -88
  39. package/src/marks/Mark.js +0 -195
  40. package/src/marks/RasterMark.js +0 -122
  41. package/src/marks/RasterTileMark.js +0 -332
  42. package/src/marks/RegressionMark.js +0 -117
  43. package/src/marks/util/bin-field.js +0 -17
  44. package/src/marks/util/density.js +0 -226
  45. package/src/marks/util/extent.js +0 -56
  46. package/src/marks/util/grid.js +0 -57
  47. package/src/marks/util/handle-param.js +0 -14
  48. package/src/marks/util/is-arrow-table.js +0 -3
  49. package/src/marks/util/is-color.js +0 -18
  50. package/src/marks/util/is-constant-option.js +0 -40
  51. package/src/marks/util/is-symbol.js +0 -20
  52. package/src/marks/util/raster.js +0 -44
  53. package/src/marks/util/stats.js +0 -133
  54. package/src/marks/util/to-data-array.js +0 -58
  55. package/src/plot-attributes.js +0 -211
  56. package/src/plot-renderer.js +0 -161
  57. package/src/plot.js +0 -136
  58. package/src/spec/parse-data.js +0 -69
  59. package/src/spec/parse-spec.js +0 -422
  60. package/src/spec/to-module.js +0 -465
  61. package/src/spec/util.js +0 -43
  62. package/src/symbols.js +0 -3
  63. package/src/transforms/bin.js +0 -81
  64. package/src/transforms/index.js +0 -3
  65. /package/src/{directives → plot}/data.js +0 -0
package/src/index.js CHANGED
@@ -1,316 +1,27 @@
1
1
  export {
2
2
  Coordinator,
3
3
  MosaicClient,
4
- Param,
5
- Selection,
6
- coordinator,
7
- restConnector, socketConnector, wasmConnector
4
+ restConnector,
5
+ socketConnector,
6
+ wasmConnector
8
7
  } from '@uwdata/mosaic-core';
9
8
 
10
- export {
11
- menu,
12
- search,
13
- slider,
14
- table
15
- } from '@uwdata/mosaic-inputs';
16
-
17
- export {
18
- Query, agg, sql, column, literal,
19
- cast, castDouble, castInteger,
20
- argmax, argmin, arrayAgg, avg, count, corr, covarPop, entropy,
21
- kurtosis, mad, max, median, min, mode, last, product, quantile,
22
- skewness, stddev, stddevPop, stringAgg, sum, variance, varPop,
23
- row_number, rank, dense_rank, percent_rank, cume_dist,
24
- ntile, lag, lead, first_value, last_value, nth_value,
25
- dateDay, dateMonth, dateMonthDay,
26
- and, or, not, eq, neq, gt, gte, lt, lte,
27
- isBetween, isNotBetween,
28
- isDistinct, isNotDistinct,
29
- isNull, isNotNull,
30
- loadCSV, loadJSON, loadObjects, loadParquet
31
- } from '@uwdata/mosaic-sql';
32
-
33
- export {
34
- bin
35
- } from './transforms/index.js';
36
-
37
- export {
38
- name,
39
- attribute,
40
- attributes,
41
- margins,
42
- xyDomain,
43
- style,
44
- width,
45
- height,
46
- margin,
47
- marginLeft,
48
- marginRight,
49
- marginTop,
50
- marginBottom,
51
- align,
52
- aspectRatio,
53
- axis,
54
- inset,
55
- grid,
56
- label,
57
- padding,
58
- round,
59
- xScale,
60
- xDomain,
61
- xRange,
62
- xNice,
63
- xInset,
64
- xInsetLeft,
65
- xInsetRight,
66
- xClamp,
67
- xRound,
68
- xAlign,
69
- xPadding,
70
- xPaddingInner,
71
- xPaddingOuter,
72
- xAxis,
73
- xTicks,
74
- xTickSize,
75
- xTickSpacing,
76
- xTickPadding,
77
- xTickFormat,
78
- xTickRotate,
79
- xGrid,
80
- xLine,
81
- xLabel,
82
- xLabelAnchor,
83
- xLabelOffset,
84
- xFontVariant,
85
- xAriaLabel,
86
- xAriaDescription,
87
- xReverse,
88
- xZero,
89
- yScale,
90
- yDomain,
91
- yRange,
92
- yNice,
93
- yInset,
94
- yInsetTop,
95
- yInsetBottom,
96
- yClamp,
97
- yRound,
98
- yAlign,
99
- yPadding,
100
- yPaddingInner,
101
- yPaddingOuter,
102
- yAxis,
103
- yTicks,
104
- yTickSize,
105
- yTickSpacing,
106
- yTickPadding,
107
- yTickFormat,
108
- yTickRotate,
109
- yGrid,
110
- yLine,
111
- yLabel,
112
- yLabelAnchor,
113
- yLabelOffset,
114
- yFontVariant,
115
- yAriaLabel,
116
- yAriaDescription,
117
- yReverse,
118
- yZero,
119
- facetMargin,
120
- facetMarginTop,
121
- facetMarginBottom,
122
- facetMarginLeft,
123
- facetMarginRight,
124
- facetGrid,
125
- facetLabel,
126
- fxDomain,
127
- fxRange,
128
- fxNice,
129
- fxInset,
130
- fxInsetLeft,
131
- fxInsetRight,
132
- fxRound,
133
- fxAlign,
134
- fxPadding,
135
- fxPaddingInner,
136
- fxPaddingOuter,
137
- fxAxis,
138
- fxTicks,
139
- fxTickSize,
140
- fxTickSpacing,
141
- fxTickPadding,
142
- fxTickFormat,
143
- fxTickRotate,
144
- fxGrid,
145
- fxLine,
146
- fxLabel,
147
- fxLabelAnchor,
148
- fxLabelOffset,
149
- fxFontVariant,
150
- fxAriaLabel,
151
- fxAriaDescription,
152
- fxReverse,
153
- fyDomain,
154
- fyRange,
155
- fyNice,
156
- fyInset,
157
- fyInsetTop,
158
- fyInsetBottom,
159
- fyRound,
160
- fyAlign,
161
- fyPadding,
162
- fyPaddingInner,
163
- fyPaddingOuter,
164
- fyAxis,
165
- fyTicks,
166
- fyTickSize,
167
- fyTickSpacing,
168
- fyTickPadding,
169
- fyTickFormat,
170
- fyTickRotate,
171
- fyGrid,
172
- fyLine,
173
- fyLabel,
174
- fyLabelAnchor,
175
- fyLabelOffset,
176
- fyFontVariant,
177
- fyAriaLabel,
178
- fyAriaDescription,
179
- fyReverse,
180
- colorScale,
181
- colorDomain,
182
- colorRange,
183
- colorClamp,
184
- colorNice,
185
- colorScheme,
186
- colorInterpolate,
187
- colorPivot,
188
- colorSymmetric,
189
- colorLabel,
190
- colorReverse,
191
- colorZero,
192
- colorTickFormat,
193
- opacityScale,
194
- opacityDomain,
195
- opacityRange,
196
- opacityClamp,
197
- opacityNice,
198
- opacityLabel,
199
- opacityReverse,
200
- opacityZero,
201
- opacityTickFormat,
202
- rScale,
203
- rDomain,
204
- rRange,
205
- rClamp,
206
- rNice,
207
- rZero,
208
- lengthScale,
209
- lengthDomain,
210
- lengthRange,
211
- lengthClamp,
212
- lengthNice,
213
- lengthZero,
214
- projectionType,
215
- projectionParallels,
216
- projectionPrecision,
217
- projectionRotate,
218
- projectionDomain,
219
- projectionInset,
220
- projectionInsetLeft,
221
- projectionInsetRight,
222
- projectionInsetTop,
223
- projectionInsetBottom,
224
- projectionClip,
225
- } from './directives/attributes.js';
226
-
227
- export {
228
- from
229
- } from './directives/data.js';
230
-
231
- export {
232
- area, areaX, areaY,
233
- line, lineX, lineY,
234
- barX, barY,
235
- cell, cellX, cellY,
236
- rect, rectX, rectY,
237
- dot, dotX, dotY, circle, hexagon,
238
- text, textX, textY,
239
- image,
240
- tickX, tickY,
241
- ruleX, ruleY,
242
- density, densityX, densityY, denseLine,
243
- raster, rasterTile,
244
- contour,
245
- hexbin, hexgrid,
246
- regressionY,
247
- vector, vectorX, vectorY, spike,
248
- voronoi, voronoiMesh, delaunayLink, delaunayMesh, hull,
249
- arrow, link,
250
- frame,
251
- axisX, axisY, axisFx, axisFy,
252
- gridX, gridY, gridFx, gridFy,
253
- geo, sphere, graticule
254
- } from './directives/marks.js';
255
-
256
- export {
257
- highlight,
258
- intervalX,
259
- intervalY,
260
- intervalXY,
261
- nearestX,
262
- nearestY,
263
- toggle,
264
- toggleX,
265
- toggleY,
266
- toggleColor,
267
- pan,
268
- panX,
269
- panY,
270
- panZoom,
271
- panZoomX,
272
- panZoomY
273
- } from './directives/interactors.js';
274
-
275
- export {
276
- colorLegend,
277
- opacityLegend,
278
- symbolLegend
279
- } from './directives/legends.js';
9
+ export * from './api.js';
280
10
 
281
11
  export {
282
12
  namedPlots,
283
- plot,
284
- reset
285
- } from './directives/plot.js';
286
-
287
- export {
288
- hconcat,
289
- vconcat
290
- } from './layout/concat.js';
291
-
292
- export {
293
- hspace,
294
- vspace
295
- } from './layout/space.js';
296
-
297
- export {
298
- Fixed
299
- } from './symbols.js';
13
+ requestNamedPlot
14
+ } from './plot/named-plots.js';
300
15
 
301
16
  export {
302
- parseSpec,
303
- ParseContext
304
- } from './spec/parse-spec.js';
17
+ connect
18
+ } from './connect.js';
305
19
 
306
20
  export {
307
- specToModule
308
- } from './spec/to-module.js';
21
+ createAPIContext
22
+ } from './context.js';
309
23
 
310
- export {
311
- Plot
312
- } from './plot.js';
313
-
314
- export {
315
- Mark
316
- } from './marks/Mark.js';
24
+ export * as attributeDirectives from './plot/attributes.js';
25
+ export * as markDirectives from './plot/marks.js';
26
+ export * as interactorDirectives from './plot/interactors.js';
27
+ export * as legendDirectives from './plot/legends.js';
package/src/inputs.js ADDED
@@ -0,0 +1,24 @@
1
+ import { Menu, Search, Slider, Table } from '@uwdata/mosaic-inputs';
2
+ import { connect } from './connect.js';
3
+
4
+ function input(ctx, InputClass, options) {
5
+ const input = new InputClass(options);
6
+ connect(ctx, input); // ctx <- optional API context
7
+ return input.element;
8
+ }
9
+
10
+ export function menu(options) {
11
+ return input(this, Menu, options);
12
+ }
13
+
14
+ export function search(options) {
15
+ return input(this, Search, options);
16
+ }
17
+
18
+ export function slider(options) {
19
+ return input(this, Slider, options);
20
+ }
21
+
22
+ export function table(options) {
23
+ return input(this, Table, options);
24
+ }
@@ -1,8 +1,8 @@
1
1
  import { isParam } from '@uwdata/mosaic-core';
2
- import { namedPlots } from './plot.js';
2
+ import { setNamedPlot } from './named-plots.js';
3
3
 
4
4
  export function name(name) {
5
- return plot => namedPlots.set(name, plot);
5
+ return plot => setNamedPlot(this, name, plot);
6
6
  }
7
7
 
8
8
  function setAttribute(plot, name, value) {
@@ -19,11 +19,11 @@ function setAttribute(plot, name, value) {
19
19
  }
20
20
  }
21
21
 
22
- export function attribute(name, value) {
22
+ function attribute(name, value) {
23
23
  return plot => { setAttribute(plot, name, value); };
24
24
  }
25
25
 
26
- export function attributes(values) {
26
+ function attributes(values) {
27
27
  return plot => {
28
28
  for (const [name, value] of Object.entries(values)) {
29
29
  setAttribute(plot, name, value)
@@ -41,6 +41,15 @@ export function margins(object) {
41
41
  return attributes(attr);
42
42
  }
43
43
 
44
+ export function margin(value) {
45
+ return attributes({
46
+ marginTop: value,
47
+ marginBottom: value,
48
+ marginLeft: value,
49
+ marginRight: value
50
+ });
51
+ }
52
+
44
53
  export function xyDomain(value) {
45
54
  return attributes({ xDomain: value, yDomain: value });
46
55
  }
@@ -51,7 +60,6 @@ const attrf = name => value => attribute(name, value);
51
60
  export const style = attrf('style');
52
61
  export const width = attrf('width');
53
62
  export const height = attrf('height');
54
- export const margin = attrf('margin');
55
63
  export const marginLeft = attrf('marginLeft');
56
64
  export const marginRight = attrf('marginRight');
57
65
  export const marginTop = attrf('marginTop');
@@ -96,6 +104,9 @@ export const xAriaLabel = attrf('xAriaLabel');
96
104
  export const xAriaDescription = attrf('xAriaDescription');
97
105
  export const xReverse = attrf('xReverse');
98
106
  export const xZero = attrf('xZero');
107
+ export const xBase = attrf('xBase');
108
+ export const xExponent = attrf('xExponent');
109
+ export const xConstant = attrf('xConstant');
99
110
 
100
111
  // y scale attributes
101
112
  export const yScale = attrf('yScale');
@@ -128,6 +139,9 @@ export const yAriaLabel = attrf('yAriaLabel');
128
139
  export const yAriaDescription = attrf('yAriaDescription');
129
140
  export const yReverse = attrf('yReverse');
130
141
  export const yZero = attrf('yZero');
142
+ export const yBase = attrf('yBase');
143
+ export const yExponent = attrf('yExponent');
144
+ export const yConstant = attrf('yConstant');
131
145
 
132
146
  // facet attributes
133
147
  export const facetMargin = attrf('facetMargin');
@@ -201,6 +215,7 @@ export const colorScale = attrf('colorScale');
201
215
  export const colorDomain = attrf('colorDomain');
202
216
  export const colorRange = attrf('colorRange');
203
217
  export const colorClamp = attrf('colorClamp');
218
+ export const colorN = attrf('colorN');
204
219
  export const colorNice = attrf('colorNice');
205
220
  export const colorScheme = attrf('colorScheme');
206
221
  export const colorInterpolate = attrf('colorInterpolate');
@@ -210,6 +225,9 @@ export const colorLabel = attrf('colorLabel');
210
225
  export const colorReverse = attrf('colorReverse');
211
226
  export const colorZero = attrf('colorZero');
212
227
  export const colorTickFormat = attrf('colorTickFormat');
228
+ export const colorBase = attrf('colorBase');
229
+ export const colorExponent = attrf('colorExponent');
230
+ export const colorConstant = attrf('colorConstant');
213
231
 
214
232
  // opacity scale attributes
215
233
  export const opacityScale = attrf('opacityScale');
@@ -221,6 +239,9 @@ export const opacityLabel = attrf('opacityLabel');
221
239
  export const opacityReverse = attrf('opacityReverse');
222
240
  export const opacityZero = attrf('opacityZero');
223
241
  export const opacityTickFormat = attrf('opacityTickFormat');
242
+ export const opacityBase = attrf('opacityBase');
243
+ export const opacityExponent = attrf('opacityExponent');
244
+ export const opacityConstant = attrf('opacityConstant');
224
245
 
225
246
  // r scale attributes
226
247
  export const rScale = attrf('rScale');
@@ -229,6 +250,9 @@ export const rRange = attrf('rRange');
229
250
  export const rClamp = attrf('rClamp');
230
251
  export const rNice = attrf('rNice');
231
252
  export const rZero = attrf('rZero');
253
+ export const rBase = attrf('rBase');
254
+ export const rExponent = attrf('rExponent');
255
+ export const rConstant = attrf('rConstant');
232
256
 
233
257
  // length scale attributes
234
258
  export const lengthScale = attrf('lengthScale');
@@ -237,6 +261,9 @@ export const lengthRange = attrf('lengthRange');
237
261
  export const lengthClamp = attrf('lengthClamp');
238
262
  export const lengthNice = attrf('lengthNice');
239
263
  export const lengthZero = attrf('lengthZero');
264
+ export const lengthBase = attrf('lengthBase');
265
+ export const lengthExponent = attrf('lengthExponent');
266
+ export const lengthConstant = attrf('lengthConstant');
240
267
 
241
268
  // projection attributes
242
269
  export const projectionType = attrf('projectionType');
@@ -1,9 +1,11 @@
1
- import { Highlight } from '../interactors/Highlight.js';
2
- import { Toggle } from '../interactors/Toggle.js';
3
- import { Interval1D } from '../interactors/Interval1D.js';
4
- import { Interval2D } from '../interactors/Interval2D.js';
5
- import { PanZoom } from '../interactors/PanZoom.js';
6
- import { Nearest } from '../interactors/Nearest.js';
1
+ import {
2
+ Highlight,
3
+ Toggle,
4
+ Interval1D,
5
+ Interval2D,
6
+ PanZoom,
7
+ Nearest
8
+ } from '@uwdata/mosaic-plot';
7
9
 
8
10
  function interactor(InteractorClass, options) {
9
11
  return plot => {
@@ -1,5 +1,5 @@
1
- import { Legend } from '../legend.js';
2
- import { namedPlots } from './plot.js';
1
+ import { Legend } from '@uwdata/mosaic-plot';
2
+ import { requestNamedPlot } from './named-plots.js';
3
3
 
4
4
  function legend(channel, options = {}) {
5
5
  if (options.for) {
@@ -8,7 +8,7 @@ function legend(channel, options = {}) {
8
8
  const type = typeof maybePlot;
9
9
  const add = plot => plot.addLegend(legend, false);
10
10
  if (type === 'string') {
11
- namedPlots.request(maybePlot, add);
11
+ requestNamedPlot(this, maybePlot, add);
12
12
  } else if (maybePlot.value) {
13
13
  add(maybePlot.value);
14
14
  }
@@ -18,6 +18,14 @@ function legend(channel, options = {}) {
18
18
  }
19
19
  }
20
20
 
21
- export const colorLegend = options => legend('color', options);
22
- export const opacityLegend = options => legend('opacity', options);
23
- export const symbolLegend = options => legend('symbol', options);
21
+ export function colorLegend(options) {
22
+ return legend.call(this, 'color', options);
23
+ }
24
+
25
+ export function opacityLegend(options) {
26
+ return legend.call(this, 'opacity', options);
27
+ }
28
+
29
+ export function symbolLegend(options) {
30
+ return legend.call(this, 'symbol', options);
31
+ }
@@ -1,13 +1,17 @@
1
- import { Mark } from '../marks/Mark.js';
2
- import { ConnectedMark } from '../marks/ConnectedMark.js';
3
- import { Density1DMark } from '../marks/Density1DMark.js';
4
- import { Density2DMark } from '../marks/Density2DMark.js';
5
- import { DenseLineMark } from '../marks/DenseLineMark.js';
6
- import { ContourMark } from '../marks/ContourMark.js';
7
- import { HexbinMark } from '../marks/HexbinMark.js';
8
- import { RasterMark } from '../marks/RasterMark.js';
9
- import { RasterTileMark } from '../marks/RasterTileMark.js';
10
- import { RegressionMark } from '../marks/RegressionMark.js';
1
+ import {
2
+ Mark,
3
+ ConnectedMark,
4
+ ContourMark,
5
+ Density1DMark,
6
+ Density2DMark,
7
+ DenseLineMark,
8
+ GeoMark,
9
+ HeatmapMark,
10
+ HexbinMark,
11
+ RasterMark,
12
+ RasterTileMark,
13
+ RegressionMark
14
+ } from '@uwdata/mosaic-plot';
11
15
 
12
16
  const decorators = new Set([
13
17
  'frame',
@@ -17,8 +21,8 @@ const decorators = new Set([
17
21
  'graticule', 'sphere'
18
22
  ]);
19
23
 
20
- function mark(type, data, channels) {
21
- if (arguments.length === 2) {
24
+ function mark(type, data, channels = {}) {
25
+ if (arguments.length === 2 && !Array.isArray(data)) {
22
26
  channels = data;
23
27
  data = decorators.has(type) ? null : [{}];
24
28
  }
@@ -89,6 +93,7 @@ export const densityY = (...args) => explicitType(Density1DMark, 'areaY', ...arg
89
93
  export const density = (...args) => implicitType(Density2DMark, ...args);
90
94
  export const denseLine = (...args) => implicitType(DenseLineMark, ...args);
91
95
  export const contour = (...args) => implicitType(ContourMark, ...args);
96
+ export const heatmap = (...args) => implicitType(HeatmapMark, ...args);
92
97
  export const raster = (...args) => implicitType(RasterMark, ...args);
93
98
  export const rasterTile = (...args) => implicitType(RasterTileMark, ...args);
94
99
 
@@ -118,6 +123,6 @@ export const gridY = (...args) => mark('gridY', ...args);
118
123
  export const gridFx = (...args) => mark('gridFx', ...args);
119
124
  export const gridFy = (...args) => mark('gridFy', ...args);
120
125
 
121
- export const geo = (...args) => mark('geo', ...args);
126
+ export const geo = (...args) => implicitType(GeoMark, ...args);
122
127
  export const sphere = (...args) => mark('sphere', ...args);
123
128
  export const graticule = (...args) => mark('graticule', ...args);
@@ -0,0 +1,49 @@
1
+ export class NamedPlots extends Map {
2
+ request(name, callback) {
3
+ if (this.has(name)) {
4
+ callback(this.get(name));
5
+ } else {
6
+ const waiting = this.waiting || (this.waiting = new Map);
7
+ const list = waiting.get(name) || [];
8
+ waiting.set(name, list.concat(callback));
9
+ }
10
+ }
11
+ set(name, plot) {
12
+ if (this.has(name)) {
13
+ console.warn(`Overwriting named plot "${name}".`);
14
+ }
15
+ const { waiting } = this;
16
+ if (waiting?.has(name)) {
17
+ waiting.get(name).forEach(fn => fn(plot));
18
+ waiting.delete(name);
19
+ }
20
+ return super.set(name, plot);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Default instance of named plots map.
26
+ */
27
+ export const namedPlots = new NamedPlots();
28
+
29
+ /**
30
+ * Context-sensitive lookup of named plots.
31
+ * This method proxies access to the NamedPlots.request().
32
+ * If the provided context object has a local namedPlots, that is used.
33
+ * Otherwise the default instance is used.
34
+ */
35
+ export function requestNamedPlot(ctx, name, callback) {
36
+ const map = ctx?.context?.namedPlots ?? namedPlots;
37
+ map.request(name, callback);
38
+ }
39
+
40
+ /**
41
+ * Context-sensitive addition of named plots.
42
+ * This method proxies access to the NamedPlots.set().
43
+ * If the provided context object has a local namedPlots, that is used.
44
+ * Otherwise the default instance is used.
45
+ */
46
+ export function setNamedPlot(ctx, name, plot) {
47
+ const map = ctx?.context?.namedPlots ?? namedPlots;
48
+ map.set(name, plot);
49
+ }
@@ -0,0 +1,9 @@
1
+ import { Plot } from '@uwdata/mosaic-plot';
2
+ import { connect } from '../connect.js';
3
+
4
+ export function plot(...directives) {
5
+ const p = new Plot();
6
+ directives.flat().forEach(dir => dir(p));
7
+ connect(this, ...p.marks); // this -> optional API context
8
+ return p.element;
9
+ }
@@ -1,39 +0,0 @@
1
- import { coordinator } from '@uwdata/mosaic-core';
2
- import { Plot } from '../plot.js';
3
-
4
- export function plot(...directives) {
5
- const p = new Plot();
6
- directives.flat().forEach(dir => dir(p));
7
- p.marks.forEach(mark => coordinator().connect(mark));
8
- return p.element;
9
- }
10
-
11
- export class NamedPlots extends Map {
12
- request(name, callback) {
13
- if (this.has(name)) {
14
- callback(this.get(name));
15
- } else {
16
- const waiting = this.waiting || (this.waiting = new Map);
17
- const list = waiting.get(name) || [];
18
- waiting.set(name, list.concat(callback));
19
- }
20
- }
21
- set(name, plot) {
22
- if (this.has(name)) {
23
- console.warn(`Overwriting named plot "${name}".`);
24
- }
25
- const { waiting } = this;
26
- if (waiting?.has(name)) {
27
- waiting.get(name).forEach(fn => fn(plot));
28
- waiting.delete(name);
29
- }
30
- return super.set(name, plot);
31
- }
32
- }
33
-
34
- export const namedPlots = new NamedPlots();
35
-
36
- export function reset() {
37
- namedPlots.clear();
38
- coordinator().clear();
39
- }