diff options
| author | Alexis Jacomy <alexis.jacomy@gmail.com> | 2011-06-16 13:52:53 +0200 |
|---|---|---|
| committer | Alexis Jacomy <alexis.jacomy@gmail.com> | 2011-06-16 13:52:53 +0200 |
| commit | 713dea1ee1be5d8d8cf5ae8023cc2015b16463ae (patch) | |
| tree | 55232a57efa7143c02275bd1b7db8e832dc2ead7 /public/javascripts | |
| parent | add app.psgi (diff) | |
| download | stargit-713dea1ee1be5d8d8cf5ae8023cc2015b16463ae.tar.gz | |
Interface update (WARNING: Flash to JS communication is currently broken, and JS to Flash does not work on Firefox, to be fixed soon)
Diffstat (limited to 'public/javascripts')
| -rw-r--r-- | public/javascripts/github-connector.js | 152 | ||||
| -rw-r--r-- | public/javascripts/sigma-connector.js | 125 | ||||
| -rw-r--r-- | public/javascripts/stargit.js | 150 |
3 files changed, 150 insertions, 277 deletions
diff --git a/public/javascripts/github-connector.js b/public/javascripts/github-connector.js deleted file mode 100644 index 976f8de..0000000 --- a/public/javascripts/github-connector.js +++ /dev/null @@ -1,152 +0,0 @@ -var githubNodesObj = {}; -var githubEdgesObj = {}; -var graphAttributes = {}; - -// Interface: -function init(){ - getGraphAttributes() -} - -function newQuery(query){ - sigmaDOM = thisMovie("SiGMa"); - - getGithubGraph(query); -} - -function thisMovie(movieName) { - if (navigator.appName.indexOf("Microsoft") != -1) { - return window[movieName]; - } else { - return document[movieName]; - } -} - -function setComboBoxes(){ - var colorAtts = []; - var sizeAtts = []; - - for(var att in graphAttributes){ - graphAttributes[att]["id"] = att; - - if(graphAttributes[att]["type"]=="Num"){ - sizeAtts.push(graphAttributes[att]); - colorAtts.push(graphAttributes[att]); - }else{ - colorAtts.push(graphAttributes[att]); - } - } - - var nodes_color = document.forms["node_properties"]["nodes_color"]; - var nodes_size = document.forms["node_properties"]["nodes_size"]; - - while(nodes_color.options.length) nodes_color.options.remove(0); - while(nodes_size.options.length) nodes_size.options.remove(0); - - var i; - var optn; - - var l=colorAtts.length; - for(i=0;i<l;i++){ - optn = document.createElement("OPTION"); - optn.text = colorAtts[i]["label"] ? colorAtts[i]["label"] : colorAtts[i]["id"]; - optn.value = colorAtts[i]["id"]; - - nodes_color.options.add(optn); - } - - l=sizeAtts.length; - for(i=0;i<l;i++){ - optn = document.createElement("OPTION"); - optn.text = sizeAtts[i]["label"] ? sizeAtts[i]["label"] : sizeAtts[i]["id"]; - optn.value = sizeAtts[i]["id"]; - - nodes_size.options.add(optn) - } -} - -// SiGMa interaction: -function toggleDisplayLabels(){ - if(sigmaDOM){ - if(sigmaDOM.getDisplayLabels()){ - sigmaDOM.setDisplayLabels(false); - }else{ - sigmaDOM.setDisplayLabels(true); - } - } -} - -function toggleDisplayEdges(){ - if(sigmaDOM){ - if(sigmaDOM.getDisplayEdges()){ - sigmaDOM.setDisplayEdges(false); - }else{ - sigmaDOM.setDisplayEdges(true); - } - } -} - -function toggleFishEye(){ - if(sigmaDOM){ - if(sigmaDOM.hasFishEye()){ - sigmaDOM.deactivateFishEye(); - }else{ - sigmaDOM.activateFishEye(); - } - } -} - -function resetGraph(graph){ - recenterGraph(); - - killForceAtlas(); - deleteGraph(); - updateGraph(graph); - initForceAtlas(); - - setColor(document.forms["node_properties"]["nodes_color"].value,graphAttributes); - setSize(document.forms["node_properties"]["nodes_size"].value); -} - -function onClickNodes(nodesArray){ - if(nodesArray.length){ - sigmaDOM = thisMovie("SiGMa"); - query = nodesArray[0]; - - getGithubGraph(query); - document.getElementById("query").value = query; - } -} - -function onOverNodes(nodesArray){ - for(var i=0;i<nodesArray.length;i++){ - console.debug("node: "+nodesArray[i]); - } -} - -// Github network: -function getGithubGraph(user){ - url = "/graph/local/"+user; - - $.ajax({ - url: url, - dataType: 'json', - success: - function(json){ - resetGraph(json); - } - }); -} - -function getGraphAttributes(){ - url = "/graph/attributes"; - - $.ajax({ - url: url, - dataType: 'json', - success: - function(json){ - graphAttributes = (json && json["attributes"]) ? json["attributes"] : {}; - setComboBoxes(); - } - }); -} diff --git a/public/javascripts/sigma-connector.js b/public/javascripts/sigma-connector.js deleted file mode 100644 index c511de9..0000000 --- a/public/javascripts/sigma-connector.js +++ /dev/null @@ -1,125 +0,0 @@ -// --- SiGMa (API version) JavaSCript connector --- -// Contains the functions to send data to a SiGMa.swf instance. - -// You have to initialize this parameter before using the -// different functions: -var sigmaDOM; -var outputFunction; - -// This function starts the layout algorithm: -function initForceAtlas(){ - try{ - sigmaDOM.initForceAtlas(); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function stops the layout algorithm: -function killForceAtlas(){ - try{ - sigmaDOM.killForceAtlas(); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function delete the whole graph in SiGMa: -function deleteGraph(){ - try{ - sigmaDOM.deleteGraph(); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function pushes each non-existing node and edge in the graph, -// and removes the ones that were in SiGMa: -function updateGraph(graph){ - try{ - sigmaDOM.updateGraph(graph); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function pushes each non-existing node and edge in the graph, -// and updates the ones that are already in SiGMa: -function pushGraph(graph){ - try{ - sigmaDOM.pushGraph(graph); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function activates the fish-eye zoom: -function activateFishEye(){ - try{ - sigmaDOM.activateFishEye(); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function desactivates the fish-eye zoom: -function deactivateFishEye(){ - try{ - sigmaDOM.deactivateFishEye(); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function sets the color of the nodes relatively to one -// attribute: -function setColor(field,attributes){ - try{ - sigmaDOM.setColor(field,attributes); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function sets the color of the nodes relatively to one -// attribute: -function setSize(field){ - try{ - sigmaDOM.setSize(field); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// This function recenters the graph in SiGMa (basically, it -// cancels each zooming action and every drag'n'drop): -function recenterGraph(){ - try{ - sigmaDOM.resetGraphPosition(); - }catch(e){ - if(outputFunction){ - outputFunction(e.description); - } - } -} - -// /!\ This script is just a draft, most of the methods might change -// soon, and a lot of missing features are already in development... diff --git a/public/javascripts/stargit.js b/public/javascripts/stargit.js new file mode 100644 index 0000000..82c414d --- /dev/null +++ b/public/javascripts/stargit.js @@ -0,0 +1,150 @@ +var stargit=(function(){ + // Functions: + var flash; + var githubNodesObj = {}; + var githubEdgesObj = {}; + var graphAttributes = {}; + + function setFlash(){ + flash = $('#SiGMa')[0]; + + if(!flash){ + return false; + }else{ + return true; + } + } + + // This function refreshes the graph from the login of + // a user: + function getGithubGraph(user){ + url = "/graph/local/"+user; + + $.ajax({ + url: url, + dataType: 'json', + success: + function(json){ + resetGraph(json); + } + }); + } + + // This function gets the graph attributes to refresh + // the different comboboxes: + function getGraphAttributes(){ + url = "/graph/attributes"; + + $.ajax({ + url: url, + dataType: 'json', + success: + function(json){ + graphAttributes = (json && json["attributes"]) ? json["attributes"] : {}; + setComboBoxes(); + } + }); + } + + function resetGraph(graph){ + if(!setFlash()){ + return; + } + + flash.resetGraphPosition(); + + flash.killForceAtlas(); + flash.deleteGraph(); + flash.updateGraph(graph); + flash.initForceAtlas(); + + if($("#query_color").value) flash.setColor($("#query_color").value,graphAttributes); + if($("#query_size").value) flash.setSize($("#query_size").value); + } + + // This function updates the comboboxes: + function setComboBoxes(){ + var colorAtts = []; + var sizeAtts = []; + + for(var att in graphAttributes){ + graphAttributes[att]["id"] = att; + + if(graphAttributes[att]["type"]=="Num"){ + sizeAtts.push(graphAttributes[att]); + colorAtts.push(graphAttributes[att]); + }else{ + colorAtts.push(graphAttributes[att]); + } + } + + var nodes_color = $("#query_color"); + var nodes_size = $("#query_size"); + + while(nodes_color.options.length) nodes_color.options.remove(0); + while(nodes_size.options.length) nodes_size.options.remove(0); + + var i; + var optn; + + var l=colorAtts.length; + for(i=0;i<l;i++){ + optn = document.createElement("OPTION"); + optn.text = colorAtts[i]["label"] ? colorAtts[i]["label"] : colorAtts[i]["id"]; + optn.value = colorAtts[i]["id"]; + + nodes_color.options.add(optn); + } + + l=sizeAtts.length; + for(i=0;i<l;i++){ + optn = document.createElement("OPTION"); + optn.text = sizeAtts[i]["label"] ? sizeAtts[i]["label"] : sizeAtts[i]["id"]; + optn.value = sizeAtts[i]["id"]; + + nodes_size.options.add(optn) + } + } + + // PUBLIC FUNCTIONS: + return { + loadUser: function(name){ + getGithubGraph(name); + }, + + setSize: function(e){ + if(!setFlash()) return; + flash.setSize(e.value); + }, + + setColor: function(e){ + if(!setFlash()) return; + flash.setColor(e.value,graphAttributes); + }, + + toggleEdges: function(){ + if(!setFlash()) return; + var areEdgesDisplayed = flash.getDisplayEdges(); + flash.setDisplayEdges(!areEdgesDisplayed); + return !areEdgesDisplayed; + }, + + toggleLabels: function(){ + if(!setFlash()) return; + var areLabelsDisplayed = flash.getDisplayLabels(); + flash.setDisplayLabels(!areLabelsDisplayed); + return !areLabelsDisplayed; + }, + + toggleFishEye: function(){ + if(!setFlash()) return; + var isFishEye = flash.hasFishEye(); + if(isFishEye){ + flash.deactivateFishEye(); + }else{ + flash.activateFishEye(); + } + return !isFishEye; + } + }; +})();
\ No newline at end of file |
