GeezerVison is showing maxgraph.github.io — CellMarker | @maxgraph/core
A helper class to process mouse locations and highlight cells.
To add a cell marker to an existing graph for highlighting all cells, the following code is used:
const marker = new CellMarker(graph); graph.addMouseListener({ mouseDown: ()=> {}, mouseMove: (sender, me) => { marker.process(me); }, mouseUp: ()=> {} });
Events
InternalEvent.MARK
Fires after a cell has been marked or unmarked. The state property contains the marked CellState or null if no state is marked.
Constructors
constructor
-
new CellMarker( graph: AbstractGraph, validColor?: string, invalidColor?: string, hotspot?: number,): CellMarker
Constructs a new cell marker.
Parameters
- graph: AbstractGraph
- validColor: string = DEFAULT_VALID_COLOR
- invalidColor: string = DEFAULT_INVALID_COLOR
- hotspot: number = DEFAULT_HOTSPOT
Portion of the width and height where a state intersects a given coordinate pair. A value of 0 means always highlight. Default is DEFAULT_HOTSPOT.
Returns CellMarker
Properties
currentColor
currentColor: string = NONE
Holds the current marker color.
enabled
enabled: boolean = true
Specifies if the marker is enabled.
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.
eventsEnabled
eventsEnabled: boolean = true
Specifies if events can be fired. Default is true.
eventSource
eventSource: EventTarget | null = null
Optional source for events.
hotspot
hotspot: number = DEFAULT_HOTSPOT
Specifies the portion of the width and height that should trigger a highlight.
The area around the center of the cell to be marked is used as the hotspot. Possible values are between 0 and 1.
hotspotEnabled
hotspotEnabled: boolean = false
Specifies if the hotspot is enabled.
invalidColor
invalidColor: string
Holds the invalid marker color.
validColor
validColor: string
Holds the valid marker color.
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
ProtectedcreateCellHighlight
-
Hook method to override the implementation of highlight.
destroy
-
Destroys the handler and all its resources and DOM nodes.
Returns void
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
- sender: EventTarget | null = null
Optional sender to be passed to the listener. Default value is the return value of getEventSource.
Returns void
getCell
-
Returns the Cell for the given event and cell.
This implementation returns the given cell.
Returns Cell | null
getEventSource
-
getEventSource(): EventTarget | null
Returns EventTarget | null
getMarkerColor
-
getMarkerColor(evt: Event, state: CellState | null, isValid: boolean): string
Parameters
- evt: Event
- state: CellState | null
- isValid: boolean
Returns string
getStateToMark
-
Returns the CellState to be marked for the given CellState under the mouse.
This implementation returns the given state.
intersects
-
Returns true if the given coordinate pair intersects the given state.
This returns true if the hotspot is 0 or the coordinates are inside the hotspot for the given cell state.
Returns boolean
isEnabled
-
Returns true if events are handled.
This implementation returns enabled.
Returns boolean
isEventsEnabled
-
isEventsEnabled(): boolean
isHotspotEnabled
-
isHotspotEnabled(): boolean
Returns true if hotspot is used in .
Returns boolean
isValidState
-
Returns true if the given CellState is a valid state.
If this returns true, then the state is stored in validState.
The return value of this method is used as the argument for getMarkerColor.
Returns boolean
markCell
-
markCell(cell: Cell, color: string): void
Marks the given cell using the given color, or validColor if no color is specified.
Returns void
process
-
Processes the given event and cell and marks the state returned by getState with the color returned by getMarkerColor.
If the markerColor is not null, then the state is stored in markedState.
If isValidState returns true, then the state is stored in validState regardless of the marker color.
The state is returned regardless of the marker color and valid state.
removeListener
-
removeListener(funct: Function): void
reset
-
Resets the state of the cell marker.
Returns void
setCurrentState
-
Sets and marks the current valid state.
Returns void
setEnabled
-
setEnabled(enabled: boolean): void
Enables or disables event handling.
This implementation updates enabled.
Parameters
- enabled: boolean
Boolean that specifies the new enabled state.
Returns void
setEventsEnabled
-
setEventsEnabled(value: boolean): void
setEventSource
-
setEventSource(value: EventTarget | null): void
Parameters
- value: EventTarget | null
Returns void
setHotspot
-
setHotspot(hotspot: number): void
setHotspotEnabled
-
setHotspotEnabled(enabled: boolean): void
Specifies whether the hotspot should be used in .
Returns void
On This Page
Events
Constructors
Properties
Methods
|