@uwdata/mosaic-spec 0.7.1 → 0.9.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 (158) hide show
  1. package/dist/mosaic-schema.json +192673 -0
  2. package/dist/mosaic-spec.js +5077 -5774
  3. package/dist/mosaic-spec.min.js +23 -23
  4. package/dist/types/ast/ASTNode.d.ts +26 -0
  5. package/dist/types/ast/DataNode.d.ts +60 -0
  6. package/dist/types/ast/ExpressionNode.d.ts +15 -0
  7. package/dist/types/ast/HConcatNode.d.ts +10 -0
  8. package/dist/types/ast/HSpaceNode.d.ts +11 -0
  9. package/dist/types/ast/InputNode.d.ts +8 -0
  10. package/dist/types/ast/LiteralNode.d.ts +7 -0
  11. package/dist/types/ast/OptionsNode.d.ts +10 -0
  12. package/dist/types/ast/ParamNode.d.ts +9 -0
  13. package/dist/types/ast/ParamRefNode.d.ts +8 -0
  14. package/dist/types/ast/PlotAttributeNode.d.ts +18 -0
  15. package/dist/types/ast/PlotFromNode.d.ts +9 -0
  16. package/dist/types/ast/PlotInteractorNode.d.ts +8 -0
  17. package/dist/types/ast/PlotLegendNode.d.ts +10 -0
  18. package/dist/types/ast/PlotMarkNode.d.ts +10 -0
  19. package/dist/types/ast/PlotNode.d.ts +11 -0
  20. package/dist/types/ast/SelectionNode.d.ts +12 -0
  21. package/dist/types/ast/SpecNode.d.ts +10 -0
  22. package/dist/types/ast/TransformNode.d.ts +13 -0
  23. package/dist/types/ast/VConcatNode.d.ts +10 -0
  24. package/dist/types/ast/VSpaceNode.d.ts +11 -0
  25. package/dist/types/ast-to-dom.d.ts +38 -0
  26. package/dist/types/ast-to-esm.d.ts +64 -0
  27. package/dist/types/config/components.d.ts +4 -0
  28. package/dist/types/config/extensions.d.ts +9 -0
  29. package/dist/types/config/inputs.d.ts +5 -0
  30. package/dist/types/config/plots.d.ts +34 -0
  31. package/dist/types/config/transforms.d.ts +4 -0
  32. package/dist/types/constants.d.ts +30 -0
  33. package/dist/types/index.d.ts +29 -0
  34. package/dist/types/parse-spec.d.ts +86 -0
  35. package/dist/types/spec/CSSStyles.d.ts +3 -0
  36. package/dist/types/spec/Data.d.ts +165 -0
  37. package/dist/types/spec/Expression.d.ts +27 -0
  38. package/dist/types/spec/HConcat.d.ts +8 -0
  39. package/dist/types/spec/HSpace.d.ts +9 -0
  40. package/dist/types/spec/Input.d.ts +207 -0
  41. package/dist/types/spec/Param.d.ts +51 -0
  42. package/dist/types/spec/Plot.d.ts +14 -0
  43. package/dist/types/spec/PlotAttribute.d.ts +1522 -0
  44. package/dist/types/spec/PlotFrom.d.ts +20 -0
  45. package/dist/types/spec/PlotInteractor.d.ts +8 -0
  46. package/dist/types/spec/PlotLegend.d.ts +68 -0
  47. package/dist/types/spec/PlotMark.d.ts +27 -0
  48. package/dist/types/spec/PlotTypes.d.ts +293 -0
  49. package/dist/types/spec/Spec.d.ts +52 -0
  50. package/dist/types/spec/Transform.d.ts +314 -0
  51. package/dist/types/spec/VConcat.d.ts +8 -0
  52. package/dist/types/spec/VSpace.d.ts +9 -0
  53. package/dist/types/spec/interactors/Highlight.d.ts +37 -0
  54. package/dist/types/spec/interactors/Interval1D.d.ts +63 -0
  55. package/dist/types/spec/interactors/Interval2D.d.ts +46 -0
  56. package/dist/types/spec/interactors/Nearest.d.ts +44 -0
  57. package/dist/types/spec/interactors/PanZoom.d.ts +58 -0
  58. package/dist/types/spec/interactors/Toggle.d.ts +59 -0
  59. package/dist/types/spec/marks/Area.d.ts +139 -0
  60. package/dist/types/spec/marks/Arrow.d.ts +94 -0
  61. package/dist/types/spec/marks/Axis.d.ts +281 -0
  62. package/dist/types/spec/marks/Bar.d.ts +150 -0
  63. package/dist/types/spec/marks/Cell.d.ts +57 -0
  64. package/dist/types/spec/marks/Contour.d.ts +23 -0
  65. package/dist/types/spec/marks/Delaunay.d.ts +86 -0
  66. package/dist/types/spec/marks/DenseLine.d.ts +27 -0
  67. package/dist/types/spec/marks/Density.d.ts +121 -0
  68. package/dist/types/spec/marks/Dot.d.ts +133 -0
  69. package/dist/types/spec/marks/ErrorBar.d.ts +82 -0
  70. package/dist/types/spec/marks/Frame.d.ts +21 -0
  71. package/dist/types/spec/marks/Geo.d.ts +53 -0
  72. package/dist/types/spec/marks/Hexbin.d.ts +30 -0
  73. package/dist/types/spec/marks/Hexgrid.d.ts +25 -0
  74. package/dist/types/spec/marks/Image.d.ts +89 -0
  75. package/dist/types/spec/marks/Line.d.ts +82 -0
  76. package/dist/types/spec/marks/Link.d.ts +60 -0
  77. package/dist/types/spec/marks/Marks.d.ts +905 -0
  78. package/dist/types/spec/marks/Raster.d.ts +124 -0
  79. package/dist/types/spec/marks/Rect.d.ts +166 -0
  80. package/dist/types/spec/marks/Regression.d.ts +58 -0
  81. package/dist/types/spec/marks/Rule.d.ts +100 -0
  82. package/dist/types/spec/marks/Text.d.ts +110 -0
  83. package/dist/types/spec/marks/Tick.d.ts +61 -0
  84. package/dist/types/spec/marks/Vector.d.ts +99 -0
  85. package/dist/types/util.d.ts +12 -0
  86. package/jsconfig.json +10 -0
  87. package/package.json +14 -9
  88. package/src/ast/ASTNode.js +23 -2
  89. package/src/ast/DataNode.js +79 -21
  90. package/src/ast/HSpaceNode.js +1 -1
  91. package/src/ast/InputNode.js +1 -2
  92. package/src/ast/ParamNode.js +1 -2
  93. package/src/ast/PlotAttributeNode.js +1 -2
  94. package/src/ast/PlotInteractorNode.js +1 -2
  95. package/src/ast/PlotLegendNode.js +1 -2
  96. package/src/ast/PlotMarkNode.js +3 -2
  97. package/src/ast/TransformNode.js +1 -2
  98. package/src/ast/VSpaceNode.js +1 -1
  99. package/src/ast-to-dom.js +9 -3
  100. package/src/ast-to-esm.js +41 -12
  101. package/src/config/inputs.js +1 -0
  102. package/src/config/plots.js +4 -0
  103. package/src/config/transforms.js +6 -0
  104. package/src/index.js +4 -0
  105. package/src/parse-spec.js +38 -5
  106. package/src/spec/CSSStyles.ts +9 -0
  107. package/src/spec/Data.ts +184 -0
  108. package/src/spec/Expression.ts +31 -0
  109. package/src/spec/HConcat.ts +9 -0
  110. package/src/spec/HSpace.ts +9 -0
  111. package/src/spec/Input.ts +204 -0
  112. package/src/spec/Param.ts +68 -0
  113. package/src/spec/Plot.ts +15 -0
  114. package/src/spec/PlotAttribute.ts +1783 -0
  115. package/src/spec/PlotFrom.ts +23 -0
  116. package/src/spec/PlotInteractor.ts +25 -0
  117. package/src/spec/PlotLegend.ts +70 -0
  118. package/src/spec/PlotMark.ts +53 -0
  119. package/src/spec/PlotTypes.ts +519 -0
  120. package/src/spec/Spec.ts +70 -0
  121. package/src/spec/Transform.ts +446 -0
  122. package/src/spec/VConcat.ts +9 -0
  123. package/src/spec/VSpace.ts +9 -0
  124. package/src/spec/interactors/Highlight.ts +38 -0
  125. package/src/spec/interactors/Interval1D.ts +67 -0
  126. package/src/spec/interactors/Interval2D.ts +48 -0
  127. package/src/spec/interactors/Nearest.ts +48 -0
  128. package/src/spec/interactors/PanZoom.ts +65 -0
  129. package/src/spec/interactors/Toggle.ts +65 -0
  130. package/src/spec/marks/Area.ts +154 -0
  131. package/src/spec/marks/Arrow.ts +108 -0
  132. package/src/spec/marks/Axis.ts +305 -0
  133. package/src/spec/marks/Bar.ts +160 -0
  134. package/src/spec/marks/Cell.ts +62 -0
  135. package/src/spec/marks/Contour.ts +25 -0
  136. package/src/spec/marks/Delaunay.ts +95 -0
  137. package/src/spec/marks/DenseLine.ts +30 -0
  138. package/src/spec/marks/Density.ts +145 -0
  139. package/src/spec/marks/Dot.ts +152 -0
  140. package/src/spec/marks/ErrorBar.ts +91 -0
  141. package/src/spec/marks/Frame.ts +23 -0
  142. package/src/spec/marks/Geo.ts +58 -0
  143. package/src/spec/marks/Hexbin.ts +34 -0
  144. package/src/spec/marks/Hexgrid.ts +27 -0
  145. package/src/spec/marks/Image.ts +101 -0
  146. package/src/spec/marks/Line.ts +93 -0
  147. package/src/spec/marks/Link.ts +70 -0
  148. package/src/spec/marks/Marks.ts +1088 -0
  149. package/src/spec/marks/Raster.ts +145 -0
  150. package/src/spec/marks/Rect.ts +183 -0
  151. package/src/spec/marks/Regression.ts +63 -0
  152. package/src/spec/marks/Rule.ts +113 -0
  153. package/src/spec/marks/Text.ts +127 -0
  154. package/src/spec/marks/Tick.ts +69 -0
  155. package/src/spec/marks/Vector.ts +113 -0
  156. package/src/util.js +8 -0
  157. package/tsconfig.json +11 -0
  158. package/LICENSE +0 -47
