@@ -5,23 +5,6 @@ import type {plot} from "./plot.js";
5
5
import type { ScaleFunctions } from "./scales.js" ;
6
6
import type { InitializerFunction , SortOrder , TransformFunction } from "./transforms/basic.js" ;
7
7
8
- export type Facet = "auto" | "include" | "exclude" | "super" ;
9
-
10
- export type FacetAnchor =
11
- | "top"
12
- | "right"
13
- | "bottom"
14
- | "left"
15
- | "top-left"
16
- | "top-right"
17
- | "bottom-left"
18
- | "bottom-right"
19
- | "top-empty"
20
- | "right-empty"
21
- | "bottom-empty"
22
- | "left-empty"
23
- | "empty" ;
24
-
25
8
export type FrameAnchor =
26
9
| "middle"
27
10
| "top-left"
@@ -35,20 +18,36 @@ export type FrameAnchor =
35
18
36
19
export type Data = Iterable < any > | ArrayLike < any > ;
37
20
21
+ /**
22
+ * A bare renderable mark implementation. Given the mark’s *index*, an object of
23
+ * the plot’s *scales*, the mark’s (possibly scaled) channel *values*, the
24
+ * plot’s *dimensions* and *context*, returns a new SVGElement, or null if the
25
+ * mark should display nothing.
26
+ */
38
27
export type RenderFunction = (
28
+ /** The mark’s (filtered and transformed) index. */
39
29
index : number [ ] ,
30
+ /** The plot’s scale functions. */
40
31
scales : ScaleFunctions ,
32
+ /** The mark’s (possibly scaled and transformed) channel values. */
41
33
values : ChannelValues ,
34
+ /** The plot’s dimensions. */
42
35
dimensions : Dimensions ,
36
+ /** The plot’s context. */
43
37
context : Context
44
38
) => SVGElement | null ;
45
39
46
- export type Markish = RenderFunction | Renderable | Markish [ ] | null | undefined ;
47
-
48
- export interface Renderable {
49
- render : RenderFunction ;
50
- }
51
-
40
+ /**
41
+ * A mark implementation or mark-like object; one of:
42
+ *
43
+ * - a renderable mark, extending Mark and implementing *mark*.render
44
+ * - a bare render function, for a one-off custom mark
45
+ * - an array of mark implementations or mark-like objects
46
+ * - null or undefined, to render nothing
47
+ */
48
+ export type Markish = RenderableMark | RenderFunction | Markish [ ] | null | undefined ;
49
+
50
+ /** Shared options for all marks. */
52
51
export interface MarkOptions {
53
52
// transforms
54
53
filter ?: ChannelValue ;
@@ -57,17 +56,108 @@ export interface MarkOptions {
57
56
transform ?: TransformFunction ;
58
57
initializer ?: InitializerFunction ;
59
58
60
- // faceting
59
+ /**
60
+ * The horizontal facet position, an optional channel for mark-level faceting
61
+ * bound to the *fx* scale.
62
+ */
61
63
fx ?: ChannelValue ;
64
+
65
+ /**
66
+ * The vertical facet position, an optional channel for mark-level faceting
67
+ * bound to the *fy* scale.
68
+ */
62
69
fy ?: ChannelValue ;
63
- facet ?: Facet | boolean | null ;
64
- facetAnchor ?: FacetAnchor | null ;
65
70
66
- // axis margins
71
+ /**
72
+ * Whether to enable or disable faceting; one of:
73
+ *
74
+ * - *auto* (default) - automatically determine if this mark should be faceted
75
+ * - *include* (or true) - draw the subset of the mark’s data in the current facet
76
+ * - *exclude* - draw the subset of the mark’s data *not* in the current facet
77
+ * - *super* - draw this mark in a single frame that covers all facets
78
+ * - null (or false) - repeat this mark’s data across all facets (*i.e.*, no faceting)
79
+ *
80
+ * When a mark uses *super* faceting, it is not allowed to use position scales
81
+ * (*x*, *y*, *fx*, or *fy*); *super* faceting is intended for decorations,
82
+ * such as labels and legends.
83
+ *
84
+ * When top-level faceting is used, the default *auto* setting is equivalent
85
+ * to *include* when the mark data is strictly equal to the top-level facet
86
+ * data; otherwise it is equivalent to null. When the *include* or *exclude*
87
+ * facet mode is chosen, the mark data must be parallel to the top-level facet
88
+ * data: the data must have the same length and order. If the data are not
89
+ * parallel, then the wrong data may be shown in each facet. The default
90
+ * *auto* therefore requires strict equality (`===`) for safety, and using the
91
+ * facet data as mark data is recommended when using the *exclude* facet mode.
92
+ * (To construct parallel data safely, consider using [*array*.map][1] on the
93
+ * facet data.)
94
+ *
95
+ * When mark-level faceting is used, the default *auto* setting is equivalent
96
+ * to *include*: the mark will be faceted if either the **fx** or **fy**
97
+ * channel option (or both) is specified. The null or false option will
98
+ * disable faceting, while *exclude* draws the subset of the mark’s data *not*
99
+ * in the current facet.
100
+ *
101
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map
102
+ */
103
+ facet ?: "auto" | "include" | "exclude" | "super" | boolean | null ;
104
+
105
+ /**
106
+ * How to place the mark with respect to facets; one of:
107
+ *
108
+ * - null (default for most marks) - display the mark in each non-empty facet
109
+ * - *top*, *right*, *bottom*, or *left* - display the mark only in facets on
110
+ * the given side
111
+ * - *top-empty*, *right-empty*, *bottom-empty*, or *left-empty* (default for
112
+ * axis marks) - display the mark only in facets that have empty space on
113
+ * the given side: either the margin, or an empty facet
114
+ * - *empty* - display the mark in empty facets only
115
+ */
116
+ facetAnchor ?:
117
+ | "top"
118
+ | "right"
119
+ | "bottom"
120
+ | "left"
121
+ | "top-left"
122
+ | "top-right"
123
+ | "bottom-left"
124
+ | "bottom-right"
125
+ | "top-empty"
126
+ | "right-empty"
127
+ | "bottom-empty"
128
+ | "left-empty"
129
+ | "empty"
130
+ | null ;
131
+
132
+ /**
133
+ * Shorthand to set the same default for all four mark margins: **marginTop**,
134
+ * **marginRight**, **marginBottom**, and **marginLeft**; typically defaults
135
+ * to 0, except for axis marks.
136
+ */
67
137
margin ?: number ;
138
+
139
+ /**
140
+ * The mark’s top margin; the minimum distance in pixels between the top edges
141
+ * of the inner and outer plot area.
142
+ */
68
143
marginTop ?: number ;
144
+
145
+ /**
146
+ * The mark’s right margin; the minimum distance in pixels between the right
147
+ * edges of the mark’s inner and outer plot area.
148
+ */
69
149
marginRight ?: number ;
150
+
151
+ /**
152
+ * The mark’s bottom margin; the minimum distance in pixels between the bottom
153
+ * edges of the inner and outer plot area.
154
+ */
70
155
marginBottom ?: number ;
156
+
157
+ /**
158
+ * The mark’s left margin; the minimum distance in pixels between the left
159
+ * edges of the inner and outer plot area.
160
+ */
71
161
marginLeft ?: number ;
72
162
73
163
// accessibility and interaction
@@ -104,14 +194,24 @@ export interface MarkOptions {
104
194
channels ?: Channels ;
105
195
}
106
196
197
+ /** The abstract base class for Mark implementations. */
107
198
export class Mark {
199
+ /**
200
+ * Renders a new plot, prepending this mark as the first element of **marks**
201
+ * of the specified *options*, and returns the corresponding SVG element, or
202
+ * an HTML figure element if a caption or legend is requested.
203
+ */
108
204
plot : typeof plot ;
109
205
}
110
206
111
- export class RenderableMark extends Mark implements Renderable {
207
+ /** A concrete Mark implementation. */
208
+ export class RenderableMark extends Mark {
209
+ /** Renders this mark, returning a new SVGElement (or null). */
112
210
render : RenderFunction ;
113
211
}
114
212
115
- export type CompoundMark = Markish [ ] & { plot : typeof plot } ;
213
+ /** A compound Mark, comprising other marks. */
214
+ export type CompoundMark = Markish [ ] & Pick < Mark , "plot" > ;
116
215
216
+ /** Given an array of marks, returns a compound mark; supports *mark.plot shorthand. */
117
217
export function marks ( ...marks : Markish [ ] ) : CompoundMark ;
0 commit comments