graflow: refacto & facto of buildSegment
This commit is contained in:
57
bzGraflow.js
57
bzGraflow.js
@@ -459,6 +459,24 @@ class BZgraflow extends Buildoz{
|
|||||||
return({ x: x - r.left, y: y - r.top })
|
return({ x: x - r.left, y: y - r.top })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
emitWireSegment(x1, y1, c1x, c1y, c2x, c2y, x2, y2, wireType, startAxis, loop=false){
|
||||||
|
if(loop) wireType = 'bezier' // loops only use bezier to look good
|
||||||
|
|
||||||
|
if(wireType === 'bezier'){
|
||||||
|
return(`C ${c1x} ${c1y}, ${c2x} ${c2y}, ${x2} ${y2}`)
|
||||||
|
}
|
||||||
|
if(wireType === 'straight'){
|
||||||
|
return(`L ${c1x} ${c1y} L ${c2x} ${c2y} L ${x2} ${y2}`)
|
||||||
|
}
|
||||||
|
if(wireType === 'ortho'){
|
||||||
|
if(startAxis === 'v'){
|
||||||
|
return(`V ${(c1y + c2y) / 2} H ${c2x} V ${y2}`)
|
||||||
|
}
|
||||||
|
return(`H ${(c1x + c2x) / 2} V ${c2y} H ${x2}`)
|
||||||
|
}
|
||||||
|
return('')
|
||||||
|
}
|
||||||
|
|
||||||
linkNodes(idNode1, idPort1, idNode2, idPort2) {
|
linkNodes(idNode1, idPort1, idNode2, idPort2) {
|
||||||
const tension = parseInt(this.getBZAttribute('tension')) || 60
|
const tension = parseInt(this.getBZAttribute('tension')) || 60
|
||||||
const wireType = this.getBZAttribute('wiretype') || 'bezier'
|
const wireType = this.getBZAttribute('wiretype') || 'bezier'
|
||||||
@@ -494,23 +512,10 @@ class BZgraflow extends Buildoz{
|
|||||||
c2y -= 1*tension
|
c2y -= 1*tension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const startAxis = ['n', 's'].includes(port1.direction) ? 'v' : 'h'
|
||||||
if((wireType === 'bezier') || loop) { // loops only use bezier to look good
|
const seg = this.emitWireSegment(x1, y1, c1x, c1y, c2x, c2y, x2, y2, wireType, startAxis, loop)
|
||||||
return(`M ${x1} ${y1} C ${c1x} ${c1y}, ${c2x} ${c2y}, ${x2} ${y2}`)
|
if(!seg) return('')
|
||||||
}
|
return(`M ${x1} ${y1} ${seg}`)
|
||||||
if((wireType === 'straight') && (!loop)) {
|
|
||||||
return(`M ${x1} ${y1} L ${c1x} ${c1y} L ${c2x} ${c2y} L ${x2} ${y2}`)
|
|
||||||
}
|
|
||||||
if((wireType === 'ortho') && (!loop)) {
|
|
||||||
let path = `M ${x1} ${y1} `
|
|
||||||
if(['n', 's'].includes(port1.direction)) {
|
|
||||||
path += `V ${(c1y+c2y)/2} H ${c2x} V ${y2}`
|
|
||||||
} else {
|
|
||||||
path += `H ${(c1x+c2x)/2} V ${c2y} H ${x2}`
|
|
||||||
}
|
|
||||||
return(path)
|
|
||||||
}
|
|
||||||
return('')
|
|
||||||
}
|
}
|
||||||
linkInterNodes(idNode1, idPort1, idNode2, idPort2, interNodes, orientation='horizontal') {
|
linkInterNodes(idNode1, idPort1, idNode2, idPort2, interNodes, orientation='horizontal') {
|
||||||
const tension = parseInt(this.getBZAttribute('tension')) || 60
|
const tension = parseInt(this.getBZAttribute('tension')) || 60
|
||||||
@@ -540,22 +545,8 @@ class BZgraflow extends Buildoz{
|
|||||||
c2x = x2
|
c2x = x2
|
||||||
c2y = Math.floor(y2 - tension)
|
c2y = Math.floor(y2 - tension)
|
||||||
}
|
}
|
||||||
if(wireType === 'bezier') {
|
const startAxis = (orientation1=='vertical') ? 'v' : 'h'
|
||||||
return(`C ${c1x} ${c1y}, ${c2x} ${c2y}, ${x2} ${y2}`)
|
return(this.emitWireSegment(x1, y1, c1x, c1y, c2x, c2y, x2, y2, wireType, startAxis, false))
|
||||||
}
|
|
||||||
if(wireType === 'straight') {
|
|
||||||
return(`L ${c1x} ${c1y} L ${c2x} ${c2y} L ${x2} ${y2}`)
|
|
||||||
}
|
|
||||||
if(wireType === 'ortho') {
|
|
||||||
let path = `M ${x1} ${y1} `
|
|
||||||
if(['n', 's'].includes(port1.direction)) {
|
|
||||||
path += `V ${(c1y+c2y)/2} H ${c2x} V ${y2}`
|
|
||||||
} else {
|
|
||||||
path += `H ${(c1x+c2x)/2} V ${c2y} H ${x2}`
|
|
||||||
}
|
|
||||||
return(path)
|
|
||||||
}
|
|
||||||
return(``)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start/end points in SVG coords (works for both bezier and line)
|
// Start/end points in SVG coords (works for both bezier and line)
|
||||||
|
|||||||
Reference in New Issue
Block a user