Path
extends Mark
Subclasses: Rect, Area, Polygon, Arc, Ring
The Path class represents a geometric path consisting of multiple vertices connected by segments. To create a path object, use the mark method in the Scene class, for example:
let path = scene.mark("path", {
vertices: [
[200, 50], [350, 50], [500, 50]
],
strokeColor: "#95D0F5"
});
The geometry can also be given as SVG path data, the format of the d attribute of an SVG <path> element:
let snake = scene.mark("path", {
d: "M 100 245 V 336 a 21 21 0 0 0 42 0 V 160",
strokeWidth: 26, strokeColor: "#ddd"
});
All path commands are supported, absolute and relative (M, L, H, V, C, S, Q, T, A, Z); curves and arcs are sampled into short straight segments, so the result is an ordinary path with vertices. A path mark is a single line, so the data can have only one moveto (M) at the start, and Z is allowed only at the end, where it makes the path closed. If both vertices and d are given, vertices is used.
A straight line is also represented as a path object in Mascot. The following code returns a Path object with two vertices.
let line = scene.mark("line", {x1: 0, y1: 20, x2: 300, y2: 50});
Properties
| property | explanation | type | default value |
|---|---|---|---|
anyVertex ![]() | returns any vertex of the path | Vertex | |
| curveMode | how the segments are drawn, possible values | String | “linear” |
firstSegment ![]() | returns the first segment of the path | Segment | |
firstVertex ![]() | returns the first vertex of the path | Vertex | |
| pathLength | the length of the path in pixels. For a path in a stack layout along a path (e.g. a piece of a divided path), it is the length the path takes along the guide path, and setting it re-lays the paths end to end. Elsewhere, setting it resizes the path: from its start, the path is cut short, or its last segment is extended, to the new length (measured on the shape the path had before its length was first set). Encoded by the “length” channel. | Number | the length of its vertices |
segments ![]() | the segments on the path | Array of Segment | |
vertices ![]() | the vertices along the path | Array of Vertex | |
| vxFillColor | the fill color of the vertices on this path | Color | “#555555” |
| vxHeight | the height of the vertices on this path | Number | 0 |
| vxOpacity | the opacity of the vertices on this path | Number | 1 |
| vxRadius | the radius of the vertices on this path if the shape is “circle” | Number | 0 |
| vxShape | the shape of the vertices on this path possible values: “rect”, “circle” | String | undefined |
| vxStrokeColor | the stroke color of the vertices on this path | Color | “#aaaaaa” |
| vxStrokeWidth | the stroke width of the vertices on this path in pixels | Number | 0 |
| vxWidth | the width of the vertices on this path | Number | 0 |
x ![]() | the x coordinate of the center of the path bounds | Number | |
y ![]() | the y coordinate of the center of the path bounds | Number |
Properties inherited from Mark
| property | explanation | type | default value |
|---|---|---|---|
bounds ![]() | the bounding rectangle of the path | Rectangle | |
| dataScope | the data scope of the path | DataScope | undefined |
| fillColor | the fill color of the path if it is closed | Color | “none” |
id ![]() | the unique id of the path | String | |
| opacity | the opacity value of the path (between 0 and 1) | Number | 1 |
| strokeColor | the stroke color of the path | Color | “#ccc” |
| strokeDash | the dashes and gaps for the path stroke | String | “none” |
| strokeWidth | the stroke width of the path in pixels | Number | 1 |
type ![]() | the type of the path | String | “path” |
| visibility | whether the path is visible (“visible” or “hidden”) | String | “visible” |
Methods
| method | explanation | return type |
|---|---|---|
| addVertex(x, y, i) | adds a vertex at the specified index with specified coordinates x (Number): x coordinate y (Number): y coordinate i (Number): index to add the vertex | void |
| getSVGPathData() | returns a string to be used as the d parameter in an SVG path element | String |
| resize(wd, ht, xRef, yRef) | change the width and height of the path wd (Number): width ht (Number): height xRef (String, optional): horizontal reference point yRef (String, optional): vertical reference point | void |
| sortVertices (channel, descending) | sort the vertices by a visual channel channel (String): the channel to sort the vertices by descending (Boolean, optional): setting to true will sort in descending order; default is false. | void |
| sortVerticesByData (field, descending, order) | sort the vertices by a data field field (String): the data field to sort the vertices by descending (Boolean, optional): setting to true will sort in descending order; default is false. order (Array, optional): an array of field values in ascending order | void |
