@@ -4,30 +4,211 @@ import type {InsetOptions} from "../inset.js";
4
4
import type { Data , MarkOptions , RenderableMark } from "../mark.js" ;
5
5
import type { StackOptions } from "../transforms/stack.js" ;
6
6
7
+ /** Options for the barX and barY marks. */
7
8
interface BarOptions extends MarkOptions , InsetOptions , StackOptions {
8
- interval ?: Interval ;
9
+ /**
10
+ * The rounded corner [*x*-radius][1], either in pixels or as a percentage of
11
+ * the bar width. If **rx** is not specified, it defaults to **ry** if
12
+ * present, and otherwise draws square corners.
13
+ *
14
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx
15
+ */
9
16
rx ?: number | string ;
17
+
18
+ /**
19
+ * The rounded corner [*y*-radius][1], either in pixels or as a percentage of
20
+ * the bar height. If **ry** is not specified, it defaults to **rx** if
21
+ * present, and otherwise draws square corners.
22
+ *
23
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry
24
+ */
10
25
ry ?: number | string ;
26
+
27
+ /**
28
+ * How to convert a continuous value (**x** for barX, or **y** for barY) into
29
+ * an interval (**x1** and **x2** for barX, or **y1** and **y2** for barY);
30
+ * one of:
31
+ *
32
+ * - an object that implements *floor*, *offset*, and *range* methods
33
+ * - a named time interval such as *day* (for date intervals)
34
+ * - a number (for number intervals), defining intervals at integer multiples of *n*
35
+ *
36
+ * For example, for a scatterplot showing the frequency distribution of
37
+ * English letters, where the vertical extent of each bar covers a unit
38
+ * percentage:
39
+ *
40
+ * ```js
41
+ * Plot.barY(alphabet, {x: "letter", y: "frequency", interval: 0.01})
42
+ * ```
43
+ *
44
+ * Setting this option disables the implicit stack transform (stackX or barX,
45
+ * or stackY for barY).
46
+ */
47
+ interval ?: Interval ;
11
48
}
12
49
50
+ /** Options for the barX mark. */
13
51
export interface BarXOptions extends BarOptions {
52
+ /**
53
+ * The horizontal position (or length/width) channel, typically bound to the
54
+ * *x* scale.
55
+ *
56
+ * If neither **x1** nor **x2** nor **interval** is specified, an implicit
57
+ * stackX transform is applied and **x** defaults to the identity function,
58
+ * assuming that *data* = [*x₀*, *x₁*, *x₂*, …]. Otherwise if an **interval**
59
+ * is specified, then **x1** and **x2** are derived from **x**, representing
60
+ * the lower and upper bound of the containing interval, respectively.
61
+ * Otherwise, if only one of **x1** or **x2** is specified, the other defaults
62
+ * to **x**, which defaults to zero.
63
+ */
14
64
x ?: ChannelValueIntervalSpec ;
65
+
66
+ /**
67
+ * The required primary (starting) horizontal position channel, typically
68
+ * bound to the *x* scale. Setting this option disables the implicit stackX
69
+ * transform.
70
+ */
15
71
x1 ?: ChannelValueSpec ;
72
+
73
+ /**
74
+ * The required secondary (ending) horizontal position channel, typically
75
+ * bound to the *x* scale. Setting this option disables the implicit stackX
76
+ * transform.
77
+ */
16
78
x2 ?: ChannelValueSpec ;
79
+
80
+ /**
81
+ * The optional vertical position of the bar; a categorical channel typically
82
+ * bound to the *y* scale. If not specified, the bar spans the vertical extent
83
+ * of the frame; otherwise the *y* scale must be a *band* scale.
84
+ *
85
+ * If *y* represents quantitative or temporal values, use a rectX mark
86
+ * instead.
87
+ */
17
88
y ?: ChannelValueSpec ;
18
89
}
19
90
91
+ /** Options for the barY mark. */
20
92
export interface BarYOptions extends BarOptions {
93
+ /**
94
+ * The vertical position (or length/height) channel, typically bound to the
95
+ * *y* scale.
96
+ *
97
+ * If neither **y1** nor **y2** nor **interval** is specified, an implicit
98
+ * stackY transform is applied and **y** defaults to the identity function,
99
+ * assuming that *data* = [*y₀*, *y₁*, *y₂*, …]. Otherwise if an **interval**
100
+ * is specified, then **y1** and **y2** are derived from **y**, representing
101
+ * the lower and upper bound of the containing interval, respectively.
102
+ * Otherwise, if only one of **y1** or **y2** is specified, the other defaults
103
+ * to **y**, which defaults to zero.
104
+ */
21
105
y ?: ChannelValueIntervalSpec ;
106
+
107
+ /**
108
+ * The required primary (starting) vertical position channel, typically bound
109
+ * to the *y* scale. Setting this option disables the implicit stackY
110
+ * transform.
111
+ */
22
112
y1 ?: ChannelValueSpec ;
113
+
114
+ /**
115
+ * The required secondary (ending) horizontal position channel, typically
116
+ * bound to the *y* scale. Setting this option disables the implicit stackY
117
+ * transform.
118
+ */
23
119
y2 ?: ChannelValueSpec ;
120
+
121
+ /**
122
+ * The optional horizontal position of the bar; a categorical channel
123
+ * typically bound to the *x* scale. If not specified, the bar spans the
124
+ * horizontal extent of the frame; otherwise the *x* scale must be a *band*
125
+ * scale.
126
+ *
127
+ * If *x* represents quantitative or temporal values, use a rectY mark
128
+ * instead.
129
+ */
24
130
x ?: ChannelValueSpec ;
25
131
}
26
132
133
+ /**
134
+ * Returns a new horizontal bar mark for the given *data* and *options*; the
135
+ * required *x* values must be quantitative, and the optional *y* values must be
136
+ * ordinal. For example, for a horizontal bar chart of English letter frequency:
137
+ *
138
+ * ```js
139
+ * Plot.barX(alphabet, {x: "frequency", y: "letter"})
140
+ * ```
141
+ *
142
+ * If neither **x1** nor **x2** nor **interval** is specified, an implicit
143
+ * stackX transform is applied and **x** defaults to the identity function,
144
+ * assuming that *data* = [*x₀*, *x₁*, *x₂*, …]. Otherwise if an **interval** is
145
+ * specified, then **x1** and **x2** are derived from **x**, representing the
146
+ * lower and upper bound of the containing interval, respectively. Otherwise, if
147
+ * only one of **x1** or **x2** is specified, the other defaults to **x**, which
148
+ * defaults to zero.
149
+ *
150
+ * The optional **y** ordinal channel specifies the vertical position; it is
151
+ * typically bound to the *y* scale, which must be a *band* scale. If the **y**
152
+ * channel is not specified, the bar will span the vertical extent of the plot’s
153
+ * frame. The barX mark is often used in conjunction with the groupY transform.
154
+ * For a stacked histogram of penguins by species, colored by sex:
155
+ *
156
+ * ```js
157
+ * Plot.barX(penguins, Plot.groupY({x: "count"}, {y: "species", fill: "sex"}))
158
+ * ```
159
+ *
160
+ * If *y* is quantitative, use the rectX mark instead, possibly with a binY
161
+ * transform.
162
+ *
163
+ * If *options* is undefined, then **y** defaults to the zero-based index of
164
+ * *data* [0, 1, 2, …], allowing a quick bar chart from an array of numbers:
165
+ *
166
+ * ```js
167
+ * Plot.barX([4, 9, 24, 46, 66, 7])
168
+ * ```
169
+ */
27
170
export function barX ( data ?: Data , options ?: BarXOptions ) : BarX ;
28
171
172
+ /**
173
+ * Returns a new vertical bar mark for the given *data* and *options*; the
174
+ * required *y* values must be quantitative, and the optional *x* values must be
175
+ * ordinal. For example, for a vertical bar chart of English letter frequency:
176
+ *
177
+ * ```js
178
+ * Plot.barY(alphabet, {y: "frequency", x: "letter"})
179
+ * ```
180
+ * If neither **y1** nor **y2** nor **interval** is specified, an implicit
181
+ * stackY transform is applied and **y** defaults to the identity function,
182
+ * assuming that *data* = [*y₀*, *y₁*, *y₂*, …]. Otherwise if an **interval** is
183
+ * specified, then **y1** and **y2** are derived from **y**, representing the
184
+ * lower and upper bound of the containing interval, respectively. Otherwise, if
185
+ * only one of **y1** or **y2** is specified, the other defaults to **y**, which
186
+ * defaults to zero.
187
+ *
188
+ * The optional **x** ordinal channel specifies the horizontal position; it is
189
+ * typically bound to the *x* scale, which must be a *band* scale. If the **x**
190
+ * channel is not specified, the bar will span the horizontal extent of the
191
+ * plot’s frame. The barY mark is often used in conjunction with the groupX
192
+ * transform. For a stacked histogram of penguins by species, colored by sex:
193
+ *
194
+ * ```js
195
+ * Plot.barY(penguins, Plot.groupX({y: "count"}, {x: "species", fill: "sex"}))
196
+ * ```
197
+ *
198
+ * If *x* is quantitative, use the rectY mark instead, possibly with a binX
199
+ * transform.
200
+ *
201
+ * If *options* is undefined, then **x** defaults to the zero-based index of
202
+ * *data* [0, 1, 2, …], allowing a quick bar chart from an array of numbers:
203
+ *
204
+ * ```js
205
+ * Plot.barY([4, 9, 24, 46, 66, 7])
206
+ * ```
207
+ */
29
208
export function barY ( data ?: Data , options ?: BarYOptions ) : BarY ;
30
209
210
+ /** The barX mark. */
31
211
export class BarX extends RenderableMark { }
32
212
213
+ /** The barY mark. */
33
214
export class BarY extends RenderableMark { }
0 commit comments