-
Notifications
You must be signed in to change notification settings - Fork 185
document vector #1377
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
document vector #1377
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,114 @@ | ||
import type {ChannelValue, ChannelValueSpec} from "../channel.js"; | ||
import type {Data, FrameAnchor, MarkOptions, RenderableMark} from "../mark.js"; | ||
|
||
/** The built-in vector shape implementations. */ | ||
export type VectorShapeName = "arrow" | "spike"; | ||
|
||
/** A vector shape implementation. */ | ||
export interface VectorShapeImplementation { | ||
draw(context: CanvasPath, length: number, radius: number): void; | ||
} | ||
|
||
export type VectorShapeSpec = VectorShapeName | VectorShapeImplementation; | ||
/** How to draw a vector. */ | ||
export type VectorShape = VectorShapeName | VectorShapeImplementation; | ||
|
||
/** Options for the vector mark. */ | ||
export interface VectorOptions extends MarkOptions { | ||
/** | ||
* The horizontal position of the vector’s anchor point; an optional channel | ||
* bound to the *x* scale. Default depends on the **frameAnchor**. | ||
*/ | ||
x?: ChannelValueSpec; | ||
|
||
/** | ||
* The vertical position of the vector’s anchor point; an optional channel bound to the | ||
* *y* scale. Default depends on the **frameAnchor**. | ||
*/ | ||
y?: ChannelValueSpec; | ||
r?: ChannelValueSpec; | ||
|
||
/** | ||
* The vector shape’s radius, such as half the width of the *arrow*’s head or | ||
* the *spike*’s base; a constant number in pixels. Defaults to 3.5 pixels. | ||
*/ | ||
r?: number; | ||
|
||
/** | ||
* The vector’s length; either an optional channel bound to the *length* scale | ||
* or a constant number in pixels. Defaults to 12 pixels. | ||
*/ | ||
length?: ChannelValueSpec; | ||
|
||
/** | ||
* The vector’s orientation (rotation angle); either a constant number in | ||
* degrees clockwise, or an optional channel (with no associated scale). | ||
* Defaults to 0 degrees with the vector pointing up; positive angles proceed | ||
* clockwise. | ||
*/ | ||
rotate?: ChannelValue; | ||
shape?: VectorShapeSpec; | ||
|
||
/** The shape of the vector; a constant. Defaults to *arrow*. */ | ||
shape?: VectorShape; | ||
|
||
/** | ||
* The vector’s position along its orientation relative to its anchor point; a | ||
* constant. Assuming a default **rotate** angle of 0°, one of: | ||
* | ||
* * *start* - from [*x*, *y*] to [*x*, *y* - *l*] | ||
* * *middle* (default) - from [*x*, *y* + *l* / 2] to [*x*, *y* - *l* / 2] | ||
* * *end* - from [*x*, *y* + *l*] to [*x*, *y*] | ||
* | ||
* where [*x*, *y*] is the vector’s anchor point and *l* is the vector’s | ||
* (possibly scaled) length in pixels. | ||
*/ | ||
anchor?: "start" | "middle" | "end"; | ||
|
||
/** | ||
* The vector’s frame anchor, to default **x** and **y** relative to the | ||
* frame; a constant representing one of the frame corners (*top-left*, | ||
* *top-right*, *bottom-right*, *bottom-left*), sides (*top*, *right*, | ||
* *bottom*, *left*), or *middle* (default). Has no effect if both **x** and | ||
* **y** are specified. | ||
*/ | ||
frameAnchor?: FrameAnchor; | ||
} | ||
|
||
/** | ||
* Returns a new vector mark for the given *data* and *options*. For example, to | ||
* create a vector field from spatial samples of wind observations: | ||
* | ||
* ```js | ||
* Plot.vector(wind, {x: "longitude", y: "latitude", length: "speed", rotate: "direction"}) | ||
* ``` | ||
* | ||
* If none of **frameAnchor**, **x**, and **y** are specified, then **x** and | ||
* **y** default to accessors assuming that *data* contains tuples [[*x₀*, | ||
* *y₀*], [*x₁*, *y₁*], [*x₂*, *y₂*], …] | ||
*/ | ||
export function vector(data?: Data, options?: VectorOptions): Vector; | ||
|
||
/** | ||
* Like vector, but **x** instead defaults to the identity function and **y** | ||
* defaults to null, assuming that *data* is an array of numbers [*x₀*, *x₁*, | ||
* *x₂*, …]. | ||
*/ | ||
export function vectorX(data?: Data, options?: VectorOptions): Vector; | ||
|
||
/** | ||
* Like vector, but **y** instead defaults to the identity function and **x** | ||
* defaults to null, assuming that *data* is an array of numbers [*y₀*, *y₁*, | ||
* *y₂*, …]. | ||
*/ | ||
export function vectorY(data?: Data, options?: VectorOptions): Vector; | ||
|
||
/** | ||
* Like vector, but with default *options* suitable for drawing a spike map. For | ||
* example, to show city populations: | ||
* | ||
* ```js | ||
* Plot.spike(cities, {x: "longitude", y: "latitude", stroke: "red", length: "population"}) | ||
* ``` | ||
*/ | ||
export function spike(data?: Data, options?: VectorOptions): Vector; | ||
|
||
/** The vector mark. */ | ||
export class Vector extends RenderableMark {} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
repeats "clockwise"