/** * Copyright (c) 2006-2013, JGraph Ltd */ import React from 'react'; import mxEvent from '../mxgraph/util/mxEvent'; import mxGraph from '../mxgraph/view/mxGraph'; import mxRubberband from '../mxgraph/handler/mxRubberband'; import { convertPoint, getValue } from '../../packages/core/src/util/utils'; class MYNAMEHERE extends React.Component { constructor(props) { super(props); } render() { // A container for the graph return ( <>

mxGraph using Server-side Image

This example demonstrates using a server-side image of the graph as the diagram in the client. This may be used to improve drawing-speed in older browser and on devices with slower processors.
{ this.el = el; }} style={{ }} /> ); }; componentDidMount() { }; } export default MYNAMEHERE; // Makes the background of the in-place editor non-transparent let previousStartEditing = CellEditorHandler.prototype.startEditing; CellEditorHandler.prototype.startEditing = (cell, trigger) => { previousStartEditing.apply(this, arguments); let state = this.graph.getView().getState(cell); if (state != null) { let color = getValue(state.style, 'fillColor', 'white'); this.textarea.style.background = color; } }; // Replaces the event firing mechanism in the graph view since there are // no longer any DOM elements that fire events for the actual states we // have to find the state under the mouse using graph.getCellAt and then // fire the event for the state from here instead. // FIXME: Since we do not render the label we don't have the label bounds // here which means hit detection will only work for the vertex bounds, // the edge but not for overlapping labels or most part of the edge labels. GraphView.prototype.installListeners = function() { let graph = this.graph; let container = graph.container; if (container != null) { mxEvent.addGestureListeners(container, (evt) => { let pt = convertPoint(graph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt)); let cell = graph.getCellAt(pt.x, pt.y); let state = this.getState(cell); if (state != null) { graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new InternalMouseEvent(evt, state)); } // Condition to avoid scrollbar events starting a rubberband // selection else if (this.isContainerEvent(evt) && ((!Client.IS_GC && !Client.IS_SF) || !this.isScrollEvent(evt))) { graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new InternalMouseEvent(evt)); } }), ((evt) => { let pt = convertPoint(graph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt)); let cell = graph.getCellAt(pt.x, pt.y); let state = this.getState(cell); if (state != null) { graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new InternalMouseEvent(evt, state)); } else if (this.isContainerEvent(evt)) { graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new InternalMouseEvent(evt)); } }), ((evt) => { let pt = convertPoint(graph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt)); let cell = graph.getCellAt(pt.x, pt.y); let state = this.getState(cell); if (state != null) { graph.fireMouseEvent(mxEvent.MOUSE_UP, new InternalMouseEvent(evt, state)); } else if (this.isContainerEvent(evt)) { graph.fireMouseEvent(mxEvent.MOUSE_UP, new InternalMouseEvent(evt)); } })); // Adds listener for double click handling on background mxEvent.addListener(container, 'dblclick', ((evt) => { let pt = convertPoint(graph.container, mxEvent.getClientX(evt), mxEvent.getClientY(evt)); let cell = graph.getCellAt(pt.x, pt.y); graph.dblClick(evt, cell); }) ); // Adds basic listeners for graph event dispatching outside of the // container and finishing the handling of a single gesture mxEvent.addGestureListeners(document, ((evt) => { if (this.isContainerEvent(evt)) { graph.getPlugin('PopupMenuHandler').hideMenu(); } }), ((evt) => { // Hides the tooltip if mouse is outside container if (graph.getPlugin('TooltipHandler') != null && graph.getPlugin('TooltipHandler').isHideOnHover()) { graph.getPlugin('TooltipHandler').hide(); } if (this.captureDocumentGesture && graph.isMouseDown && !mxEvent.isConsumed(evt)) { graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new InternalMouseEvent(evt)); } }), ((evt) => { if (this.captureDocumentGesture) { graph.fireMouseEvent(mxEvent.MOUSE_UP, new InternalMouseEvent(evt)); } }) ); } };

Important:

To use this example, start com.mxgraph.examples.web.Main in Java and point your
browser to: http://localhost:8080/mxgraph/javascript/examples/serverview.html