Skip to content

Commit 7da8c60

Browse files
Filchaichontat
authored andcommitted
document line (observablehq#1401)
* document line * z
1 parent c5e9631 commit 7da8c60

File tree

2 files changed

+140
-6
lines changed

2 files changed

+140
-6
lines changed

src/marks/area.d.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export interface AreaOptions extends MarkOptions, StackOptions, CurveOptions {
3838

3939
/**
4040
* The optional ordinal **z** channel, for grouping data into (possibly
41-
* stacked) series to be drawn as separate areas. If not specified, it
42-
* defaults to **fill** if a channel, or **stroke** if a channel.
41+
* stacked) series to be drawn as separate areas; defaults to **fill** if a
42+
* channel, or **stroke** if a channel.
4343
*/
4444
z?: ChannelValue;
4545
}
@@ -59,9 +59,9 @@ export interface AreaXOptions extends Omit<AreaOptions, "y1" | "y2">, BinOptions
5959

6060
/**
6161
* The vertical position channel, typically bound to the *y* scale; defaults
62-
* to the zero-based index of the data.
62+
* to the zero-based index of the data [0, 1, 2, …].
6363
*
64-
* If an **interval** is specified, **x** values are binned accordingly,
64+
* If an **interval** is specified, **y** values are binned accordingly,
6565
* allowing zeroes for empty bins instead of interpolating across gaps. This
6666
* is recommended to “regularize” sampled data; for example, if your data
6767
* represents timestamped observations and you expect one observation per day,
@@ -77,6 +77,9 @@ export interface AreaXOptions extends Omit<AreaOptions, "y1" | "y2">, BinOptions
7777
* ```js
7878
* Plot.areaX(data, {y: "value", interval: 0.5, reduce: "count"})
7979
* ```
80+
*
81+
* To default to zero instead of showing gaps in data, as when the observed
82+
* value represents a quantity, use the *sum* reducer.
8083
*/
8184
reduce?: BinReducer;
8285
}
@@ -85,7 +88,7 @@ export interface AreaXOptions extends Omit<AreaOptions, "y1" | "y2">, BinOptions
8588
export interface AreaYOptions extends Omit<AreaOptions, "x1" | "x2">, BinOptions {
8689
/**
8790
* The horizontal position channel, typically bound to the *x* scale; defaults
88-
* to the zero-based index of the data.
91+
* to the zero-based index of the data [0, 1, 2, …].
8992
*
9093
* If an **interval** is specified, **x** values are binned accordingly,
9194
* allowing zeroes for empty bins instead of interpolating across gaps. This
@@ -114,6 +117,9 @@ export interface AreaYOptions extends Omit<AreaOptions, "x1" | "x2">, BinOptions
114117
* ```js
115118
* Plot.areaY(records, {x: "Date", interval: "month", reduce: "count"})
116119
* ```
120+
*
121+
* To default to zero instead of showing gaps in data, as when the observed
122+
* value represents a quantity, use the *sum* reducer.
117123
*/
118124
reduce?: BinReducer;
119125
}
@@ -148,7 +154,7 @@ export function area(data?: Data, options?: AreaOptions): Area;
148154
export function areaX(data?: Data, options?: AreaXOptions): Area;
149155

150156
/**
151-
* Returns a new horizontall-oriented area for the given *data* and *options*,
157+
* Returns a new horizontally-oriented area for the given *data* and *options*,
152158
* where the baseline and topline share **x** values, as in a time-series area
153159
* chart where time goes right→.
154160
*

src/marks/line.d.ts

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,154 @@ import type {Data, MarkOptions, RenderableMark} from "../mark.js";
44
import type {MarkerOptions} from "../marker.js";
55
import type {BinOptions, BinReducer} from "../transforms/bin.js";
66

7+
/** Options for the line mark. */
78
export interface LineOptions extends MarkOptions, MarkerOptions, CurveAutoOptions {
9+
/**
10+
* The required horizontal position channel, typically bound to the *x* scale.
11+
*/
812
x?: ChannelValueSpec;
13+
14+
/**
15+
* The required vertical position channel, typically bound to the *y* scale.
16+
*/
917
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+
*/
1024
z?: ChannelValue;
1125
}
1226

27+
/** Options for the lineX mark. */
1328
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+
*/
1439
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+
*/
1553
reduce?: BinReducer;
1654
}
1755

56+
/** Options for the lineY mark. */
1857
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+
*/
1968
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+
*/
2082
reduce?: BinReducer;
2183
}
2284

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+
*/
23113
export function line(data?: Data, options?: LineOptions): Line;
24114

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+
*/
25133
export function lineX(data?: Data, options?: LineXOptions): Line;
26134

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+
*/
27154
export function lineY(data?: Data, options?: LineYOptions): Line;
28155

156+
/** The line mark. */
29157
export class Line extends RenderableMark {}

0 commit comments

Comments
 (0)