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

remove .index "decorator" that was too opaque

parent baa586a0
......@@ -4,19 +4,25 @@
function SelectionEngine() {
// creates the union of prevsels and currsels, if addvalue
this.SelectorEngine = (function(addvalue , prevsels , currsels ) {
// console.log("addvalue, prevsels, currsels",addvalue, prevsels, currsels)
this.SelectorEngine = function( args ) {
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 buffer = Object.keys(prevsels);
var buffer = Object.keys(args.prevsels);
// currsels = bunch of nodes from a click in the map
if(addvalue) {
// FOR SIMPLE ADD WITHOUT COMPLEMENT
targeted = currsels.concat(buffer.filter(function (item) {
return currsels.indexOf(item) < 0;
if(args.addvalue) {
// FOR SIMPLE UNIQUE UNION
targeted = args.currsels.concat(buffer.filter(function (item) {
return args.currsels.indexOf(item) < 0;
}));
} else targeted = currsels;
} else targeted = args.currsels;
if(targeted.length==0) return [];
......@@ -47,7 +53,7 @@ function SelectionEngine() {
// targeted = Object.keys(whitelist);
// } else {// inter = 0 ==> click in other portion of the graph (!= current selection)
// // Union!
// if(addvalue) {
// if(args.addvalue) {
// targeted = currsels.concat(buffer.filter(function (item) {
// return currsels.indexOf(item) < 0;
// }));
......@@ -57,7 +63,7 @@ function SelectionEngine() {
// ---------------------------------------------------------->8---------
return targeted;
}).index();
};
// uses: SelectorEngine() and MultipleSelection2()
......@@ -145,13 +151,18 @@ function SelectionEngine() {
* 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) {
var tMS2_deb = performance.now()
console.log("IN SelectionEngine.MultipleSelection2:")
console.log("nodes", nodes)
console.log("nodes", args.nodes)
}
greyEverything();
......@@ -174,17 +185,17 @@ function SelectionEngine() {
// console.log (" - - - - - - ")
// Dictionaries of: selection+neighbors
var nodes_2_colour = (nodesDict)? nodesDict : {};
var edges_2_colour = (edgesDict)? edgesDict : {};
var nodes_2_colour = args.nodesDict
var edges_2_colour = args.edgesDict
selections = {}
// targeted arg 'nodes' can be nid array or single nid
var ndsids=[]
if(nodes) {
if(! $.isArray(nodes)) ndsids.push(nodes);
else ndsids=nodes;
if(args.nodes) {
if(! $.isArray(args.nodes)) ndsids.push(args.nodes);
else ndsids=args.nodes;
for(var i in ndsids) {
var s = ndsids[i];
......@@ -339,7 +350,7 @@ function SelectionEngine() {
}).index()
}
};
// TODO TW.SelInst
......@@ -361,7 +372,7 @@ TinaWebJS = function ( sigmacanvas ) {
else {
this.prepareSigmaCustomIndices(sigma)
if (TW.conf.ourRendering)
if (TW.conf.twRendering)
this.prepareSigmaCustomRenderers(sigma)
}
......@@ -1024,7 +1035,7 @@ TinaWebJS = function ( sigmacanvas ) {
$("#zoomPlusButton").click(function () {
var newRatio = TW.cam.ratio * .75
if (newRatio >= TW.conf.sigmaJsMouseProperties.minRatio) {
if (newRatio >= TW.conf.zoomMin) {
// triggers coordinatesUpdated which sets the slider cursor
partialGraph.camera.goTo({ratio: newRatio});
return false;
......@@ -1033,7 +1044,7 @@ TinaWebJS = function ( sigmacanvas ) {
$("#zoomMinusButton").click(function () {
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
partialGraph.camera.goTo({ratio: newRatio});
return false;
......
'use strict';
// Function.prototype.index
// ---
// 'decorator'
// (used here and in Tinaweb.js for MultipleSelection2)
// ---
// transforms calls like foobar({arg1:a, arg2:b})
// into calls like foobar(a, b)
(function(reComments, reParams, reNames) {
Function.prototype.index = function(arrParamNames) {
var fnMe = this;
arrParamNames = arrParamNames
|| (((fnMe + '').replace(reComments, '')
.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
);
// ajax request
// args:
// - 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 AjaxSync = (function(TYPE, URL, DATA, DT) {
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)
console.log("---AjaxSync---\n", TYPE, URL, DATA, DT, "\n--------------")
console.log("---AjaxSync---", args)
$.ajax({
type: TYPE,
url: URL,
dataType: DT, // <= the expected response format
type: args.type,
url: args.url,
dataType: args.datatype,
async: false, // <= synchronous (POSS alternative: cb + waiting display)
// our payload: filters...
data: DATA,
data: args.data,
contentType: 'application/json',
success : function(data, textStatus, jqXHR) {
var header = jqXHR.getResponseHeader("Content-Type")
......@@ -61,7 +40,7 @@ var AjaxSync = (function(TYPE, URL, DATA, DT) {
}
else {
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" ;
}
Result = { "OK":true , "format":format , "data":data };
......@@ -72,7 +51,7 @@ var AjaxSync = (function(TYPE, URL, DATA, DT) {
}
});
return Result;
}).index();
}
// === [ what to do at start ] === //
......@@ -232,7 +211,7 @@ function syncRemoteGraphData () {
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
inData = bridgeRes.data
......@@ -270,7 +249,7 @@ function syncRemoteGraphData () {
var infofile = TW.conf.sourceMenu
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) {
console.log('initial AjaxSync result preRES', preRES)
......@@ -344,7 +323,7 @@ function syncRemoteGraphData () {
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"]
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