Skip to content

Commit e929e17

Browse files
committed
mark docs
1 parent c99f0a8 commit e929e17

File tree

2 files changed

+94
-7
lines changed

2 files changed

+94
-7
lines changed

src/channel.d.ts

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,12 @@ export type ChannelValueDenseBinSpec = ChannelValue | ({value: ChannelValue; sca
169169
* - *width* - impute from |*x2* - *x1*|
170170
* - *height* - impute from |*y2* - *y1*|
171171
* - null - impute from input order
172+
*
173+
* If the *x* channel is not defined, the *x2* channel will be used instead if
174+
* available, and similarly for *y* and *y2*; this is useful for marks that
175+
* implicitly stack. The *data* input is typically used in conjunction with a
176+
* custom **reduce** function, as when the built-in single-channel reducers are
177+
* insufficient.
172178
*/
173179
export type ChannelDomainValue = ChannelName | "data" | "width" | "height" | null;
174180

@@ -190,12 +196,22 @@ export interface ChannelDomainOptions {
190196
reverse?: boolean;
191197

192198
/**
193-
* If a positive number, limit the domain to the first *n* sorted values; if a
194-
* negative number, limit the domain to the last *-n* sorted values. Otherwise
195-
* slices the sorted domain from *lo* (inclusive) to *hi* (exclusive); if
196-
* either *lo* or *hi* are negative, it indicates an offset from the end of
197-
* the array; if *lo* is undefined it defaults to 0, and if *hi* is undefined
198-
* it defaults to Infinity.
199+
* If a positive number, limit the domain to the first *n* sorted values. If a
200+
* negative number, limit the domain to the last *-n* sorted values. Hence, a
201+
* positive **limit** with **reverse** true will return the top *n* values in
202+
* descending order.
203+
*
204+
* If an array [*lo*, *hi*], slices the sorted domain from *lo* (inclusive) to
205+
* *hi* (exclusive). As with [*array*.slice][1], if either *lo* or *hi* are
206+
* negative, it indicates an offset from the end of the array; if *lo* is
207+
* undefined it defaults to 0, and if *hi* is undefined it defaults to
208+
* Infinity.
209+
*
210+
* Note: limiting the imputed domain of one scale, say *x*, does not affect
211+
* the imputed domain of another scale, say *y*; each scale domain is imputed
212+
* independently.
213+
*
214+
* [1]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice
199215
*/
200216
limit?: number | [lo?: number, hi?: number];
201217
}

src/mark.d.ts

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ import type {plot} from "./plot.js";
55
import type {ScaleFunctions} from "./scales.js";
66
import type {InitializerFunction, SortOrder, TransformFunction} from "./transforms/basic.js";
77

8+
/**
9+
* How to anchor a mark relative to the plot’s frame; one of:
10+
*
11+
* - *middle* - centered in the middle
12+
* - in the middle of one of the edges: *top*, *right*, *bottom*, *left*
13+
* - in one of the corners: *top-left*, *top-right*, *bottom-right*, *bottom-left*
14+
*/
815
export type FrameAnchor =
916
| "middle"
1017
| "top-left"
@@ -16,6 +23,12 @@ export type FrameAnchor =
1623
| "bottom-left"
1724
| "left";
1825

26+
/**
27+
* A mark’s data; one of:
28+
*
29+
* - an array, typed array, or other iterable
30+
* - an object with a length property and indexed values
31+
*/
1932
export type Data = Iterable<any> | ArrayLike<any>;
2033

2134
/**
@@ -49,11 +62,69 @@ export type Markish = RenderableMark | RenderFunction | Markish[] | null | undef
4962

5063
/** Shared options for all marks. */
5164
export interface MarkOptions {
52-
// transforms
65+
/**
66+
* Applies a transform to filter the mark’s index according to the given
67+
* channel values; only truthy values are retained. For example, to show only
68+
* data whose body mass is greater than 3,000g:
69+
*
70+
* ```js
71+
* filter: (d) => d.body_mass_g > 3000
72+
* ```
73+
*
74+
* Note that filtering only affects the rendered mark index, not the
75+
* associated channel values, and thus has no effect on imputed scale domains.
76+
*/
5377
filter?: ChannelValue;
78+
79+
/**
80+
* Applies a transform to reverse the order of the mark’s index, say for
81+
* reverse input order.
82+
*/
5483
reverse?: boolean;
84+
85+
/**
86+
* Either applies a transform to sort the mark’s render index by the specified
87+
* channel values, or imputes ordinal scale domains from this mark’s channels.
88+
*
89+
* When imputing ordinal scale domains from channel values, the **sort**
90+
* option is an object whose keys are ordinal scale names such as *x* or *fx*,
91+
* and whose values are channel names such as *y*, *y1*, or *y2*. For example,
92+
* to impute the *y* scale’s domain from the associated *x* channel values in
93+
* ascending order:
94+
*
95+
* ```js
96+
* sort: {y: "x"}
97+
* ```
98+
*
99+
* For different sort options for different scales, replace the channel name
100+
* with a *value* object and per-scale options:
101+
*
102+
* ```js
103+
* sort: {y: {value: "x", reverse: true}}
104+
* ```
105+
*
106+
* When sorting the mark’s render index, the **sort** option is instead one
107+
* of:
108+
*
109+
* - a function for comparing data, returning a signed number
110+
* - a channel value definition for sorting given values in ascending order
111+
* - a {value, order} object for sorting given values
112+
* - a {channel, order} object for sorting the named channel’s values
113+
*
114+
* For example, to render in order of ascending body mass:
115+
*
116+
* ```js
117+
* sort: "body_mass_g"
118+
* ```
119+
*
120+
* See also the Plot.sort transform.
121+
*/
55122
sort?: SortOrder | ChannelDomainSort;
123+
124+
/** A custom mark transform. */
56125
transform?: TransformFunction;
126+
127+
/** A custom mark initializer. */
57128
initializer?: InitializerFunction;
58129

59130
/**

0 commit comments

Comments
 (0)