Skip to content

Commit 65237c6

Browse files
Filmbostock
andauthored
document rect (#1383)
* document recct * link style * edits * more edits --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent f094bdf commit 65237c6

File tree

5 files changed

+223
-49
lines changed

5 files changed

+223
-49
lines changed

src/marks/area.d.ts

+14-14
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,32 @@ import type {StackOptions} from "../transforms/stack.js";
77
/** Options for the area, areaX, and areaY marks. */
88
export interface AreaOptions extends MarkOptions, StackOptions, CurveOptions {
99
/**
10-
* The required primary horizontal position channel, representing the area’s
11-
* baseline, typically bound to the *x* scale. For areaX, setting this option
12-
* disables the implicit stackX transform.
10+
* The required primary (starting, often left) horizontal position channel,
11+
* representing the area’s baseline, typically bound to the *x* scale. For
12+
* areaX, setting this option disables the implicit stackX transform.
1313
*/
1414
x1?: ChannelValueSpec;
1515

1616
/**
17-
* The optional secondary horizontal position channel, representing the area’s
18-
* topline, typically bound to the *x* scale; if not specified, **x1** is
19-
* used. For areaX, setting this option disables the implicit stackX
20-
* transform.
17+
* The optional secondary (ending, often right) horizontal position channel,
18+
* representing the area’s topline, typically bound to the *x* scale; if not
19+
* specified, **x1** is used. For areaX, setting this option disables the
20+
* implicit stackX transform.
2121
*/
2222
x2?: ChannelValueSpec;
2323

2424
/**
25-
* The required primary vertical position channel, representing the area’s
26-
* baseline, typically bound to the *y* scale. For areaY, setting this option
27-
* disables the implicit stackY transform.
25+
* The required primary (starting, often bottom) vertical position channel,
26+
* representing the area’s baseline, typically bound to the *y* scale. For
27+
* areaY, setting this option disables the implicit stackY transform.
2828
*/
2929
y1?: ChannelValueSpec;
3030

3131
/**
32-
* The optional secondary vertical position channel, representing the area’s
33-
* topline, typically bound to the *y* scale; if not specified, **y1** is
34-
* used. For areaY, setting this option disables the implicit stackY
35-
* transform.
32+
* The optional secondary (ending, often top) vertical position channel,
33+
* representing the area’s topline, typically bound to the *y* scale; if not
34+
* specified, **y1** is used. For areaY, setting this option disables the
35+
* implicit stackY transform.
3636
*/
3737
y2?: ChannelValueSpec;
3838

src/marks/bar.d.ts

+31-19
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ interface BarOptions extends MarkOptions, InsetOptions, StackOptions {
4141
* Plot.barY(alphabet, {x: "letter", y: "frequency", interval: 0.01})
4242
* ```
4343
*
44-
* Setting this option disables the implicit stack transform (stackX or barX,
44+
* Setting this option disables the implicit stack transform (stackX for barX,
4545
* or stackY for barY).
4646
*/
4747
interval?: Interval;
@@ -64,16 +64,20 @@ export interface BarXOptions extends BarOptions {
6464
x?: ChannelValueIntervalSpec;
6565

6666
/**
67-
* The required primary (starting) horizontal position channel, typically
68-
* bound to the *x* scale. Setting this option disables the implicit stackX
69-
* transform.
67+
* The required primary (starting, often left) horizontal position channel,
68+
* typically bound to the *x* scale. Setting this option disables the implicit
69+
* stackX transform.
70+
*
71+
* If *x* represents ordinal values, use a cell mark instead.
7072
*/
7173
x1?: ChannelValueSpec;
7274

7375
/**
74-
* The required secondary (ending) horizontal position channel, typically
75-
* bound to the *x* scale. Setting this option disables the implicit stackX
76-
* transform.
76+
* The required secondary (ending, often right) horizontal position channel,
77+
* typically bound to the *x* scale. Setting this option disables the implicit
78+
* stackX transform.
79+
*
80+
* If *x* represents ordinal values, use a cell mark instead.
7781
*/
7882
x2?: ChannelValueSpec;
7983

@@ -105,16 +109,20 @@ export interface BarYOptions extends BarOptions {
105109
y?: ChannelValueIntervalSpec;
106110

107111
/**
108-
* The required primary (starting) vertical position channel, typically bound
109-
* to the *y* scale. Setting this option disables the implicit stackY
110-
* transform.
112+
* The required primary (starting, often bottom) vertical position channel,
113+
* typically bound to the *y* scale. Setting this option disables the implicit
114+
* stackY transform.
115+
*
116+
* If *y* represents ordinal values, use a cell mark instead.
111117
*/
112118
y1?: ChannelValueSpec;
113119

114120
/**
115-
* The required secondary (ending) horizontal position channel, typically
116-
* bound to the *y* scale. Setting this option disables the implicit stackY
117-
* transform.
121+
* The required secondary (ending, often top) horizontal position channel,
122+
* typically bound to the *y* scale. Setting this option disables the implicit
123+
* stackY transform.
124+
*
125+
* If *y* represents ordinal values, use a cell mark instead.
118126
*/
119127
y2?: ChannelValueSpec;
120128

@@ -132,8 +140,9 @@ export interface BarYOptions extends BarOptions {
132140

133141
/**
134142
* 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:
143+
* required *x* values should be quantitative or temporal, and the optional *y*
144+
* values should be ordinal. For example, for a horizontal bar chart of English
145+
* letter frequency:
137146
*
138147
* ```js
139148
* Plot.barX(alphabet, {x: "frequency", y: "letter"})
@@ -158,7 +167,8 @@ export interface BarYOptions extends BarOptions {
158167
* ```
159168
*
160169
* If *y* is quantitative, use the rectX mark instead, possibly with a binY
161-
* transform.
170+
* transform. If *x* is ordinal, use the cell mark instead, possibly with a
171+
* group transform.
162172
*
163173
* If *options* is undefined, then **y** defaults to the zero-based index of
164174
* *data* [0, 1, 2, …], allowing a quick bar chart from an array of numbers:
@@ -171,8 +181,9 @@ export function barX(data?: Data, options?: BarXOptions): BarX;
171181

172182
/**
173183
* 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:
184+
* required *y* values should be quantitative or temporal, and the optional *x*
185+
* values should be ordinal. For example, for a vertical bar chart of English
186+
* letter frequency:
176187
*
177188
* ```js
178189
* Plot.barY(alphabet, {y: "frequency", x: "letter"})
@@ -196,7 +207,8 @@ export function barX(data?: Data, options?: BarXOptions): BarX;
196207
* ```
197208
*
198209
* If *x* is quantitative, use the rectY mark instead, possibly with a binX
199-
* transform.
210+
* transform. If *y* is ordinal, use the cell mark instead, possibly with a
211+
* group transform.
200212
*
201213
* If *options* is undefined, then **x** defaults to the zero-based index of
202214
* *data* [0, 1, 2, …], allowing a quick bar chart from an array of numbers:

src/marks/rect.d.ts

+163
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,193 @@ import type {Interval} from "../interval.js";
44
import type {Data, MarkOptions, RenderableMark} from "../mark.js";
55
import type {StackOptions} from "../transforms/stack.js";
66

7+
/** Options for the rect mark. */
78
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+
*/
823
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+
*/
932
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+
*/
1041
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+
*/
1157
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+
*/
1266
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+
*/
1375
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+
*/
1496
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+
*/
15105
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+
*/
16114
ry?: number | string;
17115
}
18116

117+
/** Options for the rectX mark. */
19118
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+
*/
20128
x?: ChannelValueSpec; // disallow x interval
21129
}
22130

131+
/** Options for the rectY mark. */
23132
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+
*/
24142
y?: ChannelValueSpec; // disallow y interval
25143
}
26144

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+
*/
27167
export function rect(data?: Data, options?: RectOptions): Rect;
28168

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+
*/
29180
export function rectX(data?: Data, options?: RectXOptions): Rect;
30181

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+
*/
31193
export function rectY(data?: Data, options?: RectYOptions): Rect;
32194

195+
/** The rect mark. */
33196
export class Rect extends RenderableMark {}

src/marks/rule.d.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,16 @@ export interface RuleXOptions extends RuleOptions, Omit<InsetOptions, "insetLeft
4141
y?: ChannelValueIntervalSpec;
4242

4343
/**
44-
* The primary (starting) vertical position of the tick; a channel bound to
45-
* the *y* scale.
44+
* The primary (starting, often bottom) vertical position of the tick; a
45+
* channel bound to the *y* scale.
4646
*
4747
* If *y* represents ordinal values, use a tickX mark instead.
4848
*/
4949
y1?: ChannelValueSpec;
5050

5151
/**
52-
* The secondary (ending) vertical position of the tick; a channel bound to
53-
* the *y* scale.
52+
* The secondary (ending, often top) vertical position of the tick; a channel
53+
* bound to the *y* scale.
5454
*
5555
* If *y* represents ordinal values, use a tickX mark instead.
5656
*/
@@ -67,16 +67,16 @@ export interface RuleYOptions extends RuleOptions, Omit<InsetOptions, "insetTop"
6767
x?: ChannelValueIntervalSpec;
6868

6969
/**
70-
* The primary (starting) horizontal position of the tick; a channel bound to
71-
* the *x* scale.
70+
* The primary (starting, often left) horizontal position of the tick; a
71+
* channel bound to the *x* scale.
7272
*
7373
* If *x* represents ordinal values, use a tickY mark instead.
7474
*/
7575
x1?: ChannelValueSpec;
7676

7777
/**
78-
* The secondary (ending) horizontal position of the tick; a channel bound to
79-
* the *x* scale.
78+
* The secondary (ending, often right) horizontal position of the tick; a
79+
* channel bound to the *x* scale.
8080
*
8181
* If *x* represents ordinal values, use a tickY mark instead.
8282
*/

0 commit comments

Comments
 (0)