Skip to content

Commit 666a547

Browse files
Filmbostock
andauthored
document cell (#1396)
* document cell * a note about barX/Y * edits * edit --------- Co-authored-by: Mike Bostock <[email protected]>
1 parent a90261f commit 666a547

File tree

4 files changed

+92
-68
lines changed

4 files changed

+92
-68
lines changed

src/marks/bar.d.ts

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
import type {ChannelValueIntervalSpec, ChannelValueSpec} from "../channel.js";
2-
import type {Interval} from "../interval.js";
32
import type {InsetOptions} from "../inset.js";
3+
import type {Interval} from "../interval.js";
44
import type {Data, MarkOptions, RenderableMark} from "../mark.js";
55
import type {StackOptions} from "../transforms/stack.js";
6+
import type {RectCornerOptions} from "./rect.js";
67

78
/** Options for the barX and barY marks. */
8-
interface BarOptions extends MarkOptions, InsetOptions, StackOptions {
9-
/**
10-
* The rounded corner [*x*-radius][1], either in pixels or as a percentage of
11-
* the bar width. If **rx** is not specified, it defaults to **ry** if
12-
* present, and otherwise draws square corners.
13-
*
14-
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx
15-
*/
16-
rx?: number | string;
17-
18-
/**
19-
* The rounded corner [*y*-radius][1], either in pixels or as a percentage of
20-
* the bar height. If **ry** is not specified, it defaults to **rx** if
21-
* present, and otherwise draws square corners.
22-
*
23-
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry
24-
*/
25-
ry?: number | string;
26-
9+
interface BarOptions extends MarkOptions, InsetOptions, RectCornerOptions, StackOptions {
2710
/**
2811
* How to convert a continuous value (**x** for barX, or **y** for barY) into
2912
* an interval (**x1** and **x2** for barX, or **y1** and **y2** for barY);
@@ -82,7 +65,7 @@ export interface BarXOptions extends BarOptions {
8265
x2?: ChannelValueSpec;
8366

8467
/**
85-
* The optional vertical position of the bar; a categorical channel typically
68+
* The optional vertical position of the bar; a ordinal channel typically
8669
* bound to the *y* scale. If not specified, the bar spans the vertical extent
8770
* of the frame; otherwise the *y* scale must be a *band* scale.
8871
*
@@ -127,10 +110,9 @@ export interface BarYOptions extends BarOptions {
127110
y2?: ChannelValueSpec;
128111

129112
/**
130-
* The optional horizontal position of the bar; a categorical channel
131-
* typically bound to the *x* scale. If not specified, the bar spans the
132-
* horizontal extent of the frame; otherwise the *x* scale must be a *band*
133-
* scale.
113+
* The optional horizontal position of the bar; a ordinal channel typically
114+
* bound to the *x* scale. If not specified, the bar spans the horizontal
115+
* extent of the frame; otherwise the *x* scale must be a *band* scale.
134116
*
135117
* If *x* represents quantitative or temporal values, use a rectY mark
136118
* instead.

src/marks/cell.d.ts

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,74 @@
11
import type {ChannelValueSpec} from "../channel.js";
22
import type {InsetOptions} from "../inset.js";
33
import type {Data, MarkOptions, RenderableMark} from "../mark.js";
4+
import type {RectCornerOptions} from "./rect.js";
45

5-
export interface CellOptions extends MarkOptions, InsetOptions {
6+
/** Options for the cell mark. */
7+
export interface CellOptions extends MarkOptions, InsetOptions, RectCornerOptions {
8+
/**
9+
* The horizontal position of the cell; an optional ordinal channel typically
10+
* bound to the *x* scale. If not specified, the cell spans the horizontal
11+
* extent of the frame; otherwise the *x* scale must be a *band* scale.
12+
*
13+
* If *x* represents quantitative or temporal values, use a barX mark instead;
14+
* if *y* is also quantitative or temporal, use a rect mark.
15+
*/
616
x?: ChannelValueSpec;
17+
18+
/**
19+
* The vertical position of the cell; an optional ordinal channel typically
20+
* bound to the *y* scale. If not specified, the cell spans the vertical
21+
* extent of the frame; otherwise the *y* scale must be a *band* scale.
22+
*
23+
* If *y* represents quantitative or temporal values, use a barY mark instead;
24+
* if *x* is also quantitative or temporal, use a rect mark.
25+
*/
726
y?: ChannelValueSpec;
8-
rx?: number | string;
9-
ry?: number | string;
1027
}
1128

29+
/**
30+
* Returns a rectangular cell mark for the given *data* and *options*. Along
31+
* with **x** and/or **y**, a **fill** channel is typically specified to encode
32+
* value as color. For example, for a heatmap of the IMDb ratings of Simpons
33+
* episodes by season:
34+
*
35+
* ```js
36+
* Plot.cell(simpsons, {x: "number_in_season", y: "season", fill: "imdb_rating"})
37+
* ```
38+
*
39+
* If neither **x** nor **y** are specified, *data* is assumed to be an array of
40+
* pairs [[*x₀*, *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …] such that **x** = [*x₀*,
41+
* *x₁*, *x₂*, …] and **y** = [*y₀*, *y₁*, *y₂*, …].
42+
*
43+
* Both **x** and **y** should be ordinal; if only **x** is quantitative (or
44+
* temporal), use a barX mark; if only **y** is quantitative, use a barY mark;
45+
* if both are quantitative, use a rect mark.
46+
*/
1247
export function cell(data?: Data, options?: CellOptions): Cell;
1348

49+
/**
50+
* Like cell, but **x** defaults to the zero-based index [0, 1, 2, …], and if
51+
* **stroke** is not a channel, **fill** defaults to the identity function,
52+
* assuming that *data* = [*x₀*, *x₁*, *x₂*, …]. For a quick horizontal stripe
53+
* map visualizating an array of numbers:
54+
*
55+
* ```js
56+
* Plot.cellX(values)
57+
* ```
58+
*/
1459
export function cellX(data?: Data, options?: CellOptions): Cell;
1560

61+
/**
62+
* Like cell, but **y** defaults to the zero-based index [0, 1, 2, …], and if
63+
* **stroke** is not a channel, **fill** defaults to the identity function,
64+
* assuming that *data* = [*y₀*, *y₁*, *y₂*, …]. For a quick vertical stripe map
65+
* visualizating an array of numbers:
66+
*
67+
* ```js
68+
* Plot.cellY(values)
69+
* ```
70+
*/
1671
export function cellY(data?: Data, options?: CellOptions): Cell;
1772

73+
/** The cell mark. */
1874
export class Cell extends RenderableMark {}

src/marks/frame.d.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,15 @@
11
import type {InsetOptions} from "../inset.js";
22
import type {MarkOptions, RenderableMark} from "../mark.js";
3+
import type {RectCornerOptions} from "./rect.js";
34

45
/** Options for the frame decoration mark. */
5-
export interface FrameOptions extends MarkOptions, InsetOptions {
6+
export interface FrameOptions extends MarkOptions, InsetOptions, RectCornerOptions {
67
/**
78
* If null (default), the rectangular outline of the frame is drawn; otherwise
89
* the frame is drawn as a line only on the given side, and the **rx**,
910
* **ry**, **fill**, and **fillOpacity** options are ignored.
1011
*/
1112
anchor?: "top" | "right" | "bottom" | "left" | null;
12-
13-
/**
14-
* The rounded corner [*x*-radius][1], either in pixels or as a percentage of
15-
* the frame width. If **rx** is not specified, it defaults to **ry** if
16-
* present, and otherwise draws square corners.
17-
*
18-
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx
19-
*/
20-
rx?: number | string;
21-
22-
/**
23-
* The rounded corner [*y*-radius][1], either in pixels or as a percentage of
24-
* the frame height. If **ry** is not specified, it defaults to **rx** if
25-
* present, and otherwise draws square corners.
26-
*
27-
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry
28-
*/
29-
ry?: number | string;
3013
}
3114

3215
/**

src/marks/rect.d.ts

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,29 @@ import type {Interval} from "../interval.js";
44
import type {Data, MarkOptions, RenderableMark} from "../mark.js";
55
import type {StackOptions} from "../transforms/stack.js";
66

7+
/** Options for marks that render rectangles, including bar, cell, and rect. */
8+
export interface RectCornerOptions {
9+
/**
10+
* The rounded corner [*x*-radius][1], either in pixels or as a percentage of
11+
* the rect width. If **rx** is not specified, it defaults to **ry** if
12+
* present, and otherwise draws square corners.
13+
*
14+
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx
15+
*/
16+
rx?: number | string;
17+
18+
/**
19+
* The rounded corner [*y*-radius][1], either in pixels or as a percentage of
20+
* the rect height. If **ry** is not specified, it defaults to **rx** if
21+
* present, and otherwise draws square corners.
22+
*
23+
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry
24+
*/
25+
ry?: number | string;
26+
}
27+
728
/** Options for the rect mark. */
8-
export interface RectOptions extends MarkOptions, InsetOptions, StackOptions {
29+
export interface RectOptions extends MarkOptions, InsetOptions, RectCornerOptions, StackOptions {
930
/**
1031
* The horizontal position (or length/width) channel, typically bound to the
1132
* *x* scale.
@@ -94,24 +115,6 @@ export interface RectOptions extends MarkOptions, InsetOptions, StackOptions {
94115
* or stackY for rectY).
95116
*/
96117
interval?: Interval;
97-
98-
/**
99-
* The rounded corner [*x*-radius][1], either in pixels or as a percentage of
100-
* the bar width. If **rx** is not specified, it defaults to **ry** if
101-
* present, and otherwise draws square corners.
102-
*
103-
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/rx
104-
*/
105-
rx?: number | string;
106-
107-
/**
108-
* The rounded corner [*y*-radius][1], either in pixels or as a percentage of
109-
* the bar height. If **ry** is not specified, it defaults to **rx** if
110-
* present, and otherwise draws square corners.
111-
*
112-
* [1]: https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/ry
113-
*/
114-
ry?: number | string;
115118
}
116119

117120
/** Options for the rectX mark. */
@@ -145,8 +148,8 @@ export interface RectYOptions extends RectOptions {
145148
/**
146149
* Returns a rect mark for the given *data* and *options*. The rectangle extends
147150
* horizontally from **x1** to **x2**, and vertically from **y1** to **y2**. The
148-
* position channels are often derived with a transform. For example, to create
149-
* a heatmap of athletes, binned by weight and height:
151+
* position channels are often derived with a transform. For example, for a
152+
* heatmap of athletes, binned by weight and height:
150153
*
151154
* ```js
152155
* Plot.rect(athletes, Plot.bin({fill: "proportion"}, {x: "weight", y: "height"}))

0 commit comments

Comments
 (0)