Mercurial > hg > Members > nobuyasu > Consensus
changeset 108:bf0b1f71ac81 draft
modified graph -> node
author | Nobuyasu Oshiro <dimolto@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sun, 17 Mar 2013 22:19:31 +0900 |
parents | 42799d9c3753 |
children | 2633ac31c233 |
files | public/viewer/viewer_white.html |
diffstat | 1 files changed, 75 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/public/viewer/viewer_white.html Sun Mar 17 19:53:59 2013 +0900 +++ b/public/viewer/viewer_white.html Sun Mar 17 22:19:31 2013 +0900 @@ -121,8 +121,8 @@ $(function() { userName = localStorage.userName; - if(userName) {start();} - else { } +// start(); + testStart(); }) function beginScript() { @@ -230,17 +230,23 @@ var nodeNum = 0; var OFFSET = 100; +var miniD = $('#miniDisplay')[0].style; +var offsetLeft = parseInt(miniD.width.split('px')[0]); +var offsetTop = parseInt(miniD.height.split('px')[0]); +function calcNewNodePosition() { + var position = {}; + position = {x: nodeNum*OFFSET + offsetLeft, y: nodeNum*OFFSET + offsetTop/2}; + nodeNum++; + return position; +} + function createNodeDiv(node) { node.view = $("<div class='graphNode'/>"); - var miniD = $('#miniDisplay')[0].style; - var offsetLeft = parseInt(miniD.width.split('px')[0]); - var offsetTop = parseInt(miniD.height.split('px')[0]); - node.position = {x:nodeNum*OFFSET + offsetLeft, y: nodeNum*OFFSET + offsetTop/2}; + node.position = calcNewNodePosition(); node.view.hover(); var div = $("<div class='graphNodeContent'/>")[0]; div.innerHTML = node.property.title; node.view[0].appendChild(div); - nodeNum++; return node; } @@ -288,24 +294,6 @@ intervalY:120 }; -function start() { - init(); - var rootNode = new Object(); - rootNode.property = sampleJSON1; - showMiniDisplay(rootNode); - updateNode(rootNode); - /* test code */ - var n1 = {property:{title:"task2"}}; - var n2 = {property:{title:"task3"}}; - updateNode(n1); - updateNode(n2); - - var e1 = new Edge(rootNode, n1, "dependency"); - var e2 = new Edge(n1, n2, "dependency"); - edgeArray.push(e1); - edgeArray.push(e2); - paintEdge(); -} var edgeArray = new Array(); function Edge(fromNode, toNode, relation) { @@ -361,31 +349,80 @@ } */ var graphData = {}; - graphData.graphs = {}; + graphData.nodes = {}; graphData.edges = {}; return graphData; } function parseJSONGraphData(memory ,jsonObj) { - var graphs = jsonObj.graphs; - for (var i=0; i<graphs.length; i++) { - var graph = graphs[i]; - memory.graphs[graph.id].property = graph; + var nodes = jsonObj.nodes; + for (var i=0; i<nodes.length; i++) { + var node = nodes[i]; + memory.nodes[node.id] = {}; + memory.nodes[node.id].in = []; + memory.nodes[node.id].out = []; + memory.nodes[node.id].both = []; + memory.nodes[node.id].property = node; } var edges = jsonObj.edges; for (var i=0; i<edges.length; i++) { var edge = edges[i]; var edgeId = edge.id; + memory.edges[edgeId] = {}; memory.edges[edgeId].property = edge; if (edge.kind == "both") { - memory.graphs[edge.from].both.append(edgeId); - memory.graphs[edge.to].both.append(edgeId); + memory.nodes[edge.from].both.push(edgeId); + memory.nodes[edge.to].both.push(edgeId); } else { - memory.graphs[edge.from].out.append(edgeId); - memory.graphs[edge.to].in.append(edgeId); + memory.nodes[edge.from].out.push(edgeId); + memory.nodes[edge.to].in.push(edgeId); } } + return memory; +} + +function start() { + init(); + var rootNode = new Object(); + rootNode.property = sampleJSON1; + showMiniDisplay(rootNode); + updateNode(rootNode); + /* test code */ + var n1 = {property:{title:"task2"}}; + var n2 = {property:{title:"task3"}}; + updateNode(n1); + updateNode(n2); + + var e1 = new Edge(rootNode, n1, "dependency"); + var e2 = new Edge(n1, n2, "dependency"); + edgeArray.push(e1); + edgeArray.push(e2); + paintEdge(); +} + + +function updateRelationNodes(graphData, node) { + var id = node.property.id; + var nodes = graphData.graphs; + var edges = graphData.edges; +} + +function testStart() { + init(); + var graphData = new GraphData(); + parseJSONGraphData(graphData, sampleJSONData); + var rootNodeId = "1"; + var rootNode = graphData.nodes[rootNodeId]; + updateNode(rootNode); + updateRelationNodes(graphData,rootNode); +} + + +function logProperty(d) { + for(var key in d) { + console.log("key: "+key+ "\nvalue: "+d[key]); + } } /* sample data */ @@ -398,19 +435,22 @@ }; sampleJSONData = { - graphs: [ + nodes: [ { id:"1", + title:"task1", kind:"agree", createdUser:"osrhiro" }, { id:"2", + title:"task2", kind:"reject", createdUser:"kinjo" }, { id:"3", + title:"task3", kind:"agree", createdUser:"tamayose" }