GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • @maxgraph/core

This view

  • Original page
  • New address

GeezerVison is showing maxgraph.github.io — CellOverlay | @maxgraph/core

  • CellOverlay

Class CellOverlay

Extends EventSource to implement a graph overlay, represented by an icon and a tooltip.

Overlays can handle and fire InternalEvent.CLICK events and are added to the graph using AbstractGraph.addCellOverlay, and removed using AbstractGraph.removeCellOverlay, or AbstractGraph.removeCellOverlays to remove all overlays. The AbstractGraph.getCellOverlays function returns the array of overlays for a given cell in a graph. If multiple overlays exist for the same cell, then getBounds should be overridden in at least one of the overlays.

Overlays appear on top of all cells in a special layer. If this is not desirable, then the image must be rendered as part of the shape or label of the cell instead.

For cell overlays to be printed, use PrintPreview.printOverlays.

Example

The following adds a new overlay for a given vertex and selects the cell if the overlay is clicked.

const overlay = new CellOverlay(img, html);
graph.addCellOverlay(vertex, overlay);
overlay.addListener(InternalEvent.CLICK, (sender, evt) => {
const cell = evt.getProperty('cell');
graph.setSelectionCell(cell);
});

Events

InternalEvent.CLICK

Fires when the user clicks on the overlay. In the EventObject parameter of the listener function:

  • the event property contains the corresponding MouseEvent
  • the cell property contains the Cell.

For touch devices this is fired if the element receives a touchend event.

Hierarchy (View Summary)

  • EventSource
    • CellOverlay

Implements

  • ObjectIdentity
  • Defined in view/cell/CellOverlay.ts:64
Index

Constructors

constructor

Properties

align cursor defaultOverlap eventListeners eventsEnabled eventSource image offset tooltip? verticalAlign

Methods

addListener destroy fireEvent getBounds getEventSource isEventsEnabled removeListener setEventsEnabled setEventSource toString

Constructors

constructor

  • new CellOverlay(
        image: ImageBox,
        tooltip?: string | null,
        align?: AlignValue,
        verticalAlign?: VAlignValue,
        offset?: Point,
        cursor?: string,
    ): CellOverlay

    Constructs a new overlay using the given image and tooltip.

    Parameters

    • image: ImageBox

      ImageBox that represents the icon to be displayed.

    • tooltip: string | null = null

      Optional string that specifies the tooltip.

    • align: AlignValue = 'right'

      Optional horizontal alignment for the overlay. Possible values are 'left', 'center' and 'right' (default).

    • verticalAlign: VAlignValue = 'bottom'

      Vertical alignment for the overlay. Possible values are 'top', 'middle' and 'bottom' (default).

    • offset: Point = ...

      Optional offset for positioning the overlay relative to its alignment. Scaled according to the current graph scale. Default is new Point().

    • cursor: string = 'help'

      Optional CSS cursor for the overlay. Default is 'help'.

    Returns CellOverlay

    Overrides EventSource.constructor

    • Defined in view/cell/CellOverlay.ts:75

Properties

align

align: AlignValue = 'right'

Holds the horizontal alignment for the overlay.

For edges, the overlay always appears in the center of the edge.

Default

'right'
  • Defined in view/cell/CellOverlay.ts:109

cursor

cursor: string = 'help'

Holds the cursor for the overlay.

Default

'help'.
  • Defined in view/cell/CellOverlay.ts:128

defaultOverlap

defaultOverlap: number = 0.5

Defines the overlapping for the overlay, that is, the proportional distance from the origin to the point defined by the alignment.

Default

0.5
  • Defined in view/cell/CellOverlay.ts:134

eventListeners

eventListeners: EventListenerObject[] = []

Holds the event names and associated listeners in an array. The array contains the event name followed by the respective listener for each registered listener.

Inherited from EventSource.eventListeners

  • Defined in view/event/EventSource.ts:58

eventsEnabled

eventsEnabled: boolean = true

Specifies if events can be fired. Default is true.

Inherited from EventSource.eventsEnabled

  • Defined in view/event/EventSource.ts:63

eventSource

eventSource: EventTarget | null = null

Optional source for events.

Default

null

Inherited from EventSource.eventSource

  • Defined in view/event/EventSource.ts:69

image

image: ImageBox

Holds the Image to be used as the icon.

  • Defined in view/cell/CellOverlay.ts:96

offset

offset: Point = ...

