SVGScene
class SVGScene extends PIXI.DisplayObject
SVGScene can be used to build an interactive viewer for scalable vector graphics images. You must specify the size of the svg viewer.
SVG Scene Graph
SVGScene has an internal, disconnected scene graph that is optimized for lazy updates. It will listen to the following events fired by a node:
nodetransformdirty
: This will invalidate the transform calculations.
Constructor
new SVGScene(content: SVGSVGElement, context: Partial<SVGSceneContext>) → {}
Name | Type | Attributes | Description |
---|---|---|---|
content | SVGSVGElement |
The SVG node to render |
|
context | Partial<SVGSceneContext> |
<optional> |
This can be used to configure the scene |
Summary
Properties from SVGScene
SVGSVGElement |
The SVG image content being rendered by the scene. |
number |
|
PIXI.Container |
|
PIXI.Container |
The root display object of the scene. |
number |
|
SVGSceneContext |
The scene context |
Cull |
This is used to cull the SVG scene graph before rendering. |
number |
The height of the rendered scene in local space. |
boolean |
Flags whether any transform is dirty in the SVG scene graph. |
number |
The width of the rendered scene in local space. |
Methods from SVGScene
Promise<SVGScene> |
Load the SVG document and create a SVGScene asynchronously. |
void |
|
void |
|
void |
|
MaskServer |
Creates a lazy luminance mask for the |
PIXI.Container |
Creates a display object that implements the corresponding |
Paint |
|
PaintServer |
Creates a lazy paint texture for the paint server. |
{ paint : Paint } |
Embeds a content |
string |
|
void |
Populates the entire SVG scene. This should only be called once after the SVGScene.content has been set. |
PIXI.Container |
Recursively populates a subscene graph that embeds |
Paint |
Returns an (uncached) inherited paint of a content element. |
MaskServer |
Returns the rendering node for a mask. |
Paint |
|
Events from SVGScene
Properties inherited from DisplayObject
Methods inherited from DisplayObject
Inherited Events from DisplayObject
|
|
|
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
Fired when the mouse pointer is moved over a DisplayObject and its descendant's hit testing boundaries. |
|
Capture phase equivalent of |
|
Fired when the mouse pointer exits a DisplayObject and its descendants. |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Fired when the pointer is moved over a DisplayObject and its descendant's hit testing boundaries. |
|
Capture phase equivalent of |
|
Fired when the pointer leaves the hit testing boundaries of a DisplayObject and its descendants. |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
|
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
Capture phase equivalent of |
|
PIXI.FederatedWheelEvent |
Fired when a the user scrolls with the mouse cursor over a DisplayObject. |
PIXI.FederatedWheelEvent |
Capture phase equivalent of |
Public Properties
height: number
The height at which the SVG scene is being rendered. By default, this is the viewbox height specified by the root element.
renderServers: PIXI.Container
Display objects that don't render to the screen, but are required to update before the rendering nodes, e.g. mask sprites.
width: number
The width at which the SVG scene is being rendered. By default, this is the viewbox width specified by the root element.
Protected Properties
protected _cull: Cull
This is used to cull the SVG scene graph before rendering.
protected _transformDirty: boolean
Flags whether any transform is dirty in the SVG scene graph.
Public Methods
static from(url: string, context: SVGSceneContext) → {Promise<SVGScene>}
Load the SVG document and create a SVGScene asynchronously.
A cache is used for loaded SVG documents.
Name | Type | Attributes | Description |
---|---|---|---|
url | string | ||
context | SVGSceneContext |
<optional> |
Type | Description |
---|---|
Promise<SVGScene> |
calculateBounds() → {void}
Calculates the bounds of this scene, which is defined by the set width
and height
. The contents
of this scene are scaled to fit these bounds, and don't affect them whatsoever.
Type | Description |
---|---|
void |
render(renderer: PIXI.Renderer) → {void}
Name | Type | Description |
---|---|---|
renderer | PIXI.Renderer |
Type | Description |
---|---|
void |
Protected Methods
protected createMask(ref: SVGMaskElement | PIXI.Container) → {MaskServer}
Creates a lazy luminance mask for the SVGMaskElement
or its rendering node.
Name | Type | Description |
---|---|---|
ref | SVGMaskElement | PIXI.Container |
The |
Type | Description |
---|---|
MaskServer |
protected createNode(element: SVGElement) → {PIXI.Container}
Creates a display object that implements the corresponding embed*
method for the given node.
Name | Type | Description |
---|---|---|
element | SVGElement |
The element to be embedded in a display object. |
Type | Description |
---|---|
PIXI.Container |
protected createPaint(element: SVGElement) → {Paint}
Creates a Paint
object for the given element. This should only be used when sharing the Paint
is not desired; otherwise, use SVGScene.queryPaint.
This will return null
if the passed element is not an instance of SVGElement
.
Name | Type | Description |
---|---|---|
element | SVGElement |
Type | Description |
---|---|
Paint |
protected createPaintServer(paintServer: SVGGradientElement) → {PaintServer}
Creates a lazy paint texture for the paint server.
Name | Type | Description |
---|---|---|
paintServer | SVGGradientElement |
The paint server to be rendered. |
Type | Description |
---|---|
PaintServer |
protected embedIntoNode(node: PIXI.Container, element: SVGGraphicsElement | SVGMaskElement, options: { basePaint? : Paint }) → {{ paint : Paint }}
Embeds a content element
into the rendering node
.
This is not a stable API.
Name | Type | Attributes | Description |
---|---|---|---|
node | PIXI.Container |
The node in this scene that will render the |
|
element | SVGGraphicsElement | SVGMaskElement |
The content |
|
options | { basePaint? : Paint } |
Additional options |
|
options.basePaint | Paint |
<optional> |
The base paint that the element's paint should inherit from |
Type | Description |
---|---|
{ paint : Paint } |
The base attributes of the element, like paint. |
protected parseReference(url: string) → {string}
Parses the internal URL reference into a selector (that can be used to find the
referenced element using this.content.querySelector
).
Name | Type | Description |
---|---|---|
url | string |
The reference string, e.g. "url(#id)", "url('#id')", "#id" |
Type | Description |
---|---|
string |
protected populateScene() → {void}
Populates the entire SVG scene. This should only be called once after the SVGScene.content has been set.
Type | Description |
---|---|
void |
protected populateSceneRecursive(element: SVGElement, options: { basePaint? : Paint }) → {PIXI.Container}
Recursively populates a subscene graph that embeds element
. The root of the subscene is returned.
Name | Type | Attributes | Description |
---|---|---|---|
element | SVGElement |
The SVGElement to be embedded. |
|
options | { basePaint? : Paint } |
<optional> |
Inherited attributes from the element's parent, if any. |
Type | Description |
---|---|
PIXI.Container |
The display object that embeds the element for rendering. |
protected queryInheritedPaint(ref: SVGElement) → {Paint}
Returns an (uncached) inherited paint of a content element.
Name | Type | Description |
---|---|---|
ref | SVGElement |
Type | Description |
---|---|
Paint |
protected queryMask(ref: SVGMaskElement) → {MaskServer}
Returns the rendering node for a mask.
Name | Type | Description |
---|---|---|
ref | SVGMaskElement |
The mask element whose rendering node is needed. |
Type | Description |
---|---|
MaskServer |
protected queryPaint(ref: SVGElement) → {Paint}
Returns the cached paint of a content element. The returned paint will not account for any paint attributes inherited from ancestor elements.
Name | Type | Description |
---|---|---|
ref | SVGElement |
A reference to the content element. |
Type | Description |
---|---|
Paint |
Events
Fired when a pointer device button (usually a mouse left-button) is pressed and released on
the display object. DisplayObject's interactive
property must be set to true
to fire event.
A click
event fires after the pointerdown
and pointerup
events, in that
order. If the mouse is moved over another DisplayObject after the pointerdown
event, the
click
event is fired on the most specific common ancestor of the two target DisplayObjects.
The detail
property of the event is the number of clicks that occurred within a 200ms
window of each other upto the current click. For example, it will be 2
for a double click.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a mouse button (usually a mouse left-button) is pressed on the display.
object. DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
The mousedown event. |
Fired when a pointer device (usually a mouse) is moved while over the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device (usually a mouse) is moved off the display object.
DisplayObject's interactive
property must be set to true
to fire event.
This may be fired on a DisplayObject that was removed from the scene graph immediately after
a mouseover
event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device (usually a mouse) is moved onto the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device button (usually a mouse left-button) is released over the display
object. DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device button (usually a mouse left-button) is released outside the
display object that initially registered a
mousedown.
DisplayObject's interactive
property must be set to true
to fire event.
This event is specific to the Federated Events API. It does not have a capture phase, unlike most of the
other events. It only bubbles to the most specific ancestor of the targets of the corresponding pointerdown
and pointerup
events, i.e. the target of the click
event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when the operating system cancels a pointer event.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device button is pressed on the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device is moved while over the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device is moved off the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device is moved onto the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device button is pressed and released on the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device button is released over the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device button is released outside the display object that initially
registered a pointerdown.
DisplayObject's interactive
property must be set to true
to fire event.
This event is specific to the Federated Events API. It does not have a capture phase, unlike most of the
other events. It only bubbles to the most specific ancestor of the targets of the corresponding pointerdown
and pointerup
events, i.e. the target of the click
event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device secondary button (usually a mouse right-button) is pressed
and released on the display object. DisplayObject's interactive
property must be set to true
to fire event.
This event follows the semantics of click
.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device secondary button (usually a mouse right-button) is pressed
on the display object. DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device secondary button (usually a mouse right-button) is released
over the display object. DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a pointer device secondary button (usually a mouse right-button) is released
outside the display object that initially registered a
rightdown.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a touch point is placed and removed from the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when the operating system cancels a touch.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a touch point is removed from the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a touch point is removed outside of the display object that initially
registered a touchstart.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a touch point is moved along the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |
Fired when a touch point is placed on the display object.
DisplayObject's interactive
property must be set to true
to fire event.
These events are propagating from the EventSystem in @pixi/events.
Name | Type | Description |
---|---|---|
event | PIXI.FederatedPointerEvent |
Event |