Skip to content

Commit 49b403b

Browse files
committed
edits
1 parent a18896b commit 49b403b

File tree

1 file changed

+62
-28
lines changed

1 file changed

+62
-28
lines changed

src/marks/vector.d.ts

Lines changed: 62 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,80 +1,114 @@
11
import type {ChannelValue, ChannelValueSpec} from "../channel.js";
22
import type {Data, FrameAnchor, MarkOptions, RenderableMark} from "../mark.js";
33

4+
/** The built-in vector shape implementations. */
45
export type VectorShapeName = "arrow" | "spike";
56

6-
/**
7-
* A custom vector shape implementation.
8-
*/
7+
/** A vector shape implementation. */
98
export interface VectorShapeImplementation {
109
draw(context: CanvasPath, length: number, radius: number): void;
1110
}
1211

12+
/** How to draw a vector. */
1313
export type VectorShape = VectorShapeName | VectorShapeImplementation;
1414

15+
/** Options for the vector mark. */
1516
export interface VectorOptions extends MarkOptions {
16-
/** A channel for the horizontal position. */
17+
/**
18+
* The horizontal position of the vector’s anchor point; an optional channel
19+
* bound to the *x* scale. Default depends on the **frameAnchor**.
20+
*/
1721
x?: ChannelValueSpec;
18-
/** A channel for the vertical position. */
22+
23+
/**
24+
* The vertical position of the vector’s anchor point; an optional channel bound to the
25+
* *y* scale. Default depends on the **frameAnchor**.
26+
*/
1927
y?: ChannelValueSpec;
28+
2029
/**
21-
* The radius channel (in pixels) describes the mark’s secondary dimension
22-
* (typically the *arrow* head’s span, or the *spike*’s base).
30+
* The vector shape’s radius, such as half the width of the *arrow*’s head or
31+
* the *spike*’s base; a constant number in pixels. Defaults to 3.5 pixels.
2332
*/
24-
r?: ChannelValueSpec;
33+
r?: number;
34+
2535
/**
26-
* The length of the shape, typically associated with a linear *length* scale.
36+
* The vector’s length; either an optional channel bound to the *length* scale
37+
* or a constant number in pixels. Defaults to 12 pixels.
2738
*/
2839
length?: ChannelValueSpec;
29-
/** Vector rotation, in degrees; with rotate = 0, the shape points up. */
40+
41+
/**
42+
* The vector’s orientation (rotation angle); either a constant number in
43+
* degrees clockwise, or an optional channel (with no associated scale).
44+
* Defaults to 0 degrees with the vector pointing up; positive angles proceed
45+
* clockwise.
46+
*/
3047
rotate?: ChannelValue;
31-
/** Vector shape, as a name (*arrow* or *spike*), or as a custom implementation. */
48+
49+
/** The shape of the vector; a constant. Defaults to *arrow*. */
3250
shape?: VectorShape;
33-
/** Vector anchor; by default a vector is anchored at its base (*start*). */
51+
52+
/**
53+
* The vector’s position along its orientation relative to its anchor point; a
54+
* constant. Assuming a default **rotate** angle of 0°, one of:
55+
*
56+
* * *start* - from [*x*, *y*] to [*x*, *y* - *l*]
57+
* * *middle* (default) - from [*x*, *y* + *l* / 2] to [*x*, *y* - *l* / 2]
58+
* * *end* - from [*x*, *y* + *l*] to [*x*, *y*]
59+
*
60+
* where [*x*, *y*] is the vector’s anchor point and *l* is the vector’s
61+
* (possibly scaled) length in pixels.
62+
*/
3463
anchor?: "start" | "middle" | "end";
64+
3565
/**
36-
* The frame anchor, for vectors without a position, or positioned on a single
37-
* (*x* or *y*) dimension in a two-dimensional frame.
66+
* The vector’s frame anchor, to default **x** and **y** relative to the
67+
* frame; a constant representing one of the frame corners (*top-left*,
68+
* *top-right*, *bottom-right*, *bottom-left*), sides (*top*, *right*,
69+
* *bottom*, *left*), or *middle* (default). Has no effect if both **x** and
70+
* **y** are specified.
3871
*/
3972
frameAnchor?: FrameAnchor;
4073
}
4174

4275
/**
43-
* A vector of the given **length**, drawn in the **shape** of an arrow from its
44-
* **anchor** at the given [**x**, **y**] position, and an orientation indicated
45-
* by **rotate**. To create a vector field representing a wind map:
76+
* Returns a new vector mark for the given *data* and *options*. For example, to
77+
* create a vector field from spatial samples of wind observations:
4678
*
4779
* ```js
4880
* Plot.vector(wind, {x: "longitude", y: "latitude", length: "speed", rotate: "direction"})
4981
* ```
5082
*
51-
* By default, accepts an array of coordinates pairs (tuples) as *data*.
83+
* If none of **frameAnchor**, **x**, and **y** are specified, then **x** and
84+
* **y** default to accessors assuming that *data* contains tuples [[*x₀*,
85+
* *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …]
5286
*/
5387
export function vector(data?: Data, options?: VectorOptions): Vector;
5488

5589
/**
56-
* The vector mark, but the **x** channel defaults to identity, positioning one
57-
* arrow for each horizontal position passed as *data*.
90+
* Like vector, but **x** instead defaults to the identity function and **y**
91+
* defaults to null, assuming that *data* is an array of numbers [*x₀*, *x₁*,
92+
* *x₂*, …].
5893
*/
5994
export function vectorX(data?: Data, options?: VectorOptions): Vector;
6095

6196
/**
62-
* The vector mark, but the **y** channel defaults to identity, positioning one
63-
* arrow for each vertical position passed as *data*.
97+
* Like vector, but **y** instead defaults to the identity function and **x**
98+
* defaults to null, assuming that *data* is an array of numbers [*y₀*, *y₁*,
99+
* *y₂*, …].
64100
*/
65101
export function vectorY(data?: Data, options?: VectorOptions): Vector;
66102

67103
/**
68-
* A variant of the vector mark where the **shape** defaults to *spike*, the
69-
* **stroke** defaults to *currentColor*, the **strokeWidth** defaults to 1, the
70-
* **fill** defaults to **stroke**, the **fillOpacity** defaults to 0.3, and the
71-
* **anchor** defaults to *start*. Typically used to create a spike map:
104+
* Like vector, but with default *options* suitable for drawing a spike map. For
105+
* example, to show city populations:
72106
*
73107
* ```js
74-
* Plot.spike(counties, {stroke: "red", length: "population"})
108+
* Plot.spike(cities, {x: "longitude", y: "latitude", stroke: "red", length: "population"})
75109
* ```
76110
*/
77111
export function spike(data?: Data, options?: VectorOptions): Vector;
78112

79-
/** The vector mark */
113+
/** The vector mark. */
80114
export class Vector extends RenderableMark {}

0 commit comments

Comments
 (0)