Holds the offset as an Point. The offset will be scaled according to the current scale.

  • Defined in view/cell/CellOverlay.ts:122

Optionaltooltip

tooltip?: string | null

Holds the optional string to be used as the tooltip.

  • Defined in view/cell/CellOverlay.ts:101

verticalAlign

verticalAlign: VAlignValue = 'bottom'

Holds the vertical alignment for the overlay.

For edges, the overlay always appears in the center of the edge.

Default

'bottom'
  • Defined in view/cell/CellOverlay.ts:117

Methods

addListener

  • addListener(name: string, funct: Function): void

    Binds the specified function to the given event name. If no event name is given, then the listener is registered for all events.

    The parameters of the listener are the sender and an EventObject.

    Parameters

    • name: string
    • funct: Function

    Returns void

    Inherited from EventSource.addListener

    • Defined in view/event/EventSource.ts:105

destroy

  • destroy(): void

    Clears all registered event listeners.

    Subclasses with a destroy method should call super.destroy() at the end of their own cleanup to ensure no stale listeners remain.

    Returns void

    Inherited from EventSource.destroy

    • Defined in view/event/EventSource.ts:166

fireEvent

  • fireEvent(evt: EventObject, sender?: EventTarget | null): void

    Dispatches the given event to the listeners which are registered for the event. The sender argument is optional. The current execution scope ("this") is used for the listener invocation.

    Example:

    fireEvent(new EventObject("eventName", key1, val1, .., keyN, valN))
    

    Parameters

    • evt: EventObject

      EventObject that represents the event.

    • sender: EventTarget | null = null

      Optional sender to be passed to the listener. Default value is the return value of getEventSource.

    Returns void

    Inherited from EventSource.fireEvent

    • Defined in view/event/EventSource.ts:139

getBounds

  • getBounds(state: CellState): Rectangle

    Returns the bounds of the overlay for the given CellState as an Rectangle. This should be overridden when using multiple overlays per cell so that the overlays do not overlap.

    The following example will place the overlay along an edge (where x=[-1..1] from the start to the end of the edge and y is the orthogonal offset in px).

    const overlayBounds = overlay.getBounds;
    overlay.getBounds = function(state) {
    const bounds = overlayBounds.call(this, state);

    if (state.view.graph.getDataModel().isEdge(state.cell)) {
    const pt = state.view.getPoint(state, {x: 0, y: 0, relative: true});

    bounds.x = pt.x - bounds.width / 2;
    bounds.y = pt.y - bounds.height / 2;
    }

    return bounds;
    };

    Parameters

    • state: CellState

      CellState that represents the current state of the associated cell.

    Returns Rectangle

    • Defined in view/cell/CellOverlay.ts:161

getEventSource

  • getEventSource(): EventTarget | null

    Returns eventSource.

    Returns EventTarget | null

    Inherited from EventSource.getEventSource

    • Defined in view/event/EventSource.ts:88

isEventsEnabled

  • isEventsEnabled(): boolean

    Returns eventsEnabled.

    Returns boolean

    Inherited from EventSource.isEventsEnabled

    • Defined in view/event/EventSource.ts:74

removeListener

  • removeListener(funct: Function): void

    Removes all occurrences of the given listener from eventListeners.

    Parameters

    • funct: Function

    Returns void

    Inherited from EventSource.removeListener

    • Defined in view/event/EventSource.ts:112

setEventsEnabled

  • setEventsEnabled(value: boolean): void

    Sets eventsEnabled.

    Parameters

    • value: boolean

    Returns void

    Inherited from EventSource.setEventsEnabled

    • Defined in view/event/EventSource.ts:81

setEventSource

  • setEventSource(value: EventTarget | null): void

    Sets eventSource.

    Parameters

    • value: EventTarget | null

    Returns void

    Inherited from EventSource.setEventSource

    • Defined in view/event/EventSource.ts:95

toString

  • toString(): string | null | undefined

    Returns the textual representation of the overlay to be used as the tooltip.

    This implementation returns tooltip.

    Returns string | null | undefined

    • Defined in view/cell/CellOverlay.ts:240

Settings

Member Visibility
  • Protected
  • Inherited
Theme

On This Page

ExampleEvents
Constructors
constructor
Properties
aligncursordefaultOverlapeventListenerseventsEnabledeventSourceimageoffsettooltipverticalAlign
Methods
addListenerdestroyfireEventgetBoundsgetEventSourceisEventsEnabledremoveListenersetEventsEnabledsetEventSourcetoString
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.