I'm using @jsplumb/browser-ui
to create some Nodes
in my Nuxtjs/Vuejs
application, as described in its documentation. But I want to create nodes at runtime. I can not do it.
I want to create a nodes/rectangle
shape whenever the user clicks the Add Event
button. So instead of creating the Nodes
statically, I want to create it dynamically/runtime based on button click. I don't understand how to do this using the jsPlumb
documentation as they don't have a specific code example to achieve the same.
The following is my code:
<template> <div> <div class="container-fluid"> <div class="row"> <div class="col-md-6"> <button class="btn btn-primary btn-sm" @click="addConnector()"> Add Connector </button> <button class="btn btn-primary btn-sm" @click="addNode()"> Add Event </button> <button class="btn btn-success btn-sm" @click="submitEvents()"> Submit </button> </div> </div> <div class="row"> <div class="col-md-12"> <div id="diagram" ref="diagram" style="position: relative; width:100%; height:100%;" /> </div> </div> </div> </div> </template> <script> let jsPlumb = null export default { data () { return { nodeCounter: 0, nodeArray: [], connectorCounter: 0, connectorArray: [], allEventsInfoArray: [] } }, async mounted () { if (process.browser) { const jsPlumbBrowserUI = await import('@jsplumb/browser-ui') jsPlumb = jsPlumbBrowserUI.newInstance({ dragOptions: { cursor: 'pointer', zIndex: 2000 }, container: this.$refs.diagram }) console.log(jsPlumb) } }, methods: { // On click of Add Node button create the draggable node into the jsPlumb canvas addNode () { // const container = "<button class='btn btn-info' id='container_" + this.nodeCounter + "'></button>" this.nodeCounter++ }, // On click of Add Connector button create the draggable node into the jsPlumb canvas addConnector () { console.log('Add Connector : ') jsPlumb.connect({ anchor: 'AutoDefault', endpoints: ['Dot', 'Blank'], overlays: [ { type: 'Arrow', options: { location: 1 } }, { type: 'Label', options: { label: 'foo', location: 0.25, id: 'myLabel' } } ] }) } } } </script> <style scoped> </style>
Hope this answer helps someone in the future:
According to contributor GitHub's reply, we are unable to create
Nodes/Shapes
withinJsplumb Community Edition
.I started using the
DrawFlow
library instead of theJsplumb
library, it's great and meets all the requirements I need for my application.