#
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',
},
})
}]);
returns
null
#
nodes.remove
remove node(s) from the slate
arguments
slate.nodes.remove([{
options: {
id: "id_to_remove"
}
}]);
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,
});
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',
});
returns
null
#
applyTheme
applyTheme
arguments
slate.applyTheme(theme, syncWithTheme);
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);
returns
null
#
getOrientation
orientation details for the slate
arguments
slate.getOrientation(nodesToOrient, alwaysOne);
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
This function combines the scaleToFitNodes
and centerOnNodes
methods into one simplified call.
scale and center the slate on all its nodes
arguments
slate.scaleToFitAndCenter(dur, cb);
returns
null
#
scaleToFitNodes
scale the slate to show all nodes (or those selected) in the viewport
arguments
slate.scaleToFitNodes({
nodes: [],
dur: 0,
cb: null
});
returns
null
#
centerOnNodes
scale the slate to show all nodes (or those selected) in the viewport
arguments
slate.scaleToFitNodes({
nodes: [],
dur: 0,
cb: null
});
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