-
Notifications
You must be signed in to change notification settings - Fork 3
GM API Reference
loadGM(options)
Including the gm-inject.js script in an html page provides the loadGM() method. Calling it injects the gmath library, the d3 library, jquery and bootstrap, as well as several stylesheet files into the page. The options parameter needs to specify which gmath version to load, such as {version: '2.6.6'} or {version: 'latest'}.
The canvas ties together a toolbar and a working area where the user can draw and erase, as well as create canvas elements and interact with them. Each canvas element has a type, such as 'derivation' or 'textbox', and a unique id. The working area has a fixed width, but can extend vertically as needed to make space for new elements or paths.
Holds all elements on the canvas.
# cmodel.createElement(type, options, [method], [callback])
Creates a new canvas element. GM comes with the build-in element types 'derivation', 'textbox', 'image', 'ggb-panel' and 'ggb-element'. The options object is passed to the constructor of the element that is created. You should always pass pos: {x, y} as an option. The string passed as method parameter is written to the logging database, and the function passed as callback will be called with the created element as parameter once it is initialized and displayed.
# cmodel.elements()
Returns an array of all elements on the canvas.
# cmodel.scroll([y])
If called without an arguments, returns the current scrollTop position of the canvas workspace. When passed a number, it will scroll to that position.
# cmodel.size()
Returns the current size of the canvas workspace (usually bigger than the screen when the canvas is in infinite scrolling mode).
# cmodel.viewport()
Returns the currently visible rectangle of the canvas workspace.