Constructor
new Graph(container, oopt)
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
container |
object | DOM container for the widget. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
o |
object |
<optional> |
Options.
Properties
|
Methods
(private) _addSvgLine()
Adds an SVG line connecting two vertices.
(private) _addSvgVertex()
Adds a new SVG vertex representation.
(private) _calcVertexPos()
Calculates the x and y for a vertex in the graph according to its state value.
(private) _calcVertexState()
Calculates the x and y for a vertex state based on position on the graph.
(inverse of _calcVertexPos).
(private) _deleteVertex(targetVtx)
Deletes a vertex.
Parameters:
| Name | Type | Description |
|---|---|---|
targetVtx |
SVGElement | Vertex to Delete |
(private) _initHandlers()
Initializes mouse and touch event handlers.
(private) _initOptions()
Initializes the options.
(private) _initState()
Initializes state.
(private) _initStateConstraints()
Initializes state constraints.
(private) _initSvgEls()
Initializes the svg elements.
(private) _moveLine(targetLine, dPos, vtxPos0) → {object}
Moves a line.
Parameters:
| Name | Type | Description | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
targetLine |
SVGElement | The target line | ||||||||||||||||||||||||||||||||||||
dPos |
object | -
Properties
|
||||||||||||||||||||||||||||||||||||
vtxPos0 |
object | Original position (before moving)
of the two vertices immediately to the left
and right of the line being moved in the
form { vtx1: {x, y}, vtx2: {x, y}, boundaryBL: {x, y}, boundaryTR: {x, y} }
If null, will be calculated from the
corresponding svg element.
Properties
|
Returns:
Original position of the two vertices affected by the line move in the form
{ vtx1: {x, y}, vtx2: {x, y}, boundaryBL: {x, y}, boundaryTR: {x, y} }.
- Type
- object
(private) _moveVertex(targetVtx, newPos)
Moves a vertex.
Parameters:
| Name | Type | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
targetVtx |
SVGElement | The target vertex | |||||||||
newPos |
Object | The new position
Properties
|
(private) _removeSvgLine()
Removes an SVG line connecting two vertices.
(private) _removeSvgVertex()
Removes an SVG vertex.
(private) _update()
Updates (redraws) component based on state.
(private) _xPxToVal()
Converts on-screen x distance to scaled x state-value.
(private) _yPxToVal()
Converts on-screen y distance to scaled y state-value.
addFixedVertex(…vtx)
Adds a vertex with fixed x and y coordinates.
Parameters:
| Name | Type | Attributes | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
vtx |
object |
<repeatable> |
Vertex coordinates in format {x, y}
Properties
|
addFixedXVertex(…vtx)
Adds a vertex with fixed y coordinate.
Parameters:
| Name | Type | Attributes | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
vtx |
object |
<repeatable> |
Vertex coordinates in format {x, y}
Properties
|
addFixedYVertex(…vtx)
Adds a vertex with fixed y coordinate.
Parameters:
| Name | Type | Attributes | Description | |||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
vtx |
object |
<repeatable> |
Vertex coordinates in format {x, y}
Properties
|
addVertex(…vtx)
Adds new vertices to the state.
Each vertex is represented as x and y values, as well as optional boolean flags
specifying whether the x, y, or both values should be fixed (unchangeble).
The x and y values may also take the strings "min", "max" to specify that the coordinates
should be tied to the minimum or maximum possible x or y values for the graph.
Parameters:
| Name | Type | Attributes | Description | |||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
vtx |
object |
<repeatable> |
Object representing the new vertex to add.
Properties
|
getNumVertices() → {number}
Returns the number of vertices set on this graph.
Returns:
- Number of vertices.
- Type
- number
getVal()
Returns the state as an array of [x, y] pairs.
setInternalVal(vertexArray)
Sets the state as an array of [x, y] vertex pairs.
Same as setVal(), but will not trigger observer callback methods.
Parameters:
| Name | Type | Description |
|---|---|---|
vertexArray |
array | An array of [x, y] points |
setOptions()
Sets the options.
setVal(vertexArray)
Sets the state as an array of [x, y] vertex pairs.
Same as setInternalVal(), but will trigger observer callback methods.
Parameters:
| Name | Type | Description |
|---|---|---|
vertexArray |
array | An array of [x, y] points. |
setVertexVal(val, idx) → {number}
Sets the value of a particular vertex, selected by its index.
Note: will not trigger observer notifications.
Parameters:
| Name | Type | Description |
|---|---|---|
val |
number | Value to set. |
idx |
number | Index of the vertex to set the value for. |
Returns:
- Index of the vertex that has been set, or -1 if no such vertex exists.
- Type
- number