@@ -0,0 +1,69 @@
1
+ import {
2
+ ChannelValueSpec, InsetOptions, MarkData, MarkOptions, MarkerOptions
3
+ } from './Marks.js';
4
+
5
+ /** Options for the tickX mark. */
6
+ export interface TickXOptions extends MarkOptions, MarkerOptions, Omit<InsetOptions, 'insetLeft' | 'insetRight'> {
7
+ /**
8
+ * The required horizontal position of the tick; a channel typically bound to
9
+ * the *x* scale.
10
+ */
11
+ x?: ChannelValueSpec;
12
+
13
+ /**
14
+ * The optional vertical position of the tick; an ordinal channel typically
15
+ * bound to the *y* scale. If not specified, the tick spans the vertical
16
+ * extent of the frame; otherwise the *y* scale must be a *band* scale.
17
+ *
18
+ * If *y* represents quantitative or temporal values, use a ruleX mark
19
+ * instead.
20
+ */
21
+ y?: ChannelValueSpec;
22
+ }
23
+
24
+ /** Options for the tickY mark. */
25
+ export interface TickYOptions extends MarkOptions, MarkerOptions, Omit<InsetOptions, 'insetTop' | 'insetBottom'> {
26
+ /**
27
+ * The required vertical position of the tick; a channel typically bound to
28
+ * the *y* scale.
29
+ */
30
+ y?: ChannelValueSpec;
31
+
32
+ /**
33
+ * The optional horizontal position of the tick; an ordinal channel typically
34
+ * bound to the *x* scale. If not specified, the tick spans the horizontal
35
+ * extent of the frame; otherwise the *x* scale must be a *band* scale.
36
+ *
37
+ * If *x* represents quantitative or temporal values, use a ruleY mark
38
+ * instead.
39
+ */
40
+ x?: ChannelValueSpec;
41
+ }
42
+
43
+ /** The tickX mark. */
44
+ export interface TickX extends MarkData, TickXOptions {
45
+ /**
46
+ * A horizontally-positioned tickX mark (a vertical line, |). The **x**
47
+ * channel specifies the tick’s horizontal position and defaults to identity,
48
+ * assuming that *data* = [*x₀*, *x₁*, *x₂*, …]; the optional **y** ordinal
49
+ * channel specifies its vertical position.
50
+ *
51
+ * If *y* represents quantitative or temporal values, use a ruleX mark
52
+ * instead.
53
+ */
54
+ mark: 'tickX';
55
+ }
56
+
57
+ /** The tickY mark. */
58
+ export interface TickY extends MarkData, TickYOptions {
59
+ /**
60
+ * A vertically-positioned tickY mark (a horizontal line, —). The **y**
61
+ * channel specifies the tick's vertical position and defaults to identity,
62
+ * assuming that *data* = [*y₀*, *y₁*, *y₂*, …]; the optional **x** ordinal
63
+ * channel specifies its horizontal position.
64
+ *
65
+ * If *x* represents quantitative or temporal values, use a ruleY mark
66
+ * instead.
67
+ */
68
+ mark: 'tickY';
69
+ }
@@ -0,0 +1,113 @@
1
+ import { ParamRef } from '../Param.js';
2
+ import { FrameAnchor } from '../PlotTypes.js';
3
+ import { ChannelValue, ChannelValueSpec, MarkData, MarkOptions } from './Marks.js';
4
+
5
+ /**
6
+ * The built-in vector shape implementations; one of:
7
+ *
8
+ * - *arrow* - a straight line with an open arrowhead at the end (↑)
9
+ * - *spike* - an isosceles triangle with a flat base (▲)
10
+ */
11
+ export type VectorShapeName = 'arrow' | 'spike';
12
+
13
+ /** How to draw a vector: either a named shape or a custom implementation. */
14
+ export type VectorShape = VectorShapeName;
15
+
16
+ /** Options for the vector mark. */
17
+ export interface VectorOptions extends MarkOptions {
18
+ /**
19
+ * The horizontal position of the vector’s anchor point; an optional channel
20
+ * bound to the *x* scale. Default depends on the **frameAnchor**.
21
+ */
22
+ x?: ChannelValueSpec;
23
+
24
+ /**
25
+ * The vertical position of the vector’s anchor point; an optional channel
26
+ * bound to the *y* scale. Default depends on the **frameAnchor**.
27
+ */
28
+ y?: ChannelValueSpec;
29
+
30
+ /**
31
+ * The vector shape’s radius, such as half the width of the *arrow*’s head or
32
+ * the *spike*’s base; a constant number in pixels. Defaults to 3.5 pixels.
33
+ */
34
+ r?: number | ParamRef;
35
+
36
+ /**
37
+ * The vector’s length; either an optional channel bound to the *length* scale
38
+ * or a constant number in pixels. Defaults to 12 pixels.
39
+ */
40
+ length?: ChannelValueSpec;
41
+
42
+ /**
43
+ * The vector’s orientation (rotation angle); either a constant number in
44
+ * degrees clockwise, or an optional channel (with no associated scale).
45
+ * Defaults to 0 degrees with the vector pointing up.
46
+ */
47
+ rotate?: ChannelValue;
48
+
49
+ /** The shape of the vector; a constant. Defaults to *arrow*. */
50
+ shape?: VectorShape | ParamRef;
51
+
52
+ /**
53
+ * The vector’s position along its orientation relative to its anchor point; a
54
+ * constant. Assuming a default **rotate** angle of 0°, one of:
55
+ *
56
+ * - *start* - from [*x*, *y*] to [*x*, *y* - *l*]
57
+ * - *middle* (default) - from [*x*, *y* + *l* / 2] to [*x*, *y* - *l* / 2]
58
+ * - *end* - from [*x*, *y* + *l*] to [*x*, *y*]
59
+ *
60
+ * where [*x*, *y*] is the vector’s anchor point and *l* is the vector’s
61
+ * (possibly scaled) length in pixels.
62
+ */
63
+ anchor?: 'start' | 'middle' | 'end' | ParamRef;
64
+
65
+ /**
66
+ * The vector’s frame anchor, to default **x** and **y** relative to the
67
+ * frame; a constant representing one of the frame corners (*top-left*,
68
+ * *top-right*, *bottom-right*, *bottom-left*), sides (*top*, *right*,
69
+ * *bottom*, *left*), or *middle* (default). Has no effect if both **x**
70
+ * and **y** are specified.
71
+ */
72
+ frameAnchor?: FrameAnchor | ParamRef;
73
+ }
74
+
75
+ /** The vector mark. */
76
+ export interface Vector extends MarkData, VectorOptions {
77
+ /**
78
+ * A vector mark.
79
+ *
80
+ * If none of **frameAnchor**, **x**, and **y** are specified, then **x** and
81
+ * **y** default to accessors assuming that *data* contains tuples [[*x₀*,
82
+ * *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …]
83
+ */
84
+ mark: 'vector';
85
+ }
86
+
87
+ /** The vectorX mark. */
88
+ export interface VectorX extends MarkData, VectorOptions {
89
+ /**
90
+ * Like vector, but **x** instead defaults to the identity function and **y**
91
+ * defaults to null, assuming that *data* is an array of numbers [*x₀*, *x₁*,
92
+ * *x₂*, …].
93
+ */
94
+ mark: 'vectorX';
95
+ }
96
+
97
+ /** The vectorY mark. */
98
+ export interface VectorY extends MarkData, VectorOptions {
99
+ /**
100
+ * Like vector, but **y** instead defaults to the identity function and **x**
101
+ * defaults to null, assuming that *data* is an array of numbers [*y₀*, *y₁*,
102
+ * *y₂*, …].
103
+ */
104
+ mark: 'vectorY';
105
+ }
106
+
107
+ /** The spike mark. */
108
+ export interface Spike extends MarkData, VectorOptions {
109
+ /**
110
+ * Like vector, but with default *options* suitable for drawing a spike map.
111
+ */
112
+ mark: 'spike';
113
+ }
package/src/util.js CHANGED
@@ -45,3 +45,11 @@ export function isFunction(value) {
45
45
  export function error(message, data) {
46
46
  throw Object.assign(Error(message), { data });
47
47
  }
48
+
49
+ const re = /^(?:[-+]\d{2})?\d{4}(?:-\d{2}(?:-\d{2})?)?(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d{3})?)?(?:Z|[-+]\d{2}:?\d{2})?)?$/;
50
+
51
+ // adapted from https://github.com/mbostock/isoformat/
52
+ export function isoparse(string, fallback) {
53
+ if (!re.test(string += '')) return fallback;
54
+ return new Date(string);
55
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,11 @@
1
+ {
2
+ "include": ["src/**/*.js", "src/**/*.ts"],
3
+ "compilerOptions": {
4
+ "allowJs": true,
5
+ "declaration": true,
6
+ "emitDeclarationOnly": true,
7
+ "outDir": "dist/types",
8
+ "module": "node16",
9
+ "skipLibCheck": true
10
+ }
11
+ }
package/LICENSE DELETED
@@ -1,47 +0,0 @@
1
- BSD 3-Clause License
2
-
3
- Copyright (c) 2023, UW Interactive Data Lab
4
-
5
- Redistribution and use in source and binary forms, with or without
6
- modification, are permitted provided that the following conditions are met:
7
-
8
- 1. Redistributions of source code must retain the above copyright notice, this
9
- list of conditions and the following disclaimer.
10
-
11
- 2. Redistributions in binary form must reproduce the above copyright notice,
12
- this list of conditions and the following disclaimer in the documentation
13
- and/or other materials provided with the distribution.
14
-
15
- 3. Neither the name of the copyright holder nor the names of its
16
- contributors may be used to endorse or promote products derived from
17
- this software without specific prior written permission.
18
-
19
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22
- DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23
- FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24
- DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25
- SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26
- CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27
- OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
-
30
- ---
31
-
32
- Portions of this software are derived from Observable Plot, which is released
33
- under the ISC license.
34
-
35
- Copyright 2020-2023 Observable, Inc.
36
-
37
- Permission to use, copy, modify, and/or distribute this software for any purpose
38
- with or without fee is hereby granted, provided that the above copyright notice
39
- and this permission notice appear in all copies.
40
-
41
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
42
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
43
- FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
44
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
45
- OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
46
- TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
47
- THIS SOFTWARE.