Options
All
  • Public
  • Public/Protected
  • All
Menu

Class SVGNode

A JS Representation of a HTML-Node. More specifically, all the SVG Types Nodes.

Usage

import { SVGNode } from 'ts-svgmanager'

// Initialize a circle with args
const circle = new SVGNode('circle').r(5).cx(10).cy(20)

Important methods

SVGNode.set and SVGNode.get

Lets you set and get attributes, respectively

SVGNode.append

Will let you append a childnode

SVGNode.tag

Allows you to add a tag for later reference from the SVGManager

SVGNode.on

Creates a event listener on the node

SVGNode.text

Which allows you to set the innerText

Hierarchy

Index

Constructors

constructor

  • new SVGNode(tagName: SVGTag): SVGNode
  • Construct a SVGNode respresenting the tagName element with no attributes, children or inner text.

    Parameters

    • tagName: SVGTag

      created node tagName

    Returns SVGNode

Accessors

attributes

  • get attributes(): AttributeMap
  • Fetch the current attributes

    Returns AttributeMap

children

events

  • get events(): SVGManagerEventDefinition[]
  • Fetch the events defined on the node

    Returns SVGManagerEventDefinition[]

innerText

  • get innerText(): string
  • Fetch the innerText of the node

    Returns string

tagName

  • get tagName(): SVGTag
  • Fetch the tagName of the node

    Returns SVGTag

tags

  • get tags(): string[]
  • Fetch the tags set on the node

    Returns string[]

Methods

animate

append

  • Mutates the SVGNode to append an child SVGNode child to the children of the current SVGNode. Then, it returns itself, for easy programming.

    Parameters

    Returns this

class

  • class(className: string): this
  • Adds a class to a SVGNode

    Parameters

    • className: string

    Returns this

clearEvents

  • clearEvents(eventName?: SVGEventName): this
  • Remove either all events from 1 SVGEventName, or all if not given a name

    Parameters

    • Optional eventName: SVGEventName

    Returns this

copy

cx

  • cx(val: AttributeValue): this
  • Setter for the cx attribute

    Parameters

    • val: AttributeValue

    Returns this

cy

  • cy(val: AttributeValue): this
  • Setter for the cy attribute

    Parameters

    • val: AttributeValue

    Returns this

equals

  • Checks deeply whether two nodes are equal

    Parameters

    Returns boolean

fill

  • fill(color: AttributeValue, opacity?: AttributeValue): this
  • Shortcut for setting fill attributes

    Parameters

    • color: AttributeValue
    • Optional opacity: AttributeValue

    Returns this

fillDef

  • fillDef(definition: SVGManagerDefinition, opacity?: AttributeValue): this
  • Shortcut for setting fill attributes to a definition (See more at SVGManager.define)

    Parameters

    • definition: SVGManagerDefinition
    • Optional opacity: AttributeValue

    Returns this

get

  • get(attr: SVGAttribute): AttributeValue | undefined
  • Fetch a specific attribute's value

    Parameters

    • attr: SVGAttribute

    Returns AttributeValue | undefined

map

  • map(attr: SVGAttribute, f: (_value: AttributeValue) => AttributeValue): SVGNode
  • Mutates the SVGNode to change an attribute attr by putting its value through the function f. Then, it returns itself, for easy programming.

    Note

    If the attribute was not set, the call still succeeds but does nothing.

    Parameters

    • attr: SVGAttribute
    • f: (_value: AttributeValue) => AttributeValue
        • (_value: AttributeValue): AttributeValue
        • Parameters

          • _value: AttributeValue

          Returns AttributeValue

    Returns SVGNode

on

  • on(eventName: SVGEventName, func: SVGManagerEventHandler): this
  • Mutates the SVGNode to add an event. Multiple functions can be set for the same event. Then, it returns itself, for easy programming.

    Parameters

    • eventName: SVGEventName
    • func: SVGManagerEventHandler

    Returns this

r

  • r(radius: AttributeValue): this
  • Setter for the r attribute

    Parameters

    • radius: AttributeValue

    Returns this

removeChild

  • removeChild(index: number): this
  • Remove child at certain index

    Parameters

    • index: number

    Returns this

removeChildren

  • removeChildren(): this

set

  • set(attr: SVGAttribute, value: AttributeValue): this
  • Mutates the SVGNode to add/change an attribute attr to value. Then, it returns itself, for easy programming.

    Parameters

    • attr: SVGAttribute
    • value: AttributeValue

    Returns this

shallowEquals

  • shallowEquals(node: SVGNode): boolean
  • Checks shallowly whether two nodes are equal

    Parameters

    Returns boolean

stroke

  • stroke(color: AttributeValue, width?: AttributeValue, opacity?: AttributeValue): this
  • Shortcut for setting stroke attributes

    Parameters

    • color: AttributeValue
    • Optional width: AttributeValue
    • Optional opacity: AttributeValue

    Returns this

strokeDef

  • strokeDef(definition: SVGManagerDefinition, width?: AttributeValue, opacity?: AttributeValue): this
  • Shortcut for setting stroke attributes to a definition (See more at SVGManager.define)

    Parameters

    • definition: SVGManagerDefinition
    • Optional width: AttributeValue
    • Optional opacity: AttributeValue

    Returns this

tag

  • tag(tag: string): this
  • Give tag to the SVGNode to mention later

    Parameters

    • tag: string

      Tag given to SVGNode

    Returns this

text

  • text(s: string): this
  • Sets the innerText of the node

    Parameters

    • s: string

    Returns this

toHTML

  • toHTML(): SVGElement
  • Returns the JS SVGElement equavalent of current SVGNode

    Returns SVGElement

toHash

  • toHash(): string
  • Returns the hashstring of SVGNode

    Returns string

untag

  • untag(tag: string): this
  • Removes tag from node, if it does not exist it does nothing.

    Parameters

    • tag: string

    Returns this

x

  • x(val: AttributeValue): this
  • Setter for the x attribute

    Parameters

    • val: AttributeValue

    Returns this

y

  • y(val: AttributeValue): this
  • Setter for the y attribute

    Parameters

    • val: AttributeValue

    Returns this

Generated using TypeDoc