@@ -6,52 +6,57 @@ import type {SymbolType} from "../symbol.js";
6
6
/** Options for the dot mark. */
7
7
export interface DotOptions extends MarkOptions {
8
8
/**
9
- * The horizontal position of the dot’s center, typically bound to the *x*
10
- * scale.
9
+ * The horizontal position channel specifying the dot’s center, typically
10
+ * bound to the *x* scale.
11
11
*/
12
12
x ?: ChannelValueSpec ;
13
13
14
14
/**
15
- * The vertical position of the dot’s center, typically bound to the *y*
16
- * scale.
15
+ * The vertical position channel specifying the dot’s center, typically bound
16
+ * to the *y* scale.
17
17
*/
18
18
y ?: ChannelValueSpec ;
19
19
20
20
/**
21
- * The **r** option can be specified as either a channel or constant. When the
22
- * radius is specified as a number, it is interpreted as a constant, in
23
- * pixels; otherwise it is interpreted as a channel, typically bound to the
24
- * *r* channel, which defaults to the *sqrt* type for proportional symbols.
25
- * The radius defaults to 4.5 pixels when using the **symbol** channel, and
26
- * otherwise 3 pixels. Dots with a nonpositive radius are not drawn.
21
+ * The radius of dots; either a channel or constant. When a number, it is
22
+ * interpreted as a constant radius in pixels. Otherwise it is interpreted as
23
+ * a channel, typically bound to the *r* channel, which defaults to the *sqrt*
24
+ * type for proportional symbols. The radius defaults to 4.5 pixels when using
25
+ * the **symbol** channel, and otherwise 3 pixels. Dots with a nonpositive
26
+ * radius are not drawn.
27
27
*/
28
28
r ?: ChannelValueSpec | number ;
29
29
30
30
/**
31
- * An angle to rotate the **symbol** around its center, in degrees clockwise.
32
- * Defaults to 0°, pointing up. Obviously inoperant with the *circle* symbol.
31
+ * The rotation angle of dots in degrees clockwise; either a channel or a
32
+ * constant. When a number, it is interpreted as a constant; otherwise it is
33
+ * interpreted as a channel. Defaults to 0°, pointing up.
33
34
*/
34
35
rotate ?: ChannelValue | number ;
35
36
36
37
/**
37
- * The categorical symbol; if a channel, bound to the *symbol* scale. A
38
- * constant symbol can be specified by a name such as *star*, or by its
39
- * implementation as a function of the *context* and *size*. Defaults to
40
- * *circle* for the **dot** mark, and *hexagon* for the **hexagon** mark.
38
+ * The categorical symbol; either a channel or a constant. A constant symbol
39
+ * can be specified by a valid symbol name such as *star*, or a symbol object
40
+ * (implementing the draw method); otherwise it is interpreted as a channel.
41
+ * Defaults to *circle* for the **dot** mark, and *hexagon* for the
42
+ * **hexagon** mark.
43
+ *
44
+ * If the **symbol** channel’s values are all symbols, symbol names, or
45
+ * nullish, the channel is unscaled (values are interpreted literally);
46
+ * otherwise, the channel is bound to the *symbol* scale.
41
47
*/
42
48
symbol ?: ChannelValueSpec | SymbolType ;
43
49
44
50
/**
45
51
* The frame anchor may be specified as one of the four sides (*top*, *right*,
46
52
* *bottom*, *left*), one of the four corners (*top-left*, *top-right*,
47
53
* *bottom-right*, *bottom-left*), or the *middle* of the frame. It controls
48
- * any component of the dot’s position not specified by **x** or **y**.
49
- *
50
- * For example, for a dot marking each bin and positioned at the top of the
51
- * frame:
54
+ * any component of the dot’s position not specified by **x** or **y**. For
55
+ * example, for a dots distributed in a horizontal line positioned at the top
56
+ * of the frame:
52
57
*
53
58
* ```js
54
- * Plot.dot(* data*, Plot.binX( {x: "date", frameAnchor: "top"}) )
59
+ * Plot.dot(data, {x: "date", frameAnchor: "top"})
55
60
* ```
56
61
*/
57
62
frameAnchor ?: FrameAnchor ;
@@ -61,15 +66,13 @@ export interface DotOptions extends MarkOptions {
61
66
export interface DotXOptions extends Omit < DotOptions , "y" > {
62
67
/**
63
68
* The vertical position of the dot’s center, typically bound to the *y*
64
- * scale. If an **interval** is specified, such as *day*, **y** is transformed
65
- * to the middle of the day. If the interval is specified as a number *n*,
66
- * **y** will be the midpoint of two consecutive multiples of *n* that bracket
67
- * **y**.
69
+ * scale.
68
70
*/
69
71
y ?: ChannelValueIntervalSpec ;
70
72
71
73
/**
72
- * An interval (such as *day* or a number), to bin *y* values.
74
+ * An interval (such as *day* or a number), to transform **y** values to the
75
+ * middle of the interval.
73
76
*/
74
77
interval ?: Interval ;
75
78
}
@@ -78,119 +81,66 @@ export interface DotXOptions extends Omit<DotOptions, "y"> {
78
81
export interface DotYOptions extends Omit < DotOptions , "x" > {
79
82
/**
80
83
* The horizontal position of the dot’s center, typically bound to the *x*
81
- * scale. If an **interval** is specified, such as *day*, **x** is transformed
82
- * to the middle of the day. If the interval is specified as a number *n*,
83
- * **x** will be the midpoint of two consecutive multiples of *n* that bracket
84
- * **x**.
84
+ * scale.
85
85
*/
86
86
x ?: ChannelValueIntervalSpec ;
87
87
88
88
/**
89
- * An interval (such as *day* or a number), to bin *x* values.
89
+ * An interval (such as *day* or a number), to transform **x** values to the
90
+ * middle of the interval.
90
91
*/
91
92
interval ?: Interval ;
92
93
}
93
94
94
95
/**
95
- * Draws circles, or other symbols, as in a scatterplot.
96
- *
97
- * In addition to the standard mark options, the following optional channels are
98
- * supported:
99
- *
100
- * - **x** - the horizontal position; bound to the *x* scale
101
- * - **y** - the vertical position; bound to the *y* scale
102
- * - **r** - the radius (area); bound to the *radius* scale, which defaults to
103
- * *sqrt*
104
- * - **rotate** - the rotation angle in degrees clockwise
105
- * - **symbol** - the categorical symbol; bound to the *symbol* scale
106
- *
107
- * For example, a scatterplot of sales by fruit type (category) and units sold
108
- * (quantitative):
96
+ * Draws circles, or other symbols, as in a scatterplot. For example, a
97
+ * scatterplot of sales by fruit type (category) and units sold (quantitative):
109
98
*
110
99
* ```js
111
100
* Plot.dot(sales, {x: "units", y: "fruit"})
112
101
* ```
113
102
*
114
- * If either of the **x** or **y** channels are not specified, the corresponding
115
- * position is controlled by the **frameAnchor** option.
103
+ * If either **x** or **y** is not specified, the default is determined by the
104
+ * **frameAnchor** option. If none of **x**, **y**, and **frameAnchor** are
105
+ * specified, *data* is assumed to be an array of pairs [[*x₀*, *y₀*], [*x₁*,
106
+ * *y₁*], [*x₂*, *y₂*], …] such that **x** = [*x₀*, *x₁*, *x₂*, …] and **y** =
107
+ * [*y₀*, *y₁*, *y₂*, …].
116
108
*
117
- * The following options are also supported:
118
- *
119
- * - **r** - the effective radius
120
- * - **rotate** - the rotation angle in degrees clockwise; defaults to 0
121
- * - **symbol** - the categorical symbol; defaults to circle
122
- * - **frameAnchor** - the frame anchor; defaults to *middle*
123
- *
124
- *
125
- * The **stroke** defaults to none. The **fill** defaults to currentColor if the
126
- * stroke is none, and to none otherwise. The **strokeWidth** defaults to 1.5.
127
- * The **rotate** and **symbol** options can be specified as either channels or
128
- * constants. When rotate is specified as a number, it is interpreted as a
129
- * constant; otherwise it is interpreted as a channel. When symbol is a valid
130
- * symbol name or symbol object (implementing the draw method), it is
131
- * interpreted as a constant; otherwise it is interpreted as a channel. If the
132
- * **symbol** channel’s values are all symbols, symbol names, or nullish, the
133
- * channel is unscaled (values are interpreted literally); otherwise, the
134
- * channel is bound to the *symbol* scale.
135
- *
136
- * The built-in **symbol** types are: *circle*, *cross*, *diamond*, *square*,
137
- * *star*, *triangle*, and *wye* (for fill) and *circle*, *plus*, *times*,
138
- * *triangle2*, *asterisk*, *square2*, and *diamond2* (for stroke, based on
139
- * [Heman Robinson’s
140
- * research](https://www.tandfonline.com/doi/abs/10.1080/10618600.2019.1637746)).
141
- * The *hexagon* symbol is also supported. You can also specify a D3 or custom
142
- * symbol type as an object that implements the [*symbol*.draw(*context*,
143
- * *size*)](https://github.com/d3/d3-shape/blob/main/README.md#custom-symbol-types)
144
- * method.
145
- *
146
- * Dots are sorted by descending radius by default to mitigate overplotting; set
147
- * the **sort** option to null to draw them in input order.
148
- *
149
- * If neither the **x** nor **y** nor **frameAnchor** options are specified,
150
- * *data* is assumed to be an array of pairs [[*x₀*, *y₀*], [*x₁*, *y₁*], [*x₂*,
151
- * *y₂*], …] such that **x** = [*x₀*, *x₁*, *x₂*, …] and **y** = [*y₀*, *y₁*,
152
- * *y₂*, …].
109
+ * Dots are sorted by descending radius **r** by default to mitigate
110
+ * overplotting; set the **sort** option to null to draw them in input order.
153
111
*/
154
112
export function dot ( data ?: Data , options ?: DotOptions ) : Dot ;
155
113
156
114
/**
157
- * Equivalent to **dot** except that if the **x** option is not specified, it
158
- * defaults to the identity function and assumes that *data* = [*x₀*, *x₁*,
159
- * *x₂*, …].
115
+ * Like dot, except that **x** defaults to the identity function, assuming that
116
+ * *data* = [*x₀*, *x₁*, *x₂*, …].
160
117
*
161
118
* ```js
162
119
* Plot.dotX(cars.map(d => d["economy (mpg)"]))
163
120
* ```
164
121
*
165
- * If an **interval** is specified, such as "day", **y** is transformed to the
166
- * middle of the day. If the interval is specified as a number *n*, **y** will
167
- * be the midpoint of two consecutive multiples of *n* that bracket **y**.
122
+ * If an **interval** is specified, such as *day*, **y** is transformed to the
123
+ * middle of the interval.
168
124
*/
169
125
export function dotX ( data ?: Data , options ?: DotXOptions ) : Dot ;
170
126
171
127
/**
172
- * Equivalent to **dot** except that if the **y** option is not specified, it
173
- * defaults to the identity function and assumes that *data* = [*y₀*, *y₁*,
174
- * *y₂*, …].
128
+ * Like dot, except that **y** defaults to the identity function, assuming that
129
+ * *data* = [*y₀*, *y₁*, *y₂*, …].
175
130
*
176
131
* ```js
177
132
* Plot.dotY(cars.map(d => d["economy (mpg)"]))
178
133
* ```
179
134
*
180
- * If an **interval** is specified, such as "day", **x** is transformed to the
181
- * middle of the day. If the interval is specified as a number *n*, **x** will
182
- * be the midpoint of two consecutive multiples of *n* that bracket **x**.
135
+ * If an **interval** is specified, such as *day*, **x** is transformed to the
136
+ * middle of the interval.
183
137
*/
184
138
export function dotY ( data ?: Data , options ?: DotYOptions ) : Dot ;
185
139
186
- /**
187
- * Equivalent to **dot** except that the **symbol** option is set to *circle*.
188
- */
140
+ /** Like dot, except that the **symbol** option is set to *circle*. */
189
141
export function circle ( data ?: Data , options ?: Exclude < DotOptions , "symbol" > ) : Dot ;
190
142
191
- /**
192
- * Equivalent to **dot**, except that the **symbol** option is set to *hexagon*.
193
- */
143
+ /** Like dot, except that the **symbol** option is set to *hexagon*. */
194
144
export function hexagon ( data ?: Data , options ?: Exclude < DotOptions , "symbol" > ) : Dot ;
195
145
196
146
/** The dot mark. */
0 commit comments