Commit 4ef05dd8 authored by Romain Loth's avatar Romain Loth

split main in two modular functions

(it was the original design in the 2014 versions and it provides more flexibility like future calling mainStartGraph from a fileinput instead of a remote file (see next commit))
parent a949c5d2
...@@ -652,7 +652,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -652,7 +652,7 @@ TinaWebJS = function ( sigmacanvas ) {
var SelInst = new SelectionEngine(); var SelInst = new SelectionEngine();
document.getElementById('edges-switch').checked = customSettings.drawEdges document.getElementById('edges-switch').checked = TW.customSettings.drawEdges
$("#semLoader").hide(); $("#semLoader").hide();
......
...@@ -88,24 +88,32 @@ function jsActionOnGexfSelector(gexfBasename , db_json){ ...@@ -88,24 +88,32 @@ function jsActionOnGexfSelector(gexfBasename , db_json){
window.location=window.location.origin+window.location.pathname+"?file="+encodeURIComponent( gexfLegend )+db_json; window.location=window.location.origin+window.location.pathname+"?file="+encodeURIComponent( gexfLegend )+db_json;
} }
// === [ what to do at start ] === //
// NB this method-holding instance could be initialized just once or even removed?
var sigma_utils = new SigmaUtils();
// show the custom name of the app // show the custom name of the app
writeBrand(TW.branding) writeBrand(TW.branding)
console.log("Starting TWJS") console.log("Starting TWJS")
// === [ what to do at start ] === // // choosing the input (WIP: currently refactoring for simpler handling)
// --------------------- choosing the input ------------------------------------ var [inFormat, inData] = syncRemoteGraphData()
// various starting points (WIP: currently refactoring for simpler handling)
mainStartGraph(inFormat, inData)
// === [ / what to do at start ] === //
var inFormat; // = { db|api.json , somefile.json|gexf }
var inData; // = {nodes: [....], edges: [....], cats:...}
function syncRemoteGraphData () {
var inFormat; // = { db|api.json , somefile.json|gexf }
var inData; // = {nodes: [....], edges: [....], cats:...}
// case (1) read from DB => one ajax to api eg /services/api/graph?q=filters... // case (1) read from DB => one ajax to api eg /services/api/graph?q=filters...
// this one is the API case // this one is the API case
// if (getUrlParam.mode && getUrlParam.mode == "api") { // sourcemode == "api"
if (getUrlParam.type) { if (getUrlParam.type) {
console.warn("input case: @type [future: @mode=api], using TW.bridge") console.warn("input case: @type [future: @mode=api], using TW.bridge")
// the only API format, cf. inData // the only API format, cf. inData
...@@ -211,10 +219,11 @@ if (getUrlParam.type) { ...@@ -211,10 +219,11 @@ if (getUrlParam.type) {
console.warn ("=> unsupported query type !") console.warn ("=> unsupported query type !")
} }
} }
} }
// case (2) gexf => in params or in preRes db.json, then 2nd ajax for a gexf file => covered here // case (2) gexf => in params or in preRes db.json, then 2nd ajax for a gexf file => covered here
else { // sourcemode == "serverfile"
console.warn("input case: @mode=db.json or @file=... [future: @mode=local], using local gexf(s)") else {
console.warn("input case: @mode=db.json or @file=... [future: @mode=serverfile], using server's gexf(s)")
// subcases: // subcases:
// -> gexf file path is already specified in TW.mainfile // -> gexf file path is already specified in TW.mainfile
// -> gexf file path is in the urlparam @file // -> gexf file path is in the urlparam @file
...@@ -303,6 +312,10 @@ else { ...@@ -303,6 +312,10 @@ else {
$("#network").html(files_selector) $("#network").html(files_selector)
} }
// TODO avoid this ajax in the case we're used locally like an "HTA" app (ie our URL starts with file:// protocol)
// (but we could use a fileInput instead, because in this case the client machine is also the data containing machine)
var finalRes = AjaxSync({ URL: the_file }); var finalRes = AjaxSync({ URL: the_file });
inData = finalRes["data"] inData = finalRes["data"]
inFormat = finalRes["format"] inFormat = finalRes["format"]
...@@ -314,23 +327,33 @@ else { ...@@ -314,23 +327,33 @@ else {
console.log(' fetch result: typeof data', typeof inData) console.log(' fetch result: typeof data', typeof inData)
console.log("\n============================\n") console.log("\n============================\n")
} }
} }
// === [ / what to do at start ] === // return [inFormat, inData]
}
// RES == { OK: true, format: "json", data: Object }
// mainStartGraph
// ===============
// main function (once we have some gexf or json data)
// ===============
// 1 - parses the graph data
// 2 - starts the sigma instance in TW.partialGraph
// 3 - starts the tinaweb instance
// 4 - finishes setting up the environment
// (NB inspired by Samuel's legacy bringTheNoise() function)
function mainStartGraph(inFormat, inData) {
if (! inFormat || ! inData) { if (! inFormat || ! inData) {
alert("error on initial data load") alert("error on data load")
} }
else { else {
if (TW.debugFlags.logParsers) console.log("parsing the data") if (TW.debugFlags.logParsers) console.log("parsing the data")
let start = new ParseCustom( inFormat , inData ); let start = new ParseCustom( inFormat , inData );
let catsInfos = start.scanFile(); //user should choose the order of categories let catsInfos = start.scanFile();
TW.categories = catsInfos.categories TW.categories = catsInfos.categories
if (TW.debugFlags.logParsers){ if (TW.debugFlags.logParsers){
...@@ -424,8 +447,6 @@ else { ...@@ -424,8 +447,6 @@ else {
// console.log("initial state: "+initialState) // console.log("initial state: "+initialState)
// [ Poblating the Sigma-Graph ] // [ Poblating the Sigma-Graph ]
var sigma_utils = new SigmaUtils();
// preparing the data and settings // preparing the data and settings
TW.graphData = {nodes: [], edges: []} TW.graphData = {nodes: [], edges: []}
...@@ -463,8 +484,11 @@ else { ...@@ -463,8 +484,11 @@ else {
if (TW.graphData.nodes.length == 0) console.error("empty graph") if (TW.graphData.nodes.length == 0) console.error("empty graph")
if (TW.graphData.edges.length == 0) console.error("no edges in graph") if (TW.graphData.edges.length == 0) console.error("no edges in graph")
// cf github.com/jacomyal/sigma.js/wiki/Settings
var customSettings = Object.assign( // our final sigma params (cf github.com/jacomyal/sigma.js/wiki/Settings)
TW.customSettings = Object.assign(
// 1) default values
{ {
drawEdges: true, drawEdges: true,
drawNodes: true, drawNodes: true,
...@@ -491,13 +515,15 @@ else { ...@@ -491,13 +515,15 @@ else {
animationsTime:150, animationsTime:150,
mouseZoomDuration:250 mouseZoomDuration:250
}, },
// 2) settings_explorer values
sigmaJsDrawingProperties, sigmaJsDrawingProperties,
sigmaJsGraphProperties, sigmaJsGraphProperties,
sigmaJsMouseProperties sigmaJsMouseProperties
) )
if (TW.debugFlags.logSettings) console.info("sigma settings", customSettings) if (TW.debugFlags.logSettings) console.info("sigma settings", TW.customSettings)
// ================================================================== // ==================================================================
...@@ -511,7 +537,7 @@ else { ...@@ -511,7 +537,7 @@ else {
type: sigma.renderers.canvas type: sigma.renderers.canvas
// type: sigma.renderers.webgl // POSS if write custom renderers // type: sigma.renderers.webgl // POSS if write custom renderers
}, },
settings: customSettings settings: TW.customSettings
}); });
// ================================================================== // ==================================================================
...@@ -728,9 +754,11 @@ else { ...@@ -728,9 +754,11 @@ else {
// set the default legend // set the default legend
set_ClustersLegend ( "clust_default" ) set_ClustersLegend ( "clust_default" )
}
} }
// load optional modules // load optional modules
ProcessDivsFlags() ; ProcessDivsFlags() ;
......
...@@ -175,12 +175,12 @@ function scanGexf(gexfContent) { ...@@ -175,12 +175,12 @@ function scanGexf(gexfContent) {
let elsNodes = gexfContent.getElementsByTagName('nodes'); let elsNodes = gexfContent.getElementsByTagName('nodes');
// console.debug('>>> tr: elsNodes', elsNodes) // <<< // console.debug('>>> tr: elsNodes', elsNodes) // <<<
for(i=0; i<elsNodes.length; i++){ for(var i=0; i<elsNodes.length; i++){
var elNodes = elsNodes[i]; // Each xml node 'nodes' (plural) var elNodes = elsNodes[i]; // Each xml node 'nodes' (plural)
let node = elNodes.getElementsByTagName('node'); let node = elNodes.getElementsByTagName('node');
for(j=0; j<node.length; j++){ for(var j=0; j<node.length; j++){
let attvalueNodes = node[j].getElementsByTagName('attvalue'); let attvalueNodes = node[j].getElementsByTagName('attvalue');
for(k=0; k<attvalueNodes.length; k++){ for(var k=0; k<attvalueNodes.length; k++){
let attvalueNode = attvalueNodes[k]; let attvalueNode = attvalueNodes[k];
let attr = attvalueNode.getAttribute('for'); let attr = attvalueNode.getAttribute('for');
let val = attvalueNode.getAttribute('value'); let val = attvalueNode.getAttribute('value');
...@@ -1014,7 +1014,7 @@ function makeSystemStates (cats) { ...@@ -1014,7 +1014,7 @@ function makeSystemStates (cats) {
let bin_array = []; let bin_array = [];
let toadd = cats.length-bin_splitted.length; let toadd = cats.length-bin_splitted.length;
for (k = 0; k < toadd; k++) for (var k = 0; k < toadd; k++)
bin_array.push("0") bin_array.push("0")
for(var j in bin) for(var j in bin)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment