Last updated

API / geotoolkit / plot / Plot / Plot

Class: Plot

plot.Plot.Plot

A plot with 2D rendering capabilities.
The plot requires a canvas to be passed in the options to render its content.

The plot is internally structured as a SceneGraph, using Node.
Each node having a scene-transform transformation that will be applied at render time.

The plot offers an autoupdate behavior that will check regularly if a render is required (using requestanimationframe if available, polling otherwise).
When this autoupdate lands, the plot will check if it is flagged as dirty.
If so, it will trigger a render phase.
This mechanism can be configured when instantiating the Plot or changed using the corresponding setters.
One could also temporarily suspend any rendering by calling suspendUpdate in order to apply large scale changes or simply force the plot to hibernate when not used/visible.

If the autoupdate mechanism is not enabled, the client code is responsible of calling the update function to tell the plot that it should render itself.

Throws

if parameter canvasElement is not HTMLCanvasElement or HTML5 Canvas is not supported.

Hierarchy

Table of contents

Constructors
Methods

Contents

Constructors

new Plot(options)

new Plot(options?)

Creates plot

Parameters

Name Type Description
Optional optionsOptionsplot options

Overrides

EventDispatcher.constructor

Methods

dispose

dispose(disposeRoot?): void

Disposes the plot and the associated resources.
This may also call dispose on the root node (see disposeRoot).
The plot should not be used/accessed anymore after this has been called.

Parameters

Name Type Description
Optional disposeRootbooleanAlso dispose root node

Returns

void

Overrides

EventDispatcher.dispose


getAutoUpdateInterval

getAutoUpdateInterval(): number

Returns the time interval for autoupdate mechanism.

Returns

number

The time interval in ms


getBoundingClientRect

getBoundingClientRect(): DOMRect

Returns the client rect for the plots container element as DOMRect.

Returns

DOMRect

the client rect for the plots container element


getCanvas

getCanvas(): HTMLCanvasElement | HTMLCanvasElement[]

Returns the canvas element or elements used by this plot

Returns

HTMLCanvasElement | HTMLCanvasElement[]

The canvas element


getClassName

getClassName(): string

Returns

string

Inherited from

EventDispatcher.getClassName


getContainingElement

getContainingElement(): HTMLElement

Returns the containing element for the plot
This is either the canvas element or the div element depending on the chosen functionality

Returns

HTMLElement

The canvas width


getHeight

getHeight(): number

Returns the containing element height in virtual pixels.
This returns the raw size given at initialization or through the setSize function.
It ignores any Browser zoom.

Returns

number

The canvas height


getRoot

getRoot(): Node

Returns the root node of the scenegraph.

Returns

Node

The root node


getTool

getTool(): ToolsContainer

Returns root tool associated to plot

Returns

ToolsContainer


getWidth

getWidth(): number

Returns the containing element width in virtual pixels.
This returns the raw size given at initialization or through the setSize function.
It ignores any Browser zoom.

Returns

number

The canvas width


hasEventListener

hasEventListener(type, callback?): boolean

Check if a list of event listeners for this type contains this listener

Parameters

Name Type Description
typestringtype of event or property
Optional callbackFunctionto be called, if null, check if any callback is registered

Returns

boolean

Inherited from

EventDispatcher.hasEventListener


isAutoUpdate

isAutoUpdate(): boolean

Return true if auto update is enabled.

Returns

boolean

The status of autoupdate


isDisposed

isDisposed(): boolean

Returns whether this object has been disposed

Returns

boolean

Inherited from

EventDispatcher.isDisposed


isInfiniteAutoUpdate

isInfiniteAutoUpdate(): boolean

Return true if infinite auto update is enabled.

Returns

boolean

The status of infinite auto update


isSilent

isSilent(): boolean

Return true if the event dispatcher doesn't notify any events

Returns

boolean

Inherited from

EventDispatcher.isSilent


notify

notify<E>(type, source, args?): Plot

Notify listeners

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEevent types
sourcePlotof the event
Optional argsEventMap[E]arguments of the event

Returns

Plot

this

Overrides

EventDispatcher.notify


off

off<E>(type?, callback?): Plot

Detach listener on event. Calling .off() with no arguments removes all attached listeners. Calling .off(type) with no callback removes all attached listeners for specific type.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
Optional typeEtype of the event
Optional callback(eventType: E, sender: Plot, args: EventMap[E]) => voidfunction to be called

Returns

Plot

this

Overrides

EventDispatcher.off


on

on<E>(type, callback): Plot

Attach listener on event that will be called whenever the specified event is delivered to the target

If the callback function is already in the list of event listeners for this target, the function is not added a second time.

If a particular anonymous function is in the list of event listeners registered for a certain target, and then later in the code, an identical anonymous function is given in an "on" call, the second function will also be added to the list of event listeners for that target.

Type parameters

NameType
Eextends string

Parameters

Name Type Description
typeEtype of event or property
callback(eventType: E, sender: Plot, args: EventMap[E]) => voidto be called

Returns

Plot

this

Overrides

EventDispatcher.on


onResize

onResize(): Plot

Forces a resize on the plot using its known width and height.

Returns

Plot

this


resumeUpdate

resumeUpdate(refresh?): Plot

Resumes plot update, allowing the update function of triggering a render.

Parameters

Name Type Description
Optional refreshbooleanIf set to true, a render will be run immediately

Returns

Plot

this


setAutoSize

setAutoSize(autoSize): Plot

Enable or disable autosize mechanism.
If enabled, this will let the Plot resize the associated canvas whenever the plot itself is resized.

Parameters

Name Type Description
autoSizebooleanThe status of autosize

Returns

Plot

this


setAutoUpdate

setAutoUpdate(enable, infinite?): Plot

Enables or disables auto update mechanism.
If auto update is enabled, whenever a node is invalidated it will trigger a Plot update/render.

Parameters

Name Type Description
enablebooleanThe autoupdate status
Optional infinitebooleanEnables or disables infinite auto update mechanism.
if true, run timer or request animation frame in infinite loop overwise if node is invalidated it will trigger a Plot update/render. if false, browser pixel scale is not updated.

Returns

Plot

this


setAutoUpdateInterval

setAutoUpdateInterval(interval?): Plot

Sets the time interval for autoupdate mechanism.
This will define the delay for polling the status of the Plot and trigger an update/render if necessary.

Parameters

Name Type Description
Optional intervalnumberThe time interval in ms. window.requestAnimationFrame will be used if available and interval set to null.

Returns

Plot

this


setRoot

setRoot(root): Plot

Sets the root node ot be the given node.

Parameters

Name Type Description
rootNodeThe scenegraph root node

Returns

Plot

this


setSilent

setSilent(bool): Plot

Set silent mode

Parameters

Name Type Description
boolbooleanflag to enable silent mode

Returns

Plot

this

Inherited from

EventDispatcher.setSilent


setSize

setSize(width, height): Plot

Sets the plot size to the given dimensions.
This will also change the canvas size if autosize is enabled.
If autorootbounds is enabled, this will also update the bounds of the root node.

Parameters

Name Type Description
widthnumberThe width of plot
heightnumberThe height of plot

Returns

Plot

this


setWatermark

setWatermark(watermark): Plot

Sets watermark to have on a plot

Example

import {Text} from '@int/geotoolkit/scene/shapes/Text';
import {AnchorType} from '@int/geotoolkit/util/AnchorType';
const watermark = new Text({
'alignment': AnchorType.LeftBottom, // watermark position on the screen
'textstyle': {
'font': '60px sans-serif'
},
'text': 'My Watermark'
});
plot.setWatermark(watermark);

Parameters

Name Type Description
watermarkAnchoredShapewatermark shape

Returns

Plot

this


suspendUpdate

suspendUpdate(): Plot

Suspends plot update, preventing the update function from triggering a render.

Returns

Plot

this


update

update(): Plot

Updates the plot, forcing a render.
This will be called automatically when the plot has been marked as dirty if the autoupdate is enabled.

Returns

Plot

this


getClassName

Static getClassName(): string

Returns

string

Inherited from

EventDispatcher.getClassName


getPlotByNode

Static getPlotByNode(node): Plot

Get registered plot associated with node

Parameters

Name Type Description
nodeNodenode on plot

Returns

Plot

plot


setEnableDevTool

Static setEnableDevTool(enabled): void

Enable/disable dev tool support

Parameters

Name Type Description
enabledbooleanTrue to enable dev tool support, false otherwise

Returns

void