/**
* 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 (
<>
{
this.el = el;
}}
style={{
}}
/>
>
);
};
componentDidMount() {
};
}
export default MYNAMEHERE;
// Makes the background of the in-place editor non-transparent
let previousStartEditing = mxCellEditor.prototype.startEditing;
mxCellEditor.prototype.startEditing = (cell, trigger) =>
{
previousStartEditing.apply(this, arguments);
let state = this.graph.getView().getState(cell);
if (state != null)
{
let color = mxUtils.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.
mxGraphView.prototype.installListeners = function()
{
let graph = this.graph;
let container = graph.container;
if (container != null)
{
mxEvent.addGestureListeners(container,
mxUtils.bind(this, function(evt)
{
let pt = mxUtils.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 mxMouseEvent(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 mxMouseEvent(evt));
}
}),
mxUtils.bind(this, function(evt)
{
let pt = mxUtils.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 mxMouseEvent(evt, state));
}
else if (this.isContainerEvent(evt))
{
graph.fireMouseEvent(mxEvent.MOUSE_MOVE,
new mxMouseEvent(evt));
}
}),
mxUtils.bind(this, function(evt)
{
let pt = mxUtils.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 mxMouseEvent(evt, state));
}
else if (this.isContainerEvent(evt))
{
graph.fireMouseEvent(mxEvent.MOUSE_UP,
new mxMouseEvent(evt));
}
}));
// Adds listener for double click handling on background
mxEvent.addListener(container, 'dblclick',
mxUtils.bind(this, function(evt)
{
let pt = mxUtils.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,
mxUtils.bind(this, function(evt)
{
if (this.isContainerEvent(evt))
{
graph.popupMenuHandler.hideMenu();
}
}),
mxUtils.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 mxMouseEvent(evt));
}
}),
mxUtils.bind(this, function(evt)
{
if (this.captureDocumentGesture)
{
graph.fireMouseEvent(mxEvent.MOUSE_UP,
new mxMouseEvent(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