Skip to content

Commit f469f7f

Browse files
tophtuckerFilmbostock
authored
document auto (#1385)
* Draft: jsdoc comments for auto mark * channel names in boldface, string option in italics Co-authored-by: Philippe Rivière <[email protected]> * Update src/marks/auto.d.ts Co-authored-by: Philippe Rivière <[email protected]> * option (strings) in italics, marks in bold Co-authored-by: Philippe Rivière <[email protected]> * add more auto jsdocs * Correct column name in jsdoc example Co-authored-by: Philippe Rivière <[email protected]> * correct column name * MarkType jsdoc * typo Co-authored-by: Philippe Rivière <[email protected]> * edits * checkpoint edits * fix AutoSpec["color"] type * edits * edits --------- Co-authored-by: Philippe Rivière <[email protected]> Co-authored-by: Mike Bostock <[email protected]>
1 parent 9b165f8 commit f469f7f

File tree

2 files changed

+117
-6
lines changed

2 files changed

+117
-6
lines changed

src/mark.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,13 @@ export interface MarkOptions {
127127
initializer?: InitializerFunction;
128128

129129
/**
130-
* The horizontal facet position, a channel for mark-level faceting bound to
130+
* The horizontal facet position channel, for mark-level faceting, bound to
131131
* the *fx* scale.
132132
*/
133133
fx?: ChannelValue;
134134

135135
/**
136-
* The vertical facet position, a channel for mark-level faceting bound to the
136+
* The vertical facet position channel, for mark-level faceting, bound to the
137137
* *fy* scale.
138138
*/
139139
fy?: ChannelValue;

src/marks/auto.d.ts

Lines changed: 115 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,137 @@ import type {CompoundMark, Data} from "../mark.js";
33
import type {Reducer} from "../reducer.js";
44
import type {BinOptions} from "../transforms/bin.js";
55

6+
/** Options for the auto mark. */
67
export interface AutoOptions {
8+
/**
9+
* The horizontal position channel (**value**) and reducer (**reduce**).
10+
*
11+
* The **x** channel is required if a **y** channel is not specified;
12+
* otherwise it is optional.
13+
*
14+
* If an **x** **reduce** is specified, a **y** channel is required and a
15+
* **y** reduce is not allowed; the **y** channel will be grouped, and the
16+
* reducer will be applied to each group’s associated **x** channel values (if
17+
* any). If a **y** channel is set, but no **x** channel, the **x** **reduce**
18+
* defaults to *count* to produce a histogram by grouping on **y**; disable
19+
* this by setting the **x** **reduce** to null.
20+
*
21+
* The **zero** option, if true, draws a vertical rule at *x* = 0, and ensures
22+
* that the default *x* scale domain includes 0.
23+
*/
724
x?: ChannelValue | Reducer | ({value?: ChannelValue; reduce?: Reducer | null; zero?: boolean} & BinOptions);
25+
26+
/**
27+
* The vertical position channel (**value**) and reducer (**reduce**).
28+
*
29+
* The **y** channel is required if an **x** channel is not specified;
30+
* otherwise it is optional.
31+
*
32+
* If a **y** **reduce** is specified, an **x** channel is required, and an
33+
* **x** reduce is not allowed; the **x** channel will be grouped, and the
34+
* reducer will be applied to each group’s associated **y** channel values (if
35+
* any). If a **x** channel is set, but no **y** channel, the **y** **reduce**
36+
* defaults to *count* to produce a histogram by grouping on **x**; disable
37+
* this by setting the **y** **reduce** to null.
38+
*
39+
* The **zero** option, if true, draws a horizontal rule at *y* = 0, and
40+
* ensures that the default *y* scale domain includes 0.
41+
*/
842
y?: ChannelValue | Reducer | ({value?: ChannelValue; reduce?: Reducer | null; zero?: boolean} & BinOptions);
43+
44+
/**
45+
* The color channel (**value**) and reducer (**reduce**), or a constant color
46+
* such as *red* for aesthetics (**color**). This option corresponds to the
47+
* **stroke** channel for dots, lines, and rules, and the **fill** channel for
48+
* areas and bars. If a color channel or reducer is specified, the constant
49+
* color is ignored.
50+
*
51+
* If neither a **x** nor **y** **reduce** is specified, but a **color**
52+
* **reduce** is specified, both the **x** and **y** channels (if any) will be
53+
* grouped, and the reducer will be applied to each group’s associated
54+
* **color** channel values (if any), say to produce a heatmap.
55+
*/
956
color?: ChannelValue | Reducer | {value?: ChannelValue; reduce?: Reducer | null; color?: string};
57+
58+
/**
59+
* The size channel (**value**) and reducer (**reduce**). This option
60+
* corresponds to the **r** channel for dots; it may correspond to the
61+
* **length** of vectors in the future.
62+
*
63+
* If neither a **x** nor **y** **reduce** is specified, but a **size**
64+
* **reduce** is specified, both the **x** and **y** channels (if any) will be
65+
* grouped, and the reducer will be applied to each group’s associated
66+
* **size** channel values (if any), say to produce a binned scatterplot.
67+
*/
1068
size?: ChannelValue | Reducer | {value?: ChannelValue; reduce?: Reducer | null};
69+
70+
/**
71+
* The horizontal facet position channel (**value**), for mark-level faceting,
72+
* bound to the *fx* scale.
73+
*/
1174
fx?: ChannelValue | {value?: ChannelValue};
75+
76+
/**
77+
* The vertical facet position channel (**value**), for mark-level faceting,
78+
* bound to the *fy* scale.
79+
*/
1280
fy?: ChannelValue | {value?: ChannelValue};
13-
mark?: "dot" | "line" | "area" | "rule" | "bar";
81+
82+
/**
83+
* The desired mark type; one of:
84+
*
85+
* - *area* - an area
86+
* - *bar* - a rect, cell, or bar (depending on the data type)
87+
* - *dot* - a dot
88+
* - *line* - a line
89+
* - *rule* - a rule
90+
*
91+
* Whenever possible, avoid setting the mark type; the default mark type
92+
* should usually suffice, and setting an explicit mark type may lead to a
93+
* nonsensical plot (especially if you change other options).
94+
*/
95+
mark?: "area" | "bar" | "dot" | "line" | "rule";
1496
}
1597

98+
/**
99+
* An auto options object with nothing left undefined, as returned by
100+
* Plot.autoSpec; the mark type, reducers, and other options will be populated.
101+
*/
16102
export interface AutoSpec extends AutoOptions {
17-
x: {value: ChannelValue; reduce: Reducer | null; zero?: boolean} & BinOptions;
18-
y: {value: ChannelValue; reduce: Reducer | null; zero?: boolean} & BinOptions;
103+
x: {value: ChannelValue; reduce: Reducer | null; zero: boolean} & BinOptions;
104+
y: {value: ChannelValue; reduce: Reducer | null; zero: boolean} & BinOptions;
19105
color: {value: ChannelValue; reduce: Reducer | null; color?: string};
20106
size: {value: ChannelValue; reduce: Reducer | null};
21107
fx: ChannelValue;
22108
fy: ChannelValue;
23-
mark: "dot" | "line" | "area" | "rule" | "bar";
109+
mark: NonNullable<AutoOptions["mark"]>;
24110
}
25111

112+
/**
113+
* Returns a fully-specified *options* object for the auto mark, with nothing
114+
* left undefined. This is mostly for internal use, but can be used to “lock
115+
* down” the specification of an auto mark or to interrogate its behavior. For
116+
* example, if you say
117+
*
118+
* ```js
119+
* Plot.autoSpec(penguins, {x: "body_mass_g"})
120+
* ```
121+
*
122+
* the returned object will have **y** set to {value: null, reduce: *count*} and
123+
* **mark** set to *bar*, telling you that a histogram will be rendered.
124+
*/
26125
export function autoSpec(data?: Data, options?: AutoOptions): AutoSpec;
27126

127+
/**
128+
* Returns a new mark whose implementation is chosen dynamically to best
129+
* represent the dimensions of the given *data* specified in *options*,
130+
* according to a few simple heuristics. The auto mark seeks to provide a useful
131+
* initial plot as quickly as possible through opinionated defaults, and to
132+
* accelerate exploratory analysis by letting you refine views with minimal
133+
* changes to code. For example, for a histogram of penguins binned by weight:
134+
*
135+
* ```js
136+
* Plot.auto(penguins, {x: "body_mass_g"})
137+
* ```
138+
*/
28139
export function auto(data?: Data, options?: AutoOptions): CompoundMark;

0 commit comments

Comments
 (0)