|
1 |
| -import type {CompoundMark, Data, MarkOptions, RenderableMark} from "../mark.js"; |
| 1 | +import type {CompoundMark, Data, MarkOptions} from "../mark.js"; |
2 | 2 | import type {ScaleOptions} from "../scales.js";
|
3 |
| -import type {RuleXOptions, RuleYOptions} from "./rule.js"; |
| 3 | +import type {RuleX, RuleXOptions, RuleY, RuleYOptions} from "./rule.js"; |
4 | 4 | import type {TextOptions} from "./text.js";
|
5 | 5 | import type {TickXOptions, TickYOptions} from "./tick.js";
|
6 | 6 |
|
7 |
| -export type AxisAnchor = "top" | "right" | "bottom" | "left"; |
8 |
| - |
9 |
| -interface GridOptions { |
10 |
| - anchor?: AxisAnchor; |
11 |
| - interval?: ScaleOptions["interval"]; |
12 |
| - ticks?: ScaleOptions["ticks"]; |
13 |
| - tickSpacing?: ScaleOptions["tickSpacing"]; |
| 7 | +/** The subset of scale options for grids. */ |
| 8 | +type GridScaleOptions = Pick<ScaleOptions, "interval" | "ticks" | "tickSpacing">; |
| 9 | + |
| 10 | +/** The subset of scale options for axes. */ |
| 11 | +type AxisScaleOptions = Pick<ScaleOptions, "tickSize" | "tickPadding" | "tickFormat" | "tickRotate" | "label" | "labelOffset" | "labelAnchor">; // prettier-ignore |
| 12 | + |
| 13 | +/** Options for the grid marks. */ |
| 14 | +export interface GridOptions extends GridScaleOptions { |
| 15 | + /** |
| 16 | + * The side of the frame on which to place the axis: *top* or *bottom* for |
| 17 | + * horizontal axes (axisX and axisFx) and their associated vertical grids |
| 18 | + * (gridX and gridFx), or *left* or *right* for vertical axes (axisY and |
| 19 | + * axisFY) and their associated horizontal grids (gridY and gridFy). |
| 20 | + * |
| 21 | + * The default **anchor** depends on the associated scale: |
| 22 | + * |
| 23 | + * - *x* - *bottom* |
| 24 | + * - *y* - *left* |
| 25 | + * - *fx* - *top* if there is a *bottom* *x* axis, and otherwise *bottom* |
| 26 | + * - *fy* - *right* if there is a *left* *y* axis, and otherwise *right* |
| 27 | + * |
| 28 | + * For grids, the **anchor** also affects the extent of grid lines when the |
| 29 | + * opposite dimension is specified (**x** for gridY and **y** for gridX). For |
| 30 | + * example, to draw a horizontal gridY between the *right* edge of the frame |
| 31 | + * and the specified **x** value: |
| 32 | + * |
| 33 | + * ```js |
| 34 | + * Plot.gridY({x: (y) => aapl.find((d) => d.Close >= y)?.Date, anchor: "right"}) |
| 35 | + * ``` |
| 36 | + */ |
| 37 | + anchor?: "top" | "right" | "bottom" | "left"; |
| 38 | + |
| 39 | + /** |
| 40 | + * A shorthand for setting both **fill** and **stroke**; affects the stroke of |
| 41 | + * tick vectors and grid rules, and the fill of tick texts and axis label |
| 42 | + * texts; defaults to *currentColor*. |
| 43 | + */ |
14 | 44 | color?: MarkOptions["stroke"];
|
| 45 | + |
| 46 | + /** |
| 47 | + * A shorthand for setting both **fillOpacity** and **strokeOpacity**; affects |
| 48 | + * the stroke opacity of tick vectors and grid rules, and the fill opacity of |
| 49 | + * tick texts and axis label texts; defaults to 1 for axes and 0.1 for grids. |
| 50 | + */ |
| 51 | + opacity?: MarkOptions["opacity"]; |
15 | 52 | }
|
16 | 53 |
|
17 |
| -interface AxisOptions extends GridOptions, MarkOptions, TextOptions { |
18 |
| - tickSize?: ScaleOptions["tickSize"]; |
19 |
| - tickPadding?: ScaleOptions["tickPadding"]; |
20 |
| - tickFormat?: ScaleOptions["tickFormat"]; |
21 |
| - tickRotate?: ScaleOptions["tickRotate"]; |
22 |
| - grid?: ScaleOptions["grid"]; |
23 |
| - line?: ScaleOptions["line"]; |
24 |
| - label?: ScaleOptions["label"]; |
25 |
| - labelOffset?: ScaleOptions["labelOffset"]; |
26 |
| - labelAnchor?: ScaleOptions["labelAnchor"]; |
| 54 | +/** Options for the axis marks. */ |
| 55 | +export interface AxisOptions extends GridOptions, MarkOptions, TextOptions, AxisScaleOptions { |
| 56 | + /** The tick text **stroke**, say for a *white* outline to improve legibility; defaults to null. */ |
27 | 57 | textStroke?: MarkOptions["stroke"];
|
| 58 | + /** The tick text **strokeOpacity**; defaults to 1; has no effect unless **textStroke** is set. */ |
28 | 59 | textStrokeOpacity?: MarkOptions["strokeOpacity"];
|
| 60 | + /** The tick text **strokeWidth**; defaults to 4; has no effect unless **textStroke** is set. */ |
29 | 61 | textStrokeWidth?: MarkOptions["strokeWidth"];
|
30 | 62 | }
|
31 | 63 |
|
| 64 | +/** Options for the axisX and axisFx marks. */ |
32 | 65 | export interface AxisXOptions extends AxisOptions, TickXOptions {}
|
33 | 66 |
|
| 67 | +/** Options for the axisY and axisFy marks. */ |
34 | 68 | export interface AxisYOptions extends AxisOptions, TickYOptions {}
|
35 | 69 |
|
| 70 | +/** Options for the gridX and gridFx marks. */ |
36 | 71 | export interface GridXOptions extends GridOptions, Omit<RuleXOptions, "interval"> {}
|
37 | 72 |
|
| 73 | +/** Options for the gridY and gridFy marks. */ |
38 | 74 | export interface GridYOptions extends GridOptions, Omit<RuleYOptions, "interval"> {}
|
39 | 75 |
|
40 |
| -export function axisY(options?: AxisYOptions): CompoundMark; |
41 |
| - |
| 76 | +/** |
| 77 | + * Returns a new compound axis mark to document the visual encoding of the |
| 78 | + * vertical position *y* scale, comprised of (up to) three marks: a vector for |
| 79 | + * ticks, a text for tick labels, and another text for an axis label. The *data* |
| 80 | + * defaults to tick values sampled from the *y* scale’s domain; if desired, |
| 81 | + * specify the axis mark’s *data* explicitly, or use one of the **ticks**, |
| 82 | + * **tickSpacing**, or **interval** options. |
| 83 | + * |
| 84 | + * The **facetAnchor** option defaults to *right-empty* if **anchor** is |
| 85 | + * *right*, and *left-empty* if **anchor** is *left*. The default margins |
| 86 | + * likewise depend on **anchor** as follows; in order of **marginTop**, |
| 87 | + * **marginRight**, **marginBottom**, and **marginLeft**, in pixels: |
| 88 | + * |
| 89 | + * - *right* - 20, 40, 20, 0 |
| 90 | + * - *left* - 20, 0, 20, 40 |
| 91 | + * |
| 92 | + * For simplicity, and for consistent layout across plots, default axis margins |
| 93 | + * are not affected by tick labels. If tick labels are too long, either increase |
| 94 | + * the margin or shorten the labels: use the *k* SI-prefix tick format; use the |
| 95 | + * **transform** *y*-scale option to show thousands or millions; or use the |
| 96 | + * **textOverflow** and **lineWidth** options to clip. |
| 97 | + */ |
42 | 98 | export function axisY(data?: Data, options?: AxisYOptions): CompoundMark;
|
| 99 | +export function axisY(options?: AxisYOptions): CompoundMark; |
43 | 100 |
|
44 |
| -export function axisFy(options?: AxisYOptions): CompoundMark; |
45 |
| - |
| 101 | +/** |
| 102 | + * Returns a new compound axis mark to document the visual encoding of the |
| 103 | + * vertical facet position *fy* scale, comprised of (up to) three marks: a |
| 104 | + * vector for ticks, a text for tick labels, and another text for an axis label. |
| 105 | + * The *data* defaults to the *fy* scale’s domain; if desired, specify the axis |
| 106 | + * mark’s *data* explicitly, or use one of the **ticks**, **tickSpacing**, or |
| 107 | + * **interval** options. |
| 108 | + * |
| 109 | + * The **facetAnchor** option defaults to *right-empty* if **anchor** is |
| 110 | + * *right*, and *left-empty* if **anchor** is *left*. The default margins |
| 111 | + * likewise depend on **anchor** as follows; in order of **marginTop**, |
| 112 | + * **marginRight**, **marginBottom**, and **marginLeft**, in pixels: |
| 113 | + * |
| 114 | + * - *right* - 20, 40, 20, 0 |
| 115 | + * - *left* - 20, 0, 20, 40 |
| 116 | + * |
| 117 | + * For simplicity, and for consistent layout across plots, default axis margins |
| 118 | + * are not affected by tick labels. If tick labels are too long, either increase |
| 119 | + * the margin or shorten the labels, say by using the **textOverflow** and |
| 120 | + * **lineWidth** options to clip. |
| 121 | + */ |
46 | 122 | export function axisFy(data?: Data, options?: AxisYOptions): CompoundMark;
|
| 123 | +export function axisFy(options?: AxisYOptions): CompoundMark; |
47 | 124 |
|
48 |
| -export function axisX(options?: AxisXOptions): CompoundMark; |
49 |
| - |
| 125 | +/** |
| 126 | + * Returns a new compound axis mark to document the visual encoding of the |
| 127 | + * horizontal position *x* scale, comprised of (up to) three marks: a vector for |
| 128 | + * ticks, a text for tick labels, and another text for an axis label. The *data* |
| 129 | + * defaults to tick values sampled from the *x* scale’s domain; if desired, |
| 130 | + * specify the axis mark’s *data* explicitly, or use one of the **ticks**, |
| 131 | + * **tickSpacing**, or **interval** options. |
| 132 | + * |
| 133 | + * The **facetAnchor** option defaults to *bottom-empty* if **anchor** is |
| 134 | + * *bottom*, and *top-empty* if **anchor** is *top*. The default margins |
| 135 | + * likewise depend on **anchor** as follows; in order of **marginTop**, |
| 136 | + * **marginRight**, **marginBottom**, and **marginLeft**, in pixels: |
| 137 | + * |
| 138 | + * - *top* - 30, 20, 0, 20 |
| 139 | + * - *bottom* - 0, 20, 30, 20 |
| 140 | + * |
| 141 | + * For simplicity, and for consistent layout across plots, default axis margins |
| 142 | + * are not affected by tick labels. If tick labels are too long, either increase |
| 143 | + * the margin or shorten the labels: use the *k* SI-prefix tick format; use the |
| 144 | + * **transform** *x*-scale option to show thousands or millions; or use the |
| 145 | + * **textOverflow** and **lineWidth** options to clip; or use the **tickRotate** |
| 146 | + * option to rotate. |
| 147 | + */ |
50 | 148 | export function axisX(data?: Data, options?: AxisXOptions): CompoundMark;
|
| 149 | +export function axisX(options?: AxisXOptions): CompoundMark; |
51 | 150 |
|
52 |
| -export function axisFx(options?: AxisXOptions): CompoundMark; |
53 |
| - |
| 151 | +/** |
| 152 | + * Returns a new compound axis mark to document the visual encoding of the |
| 153 | + * horizontal facet position *fx* scale, comprised of (up to) three marks: a |
| 154 | + * vector for ticks, a text for tick labels, and another text for an axis label. |
| 155 | + * The *data* defaults to the *fx* scale’s domain; if desired, specify the axis |
| 156 | + * mark’s *data* explicitly, or use one of the **ticks**, **tickSpacing**, or |
| 157 | + * **interval** options. |
| 158 | + * |
| 159 | + * The **facetAnchor** and **frameAnchor** options defaults to **anchor**. The |
| 160 | + * default margins likewise depend on **anchor** as follows; in order of |
| 161 | + * **marginTop**, **marginRight**, **marginBottom**, and **marginLeft**, in |
| 162 | + * pixels: |
| 163 | + * |
| 164 | + * - *top* - 30, 20, 0, 20 |
| 165 | + * - *bottom* - 0, 20, 30, 20 |
| 166 | + * |
| 167 | + * For simplicity, and for consistent layout across plots, default axis margins |
| 168 | + * are not affected by tick labels. If tick labels are too long, either increase |
| 169 | + * the margin or shorten the labels, say by using the **textOverflow** and |
| 170 | + * **lineWidth** options to clip, or using the **tickRotate** option to rotate. |
| 171 | + */ |
54 | 172 | export function axisFx(data?: Data, options?: AxisXOptions): CompoundMark;
|
| 173 | +export function axisFx(options?: AxisXOptions): CompoundMark; |
55 | 174 |
|
56 |
| -export function gridY(options?: GridYOptions): RenderableMark; |
57 |
| - |
58 |
| -export function gridY(data?: Data, options?: GridYOptions): RenderableMark; |
59 |
| - |
60 |
| -export function gridFy(options?: GridYOptions): RenderableMark; |
61 |
| - |
62 |
| -export function gridFy(data?: Data, options?: GridYOptions): RenderableMark; |
63 |
| - |
64 |
| -export function gridX(options?: GridXOptions): RenderableMark; |
65 |
| - |
66 |
| -export function gridX(data?: Data, options?: GridXOptions): RenderableMark; |
67 |
| - |
68 |
| -export function gridFx(options?: GridXOptions): RenderableMark; |
69 |
| - |
70 |
| -export function gridFx(data?: Data, options?: GridXOptions): RenderableMark; |
| 175 | +/** |
| 176 | + * Returns a new horizontally-positioned ruleX mark (a vertical line, |) that |
| 177 | + * renders a grid for the *x* scale. The *data* defaults to tick values sampled |
| 178 | + * from the *x* scale’s domain; if desired, specify the *data* explicitly, or |
| 179 | + * use one of the **ticks**, **tickSpacing**, or **interval** options. |
| 180 | + */ |
| 181 | +export function gridX(data?: Data, options?: GridXOptions): RuleX; |
| 182 | +export function gridX(options?: GridXOptions): RuleX; |
| 183 | + |
| 184 | +/** |
| 185 | + * Returns a new horizontally-positioned ruleX mark (a vertical line, |) that |
| 186 | + * renders a grid for the *fx* scale. The *data* defaults to the *fx* scale’s |
| 187 | + * domain; if desired, specify the *data* explicitly, or use the **ticks** |
| 188 | + * option. |
| 189 | + */ |
| 190 | +export function gridFx(data?: Data, options?: GridXOptions): RuleX; |
| 191 | +export function gridFx(options?: GridXOptions): RuleX; |
| 192 | + |
| 193 | +/** |
| 194 | + * Returns a new vertically-positioned ruleY mark (a horizontal line, —) that |
| 195 | + * renders a grid for the *y* scale. The *data* defaults to tick values sampled |
| 196 | + * from the *y* scale’s domain; if desired, specify the *data* explicitly, or |
| 197 | + * use one of the **ticks**, **tickSpacing**, or **interval** options. |
| 198 | + */ |
| 199 | +export function gridY(data?: Data, options?: GridYOptions): RuleY; |
| 200 | +export function gridY(options?: GridYOptions): RuleY; |
| 201 | + |
| 202 | +/** |
| 203 | + * Returns a new vertically-positioned ruleY mark (a horizontal line, —) that |
| 204 | + * renders a grid for the *fy* scale. The *data* defaults to the *fy* scale’s |
| 205 | + * domain; if desired, specify the *data* explicitly, or use the **ticks** |
| 206 | + * option. |
| 207 | + */ |
| 208 | +export function gridFy(data?: Data, options?: GridYOptions): RuleY; |
| 209 | +export function gridFy(options?: GridYOptions): RuleY; |
0 commit comments