Skip to content

Events

click, hover, leave — the three events emitted by Svgic. Hover over and click rooms to see what each event delivers.

Event log
Hover or click the rooms above

Subscribing

ts
client.on('click', (id, item) => { ... })
client.on('hover', (id, item) => { ... })
client.on('leave', (id, item) => { ... })

Event table

EventWheniditem
clickclick on an elementelement idbound data or null
clickclick on empty areanullnull
hovercursor enters an elementelement idbound data or null
leavecursor leaves an elementelement idbound data or null

item is null when the element exists in the SVG but has no matching entry in data.

Usage example

ts
client.on('click', (id, item) => {
  if (id === null) {
    // clicked empty area — deselect
    panel.hide()
    return
  }

  if (item === null) {
    // clicked an SVG element with no bound data
    console.warn('no data for', id)
    return
  }

  panel.show(item)
})