/** * 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'; 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 = CellEditor.prototype.startEditing; CellEditor.prototype.startEditing = (cell, trigger) => { previousStartEditing.apply(this, arguments); let state = this.graph.getView().getState(cell); if (state != null) { let color = utils.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, utils.bind(this, function(evt) { let pt = utils.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) && ((!mxClient.IS_GC && !mxClient.IS_SF) || !this.isScrollEvent(evt))) { graph.fireMouseEvent(mxEvent.MOUSE_DOWN, new InternalMouseEvent(evt)); } }), utils.bind(this, function(evt) { let pt = utils.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)); } }), utils.bind(this, function(evt) { let pt = utils.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', utils.bind(this, function(evt) { let pt = utils.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, utils.bind(this, function(evt) { if (this.isContainerEvent(evt)) { graph.popupMenuHandler.hideMenu(); } }), utils.bind(this, function(evt) { // Hides the tooltip if mouse is outside container if (graph.tooltipHandler != null && graph.tooltipHandler.isHideOnHover()) { graph.tooltipHandler.hide(); } if (this.captureDocumentGesture && graph.isMouseDown && !mxEvent.isConsumed(evt)) { graph.fireMouseEvent(mxEvent.MOUSE_MOVE, new InternalMouseEvent(evt)); } }), utils.bind(this, function(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