@@ -4,30 +4,193 @@ import type {Interval} from "../interval.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 rect mark. */
7
8
export interface RectOptions extends MarkOptions , InsetOptions , StackOptions {
9
+ /**
10
+ * The horizontal position (or length/width) channel, typically bound to the
11
+ * *x* scale.
12
+ *
13
+ * If an **interval** is specified, then **x1** and **x2** are derived from
14
+ * **x**, representing the lower and upper bound of the containing interval,
15
+ * respectively. For example, for a vertical bar chart of items sold by day:
16
+ *
17
+ * ```js
18
+ * Plot.rectY(sales, {x: "date", interval: "day", y2: "items"})
19
+ * ```
20
+ *
21
+ * If *x* represents ordinal values, use a bar or cell mark instead.
22
+ */
8
23
x ?: ChannelValueIntervalSpec ;
24
+
25
+ /**
26
+ * The required primary (starting, often left) horizontal position channel,
27
+ * typically bound to the *x* scale. Setting this option disables the rectX
28
+ * mark’s implicit stackX transform.
29
+ *
30
+ * If *x* represents ordinal values, use a bar or cell mark instead.
31
+ */
9
32
x1 ?: ChannelValueSpec ;
33
+
34
+ /**
35
+ * The required secondary (ending, often right) horizontal position channel,
36
+ * typically bound to the *x* scale. Setting this option disables the rectX
37
+ * mark’s implicit stackX transform.
38
+ *
39
+ * If *x* represents ordinal values, use a bar or cell mark instead.
40
+ */
10
41
x2 ?: ChannelValueSpec ;
42
+
43
+ /**
44
+ * The vertical position (or length/height) channel, typically bound to the
45
+ * *y* scale.
46
+ *
47
+ * If an **interval** is specified, then **y1** and **y2** are derived from
48
+ * **y**, representing the lower and upper bound of the containing interval,
49
+ * respectively. For example, for a horizontal bar chart of items sold by day:
50
+ *
51
+ * ```js
52
+ * Plot.rectX(sales, {y: "date", interval: "day", x2: "items"})
53
+ * ```
54
+ *
55
+ * If *y* represents ordinal values, use a bar or cell mark instead.
56
+ */
11
57
y ?: ChannelValueIntervalSpec ;
58
+
59
+ /**
60
+ * The required primary (starting, often bottom) vertical position channel,
61
+ * typically bound to the *y* scale. Setting this option disables the rectY
62
+ * mark’s implicit stackY transform.
63
+ *
64
+ * If *y* represents ordinal values, use a bar or cell mark instead.
65
+ */
12
66
y1 ?: ChannelValueSpec ;
67
+
68
+ /**
69
+ * The required secondary (ending, often top) vertical position channel,
70
+ * typically bound to the *y* scale. Setting this option disables the rectY
71
+ * mark’s implicit stackY transform.
72
+ *
73
+ * If *y* represents ordinal values, use a bar or cell mark instead.
74
+ */
13
75
y2 ?: ChannelValueSpec ;
76
+
77
+ /**
78
+ * How to convert a continuous value (**x** for rectY, **y** for rectX, or
79
+ * both for rect) into an interval (**x1** and **x2** for rectY, or **y1** and
80
+ * **y2** for rectX, or both for rect); one of:
81
+ *
82
+ * - an object that implements *floor*, *offset*, and *range* methods
83
+ * - a named time interval such as *day* (for date intervals)
84
+ * - a number (for number intervals), defining intervals at integer multiples of *n*
85
+ *
86
+ * For example, for a scatterplot of penguin culmen length *vs.* depth, using
87
+ * rects of half-millimeter width and height:
88
+ *
89
+ * ```js
90
+ * Plot.rect(penguins, {x: "culmen_length_mm", y: "culmen_depth_mm", interval: 0.5})
91
+ * ```
92
+ *
93
+ * Setting this option disables the implicit stack transform (stackX for rectX,
94
+ * or stackY for rectY).
95
+ */
14
96
interval ?: Interval ;
97
+
98
+ /**
99
+ * The rounded corner [*x*-radius][1], either in pixels or as a percentage of
100
+ * the bar width. If **rx** is not specified, it defaults to **ry** if
101
+ * present, and otherwise draws square corners.
102
+ *
103
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx
104
+ */
15
105
rx ?: number | string ;
106
+
107
+ /**
108
+ * The rounded corner [*y*-radius][1], either in pixels or as a percentage of
109
+ * the bar height. If **ry** is not specified, it defaults to **rx** if
110
+ * present, and otherwise draws square corners.
111
+ *
112
+ * [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry
113
+ */
16
114
ry ?: number | string ;
17
115
}
18
116
117
+ /** Options for the rectX mark. */
19
118
export interface RectXOptions extends RectOptions {
119
+ /**
120
+ * The horizontal position (or length/width) channel, typically bound to the
121
+ * *x* scale.
122
+ *
123
+ * If neither **x1** nor **x2** is specified, an implicit stackX transform is
124
+ * applied and **x** defaults to the identity function, assuming that *data* =
125
+ * [*x₀*, *x₁*, *x₂*, …]. Otherwise, if only one of **x1** or **x2** is
126
+ * specified, the other defaults to **x**, which defaults to zero.
127
+ */
20
128
x ?: ChannelValueSpec ; // disallow x interval
21
129
}
22
130
131
+ /** Options for the rectY mark. */
23
132
export interface RectYOptions extends RectOptions {
133
+ /**
134
+ * The vertical position (or length/height) channel, typically bound to the
135
+ * *y* scale.
136
+ *
137
+ * If neither **y1** nor **y2** is specified, an implicit stackY transform is
138
+ * applied and **y** defaults to the identity function, assuming that *data* =
139
+ * [*y₀*, *y₁*, *y₂*, …]. Otherwise, if only one of **y1** or **y2** is
140
+ * specified, the other defaults to **y**, which defaults to zero.
141
+ */
24
142
y ?: ChannelValueSpec ; // disallow y interval
25
143
}
26
144
145
+ /**
146
+ * Returns a rect mark for the given *data* and *options*. The rectangle extends
147
+ * horizontally from **x1** to **x2**, and vertically from **y1** to **y2**. The
148
+ * position channels are often derived with a transform. For example, to create
149
+ * a heatmap of athletes, binned by weight and height:
150
+ *
151
+ * ```js
152
+ * Plot.rect(athletes, Plot.bin({fill: "proportion"}, {x: "weight", y: "height"}))
153
+ * ```
154
+ *
155
+ * When **y** extends from zero, for example for a histogram where the height of
156
+ * each rect reflects a count of values, use the rectY mark for an implicit
157
+ * stackY transform; similarly, if **x** extends from zero, use the rectX mark
158
+ * for an implicit stackX transform.
159
+ *
160
+ * If an **interval** is specified, then **x1** and **x2** are derived from
161
+ * **x**, and **y1** and **y2** are derived from **y**, each representing the
162
+ * lower and upper bound of the containing interval, respectively.
163
+ *
164
+ * Both *x* and *y* should be quantitative or temporal; otherwise, use a bar or
165
+ * cell mark.
166
+ */
27
167
export function rect ( data ?: Data , options ?: RectOptions ) : Rect ;
28
168
169
+ /**
170
+ * Like rect, but if neither **x1** nor **x2** is specified, an implicit stackX
171
+ * transform is applied to **x**, and if **x** is not specified, it defaults to
172
+ * the identity function, assuming that *data* is an array of numbers [*x₀*,
173
+ * *x₁*, *x₂*, …]. For example, for a vertical histogram of athletes by height
174
+ * with rects aligned at *x* = 0:
175
+ *
176
+ * ```js
177
+ * Plot.rectX(olympians, Plot.binY({x: "count"}, {y: "height"}))
178
+ * ```
179
+ */
29
180
export function rectX ( data ?: Data , options ?: RectXOptions ) : Rect ;
30
181
182
+ /**
183
+ * Like rect, but if neither **y1** nor **y2** is specified, apply an implicit
184
+ * stackY transform is applied to **y**, and if **y** is not specified, it
185
+ * defaults to the identity function, assuming that *data* is an array of
186
+ * numbers [*y₀*, *y₁*, *y₂*, …]. For example, for a horizontal histogram of
187
+ * athletes by weight with rects aligned at *y* = 0:
188
+ *
189
+ * ```js
190
+ * Plot.rectY(olympians, Plot.binX({y: "count"}, {x: "weight"}))
191
+ * ```
192
+ */
31
193
export function rectY ( data ?: Data , options ?: RectYOptions ) : Rect ;
32
194
195
+ /** The rect mark. */
33
196
export class Rect extends RenderableMark { }
0 commit comments