Canvas
UI canvas for displaying machine learning results.
Listeners:
This class supports event listeners, meaning that the outside world can bind functions to events
triggered explicitly by this class. Listeners can be added using addListener
and removed by
removeListener
. The emit
method is not intended for use by the outside world, and is used by
this class to emit an event to the listeners bound to it.
Constructor Summary
Public Constructor | ||
public |
constructor(el: Object, optionsUser: Object) Contructor. |
Member Summary
Public Members | ||
public |
canvas: {"element": *, "context": *} |
|
public |
|
|
public |
|
|
public |
elements: *[] |
|
public |
listeners: * |
|
public |
|
|
public |
|
|
public |
|
|
public |
|
|
public |
tmp: {} |
Method Summary
Public Methods | ||
public |
addDatapoint(datapoint: jsmlt.Dataset.Datapoint) Add a data point element to the canvas, using a dataset datapoint as its model. |
|
public |
addListener(label: string, callback: function) Add an event listener for events of some type emitted from this object. |
|
public |
clear() Clear the canvas. |
|
public |
Trigger a click at some position in the canvas. |
|
public |
convertBoundaryCoordinatesToFeatures(bx: number, by: number): Array<number> Convert coordinates on a centered, double unit square (i.e., a square from (-1, -1) to (1, 1)) to feature space. |
|
public |
Calculate normalized canvas coordinates, i.e. |
|
public |
convertFeaturesToCanvasCoordinates(f1: number, f2: number): Array<number> Calculate canvas coordinates (origin at (0,0)) for a 2-dimensional data point's features |
|
public |
drawAxes() Draw the axes on the canvas |
|
public |
Draw class boundaries |
|
public |
drawGrid() Draw a grid on the canvas |
|
public |
Emit an event, which triggers the listener callback functions bound to it. |
|
public |
getClassColor(classIndex: number): string Get drawing color for a class index. |
|
public |
getColors(): * Get available drawing colors. |
|
public |
Handle mouse events on the canvas, e.g. |
|
public |
redraw() Redraw the canvas, clearing it and drawing all elements on it. |
|
public |
refresh() Refresh (i.e. |
|
public |
removeListener(label: string, callback: function) Remove a previously added event listener for events of some type emitted from this object. |
|
public |
resize() Handle the canvas size for different device pixel ratios and on window resizes. |
|
public |
Set the class boundaries used for drawing the decision regions on the canvas. |
|
public |
Transform the absolute position of the mouse in the viewport to the mouse position relative to the top-left point of the canvas. |
Public Constructors
public constructor(el: Object, optionsUser: Object) source
Contructor. Load DOM element and user options.
Params:
Name | Type | Attribute | Description |
el | Object | DOM Canvas element |
|
optionsUser | Object |
|
User-defined options for the canvas |
optionsUser.continuousClick | boolean |
|
Whether the "click" callback should
be called any time the mouse is down (true) or only at the moment the mouse button is first
pressed (false). If true, a click event is emitted every |
optionsUser.continuousClickInterval | number |
|
Number of milliseconds between
emitting each click event when |
optionsUser.x1 | number |
|
Left bound of coordinate system for canvas |
optionsUser.y1 | number |
|
Bottom bound of coordinate system for canvas |
optionsUser.x2 | number |
|
Right bound of coordinate system for canvas |
optionsUser.y2 | number |
|
Top bound of coordinate system for canvas |
Public Members
public canvas: {"element": *, "context": *} source
public classesBoundaries: {} source
public continuousClickIntervalId: * source
public elements: *[] source
public listeners: * source
public tmp: {} source
Public Methods
public addDatapoint(datapoint: jsmlt.Dataset.Datapoint) source
Add a data point element to the canvas, using a dataset datapoint as its model.
Params:
Name | Type | Attribute | Description |
datapoint | jsmlt.Dataset.Datapoint | Dataset datapoint (model) |
public addListener(label: string, callback: function) source
Add an event listener for events of some type emitted from this object.
public convertBoundaryCoordinatesToFeatures(bx: number, by: number): Array<number> source
Convert coordinates on a centered, double unit square (i.e., a square from (-1, -1) to (1, 1)) to feature space.
public convertCanvasCoordinatesToFeatures(x: number, y: number): Array<number> source
Calculate normalized canvas coordinates, i.e. transform mouse coordinates (relative to the canvas origin = top left) to feature space for both x and y. The feature subspace shape is determined by the x1, y1, x2, and y2 parameters in the class options (see constructor).
public convertFeaturesToCanvasCoordinates(f1: number, f2: number): Array<number> source
Calculate canvas coordinates (origin at (0,0)) for a 2-dimensional data point's features
public emit(label: string, args: ...mixed): boolean source
Emit an event, which triggers the listener callback functions bound to it.
Params:
Name | Type | Attribute | Description |
label | string | Event identifier |
|
args | ...mixed | Remaining arguments contain arguments that should be passed to the callback functions |
public getClassColor(classIndex: number): string source
Get drawing color for a class index.
Params:
Name | Type | Attribute | Description |
classIndex | number | Class index |
public getColors(): * source
Get available drawing colors.
Return:
* | <Array.{string}> Colors in HEX with '#' prefix; array keys are color names |
public removeListener(label: string, callback: function) source
Remove a previously added event listener for events of some type emitted from this object.
public resize() source
Handle the canvas size for different device pixel ratios and on window resizes.
public setClassBoundaries(classesBoundaries: Object<string, Array<Array<Array<number>>>>) source
Set the class boundaries used for drawing the decision regions on the canvas.