Skip to content

Commit f094bdf

Browse files
Filmbostock
andauthored
document barX barY (#1397)
* document barX barY * Update src/marks/bar.d.ts Co-authored-by: Mike Bostock <[email protected]> * prettier * edits * edits * edits, and a bit more repetition * fix typos --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent f69d002 commit f094bdf

File tree

4 files changed

+223
-5
lines changed

4 files changed

+223
-5
lines changed

src/marks/area.d.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,23 @@ export function area(data?: Data, options?: AreaOptions): Area;
136136
/**
137137
* Returns a new vertically-oriented area for the given *data* and *options*,
138138
* where the baseline and topline share **y** values, as in a time-series area
139-
* chart where time goes up↑.
139+
* chart where time goes up↑. For example, to plot Apple’s daily stock price:
140140
*
141141
* ```js
142142
* Plot.areaX(aapl, {y: "Date", x: "Close"})
143143
* ```
144144
*
145+
* If neither **x1** nor **x2** is specified, an implicit stackX transform is
146+
* applied and **x** defaults to the identity function, assuming that *data* =
147+
* [*x₀*, *x₁*, *x₂*, …]. Otherwise, if only one of **x1** or **x2** is
148+
* specified, the other defaults to **x**, which defaults to zero.
149+
*
150+
* If an **interval** is specified, **y** values are binned accordingly,
151+
* allowing zeroes for empty bins instead of interpolating across gaps. This is
152+
* recommended to “regularize” sampled data; for example, if your data
153+
* represents timestamped observations and you expect one observation per day,
154+
* use *day* as the **interval**.
155+
*
145156
* Variable aesthetic channels are supported: if the **fill** is defined as a
146157
* channel, the area will be broken into contiguous overlapping sections when
147158
* the fill color changes; the fill color will apply to the interval spanning
@@ -156,12 +167,23 @@ export function areaX(data?: Data, options?: AreaXOptions): Area;
156167
/**
157168
* Returns a new horizontally-oriented area for the given *data* and *options*,
158169
* where the baseline and topline share **x** values, as in a time-series area
159-
* chart where time goes right→.
170+
* chart where time goes right→. For example, to plot Apple’s daily stock price:
160171
*
161172
* ```js
162173
* Plot.areaY(aapl, {x: "Date", y: "Close"})
163174
* ```
164175
*
176+
* If neither **y1** nor **y2** is specified, an implicit stackY transform is
177+
* applied and **y** defaults to the identity function, assuming that *data* =
178+
* [*y₀*, *y₁*, *y₂*, …]. Otherwise, if only one of **y1** or **y2** is
179+
* specified, the other defaults to **y**, which defaults to zero.
180+
*
181+
* If an **interval** is specified, **x** values are binned accordingly,
182+
* allowing zeroes for empty bins instead of interpolating across gaps. This
183+
* is recommended to “regularize” sampled data; for example, if your data
184+
* represents timestamped observations and you expect one observation per day,
185+
* use *day* as the **interval**.
186+
*
165187
* Variable aesthetic channels are supported: if the **fill** is defined as a
166188
* channel, the area will be broken into contiguous overlapping sections when
167189
* the fill color changes; the fill color will apply to the interval spanning

src/marks/bar.d.ts

Lines changed: 182 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,211 @@ import type {InsetOptions} from "../inset.js";
44
import type {Data, MarkOptions, RenderableMark} from "../mark.js";
55
import type {StackOptions} from "../transforms/stack.js";
66

7+
/** Options for the barX and barY marks. */
78
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+
*/
916
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+
*/
1025
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;
1148
}
1249

50+
/** Options for the barX mark. */
1351
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+
*/
1464
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+
*/
1571
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+
*/
1678
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+
*/
1788
y?: ChannelValueSpec;
1889
}
1990

91+
/** Options for the barY mark. */
2092
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+
*/
21105
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+
*/
22112
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+
*/
23119
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+
*/
24130
x?: ChannelValueSpec;
25131
}
26132

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+
*/
27170
export function barX(data?: Data, options?: BarXOptions): BarX;
28171

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+
*/
29208
export function barY(data?: Data, options?: BarYOptions): BarY;
30209

210+
/** The barX mark. */
31211
export class BarX extends RenderableMark {}
32212

213+
/** The barY mark. */
33214
export class BarY extends RenderableMark {}

src/marks/frame.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export interface FrameOptions extends MarkOptions, InsetOptions {
2020
rx?: number | string;
2121

2222
/**
23-
* The rounded corner [*y*-radius[1], either in pixels or as a percentage of
23+
* The rounded corner [*y*-radius][1], either in pixels or as a percentage of
2424
* the frame height. If **ry** is not specified, it defaults to **rx** if
2525
* present, and otherwise draws square corners.
2626
*

src/marks/rule.d.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ import type {Data, MarkOptions, RenderableMark} from "../mark.js";
77
interface RuleOptions extends MarkOptions {
88
/**
99
* How to convert a continuous value (**y** for ruleX, or **x** for ruleY)
10-
* into an interval; one of:
10+
* into an interval (**y1** and **y2** for ruleX, or **x1** and **x2** for
11+
* ruleY); one of:
1112
*
1213
* - an object that implements *floor*, *offset*, and *range* methods
1314
* - a named time interval such as *day* (for date intervals)
@@ -100,6 +101,13 @@ export interface RuleYOptions extends RuleOptions, Omit<InsetOptions, "insetTop"
100101
* Plot.ruleX(aapl, {x: "Date", y1: "Open", y2: "Close"})
101102
* ```
102103
*
104+
* The ruleX mark is often used to highlight specific *x* values. For example,
105+
* to draw a rule at *x* = 0:
106+
*
107+
* ```js
108+
* Plot.ruleX([0])
109+
* ```
110+
*
103111
* If *y* represents ordinal values, use a tickX mark instead.
104112
*/
105113
export function ruleX(data?: Data, options?: RuleXOptions): RuleX;
@@ -116,6 +124,13 @@ export function ruleX(data?: Data, options?: RuleXOptions): RuleX;
116124
* Plot.ruleY(aapl, {x: "Date", y: "Close", interval: "month"})
117125
* ```
118126
*
127+
* The ruleY mark is often used to highlight specific *y* values. For example,
128+
* to draw a rule at *y* = 0:
129+
*
130+
* ```js
131+
* Plot.ruleY([0])
132+
* ```
133+
*
119134
* If *x* represents ordinal values, use a tickY mark instead.
120135
*/
121136
export function ruleY(data?: Data, options?: RuleYOptions): RuleY;

0 commit comments

Comments
 (0)