@@ -3,26 +3,137 @@ import type {CompoundMark, Data} from "../mark.js";
3
3
import type { Reducer } from "../reducer.js" ;
4
4
import type { BinOptions } from "../transforms/bin.js" ;
5
5
6
+ /** Options for the auto mark. */
6
7
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
+ */
7
24
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
+ */
8
42
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
+ */
9
56
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
+ */
10
68
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
+ */
11
74
fx ?: ChannelValue | { value ?: ChannelValue } ;
75
+
76
+ /**
77
+ * The vertical facet position channel (**value**), for mark-level faceting,
78
+ * bound to the *fy* scale.
79
+ */
12
80
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" ;
14
96
}
15
97
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
+ */
16
102
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 ;
19
105
color : { value : ChannelValue ; reduce : Reducer | null ; color ?: string } ;
20
106
size : { value : ChannelValue ; reduce : Reducer | null } ;
21
107
fx : ChannelValue ;
22
108
fy : ChannelValue ;
23
- mark : "dot" | "line" | "area" | "rule" | "bar" ;
109
+ mark : NonNullable < AutoOptions [ "mark" ] > ;
24
110
}
25
111
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
+ */
26
125
export function autoSpec ( data ?: Data , options ?: AutoOptions ) : AutoSpec ;
27
126
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
+ */
28
139
export function auto ( data ?: Data , options ?: AutoOptions ) : CompoundMark ;
0 commit comments