Canvas

Canvas

new Canvas(config);

Canvas Renderer constructor.

  • config : Object, the configuration needed to create a canvas object, it includes the following attributes:

Attribute

Type

Description

el

String/HtmlElement

Container selector or DOM element

context

CanvasRenderingContext2D

The context of the canvas.

width

Number

Optional, width of the canvas. If it is omitted, the actual width of the canvas DOM is used by default.

height

Number

Optional, height of the canvas. If it is omitted, the actual height of the canvas DOM is used by default.

pixelRatio

Number

F2 automatically handles pixel ratio adjustments in order to render crisp drawings on all devices. Unless otherwise specified, the pixel ratio will be defaulted to the actual device pixel ratio: window.devicePixelRatio. You can override the device pixel ratio for special situations, or, if you don't want the pixel ratio to be taken into account, you can set it to 1.

Example:

const canvas = new F2.G.Canvas({
  id: 'canvas',
  width: 500,
  height: 500,
  pixelRatio: 1
});

Methods

getChildren()

isDestroyed()

getWidth()

getHeight()

changeSize(width, height)

getPointByClient(clientX, clientY)

addShape(type, config)

The config parameter passed in is the configuration of the shape, includes:

addGroup(config)

config can be Null or Object, if the config is an object, passed in is the configuration for Group can be:

add(items)

contain(item)

sort()

get(name)

set(name, value)

clear()

draw()

Draw the canvas.

destroy()

Destroy the canvas object.

Last updated