graflow, autoplacement 1.6, wires with arrows
This commit is contained in:
@@ -27,6 +27,7 @@
|
|||||||
width: 6px;
|
width: 6px;
|
||||||
background: #FFF;
|
background: #FFF;
|
||||||
z-index: 99;
|
z-index: 99;
|
||||||
|
opacity: 0.3;
|
||||||
}
|
}
|
||||||
|
|
||||||
.bzgf-node [data-direction="w"]{ left: -7px; top: 50%; transform: translateY(-50%);}
|
.bzgf-node [data-direction="w"]{ left: -7px; top: 50%; transform: translateY(-50%);}
|
||||||
@@ -149,9 +150,26 @@
|
|||||||
place-items: center;
|
place-items: center;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
.bzgf-wire{ stroke: #AAA; stroke-width: 4; }
|
.bzgf-wire{ stroke: #FF0; stroke-width: 2; }
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
|
<svg style="display:none" aria-hidden="true">
|
||||||
|
<template id="svg-arrows">
|
||||||
|
<defs>
|
||||||
|
<marker id="arrow"
|
||||||
|
viewBox="0 0 15 15"
|
||||||
|
refX="15"
|
||||||
|
refY="7"
|
||||||
|
markerWidth="15"
|
||||||
|
markerHeight="15"
|
||||||
|
orient="auto-start-reverse"
|
||||||
|
markerUnits="userSpaceOnUse">
|
||||||
|
<path d="M0,0 L15,7 L0,15 Z" fill="#FF0"/>
|
||||||
|
</marker>
|
||||||
|
</defs>
|
||||||
|
</template>
|
||||||
|
</svg>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="bzgf-node" data-nodetype="start">
|
<div class="bzgf-node" data-nodetype="start">
|
||||||
<div class="text"></div>
|
<div class="text"></div>
|
||||||
@@ -209,5 +227,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="port" data-id="inp1" data-direction="n"></div>
|
<div class="port" data-id="inp1" data-direction="n"></div>
|
||||||
<div class="port" data-id="out1" data-direction="s"></div>
|
<div class="port" data-id="out1" data-direction="s"></div>
|
||||||
|
<div class="port" data-id="inout1" data-direction="w"></div>
|
||||||
|
<div class="port" data-id="inout2" data-direction="e"></div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -20,20 +20,20 @@
|
|||||||
},
|
},
|
||||||
{ "nodeType": "database",
|
{ "nodeType": "database",
|
||||||
"id": "wcx",
|
"id": "wcx",
|
||||||
"coords": { "x": 250, "y": 650}
|
"coords": { "x": 500, "y": 450}
|
||||||
},
|
},
|
||||||
{ "nodeType": "end",
|
{ "nodeType": "end",
|
||||||
"id": "ert",
|
"id": "ert",
|
||||||
"coords": { "x": 250, "y": 850}
|
"coords": { "x": 250, "y": 650}
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"links": [
|
"links": [
|
||||||
{ "from": ["aze", "out1"], "to": ["aze2", "inout1"] },
|
{ "from": ["aze", "out1"], "to": ["aze2", "inout1"], "endArrow":true },
|
||||||
{ "from": ["aze2", "inout2"], "to": ["qsd", "inp1"] },
|
{ "from": ["aze2", "inout2"], "to": ["qsd", "inp1"], "endArrow":true },
|
||||||
{ "from": ["qsd", "out1"], "to": ["aze2", "inout3"] },
|
{ "from": ["qsd", "out1"], "to": ["aze2", "inout3"], "endArrow":true },
|
||||||
{ "from": ["qsd", "out2"], "to": ["qsd2", "inp1"] },
|
{ "from": ["qsd", "out2"], "to": ["qsd2", "inp1"], "endArrow":true },
|
||||||
{ "from": ["qsd2", "out1"], "to": ["wcx", "inout1"] },
|
{ "from": ["qsd2", "inout2"], "to": ["wcx", "inout3"], "startArrow":true , "endArrow":true },
|
||||||
{ "from": ["wcx", "inout2"], "to": ["ert", "inp1"] }
|
{ "from": ["qsd2", "out1"], "to": ["ert", "inp1"], "endArrow":true }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Vendored
+16
-8
@@ -15,7 +15,6 @@ class BZgraflow extends Buildoz{
|
|||||||
console.warn('BZgraflow: No flow URL !?')
|
console.warn('BZgraflow: No flow URL !?')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.loadFlow(flowUrl) // Let it load async while we coat
|
|
||||||
this.mainContainer = document.createElement('div')
|
this.mainContainer = document.createElement('div')
|
||||||
this.mainContainer.classList.add('bzgf-main-container')
|
this.mainContainer.classList.add('bzgf-main-container')
|
||||||
this.shadow = this.mainContainer.attachShadow({ mode: 'open' })
|
this.shadow = this.mainContainer.attachShadow({ mode: 'open' })
|
||||||
@@ -28,6 +27,7 @@ class BZgraflow extends Buildoz{
|
|||||||
this.shadow.append(this.wiresContainer)
|
this.shadow.append(this.wiresContainer)
|
||||||
this.shadow.append(this.nodesContainer)
|
this.shadow.append(this.nodesContainer)
|
||||||
this.append(this.mainContainer)
|
this.append(this.mainContainer)
|
||||||
|
this.loadFlow(flowUrl) // Let it load async
|
||||||
}
|
}
|
||||||
|
|
||||||
async loadFlow(url){
|
async loadFlow(url){
|
||||||
@@ -59,9 +59,14 @@ class BZgraflow extends Buildoz{
|
|||||||
const doc = new DOMParser().parseFromString(html, 'text/html')
|
const doc = new DOMParser().parseFromString(html, 'text/html')
|
||||||
this.nodesRegistry = {}
|
this.nodesRegistry = {}
|
||||||
for(const tpl of doc.querySelectorAll('template')){
|
for(const tpl of doc.querySelectorAll('template')){
|
||||||
const rootEl = tpl.content.querySelector('.bzgf-node')
|
if(tpl.id=='svg-arrows'){
|
||||||
if(!rootEl) continue
|
this.wiresContainer.appendChild(tpl.querySelector('defs').cloneNode(true))
|
||||||
this.nodesRegistry[rootEl.dataset.nodetype] = rootEl
|
this.arrowDefined = true
|
||||||
|
} else {
|
||||||
|
const rootEl = tpl.content.querySelector('.bzgf-node')
|
||||||
|
if(!rootEl) continue
|
||||||
|
this.nodesRegistry[rootEl.dataset.nodetype] = rootEl
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Now load styles (once)
|
// Now load styles (once)
|
||||||
@@ -88,12 +93,16 @@ class BZgraflow extends Buildoz{
|
|||||||
return(this.stagedNodes[id])
|
return(this.stagedNodes[id])
|
||||||
}
|
}
|
||||||
|
|
||||||
addWire(idNode1, idPort1, idNode2, idPort2){
|
addWire(link){
|
||||||
|
const [idNode1, idPort1] = link.from
|
||||||
|
const [idNode2, idPort2] = link.to
|
||||||
const path = this.bezier(idNode1, idPort1, idNode2, idPort2, this.getBZAttribute('tension'))
|
const path = this.bezier(idNode1, idPort1, idNode2, idPort2, this.getBZAttribute('tension'))
|
||||||
const id = `${idNode1}_${idNode2}`
|
const id = `${idNode1}_${idNode2}`
|
||||||
this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
this.stagedWires[id] = document.createElementNS('http://www.w3.org/2000/svg', 'path')
|
||||||
this.stagedWires[id].setAttribute('d', path)
|
this.stagedWires[id].setAttribute('d', path)
|
||||||
this.stagedWires[id].setAttribute('fill', 'none')
|
this.stagedWires[id].setAttribute('fill', 'none')
|
||||||
|
if(this.arrowDefined && link.endArrow) this.stagedWires[id].setAttribute('marker-end','url(#arrow)')
|
||||||
|
if(this.arrowDefined && link.startArrow) this.stagedWires[id].setAttribute('marker-start','url(#arrow)')
|
||||||
this.stagedWires[id].classList.add('bzgf-wire')
|
this.stagedWires[id].classList.add('bzgf-wire')
|
||||||
this.stagedWires[id].dataset.id = id
|
this.stagedWires[id].dataset.id = id
|
||||||
this.wiresContainer.append(this.stagedWires[id])
|
this.wiresContainer.append(this.stagedWires[id])
|
||||||
@@ -107,9 +116,7 @@ class BZgraflow extends Buildoz{
|
|||||||
const nodeEl = this.addNode(node.nodeType, node.id , node.coords.x, node.coords.y)
|
const nodeEl = this.addNode(node.nodeType, node.id , node.coords.x, node.coords.y)
|
||||||
}
|
}
|
||||||
for(const link of this.flow.links){
|
for(const link of this.flow.links){
|
||||||
const [nodeId1, portId1] = link.from
|
this.addWire(link)
|
||||||
const [nodeId2, portId2] = link.to
|
|
||||||
this.addWire(nodeId1, portId1, nodeId2, portId2)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -330,3 +337,4 @@ class BZgraflow extends Buildoz{
|
|||||||
|
|
||||||
}
|
}
|
||||||
Buildoz.define('graflow', BZgraflow)
|
Buildoz.define('graflow', BZgraflow)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user