Skip to content
Advertisement

How to drag html shapes into mxgraph canvas

I want to drag and drop those 3 shapes into mxgraph canvas (which is the black area).

Note: I want to fully preserve the drag element on the canvas, including shape, size, color, text, etc.

I don’t know whether insertVertex does it work. Dragging the orange,red or other box in to the dark area currently does not work.

JavaScript
JavaScript
JavaScript

Advertisement

Answer

In mxgraph, normally you do that using so-called “stencil”. You can define your own custom shapes using XML, and then use mxgraph to take care of the rest. RTFM 🙂

If you don’t want to follow this baseline path, then things will become increasingly harder. Anyway, back to the point – you can use this example (it’s an adopted version of the “sidebar” code you can find in the mxgraph) – for the details on functions see the Sidebar.js:

JavaScript
JavaScript

Note that your code, and the other answer focuses on generic drag-n-drop, which is not applicable to mxgraph. You need to use library-specific code.

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement