-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2nd PR on Interactive Graph 0.0.3 #348
Changes from 3 commits
7bfe6ad
b5ed70f
62a03df
db16d0d
17eda0d
784d98d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,13 +55,13 @@ export default { | |
overflow scroll | ||
border solid 1px $-left-border-color | ||
background $-left-border-color | ||
min-height 300px | ||
min-height 1300px | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason to increase the min-height so much? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changed it back. As I showed you, I will add scrolling functionality for the long graph. |
||
padding 2% 0% 2% 2% | ||
box-sizing border-box | ||
.right | ||
overflow scroll | ||
width 300px | ||
min-height 300px | ||
min-height 1300px | ||
position absolute | ||
right 0 | ||
top 0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,8 @@ | ||
<template> | ||
<div class="visual-dl-graph-charts"> | ||
<div id="container" class="cy draggable" ref="draggable"></div> | ||
<svg class="visual-dl-page-left"> | ||
<g/> | ||
</svg> | ||
</div> | ||
</template> | ||
<script> | ||
|
@@ -16,8 +18,16 @@ | |
|
||
// https://github.com/taye/interact.js | ||
import interact from 'interactjs'; | ||
import cytoscape from 'cytoscape'; | ||
import dagre from 'cytoscape-dagre'; | ||
|
||
// for cytoscape | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we will remove the cytoscape from the package.json, we can also remove this part. |
||
//import cytoscape from 'cytoscape'; | ||
//import dagre from 'cytoscape-dagre'; | ||
|
||
// for d3 drawing | ||
import * as d3 from "d3"; | ||
import * as dagre from "dagre"; | ||
import * as dagreD3 from 'dagre-d3'; | ||
|
||
|
||
export default { | ||
props: ['fitScreen', 'download', 'scale'], | ||
|
@@ -30,8 +40,6 @@ | |
data() { | ||
return { | ||
myCY: null, | ||
width: 800, | ||
height: 600, | ||
graphUrl: '', | ||
}; | ||
}, | ||
|
@@ -50,121 +58,73 @@ | |
} | ||
}, | ||
mounted() { | ||
var that = this; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you for getting rid of this. |
||
this.getOriginChartsData(); | ||
cytoscape.use( dagre ); | ||
getPluginGraphsGraph().then(({errno, data}) => { | ||
|
||
getPluginGraphsGraph().then(({errno, data}) => { | ||
var raw_data = data.data; | ||
var data = raw_data; | ||
|
||
var graph_data = { | ||
nodes: [], | ||
edges: [] | ||
}; | ||
|
||
var node_names = []; | ||
for (var i = 0; i < data.input.length; ++i) { | ||
graph_data.nodes.push({ | ||
data: {id: data.input[i].name, node_data: data.input[i].name} | ||
}); | ||
node_names.push(data.input[i].name); | ||
} | ||
|
||
for (var i = 0; i < data.edges.length; ++i) { | ||
var source = data.edges[i].source; | ||
var target = data.edges[i].target; | ||
// d3 svg drawing | ||
var g = new dagreD3.graphlib.Graph() | ||
.setGraph({}) | ||
.setDefaultEdgeLabel(function() { return {}; }); | ||
var render = new dagreD3.render(); | ||
var nodeKeys = []; | ||
|
||
if (node_names.includes(source) === false) { | ||
graph_data.nodes.push({ | ||
data: {id: source, node_data:source} | ||
}); | ||
node_names.push(source); | ||
} | ||
var buildInputNodeLabel = function(inputNode) { | ||
var nodeLabel = inputNode['data_type'] + ': ' + inputNode['shape'].join('x'); | ||
return nodeLabel + ' '.repeat(Math.floor(nodeLabel.length/5)); | ||
}; | ||
|
||
if (node_names.includes(target) === false) { | ||
var node_data = target; | ||
if (target.includes('node_')) { | ||
// it is an operator node | ||
var node_id = target.substring(5); | ||
node_data = data.node[node_id].opType; | ||
// add input nodes | ||
for (var i=0; i<data['input'].length; ++i) { | ||
var curInputNode = data['input'][i]; | ||
var nodeKey = curInputNode['name']; | ||
g.setNode( | ||
nodeKey, | ||
{ | ||
label: buildInputNodeLabel(curInputNode), | ||
class: "input" | ||
} | ||
graph_data.nodes.push({ | ||
data: {id: target, node_data:node_data} | ||
}); | ||
node_names.push(target); | ||
} | ||
|
||
graph_data.edges.push({ | ||
data: {source: source, target: target} | ||
}); | ||
); | ||
nodeKeys.push(nodeKey); | ||
} | ||
|
||
// >> cy | ||
var cy = cytoscape({ | ||
container: document.getElementById('container'), | ||
// add operator nodes then add edges from inputs to operator and from operator to output | ||
for (var i=0; i<data['node'].length; ++i) { | ||
var curOperatorNode = data['node'][i]; | ||
var nodeKey = 'opNode_' + i; | ||
|
||
boxSelectionEnabled: false, | ||
autounselectify: true, | ||
|
||
layout: { | ||
name: 'dagre' | ||
}, | ||
|
||
style: [ | ||
{ | ||
selector: 'node', | ||
style: { | ||
'width': 40, | ||
'height': 40, | ||
'content': 'data(node_data)', | ||
'text-opacity': 0.5, | ||
'text-valign': 'center', | ||
'text-halign': 'right', | ||
'background-color': '#11479e' | ||
} | ||
}, | ||
// add operator node | ||
var curOpLabel = curOperatorNode['opType']; | ||
g.setNode( | ||
nodeKey, | ||
{ | ||
selector: 'edge', | ||
style: { | ||
'curve-style': 'bezier', | ||
'width': 6, | ||
'target-arrow-shape': 'triangle', | ||
'line-color': '#9dbaea', | ||
'target-arrow-color': '#9dbaea' | ||
} | ||
label: curOpLabel + ' '.repeat(Math.floor(curOpLabel.length/5)), | ||
class: "operator" | ||
} | ||
], | ||
elements: graph_data, | ||
}); | ||
); | ||
nodeKeys.push(nodeKey); | ||
|
||
this.myCY = cy; | ||
|
||
cy.nodes().forEach(function(node){ | ||
if (node.id().includes('node_')) { | ||
node.style('width', '80px'); | ||
node.style('height', '36px'); | ||
node.style('shape', 'roundrectangle'); | ||
node.style('background-color', '#158c96'); | ||
node.style('text-valign', 'center'); | ||
node.style('text-halign', 'center'); | ||
// add output node | ||
var outputNodeKey = curOperatorNode['output'][0]; | ||
g.setNode( | ||
outputNodeKey, | ||
{ | ||
label: outputNodeKey + ' '.repeat(Math.floor(outputNodeKey.length/5)), | ||
class: "output" | ||
} | ||
); | ||
nodeKeys.push(outputNodeKey); | ||
|
||
// add edges from inputs to node and from node to output | ||
for (var e=0; e<curOperatorNode['input'].length; ++e) { | ||
g.setEdge(curOperatorNode['input'][e], nodeKey); | ||
} | ||
g.setEdge(nodeKey, curOperatorNode['output'][0]); | ||
} | ||
|
||
let collapsed = true; | ||
node.on('tap', function(evt){ | ||
if (node.id().includes('node_')) { | ||
collapsed = !collapsed; | ||
if (!collapsed) { | ||
node.style('width', '120px'); | ||
node.style('height', '54px'); | ||
} else { | ||
node.style('width', '80px'); | ||
node.style('height', '36px'); | ||
} | ||
} | ||
}); | ||
}); | ||
render(d3.select("svg g"), g); | ||
}); | ||
}, | ||
|
||
|
@@ -259,13 +219,27 @@ | |
}; | ||
</script> | ||
<style lang="stylus"> | ||
.cy | ||
height: 100% | ||
width: 70% | ||
position: absolute | ||
top: 0px | ||
left: 0px | ||
|
||
.node rect | ||
.node circle | ||
.node ellipse | ||
.node polygon | ||
stroke: #333 | ||
fill: #fff | ||
stroke-width: 1.5px | ||
|
||
.edgePath path.path | ||
stroke: #333 | ||
fill: none | ||
stroke-width: 1.5px | ||
|
||
.operator | ||
fill: red | ||
|
||
.output | ||
fill: green | ||
|
||
.input | ||
fill: purple | ||
|
||
.visual-dl-graph-charts | ||
width inherit | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there is reason for downgrading the version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tested and the higher version also works. I will work on how to get rid of dagre-d3 and use a combination of dagre and d3. The library dagre-d3 is not well-maintained. Think about the 'require' bug 😢