Commit 20aed85e authored by Romain Loth's avatar Romain Loth

remove .index "decorator" that was too opaque

parent baa586a0
...@@ -4,19 +4,25 @@ ...@@ -4,19 +4,25 @@
function SelectionEngine() { function SelectionEngine() {
// creates the union of prevsels and currsels, if addvalue // creates the union of prevsels and currsels, if addvalue
this.SelectorEngine = (function(addvalue , prevsels , currsels ) { this.SelectorEngine = function( args ) {
// console.log("addvalue, prevsels, currsels",addvalue, prevsels, currsels)
console.log("addvalue, prevsels, currsels", args)
if (!args) args = {}
if (!args.addvalue) args.addvalue = false
if (!args.prevsels) args.prevsels = {} // FIXME easier with array like currsels.concat(buffer)
if (!args.currsels) args.currsels = []
var targeted = [] var targeted = []
var buffer = Object.keys(prevsels); var buffer = Object.keys(args.prevsels);
// currsels = bunch of nodes from a click in the map // currsels = bunch of nodes from a click in the map
if(addvalue) { if(args.addvalue) {
// FOR SIMPLE ADD WITHOUT COMPLEMENT // FOR SIMPLE UNIQUE UNION
targeted = currsels.concat(buffer.filter(function (item) { targeted = args.currsels.concat(buffer.filter(function (item) {
return currsels.indexOf(item) < 0; return args.currsels.indexOf(item) < 0;
})); }));
} else targeted = currsels; } else targeted = args.currsels;
if(targeted.length==0) return []; if(targeted.length==0) return [];
...@@ -47,7 +53,7 @@ function SelectionEngine() { ...@@ -47,7 +53,7 @@ function SelectionEngine() {
// targeted = Object.keys(whitelist); // targeted = Object.keys(whitelist);
// } else {// inter = 0 ==> click in other portion of the graph (!= current selection) // } else {// inter = 0 ==> click in other portion of the graph (!= current selection)
// // Union! // // Union!
// if(addvalue) { // if(args.addvalue) {
// targeted = currsels.concat(buffer.filter(function (item) { // targeted = currsels.concat(buffer.filter(function (item) {
// return currsels.indexOf(item) < 0; // return currsels.indexOf(item) < 0;
// })); // }));
...@@ -57,7 +63,7 @@ function SelectionEngine() { ...@@ -57,7 +63,7 @@ function SelectionEngine() {
// ---------------------------------------------------------->8--------- // ---------------------------------------------------------->8---------
return targeted; return targeted;
}).index(); };
// uses: SelectorEngine() and MultipleSelection2() // uses: SelectorEngine() and MultipleSelection2()
...@@ -145,13 +151,18 @@ function SelectionEngine() { ...@@ -145,13 +151,18 @@ function SelectionEngine() {
* updateRelatedNodesPanel(); * updateRelatedNodesPanel();
*/ */
// ==================== // ====================
this.MultipleSelection2 = (function(nodes,nodesDict,edgesDict) { this.MultipleSelection2 = function(args) {
if (!args) args = {}
if (isUndef(args.nodes)) args.nodes = []
if (isUndef(args.nodesDict)) args.nodesDict = {}
if (isUndef(args.edgesDict)) args.edgesDict = {}
if (TW.conf.debug.logSelections) { if (TW.conf.debug.logSelections) {
var tMS2_deb = performance.now() var tMS2_deb = performance.now()
console.log("IN SelectionEngine.MultipleSelection2:") console.log("IN SelectionEngine.MultipleSelection2:")
console.log("nodes", nodes) console.log("nodes", args.nodes)
} }
greyEverything(); greyEverything();
...@@ -174,17 +185,17 @@ function SelectionEngine() { ...@@ -174,17 +185,17 @@ function SelectionEngine() {
// console.log (" - - - - - - ") // console.log (" - - - - - - ")
// Dictionaries of: selection+neighbors // Dictionaries of: selection+neighbors
var nodes_2_colour = (nodesDict)? nodesDict : {}; var nodes_2_colour = args.nodesDict
var edges_2_colour = (edgesDict)? edgesDict : {}; var edges_2_colour = args.edgesDict
selections = {} selections = {}
// targeted arg 'nodes' can be nid array or single nid // targeted arg 'nodes' can be nid array or single nid
var ndsids=[] var ndsids=[]
if(nodes) { if(args.nodes) {
if(! $.isArray(nodes)) ndsids.push(nodes); if(! $.isArray(args.nodes)) ndsids.push(args.nodes);
else ndsids=nodes; else ndsids=args.nodes;
for(var i in ndsids) { for(var i in ndsids) {
var s = ndsids[i]; var s = ndsids[i];
...@@ -339,7 +350,7 @@ function SelectionEngine() { ...@@ -339,7 +350,7 @@ function SelectionEngine() {
}).index() }
}; };
// TODO TW.SelInst // TODO TW.SelInst
...@@ -361,7 +372,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -361,7 +372,7 @@ TinaWebJS = function ( sigmacanvas ) {
else { else {
this.prepareSigmaCustomIndices(sigma) this.prepareSigmaCustomIndices(sigma)
if (TW.conf.ourRendering) if (TW.conf.twRendering)
this.prepareSigmaCustomRenderers(sigma) this.prepareSigmaCustomRenderers(sigma)
} }
...@@ -1024,7 +1035,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -1024,7 +1035,7 @@ TinaWebJS = function ( sigmacanvas ) {
$("#zoomPlusButton").click(function () { $("#zoomPlusButton").click(function () {
var newRatio = TW.cam.ratio * .75 var newRatio = TW.cam.ratio * .75
if (newRatio >= TW.conf.sigmaJsMouseProperties.minRatio) { if (newRatio >= TW.conf.zoomMin) {
// triggers coordinatesUpdated which sets the slider cursor // triggers coordinatesUpdated which sets the slider cursor
partialGraph.camera.goTo({ratio: newRatio}); partialGraph.camera.goTo({ratio: newRatio});
return false; return false;
...@@ -1033,7 +1044,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -1033,7 +1044,7 @@ TinaWebJS = function ( sigmacanvas ) {
$("#zoomMinusButton").click(function () { $("#zoomMinusButton").click(function () {
var newRatio = TW.cam.ratio * 1.25 var newRatio = TW.cam.ratio * 1.25
if (newRatio <= TW.conf.sigmaJsMouseProperties.maxRatio) { if (newRatio <= TW.conf.zoomMax) {
// triggers coordinatesUpdated which sets the slider cursor // triggers coordinatesUpdated which sets the slider cursor
partialGraph.camera.goTo({ratio: newRatio}); partialGraph.camera.goTo({ratio: newRatio});
return false; return false;
......
'use strict'; 'use strict';
// Function.prototype.index // ajax request
// --- // args:
// 'decorator' // - type: REST method to use: GET (by def), POST...
// (used here and in Tinaweb.js for MultipleSelection2) // - url: target url
// --- // - data: url params or payload if POST
// transforms calls like foobar({arg1:a, arg2:b}) // - datatype: expected response format: 'json', 'text' (by def)...
// into calls like foobar(a, b) var AjaxSync = function(args) {
(function(reComments, reParams, reNames) { if (!args) args = {}
Function.prototype.index = function(arrParamNames) { if (isUndef(args.url)) console.error("AjaxSync call needs url")
var fnMe = this; if (isUndef(args.type)) args.type = 'GET'
arrParamNames = arrParamNames if (isUndef(args.datatype)) args.datatype = 'text'
|| (((fnMe + '').replace(reComments, '') else if (args.datatype=="jsonp") args.datatype = "json"
.match(reParams)[1] || '')
.match(reNames) || []);
return function(namedArgs) {
var args = [], i = arrParamNames.length;
args[i] = namedArgs;
while(i--) {
args[i] = namedArgs[arrParamNames[i]];
}
return fnMe.apply(this, args);
};
};
})(
/\/\*[\s\S]*?\*\/|\/\/.*?[\r\n]/g,
/\(([\s\S]*?)\)/,
/[$\w]+/g
);
var AjaxSync = (function(TYPE, URL, DATA, DT) {
var Result = [] var Result = []
TYPE = (!TYPE)?"GET":TYPE
if(DT && (DT=="jsonp" || DT=="json")) DT="json"
else DT = 'text' // ie "if not json then raw xml string"
if (TW.conf.debug.logFetchers) if (TW.conf.debug.logFetchers)
console.log("---AjaxSync---\n", TYPE, URL, DATA, DT, "\n--------------") console.log("---AjaxSync---", args)
$.ajax({ $.ajax({
type: TYPE, type: args.type,
url: URL, url: args.url,
dataType: DT, // <= the expected response format dataType: args.datatype,
async: false, // <= synchronous (POSS alternative: cb + waiting display) async: false, // <= synchronous (POSS alternative: cb + waiting display)
// our payload: filters... // our payload: filters...
data: DATA, data: args.data,
contentType: 'application/json', contentType: 'application/json',
success : function(data, textStatus, jqXHR) { success : function(data, textStatus, jqXHR) {
var header = jqXHR.getResponseHeader("Content-Type") var header = jqXHR.getResponseHeader("Content-Type")
...@@ -61,7 +40,7 @@ var AjaxSync = (function(TYPE, URL, DATA, DT) { ...@@ -61,7 +40,7 @@ var AjaxSync = (function(TYPE, URL, DATA, DT) {
} }
else { else {
if (TW.conf.debug.logFetchers) if (TW.conf.debug.logFetchers)
console.debug("after AjaxSync("+URL+") => response header="+header +"not xml => fallback on json"); console.debug("after AjaxSync("+args.url+") => response header="+header +"not xml => fallback on json");
format = "json" ; format = "json" ;
} }
Result = { "OK":true , "format":format , "data":data }; Result = { "OK":true , "format":format , "data":data };
...@@ -72,7 +51,7 @@ var AjaxSync = (function(TYPE, URL, DATA, DT) { ...@@ -72,7 +51,7 @@ var AjaxSync = (function(TYPE, URL, DATA, DT) {
} }
}); });
return Result; return Result;
}).index(); }
// === [ what to do at start ] === // // === [ what to do at start ] === //
...@@ -232,7 +211,7 @@ function syncRemoteGraphData () { ...@@ -232,7 +211,7 @@ function syncRemoteGraphData () {
mapLabel = '"'+elements.join('" , "')+'"'; mapLabel = '"'+elements.join('" , "')+'"';
} }
var bridgeRes = AjaxSync({ URL: theurl, DATA:thedata, TYPE:'GET', DT:'json' }) var bridgeRes = AjaxSync({ url: theurl, data:thedata, type:'GET', datatype:'json' })
// should be a js object with 'nodes' and 'edges' properties // should be a js object with 'nodes' and 'edges' properties
inData = bridgeRes.data inData = bridgeRes.data
...@@ -270,7 +249,7 @@ function syncRemoteGraphData () { ...@@ -270,7 +249,7 @@ function syncRemoteGraphData () {
var infofile = TW.conf.sourceMenu var infofile = TW.conf.sourceMenu
if (TW.conf.debug.logFetchers) console.info(`attempting to load filemenu ${infofile}`) if (TW.conf.debug.logFetchers) console.info(`attempting to load filemenu ${infofile}`)
var preRES = AjaxSync({ URL: infofile, DT:"json" }); var preRES = AjaxSync({ url: infofile, datatype:"json" });
if (preRES['OK'] && preRES.data) { if (preRES['OK'] && preRES.data) {
console.log('initial AjaxSync result preRES', preRES) console.log('initial AjaxSync result preRES', preRES)
...@@ -344,7 +323,7 @@ function syncRemoteGraphData () { ...@@ -344,7 +323,7 @@ function syncRemoteGraphData () {
console.error(`No specified input and neither db.json nor TW.conf.sourceFile ${TW.conf.sourceFile} are present`) console.error(`No specified input and neither db.json nor TW.conf.sourceFile ${TW.conf.sourceFile} are present`)
} }
var finalRes = AjaxSync({ URL: the_file }); var finalRes = AjaxSync({ url: the_file });
inData = finalRes["data"] inData = finalRes["data"]
inFormat = finalRes["format"] inFormat = finalRes["format"]
......
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