#Slate Methods

Programatically control the slate with the below methods.

#nodes.add

adds new node(s) to the slate
arguments
slate.nodes.add([{ new Slatebox.node({ id: 'first_node', name: 'first_node', text: 'drag me', xPos: 25110, yPos: 25120, height: 60, width: 120, vectorPath: 'roundedrectangle', backgroundColor: '#24A8E0', lineColor: '#333', lineWidth: 5, allowMenu: true, filters: { vect: 'dropShadow', }, }) }]);
NameTypeDescription
nodeobjecteither a node object or an array of node objects.
returns

null

#nodes.remove

remove node(s) from the slate
arguments
slate.nodes.remove([{ options: { id: "id_to_remove" } }]);
NameTypeDescription
nodeobjecteither a node object or an array of node objects.
returns

null

#svg

download the slate as svg
arguments
slate.svg();

None

returns

browser will download a slate_timestamp.svg svg file

#png

download the slate as png
arguments
slate.png();

None

returns

browser will download a slate_timestamp.png png file

#canvas.zoom

zoom the slate on the z plane
arguments
slate.canvas.zoom({ dur: 500, callbacks: { after: () => { console.log('called at the end of the zoom'); }, during: () => { console.log('called once per animationFrame while zooming'); } }, easing: 'easeFromTo', zoomPercent: 100, });
NameTypeDescription
durintegerduration in millis
callbacksobjectcallbacks for after and during move
easingstringsee all easing options
returns

null

#canvas.move

move the slate on the x, y plane
arguments
slate.canvas.move({ x: 125, y: 40, dur: 500, callbacks: { after: () => { console.log('called at the end of the move'); }, during: () => { console.log('called once per animationFrame while moving'); } }, isAbsolute: false, easing: 'easeFromTo', });
NameTypeDescription
xintegerx in px to move the canvas (relative or absolute, depending on isAbsolute)
yintegery in px to move the canvas (relative or absolute, depending on isAbsolute)
durintegerduration in millis
callbacksobjectcallbacks for after and during move
isAbsolutebooleanrelative or absolute x,y coordinates
easingstringsee all easing options
returns

null

#applyTheme

applyTheme
arguments
slate.applyTheme(theme, syncWithTheme);
NameTypeDescription
themeobjectA theme object
syncWithThemebooleanSetting to true syncs the properties with created children with the theme properties instead of the default (children inheriting properties from their parents.
returns

null

#exportJSON

a JSON representation of the slate
arguments
slate.exportJSON();

None

returns an array of ...nodeObject(s) and a ...slateObject.
{ "_id": "CsiJNp8G8LiPHhxRD", "created": 1650100223609, "lastSaved": 1650100223609, "nodes": [ { ...nodeObject } ] "options": { ...slateObject }, "shareId": "ebc8e555", "userId": "xxx", "orgId": "yyy" }

#loadJSON

load a slate with the JSON string exported from exportJSON
arguments
slate.loadJSON(jsonSlate, blnPreserve, blnSkipZoom);
NameTypeDescription
jsonSlatestringA JSON string as described in the exportJSON return
blnPreservebooleanSetting to true will preserve the contents of the targeted slate.
blnSkipZoombooleanSetting to true will not zoom the slate after loading the nodes
returns

null

#getOrientation

orientation details for the slate
arguments
slate.getOrientation(nodesToOrient, alwaysOne);
NameTypeDescription
nodesToOrientarrayAn optional array of node ids to use when calculating the orientation, if ommited or null, defaults to all nodes
alwaysOnebooleanDefaults to false. Set to true to always enforce a zoom level of 1 (fit to screen) for the orientation
returns
{ orientation: 'landscape|portrait', height: 448, // height of slate in px width: 780, // width of slate in px left: 45, // left (x) of the slate as positioned against the infinite canvas in px top: 23, // top (y) coords of the slate as positioned against the infinite canvas in px }

#scaleToFitAndCenter

scale and center the slate on all its nodes
arguments
slate.scaleToFitAndCenter(dur, cb);
NameTypeDescription
durintegerThe duration in milliseconds for the scaling and centering animations to happen
cbfunctionOptional callback to fire after scaling and centering completes
returns
null

#scaleToFitNodes

scale the slate to show all nodes (or those selected) in the viewport
arguments
slate.scaleToFitNodes({ nodes: [], dur: 0, cb: null });
NameTypeDescription
nodesarrayAn optional array of node ids to use when calculating the scaling, if ommited or null, defaults to all nodes
durintegerThe duration in milliseconds for the scaling animation to happen
cbfunctionOptional callback to fire after scaling completes
returns
null

#centerOnNodes

scale the slate to show all nodes (or those selected) in the viewport
arguments
slate.scaleToFitNodes({ nodes: [], dur: 0, cb: null });
NameTypeDescription
nodesarrayAn optional array of node ids to use when calculating the centering, if ommited or null, defaults to all nodes
durintegerThe duration in milliseconds for the center move animation to happen
cbfunctionOptional callback to fire after centering completes
returns
null

#slate.grid.show

show the background grid on the slate canvas
arguments
slate.grid.show();

none

returns
null

#slate.grid.destroy

remove the background grid on the slate canvas
arguments
slate.grid.destroy();

none

returns
null