|
@ -1,6 +1,6 @@ |
|
|
<template> |
|
|
<template> |
|
|
<div class="compBox"> |
|
|
<div class="compBox"> |
|
|
<div id="container" class="compCon"> |
|
|
<div id="container" class="compCon" ref="canvas"> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</div> |
|
|
</template> |
|
|
</template> |
|
@ -12,22 +12,34 @@ export default { |
|
|
name: 'sensors', |
|
|
name: 'sensors', |
|
|
data(){ |
|
|
data(){ |
|
|
return { |
|
|
return { |
|
|
|
|
|
graph:null |
|
|
} |
|
|
} |
|
|
}, |
|
|
}, |
|
|
components: { |
|
|
components: { |
|
|
}, |
|
|
}, |
|
|
mounted(){ |
|
|
mounted(){ |
|
|
this.initGraph(); |
|
|
this.refresh(); |
|
|
|
|
|
window.addEventListener("resize", |
|
|
|
|
|
_.debounce(this.refresh.bind(this), 1000) |
|
|
|
|
|
) |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
initGraph(){ |
|
|
refresh(){ |
|
|
|
|
|
let _this = this; |
|
|
|
|
|
this.$nextTick(() => { |
|
|
|
|
|
_this.initGraph(_this.$refs["canvas"].offsetHeight); |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
|
|
|
initGraph(canvasHeight){ |
|
|
|
|
|
|
|
|
|
|
|
let unitH = 42; |
|
|
|
|
|
|
|
|
|
|
|
let average = unitH + (canvasHeight - unitH*13)/12; |
|
|
Graph.registerNode( |
|
|
Graph.registerNode( |
|
|
'sensor', |
|
|
'sensor', |
|
|
{ |
|
|
{ |
|
|
width: 180, |
|
|
width: 180, |
|
|
height: 42, |
|
|
height: unitH, |
|
|
markup: [ |
|
|
markup: [ |
|
|
{ |
|
|
{ |
|
|
tagName: 'rect', |
|
|
tagName: 'rect', |
|
@ -97,8 +109,12 @@ export default { |
|
|
}, |
|
|
}, |
|
|
true, |
|
|
true, |
|
|
) |
|
|
) |
|
|
|
|
|
if(this.graph){ |
|
|
const graph = new Graph({ |
|
|
this.graph.clearCells(); |
|
|
|
|
|
this.graph = null; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
this.graph = new Graph({ |
|
|
container: document.getElementById('container'), |
|
|
container: document.getElementById('container'), |
|
|
autoResize: true, |
|
|
autoResize: true, |
|
|
grid: false, |
|
|
grid: false, |
|
@ -114,8 +130,8 @@ export default { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function createSub(x, y, title) { |
|
|
const createSub = (x, y, title) => { |
|
|
return graph.addNode({ |
|
|
return this.graph.addNode({ |
|
|
x, |
|
|
x, |
|
|
y, |
|
|
y, |
|
|
shape: 'sensor', |
|
|
shape: 'sensor', |
|
@ -132,8 +148,8 @@ export default { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function link(source, target, vertices) { |
|
|
const link = (source, target, vertices) => { |
|
|
return graph.addEdge({ |
|
|
return this.graph.addEdge({ |
|
|
source: { |
|
|
source: { |
|
|
cell: source, |
|
|
cell: source, |
|
|
anchor: { |
|
|
anchor: { |
|
@ -153,7 +169,7 @@ export default { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
const main = graph.addNode({ |
|
|
const main = this.graph.addNode({ |
|
|
shape: 'circle', |
|
|
shape: 'circle', |
|
|
x: 310, |
|
|
x: 310, |
|
|
y: 80, |
|
|
y: 80, |
|
@ -184,7 +200,7 @@ export default { |
|
|
] |
|
|
] |
|
|
|
|
|
|
|
|
subItems.forEach((item, index) => { |
|
|
subItems.forEach((item, index) => { |
|
|
let temp = createSub(0, index * 68, item); |
|
|
let temp = createSub(0, index * average, item); |
|
|
link(main, temp); |
|
|
link(main, temp); |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
@ -219,7 +235,7 @@ export default { |
|
|
// }, |
|
|
// }, |
|
|
// ]) |
|
|
// ]) |
|
|
|
|
|
|
|
|
// graph.zoomToFit({ padding: 0, maxScale: 1, mainScale: 1 }) |
|
|
// this.graph.zoomToFit({ padding: 0, maxScale: 1, mainScale: 1 }) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|