Commit a6eb472f authored by Romain Loth's avatar Romain Loth

move variables init to main + minor

variables init was obscuring settings file + moved AjaxSync back to globalUtils + fixed selector engine instance scope
parent 20aed85e
...@@ -231,72 +231,3 @@ TW.conf = (function(TW){ ...@@ -231,72 +231,3 @@ TW.conf = (function(TW){
return TWConf return TWConf
})() })()
// INITIALIZED VARS
// ================
TW.Nodes = [];
TW.Edges = [];
TW.Relations = {}
TW.Clusters = []; // A "by value" index, built in parseCustom, (aka facets)
TW.gexfPaths={};
TW.labels=[];
// FIXME should become TW.*
var selections = [];
var deselections={};
var opossites = {};
var opos=[];
var oposMAX;
var matches = [];
var nodes1 = {};
var nodes2 = {};
var bipartiteD2N = {};
var bipartiteN2D = {};
// possible node types and their inverted map
TW.categories = [];
TW.catDict = {};
var gexfFile;
//var zoom=0;
TW.checkBox=false;
TW.shiftKey=false;
TW.manuallyChecked = false;
TW.SystemState = {}
TW.SystemState.level = true;
TW.SystemState.type = [ true, false ] // usually overridden by initialActivetypes
TW.SystemState.selections = [];
TW.SystemState.opposites = [];
TW.colorList = ["#000000", "#FFFF00", "#1CE6FF", "#FF34FF", "#FF4A46", "#008941", "#006FA6", "#A30059", "#FFDBE5", "#7A4900", "#0000A6", "#63FFAC", "#B79762", "#004D43", "#8FB0FF", "#997D87", "#5A0007", "#809693", "#FEFFE6", "#1B4400", "#4FC601", "#3B5DFF", "#4A3B53", "#FF2F80", "#61615A", "#BA0900", "#6B7900", "#00C2A0", "#FFAA92", "#FF90C9", "#B903AA", "#D16100", "#DDEFFF", "#000035", "#7B4F4B", "#A1C299", "#300018", "#0AA6D8", "#013349", "#00846F", "#372101", "#FFB500", "#C2FFED", "#A079BF", "#CC0744", "#C0B9B2", "#C2FF99", "#001E09", "#00489C", "#6F0062", "#0CBD66", "#EEC3FF", "#456D75", "#B77B68", "#7A87A1", "#788D66", "#885578", "#FAD09F", "#FF8A9A", "#D157A0", "#BEC459", "#456648", "#0086ED", "#886F4C","#34362D", "#B4A8BD", "#00A6AA", "#452C2C", "#636375", "#A3C8C9", "#FF913F", "#938A81", "#575329", "#00FECF", "#B05B6F", "#8CD0FF", "#3B9700", "#04F757", "#C8A1A1", "#1E6E00", "#7900D7", "#A77500", "#6367A9", "#A05837", "#6B002C", "#772600", "#D790FF", "#9B9700", "#549E79", "#FFF69F", "#201625", "#72418F", "#BC23FF", "#99ADC0", "#3A2465", "#922329", "#5B4534", "#FDE8DC", "#404E55", "#0089A3", "#CB7E98", "#A4E804", "#324E72", "#6A3A4C", "#83AB58", "#001C1E", "#D1F7CE", "#004B28", "#C8D0F6", "#A3A489", "#806C66", "#222800", "#BF5650", "#E83000", "#66796D", "#DA007C", "#FF1A59", "#8ADBB4", "#1E0200", "#5B4E51", "#C895C5", "#320033", "#FF6832", "#66E1D3", "#CFCDAC", "#D0AC94", "#7ED379", "#012C58"];
var ParseCustom = function () {};
var SigmaUtils = function () {};
var TinaWebJS = function () {};
// £TODO à ranger
TW.circleSize= 0;
var lastFilter = []
lastFilter["#slidercat0nodesweight"] = {"orig":"-" , "last":"-"}
lastFilter["#slidercat1nodesweight"] = {"orig":"-" , "last":"-"}
lastFilter["#slidercat0edgesweight"] = {"orig":"-" , "last":"-"}
lastFilter["#slidercat1edgesweight"] = {"orig":"-" , "last":"-"}
var desirableNodeSizeMIN=1;
var desirableNodeSizeMAX=12;
// These variables will be updated in sigma.parseCustom.js
var minNodeSize
var maxNodeSize
'use strict'; 'use strict';
// this class will be instanciated once, as SelInst (and exposed) // this class will be instanciated once (and exposed as TW.instance.selNgn)
function SelectionEngine() { function SelectionEngine() {
// creates the union of prevsels and currsels, if addvalue // creates the union of prevsels and currsels, if addvalue
...@@ -353,12 +353,11 @@ function SelectionEngine() { ...@@ -353,12 +353,11 @@ function SelectionEngine() {
} }
}; };
// TODO TW.SelInst var TinaWebJS = function ( sigmacanvas ) {
var SelInst
TinaWebJS = function ( sigmacanvas ) {
this.sigmacanvas = sigmacanvas; this.sigmacanvas = sigmacanvas;
this.selNgn = new SelectionEngine();
// functions that modify the sigma module (not sigma instance!) // functions that modify the sigma module (not sigma instance!)
this.init = function () { this.init = function () {
...@@ -499,7 +498,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -499,7 +498,7 @@ TinaWebJS = function ( sigmacanvas ) {
this.initSearchListeners = function () { this.initSearchListeners = function () {
var SelInst = new SelectionEngine(); var selInst = this.selNgn
$('input#searchinput').autocomplete({ $('input#searchinput').autocomplete({
source: function(request, response) { source: function(request, response) {
...@@ -574,7 +573,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -574,7 +573,7 @@ TinaWebJS = function ( sigmacanvas ) {
// over sigmaUtils.getnodesIndex() // over sigmaUtils.getnodesIndex()
// -> then call this.SelectorEngine // -> then call this.SelectorEngine
// and this.MultipleSelection2 // and this.MultipleSelection2
SelInst.search_n_select(query) selInst.search_n_select(query)
// ------------------------------------------------ // ------------------------------------------------
}); });
...@@ -591,7 +590,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -591,7 +590,7 @@ TinaWebJS = function ( sigmacanvas ) {
} }
setTimeout( setTimeout(
function (){ function (){
targeted = SelInst.SelectorEngine( { targeted = selInst.SelectorEngine( {
addvalue:TW.checkBox, addvalue:TW.checkBox,
clicktype:"double", clicktype:"double",
prevsels:selections, prevsels:selections,
...@@ -604,7 +603,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -604,7 +603,7 @@ TinaWebJS = function ( sigmacanvas ) {
if(targeted.length>0) { if(targeted.length>0) {
TW.circleSize = (TW.circleSize==0)? 1 : TW.circleSize; TW.circleSize = (TW.circleSize==0)? 1 : TW.circleSize;
cancelSelection(false); cancelSelection(false);
SelInst.MultipleSelection2({nodes:targeted}); this.selInst.MultipleSelection2({nodes:targeted});
TW.circleSize = prev_cursor_size; TW.circleSize = prev_cursor_size;
} }
...@@ -624,7 +623,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -624,7 +623,7 @@ TinaWebJS = function ( sigmacanvas ) {
// (but we know the results will be empty) // (but we know the results will be empty)
// (we still do it for the side effects: events, cleaning) // (we still do it for the side effects: events, cleaning)
var query = normalizeString($("#searchinput").val()) var query = normalizeString($("#searchinput").val())
SelInst.search_n_select(query) selInst.search_n_select(query)
} }
}); });
...@@ -638,7 +637,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -638,7 +637,7 @@ TinaWebJS = function ( sigmacanvas ) {
console.log("search KEY UP"); console.log("search KEY UP");
setTimeout( setTimeout(
function() { function() {
targeted = SelInst.SelectorEngine( { targeted = selInst.SelectorEngine( {
addvalue:TW.checkBox, addvalue:TW.checkBox,
clicktype:"double", clicktype:"double",
prevsels:selections, prevsels:selections,
...@@ -646,7 +645,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -646,7 +645,7 @@ TinaWebJS = function ( sigmacanvas ) {
} ) } )
if(targeted.length>0) { if(targeted.length>0) {
cancelSelection(false); cancelSelection(false);
SelInst.MultipleSelection2({nodes:targeted}); selInst.MultipleSelection2({nodes:targeted});
} }
$("input#searchinput").val(""); $("input#searchinput").val("");
...@@ -886,7 +885,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -886,7 +885,7 @@ TinaWebJS = function ( sigmacanvas ) {
// args: @partialGraph = a sigma instance // args: @partialGraph = a sigma instance
this.initSigmaListeners = function(partialGraph, initialActivetypes) { this.initSigmaListeners = function(partialGraph, initialActivetypes) {
var SelInst = new SelectionEngine(); var selInst = this.selNgn
// sigma events bindings // sigma events bindings
// --------------------- // ---------------------
...@@ -928,13 +927,13 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -928,13 +927,13 @@ TinaWebJS = function ( sigmacanvas ) {
cancelSelection(false) cancelSelection(false)
// 2) show selection + do all related effects // 2) show selection + do all related effects
var targeted = SelInst.SelectorEngine( { var targeted = selInst.SelectorEngine( {
addvalue:TW.checkBox, addvalue:TW.checkBox,
currsels:circleNodes, currsels:circleNodes,
prevsels:previousSelection prevsels:previousSelection
} ) } )
if(targeted.length>0) { if(targeted.length>0) {
SelInst.MultipleSelection2( {nodes:targeted} ) selInst.MultipleSelection2( {nodes:targeted} )
} }
} }
}) })
...@@ -952,13 +951,13 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -952,13 +951,13 @@ TinaWebJS = function ( sigmacanvas ) {
cancelSelection(false, {norender:true}); // no need to render before MS2 cancelSelection(false, {norender:true}); // no need to render before MS2
if (TW.circleSize == 0) { if (TW.circleSize == 0) {
var targeted = SelInst.SelectorEngine( { var targeted = selInst.SelectorEngine( {
addvalue:TW.checkBox, addvalue:TW.checkBox,
currsels:[theNodeId], currsels:[theNodeId],
prevsels:previousSelection prevsels:previousSelection
} ) } )
if(targeted.length>0) { if(targeted.length>0) {
SelInst.MultipleSelection2( {nodes:targeted} ) selInst.MultipleSelection2( {nodes:targeted} )
} }
} }
// case with a selector circle cursor handled // case with a selector circle cursor handled
......
...@@ -322,14 +322,12 @@ function changeType() { ...@@ -322,14 +322,12 @@ function changeType() {
// to recreate the selection in the new type graph // to recreate the selection in the new type graph
// var SelInst = new SelectionEngine(); // TW.instance.selNgn.MultipleSelection2({
// SelInst.MultipleSelection2({
// nodesDict:nodes_2_colour, // nodesDict:nodes_2_colour,
// edgesDict:edges_2_colour // edgesDict:edges_2_colour
// }); // });
var SelInst2 = new SelectionEngine(); TW.instance.selNgn.MultipleSelection2({ nodes: sels });
SelInst2.MultipleSelection2({ nodes: sels }); TW.selectionActive=true;
overNodes=true;
} }
TW.partialGraph.states[avantlastpos] = {}; TW.partialGraph.states[avantlastpos] = {};
...@@ -470,13 +468,12 @@ function changeLevel() { ...@@ -470,13 +468,12 @@ function changeLevel() {
// Nodes Selection now: // Nodes Selection now:
if(sels.length>0) { if(sels.length>0) {
var SelInst = new SelectionEngine(); TW.instance.selNgn.MultipleSelection2({
SelInst.MultipleSelection2({
nodes:sels, nodes:sels,
nodesDict:nodes_2_colour, nodesDict:nodes_2_colour,
edgesDict:edges_2_colour edgesDict:edges_2_colour
}); });
overNodes=true; TW.selectionActive=true;
} }
} }
......
// ajax request
function pr(msg) { // args:
console.log(msg); // - type: REST method to use: GET (by def), POST...
// - url: target url
// - data: url params or payload if POST
// - datatype: expected response format: 'json', 'text' (by def)...
var AjaxSync = function(args) {
if (!args) args = {}
if (isUndef(args.url)) console.error("AjaxSync call needs url")
if (isUndef(args.type)) args.type = 'GET'
if (isUndef(args.datatype)) args.datatype = 'text'
else if (args.datatype=="jsonp") args.datatype = "json"
var Result = []
if (TW.conf.debug.logFetchers)
console.log("---AjaxSync---", args)
$.ajax({
type: args.type,
url: args.url,
dataType: args.datatype,
async: false, // <= synchronous (POSS alternative: cb + waiting display)
// our payload: filters...
data: args.data,
contentType: 'application/json',
success : function(data, textStatus, jqXHR) {
var header = jqXHR.getResponseHeader("Content-Type")
var format ;
if (!header
|| header == "application/octet-stream"
|| header == "application/xml"
) {
// default parser choice if xml or if undetailed header
format = "gexf" ;
}
else {
if (TW.conf.debug.logFetchers)
console.debug("after AjaxSync("+args.url+") => response header="+header +"not xml => fallback on json");
format = "json" ;
}
Result = { "OK":true , "format":format , "data":data };
},
error: function(exception) {
console.warn('ajax error:', exception, exception.getAllResponseHeaders())
Result = { "OK":false , "format":false , "data":exception.status };
}
});
return Result;
} }
function getClientTime(){ function getClientTime(){
var totalSec = new Date().getTime() / 1000; var totalSec = new Date().getTime() / 1000;
var d = new Date(); var d = new Date();
......
'use strict'; 'use strict';
// ajax request // ======= [ variable initialization ] ======== //
// args:
// - type: REST method to use: GET (by def), POST... // INITIALIZED VARS
// - url: target url // ================
// - data: url params or payload if POST TW.Nodes = [];
// - datatype: expected response format: 'json', 'text' (by def)... TW.Edges = [];
var AjaxSync = function(args) { TW.Relations = {}
TW.Clusters = []; // A "by value" index, built in parseCustom, (aka facets)
if (!args) args = {}
if (isUndef(args.url)) console.error("AjaxSync call needs url") TW.gexfPaths={};
if (isUndef(args.type)) args.type = 'GET' TW.labels=[];
if (isUndef(args.datatype)) args.datatype = 'text'
else if (args.datatype=="jsonp") args.datatype = "json" // FIXME should become TW.*
var selections = [];
var Result = [] var deselections={};
var opossites = {};
if (TW.conf.debug.logFetchers) var opos=[];
console.log("---AjaxSync---", args) var oposMAX;
$.ajax({ var matches = [];
type: args.type,
url: args.url, var nodes1 = {};
dataType: args.datatype, var nodes2 = {};
async: false, // <= synchronous (POSS alternative: cb + waiting display) var bipartiteD2N = {};
var bipartiteN2D = {};
// our payload: filters...
data: args.data, // possible node types and their inverted map
contentType: 'application/json', TW.categories = [];
success : function(data, textStatus, jqXHR) { TW.catDict = {};
var header = jqXHR.getResponseHeader("Content-Type")
var format ; var gexfFile;
if (!header //var zoom=0;
|| header == "application/octet-stream" TW.checkBox=false;
|| header == "application/xml" TW.shiftKey=false;
) { TW.manuallyChecked = false;
// default parser choice if xml or if undetailed header
format = "gexf" ; TW.SystemState = {}
} TW.SystemState.level = true;
else { TW.SystemState.type = [ true, false ] // usually overridden by initialActivetypes
if (TW.conf.debug.logFetchers) TW.SystemState.selections = [];
console.debug("after AjaxSync("+args.url+") => response header="+header +"not xml => fallback on json"); TW.SystemState.opposites = [];
format = "json" ;
}
Result = { "OK":true , "format":format , "data":data }; TW.colorList = ["#000000", "#FFFF00", "#1CE6FF", "#FF34FF", "#FF4A46", "#008941", "#006FA6", "#A30059", "#FFDBE5", "#7A4900", "#0000A6", "#63FFAC", "#B79762", "#004D43", "#8FB0FF", "#997D87", "#5A0007", "#809693", "#FEFFE6", "#1B4400", "#4FC601", "#3B5DFF", "#4A3B53", "#FF2F80", "#61615A", "#BA0900", "#6B7900", "#00C2A0", "#FFAA92", "#FF90C9", "#B903AA", "#D16100", "#DDEFFF", "#000035", "#7B4F4B", "#A1C299", "#300018", "#0AA6D8", "#013349", "#00846F", "#372101", "#FFB500", "#C2FFED", "#A079BF", "#CC0744", "#C0B9B2", "#C2FF99", "#001E09", "#00489C", "#6F0062", "#0CBD66", "#EEC3FF", "#456D75", "#B77B68", "#7A87A1", "#788D66", "#885578", "#FAD09F", "#FF8A9A", "#D157A0", "#BEC459", "#456648", "#0086ED", "#886F4C","#34362D", "#B4A8BD", "#00A6AA", "#452C2C", "#636375", "#A3C8C9", "#FF913F", "#938A81", "#575329", "#00FECF", "#B05B6F", "#8CD0FF", "#3B9700", "#04F757", "#C8A1A1", "#1E6E00", "#7900D7", "#A77500", "#6367A9", "#A05837", "#6B002C", "#772600", "#D790FF", "#9B9700", "#549E79", "#FFF69F", "#201625", "#72418F", "#BC23FF", "#99ADC0", "#3A2465", "#922329", "#5B4534", "#FDE8DC", "#404E55", "#0089A3", "#CB7E98", "#A4E804", "#324E72", "#6A3A4C", "#83AB58", "#001C1E", "#D1F7CE", "#004B28", "#C8D0F6", "#A3A489", "#806C66", "#222800", "#BF5650", "#E83000", "#66796D", "#DA007C", "#FF1A59", "#8ADBB4", "#1E0200", "#5B4E51", "#C895C5", "#320033", "#FF6832", "#66E1D3", "#CFCDAC", "#D0AC94", "#7ED379", "#012C58"];
},
error: function(exception) {
console.warn('ajax error:', exception, exception.getAllResponseHeaders())
Result = { "OK":false , "format":false , "data":exception.status }; // £TODO à ranger
} TW.circleSize= 0;
}); var lastFilter = []
return Result; lastFilter["#slidercat0nodesweight"] = {"orig":"-" , "last":"-"}
} lastFilter["#slidercat1nodesweight"] = {"orig":"-" , "last":"-"}
lastFilter["#slidercat0edgesweight"] = {"orig":"-" , "last":"-"}
lastFilter["#slidercat1edgesweight"] = {"orig":"-" , "last":"-"}
var desirableNodeSizeMIN=1;
var desirableNodeSizeMAX=12;
// These variables will be updated in sigma.parseCustom.js
var minNodeSize
var maxNodeSize
// === [ what to do at start ] === // // ======== [ what to do at start ] ========= //
console.log("Starting TWJS") console.log("Starting TWJS")
// NB this method-holding instance could be initialized just once or even removed? // NB this method-holding instance could be initialized just once or even removed?
......
...@@ -389,8 +389,7 @@ function htmlfied_nodesatts(elems){ ...@@ -389,8 +389,7 @@ function htmlfied_nodesatts(elems){
function manualSelectNode ( nodeid ) { function manualSelectNode ( nodeid ) {
cancelSelection(false); cancelSelection(false);
var SelInst = new SelectionEngine(); TW.instance.selNgn.MultipleSelection2({nodes:[nodeid]});
SelInst.MultipleSelection2({nodes:[nodeid]});
// (MultipleSelection2 will do the re-rendering) // (MultipleSelection2 will do the re-rendering)
} }
...@@ -583,10 +582,9 @@ function graphTagCloudElem(nodes) { ...@@ -583,10 +582,9 @@ function graphTagCloudElem(nodes) {
} }
// Nodes Selection now: // Nodes Selection now:
// £TODO fix low-level selectionlogic duplicate with MultipleSelection2 function 2/2 // ££TODO fix low-level selectionlogic duplicate with MultipleSelection2 function 2/2
if(ndsids.length>0) { if(ndsids.length>0) {
var SelInst = new SelectionEngine(); TW.instance.selNgn.MultipleSelection2({
SelInst.MultipleSelection2({
nodesDict:nodes_2_colour, nodesDict:nodes_2_colour,
edgesDict:edges_2_colour edgesDict:edges_2_colour
}); });
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// (for instance loop on full gexf in scanGexf then again in dictfyGexf) // (for instance loop on full gexf in scanGexf then again in dictfyGexf)
// Level-01 // Level-01
ParseCustom = function ( format , data ) { var ParseCustom = function ( format , data ) {
if (format == 'gexf') { if (format == 'gexf') {
this.data = $.parseXML(data) this.data = $.parseXML(data)
......
'use strict'; 'use strict';
SigmaUtils = function () { var SigmaUtils = function () {
// input = GEXFstring // input = GEXFstring
this.FillGraph = function( initialActivetypes , catDict , nodes, edges , graph ) { this.FillGraph = function( initialActivetypes , catDict , nodes, edges , graph ) {
......
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