Skip to content

Commit f69d002

Browse files
Filmbostock
andauthored
document rule (#1379)
* document rule * better rules * edits * edits --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent 350ac3b commit f69d002

File tree

2 files changed

+102
-7
lines changed

2 files changed

+102
-7
lines changed

src/marks/rule.d.ts

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,125 @@ import type {InsetOptions} from "../inset.js";
33
import type {Interval} from "../interval.js";
44
import type {Data, MarkOptions, RenderableMark} from "../mark.js";
55

6+
/** Options for the ruleX and ruleY marks. */
67
interface RuleOptions extends MarkOptions {
8+
/**
9+
* How to convert a continuous value (**y** for ruleX, or **x** for ruleY)
10+
* into an interval; one of:
11+
*
12+
* - an object that implements *floor*, *offset*, and *range* methods
13+
* - a named time interval such as *day* (for date intervals)
14+
* - a number (for number intervals), defining intervals at integer multiples of *n*
15+
*
16+
* For example, to bin Apple’s daily stock price by month, plotting a sequence
17+
* of barcodes showing monthly distributions:
18+
*
19+
* ```js
20+
* Plot.ruleY(aapl, {x: "Date", y: "Close", interval: "month"})
21+
* ```
22+
*/
723
interval?: Interval;
824
}
925

26+
/** Options for the ruleX mark. */
1027
export interface RuleXOptions extends RuleOptions, Omit<InsetOptions, "insetLeft" | "insetRight"> {
28+
/**
29+
* The horizontal position of the tick; an optional channel bound to the *x*
30+
* scale. If not specified, the rule will be horizontally centered in the
31+
* plot’s frame.
32+
*/
1133
x?: ChannelValueSpec;
34+
35+
/**
36+
* Shorthand for specifying both the primary and secondary vertical position
37+
* of the tick as the bounds of the containing interval; can only be used in
38+
* conjunction with the **interval** option.
39+
*/
1240
y?: ChannelValueIntervalSpec;
41+
42+
/**
43+
* The primary (starting) vertical position of the tick; a channel bound to
44+
* the *y* scale.
45+
*
46+
* If *y* represents ordinal values, use a tickX mark instead.
47+
*/
1348
y1?: ChannelValueSpec;
49+
50+
/**
51+
* The secondary (ending) vertical position of the tick; a channel bound to
52+
* the *y* scale.
53+
*
54+
* If *y* represents ordinal values, use a tickX mark instead.
55+
*/
1456
y2?: ChannelValueSpec;
1557
}
1658

59+
/** Options for the ruleY mark. */
1760
export interface RuleYOptions extends RuleOptions, Omit<InsetOptions, "insetTop" | "insetBottom"> {
61+
/**
62+
* Shorthand for specifying both the primary and secondary horizontal position
63+
* of the tick as the bounds of the containing interval; can only be used in
64+
* conjunction with the **interval** option.
65+
*/
1866
x?: ChannelValueIntervalSpec;
67+
68+
/**
69+
* The primary (starting) horizontal position of the tick; a channel bound to
70+
* the *x* scale.
71+
*
72+
* If *x* represents ordinal values, use a tickY mark instead.
73+
*/
1974
x1?: ChannelValueSpec;
75+
76+
/**
77+
* The secondary (ending) horizontal position of the tick; a channel bound to
78+
* the *x* scale.
79+
*
80+
* If *x* represents ordinal values, use a tickY mark instead.
81+
*/
2082
x2?: ChannelValueSpec;
83+
84+
/**
85+
* The vertical position of the tick; an optional channel bound to the *y*
86+
* scale. If not specified, the rule will be vertically centered in the plot’s
87+
* frame.
88+
*/
2189
y?: ChannelValueSpec;
2290
}
2391

92+
/**
93+
* Returns a new horizontally-positioned ruleX mark (a vertical line, |) for the
94+
* given *data* and *options*. The **x** channel specifies the rule’s horizontal
95+
* position and defaults to identity, assuming that *data* = [*x₀*, *x₁*, *x₂*,
96+
* …]; the optional **y1** and **y2** channels specify its vertical extent. For
97+
* example, for a candlestick chart of Apple’s daily stock price:
98+
*
99+
* ```js
100+
* Plot.ruleX(aapl, {x: "Date", y1: "Open", y2: "Close"})
101+
* ```
102+
*
103+
* If *y* represents ordinal values, use a tickX mark instead.
104+
*/
24105
export function ruleX(data?: Data, options?: RuleXOptions): RuleX;
25106

107+
/**
108+
* Returns a new vertically-positioned ruleY mark (a horizontal line, —) for the
109+
* given *data* and *options*. The **y** channel specifies the vertical position
110+
* of the rule and defaults to identity, assuming that *data* = [*y₀*, *y₁*,
111+
* *y₂*, …]; the optional **x1** and **x2** channels specify its horizontal
112+
* extent. For example, to bin Apple’s daily stock price by month, plotting a
113+
* sequence of barcodes showing monthly distributions:
114+
*
115+
* ```js
116+
* Plot.ruleY(aapl, {x: "Date", y: "Close", interval: "month"})
117+
* ```
118+
*
119+
* If *x* represents ordinal values, use a tickY mark instead.
120+
*/
26121
export function ruleY(data?: Data, options?: RuleYOptions): RuleY;
27122

123+
/** The ruleX mark. */
28124
export class RuleX extends RenderableMark {}
29125

126+
/** The ruleY mark. */
30127
export class RuleY extends RenderableMark {}

src/marks/tick.d.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export interface TickXOptions extends MarkOptions, Omit<InsetOptions, "insetLeft
1515
* bound to the *y* scale. If not specified, the tick spans the vertical
1616
* extent of the frame; otherwise the *y* scale must be a *band* scale.
1717
*
18-
* If **y** represents quantitative or temporal values, use a ruleX mark
18+
* If *y* represents quantitative or temporal values, use a ruleX mark
1919
* instead.
2020
*/
2121
y?: ChannelValueSpec;
@@ -35,7 +35,7 @@ export interface TickYOptions extends MarkOptions, Omit<InsetOptions, "insetTop"
3535
* horizontal extent of the frame; otherwise the *x* scale must be a *band*
3636
* scale.
3737
*
38-
* If **x** represents quantitative or temporal values, use a ruleY mark
38+
* If *x* represents quantitative or temporal values, use a ruleY mark
3939
* instead.
4040
*/
4141
x?: ChannelValueSpec;
@@ -52,8 +52,7 @@ export interface TickYOptions extends MarkOptions, Omit<InsetOptions, "insetTop"
5252
* Plot.tickX(penguins, {x: "body_mass_g", y: "sex", stroke: "species"})
5353
* ```
5454
*
55-
* If **y** represents quantitative or temporal values, use a ruleX mark
56-
* instead.
55+
* If *y* represents quantitative or temporal values, use a ruleX mark instead.
5756
*/
5857
export function tickX(data?: Data, options?: TickXOptions): TickX;
5958

@@ -62,14 +61,13 @@ export function tickX(data?: Data, options?: TickXOptions): TickX;
6261
* given *data* and *options*. The **y** channel specifies the vertical position
6362
* of the tick and defaults to identity, assuming that *data* = [*y₀*, *y₁*,
6463
* *y₂*, …]; the optional **x** categorical channel specifies its horizontal
65-
* position. For example, fpr a vertical barcode plot of penguins’ weights:
64+
* position. For example, for a vertical barcode plot of penguins’ weights:
6665
*
6766
* ```js
6867
* Plot.tickY(penguins, {y: "body_mass_g", x: "sex", stroke: "species"})
6968
* ```
7069
*
71-
* If **x** represents quantitative or temporal values, use a ruleY mark
72-
* instead.
70+
* If *x* represents quantitative or temporal values, use a ruleY mark instead.
7371
*/
7472
export function tickY(data?: Data, options?: TickYOptions): TickY;
7573

0 commit comments

Comments
 (0)