@@ -4,26 +4,154 @@ import type {Data, MarkOptions, RenderableMark} from "../mark.js";
4
4
import type { MarkerOptions } from "../marker.js" ;
5
5
import type { BinOptions , BinReducer } from "../transforms/bin.js" ;
6
6
7
+ /** Options for the line mark. */
7
8
export interface LineOptions extends MarkOptions , MarkerOptions , CurveAutoOptions {
9
+ /**
10
+ * The required horizontal position channel, typically bound to the *x* scale.
11
+ */
8
12
x ?: ChannelValueSpec ;
13
+
14
+ /**
15
+ * The required vertical position channel, typically bound to the *y* scale.
16
+ */
9
17
y ?: ChannelValueSpec ;
18
+
19
+ /**
20
+ * The optional ordinal **z** channel, for grouping data into (possibly
21
+ * stacked) series to be drawn as separate lines. If not specified, it
22
+ * defaults to **fill** if a channel, or **stroke** if a channel.
23
+ */
10
24
z ?: ChannelValue ;
11
25
}
12
26
27
+ /** Options for the lineX mark. */
13
28
export interface LineXOptions extends LineOptions , BinOptions {
29
+ /**
30
+ * The vertical position channel, typically bound to the *y* scale; defaults
31
+ * to the zero-based index of the data [0, 1, 2, …].
32
+ *
33
+ * If an **interval** is specified, **y** values are binned accordingly,
34
+ * allowing zeroes for empty bins instead of interpolating across gaps. This
35
+ * is recommended to “regularize” sampled data; for example, if your data
36
+ * represents timestamped observations and you expect one observation per day,
37
+ * use *day* as the **interval**.
38
+ */
14
39
y ?: ChannelValueDenseBinSpec ;
40
+
41
+ /**
42
+ * How to reduce **x** values when the **y** channel is binned with an
43
+ * **interval**; defaults to *first*. For example, to create a vertical
44
+ * density plot (count of *y* values binned every 0.5):
45
+ *
46
+ * ```js
47
+ * Plot.lineX(data, {y: "value", interval: 0.5, reduce: "count"})
48
+ * ```
49
+ *
50
+ * To default to zero instead of showing gaps in data, as when the observed
51
+ * value represents a quantity, use the *sum* reducer.
52
+ */
15
53
reduce ?: BinReducer ;
16
54
}
17
55
56
+ /** Options for the lineY mark. */
18
57
export interface LineYOptions extends LineOptions , BinOptions {
58
+ /**
59
+ * The horizontal position channel, typically bound to the *x* scale; defaults
60
+ * to the zero-based index of the data [0, 1, 2, …].
61
+ *
62
+ * If an **interval** is specified, **x** values are binned accordingly,
63
+ * allowing zeroes for empty bins instead of interpolating across gaps. This
64
+ * is recommended to “regularize” sampled data; for example, if your data
65
+ * represents timestamped observations and you expect one observation per day,
66
+ * use *day* as the **interval**.
67
+ */
19
68
x ?: ChannelValueDenseBinSpec ;
69
+
70
+ /**
71
+ * How to reduce **y** values when the **x** channel is binned with an
72
+ * **interval**; defaults to *first*. For example, for a line chart of the
73
+ * count of records by month:
74
+ *
75
+ * ```js
76
+ * Plot.lineY(records, {x: "Date", interval: "month", reduce: "count"})
77
+ * ```
78
+ *
79
+ * To default to zero instead of showing gaps in data, as when the observed
80
+ * value represents a quantity, use the *sum* reducer.
81
+ */
20
82
reduce ?: BinReducer ;
21
83
}
22
84
85
+ /**
86
+ * Returns a new line for the given *data* and *options* by connecting control
87
+ * points. If neither the **x** nor **y** options are specified, *data* is
88
+ * assumed to be an array of pairs [[*x₀*, *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …]
89
+ * such that **x** = [*x₀*, *x₁*, *x₂*, …] and **y** = [*y₀*, *y₁*, *y₂*, …].
90
+ *
91
+ * Points along the line are connected in input order. If there are multiple
92
+ * series via the **z**, **fill**, or **stroke** channel, series are drawn in
93
+ * input order such that the last series is drawn on top. Typically *data* is
94
+ * already in sorted order, such as chronological for time series; if needed,
95
+ * consider a **sort** transform.
96
+ *
97
+ * If any **x** or **y** values are invalid (undefined, null, or NaN), the line
98
+ * will be interrupted, resulting in a break that divides the line shape into
99
+ * multiple segments. If a line segment consists of only a single point, it may
100
+ * appear invisible unless rendered with rounded or square line caps. In
101
+ * addition, some curves such as *cardinal-open* only render a visible segment
102
+ * if it contains multiple points.
103
+ *
104
+ * Variable aesthetic channels are supported: if the **stroke** is defined as a
105
+ * channel, the line will be broken into contiguous overlapping segments when
106
+ * the stroke color changes; the stroke color will apply to the interval
107
+ * spanning the current data point and the following data point. This behavior
108
+ * also applies to the **fill**, **fillOpacity**, **strokeOpacity**,
109
+ * **strokeWidth**, **opacity**, **href**, **title**, and **ariaLabel**
110
+ * channels. When any of these channels are used, setting an explicit **z**
111
+ * channel (possibly to null) is strongly recommended.
112
+ */
23
113
export function line ( data ?: Data , options ?: LineOptions ) : Line ;
24
114
115
+ /**
116
+ * Like line, except that **x** defaults to the identity function assuming that
117
+ * *data* = [*x₀*, *x₁*, *x₂*, …] and **y** defaults to the zero-based index [0,
118
+ * 1, 2, …]. For example, to draw a vertical line chart of a temperature series:
119
+ *
120
+ * ```js
121
+ * Plot.lineX(observations, {x: "temperature"})
122
+ * ```
123
+ *
124
+ * The **interval** option is recommended to “regularize” sampled data via an
125
+ * implicit binY transform. For example, if your data represents timestamped
126
+ * temperature measurements and you expect one sample per day, use *day* as the
127
+ * interval:
128
+ *
129
+ * ```js
130
+ * Plot.lineX(observations, {y: "date", x: "temperature", interval: "day"})
131
+ * ```
132
+ */
25
133
export function lineX ( data ?: Data , options ?: LineXOptions ) : Line ;
26
134
135
+ /**
136
+ * Like line, except **y** defaults to the identity function and assumes that
137
+ * *data* = [*y₀*, *y₁*, *y₂*, …] and **x** defaults to the zero-based index [0,
138
+ * 1, 2, …]. For example, to draw a horizontal line chart of a temperature
139
+ * series:
140
+ *
141
+ * ```js
142
+ * Plot.lineY(observations, {y: "temperature"})
143
+ * ```
144
+ *
145
+ * The **interval** option is recommended to “regularize” sampled data via an
146
+ * implicit binX transform. For example, if your data represents timestamped
147
+ * temperature measurements and you expect one sample per day, use *day* as the
148
+ * interval:
149
+ *
150
+ * ```js
151
+ * Plot.lineY(observations, {x: "date", y: "temperature", interval: "day"})
152
+ * ```
153
+ */
27
154
export function lineY ( data ?: Data , options ?: LineYOptions ) : Line ;
28
155
156
+ /** The line mark. */
29
157
export class Line extends RenderableMark { }
0 commit comments