This page focuses on the role of the Canvas object, the central point to interact with content.

Different types of canvas

There are currently four different classes of canvas:

View demo Get source code
View demo Get source code

How to choose my canvas

To get the most out of iink, we recommend you to use an InteractiveInkCanvas to get full interactivity: gestures, lasso, math solving, etc. There is nothing particular to do to benefit from gestures: The SDK will take care of detecting and applying the effect of the gestures from the provided input without any plumbing needed.

For the situations where you only want to get the ink recognition, you may prefer to use REST, so we recommend you to use an InkCanvas but in this case you only benefit from iink recognition features.

If you start a new project, consider using an InteractiveInkCanvas or an InkCanvas, as InteractiveInkSSRCanvas and InkCanvasDeprecated are deprecated.

How to create a canvas

There are two ways to create an canvas:

let canvas = new InteractiveInkCanvas(rootElement, options as TInteractiveInkCanvasOptions)

await canvas.initialize()
const canvasElement = document.getElementById('canvas');

  const canvas = await iink.canvas.load(canvasElement, "INTERACTIVE_INK",
        configuration: {
            server: {
                applicationKey: '#YOUR MYSCRIPT DEVELOPER APPLICATION KEY#',
                hmacKey: '#YOUR MYSCRIPT DEVELOPER HMAC KEY#'
            }
        }
  });

Configuration options of the canvas

Since not all configuration options are relevant for each canvas type, each canvas type comes with a default configuration, which is defined in its own object:

canvas canvas type canvas configuration object Recognition type possible values Protocol
InteractiveInkCanvas INTERACTIVE_INK InteractiveInkCanvasConfiguration Raw Content Websocket
InteractiveInkSSRCanvas INTERACTIVE_INK_SSR InteractiveInkSSRCanvasConfiguration MATH or TEXT Websocket
InkCanvas INK_V2 InkCanvasConfiguration MATH, TEXT, SHAPE or Raw Content REST
InkCanvasDeprecated INK_V1 InkCanvasDeprecatedConfiguration MATH, TEXT, DIAGRAM or Raw Content REST

All options have sensible defaults, and the configuration can be customized during the creation of the canvas by using any subset of the configuration options to the Canvas.load() function. Keys that are not set keep their default value.

This sample gives you an overview of all configuration options with their default values for the InteractiveInkCanvasConfiguration:

View demo Get source code
It is not possible to change the configuration of an existing canvas, so to change the configuration you must load a new canvas

Monitoring changes and errors

CanvasEventName lists all events that can be listened to on the Canvas or DOM element, which allows you, as a developer, to plug in custom logic when they occur.

You can run code on a particular CanvasEventName by registering an event listener on it. For example, to listen to canvas state changes:

canvas.event.addEventListener(CanvasEventName.CHANGED, (evt) => console.log(evt.detail))

The main events are:

The method waitForIdle() provided by iinkTS will raise an idle event when server and browser processing are over. This may be useful for instance in the case you want some synchronous recognition.

The following example let you explore by yourself how to observe changed and selected events, to display a real-time snapshot of canvas state: Same logic could be applied with any other event.

View demo Get source code