Commit c7f2dcc1 authored by Romain Loth's avatar Romain Loth

unclutter window scope of all parse-related and category-related vars +...

unclutter window scope of all parse-related and category-related vars + clarify confusion in using the word "reverse"
parent 5a45a43c
......@@ -254,7 +254,7 @@ function set_ClustersLegend ( daclass, groupedByTicks ) {
if (daclass=="clust_louvain")
daclass = "louvain"
// usually 'terms' or anything in categories[0]
// usually 'terms' or current display among TW.categories
var curType = getCurrentType()
// all infos in a bin array
......@@ -785,7 +785,7 @@ function ProcessDivsFlags() {
// load JS+CSS items corresponding to the flagname
my_src_dir = key
// HEAD check on local file presence
// TODO check if async not a problem
if (linkCheck(my_src_dir+"/init.js")) {
loadJS(my_src_dir+"/init.js") ;
}
......
......@@ -100,7 +100,7 @@ var semanticConverged=false;
// ============ < / DEVELOPER OPTIONS > ============
TW.branding = 'Politoscope: explorer les programmes'
TW.branding = 'test bipart'
TW.nodeClusAtt = "modularity_class"
TW.filterSliders = false
......
......@@ -22,7 +22,6 @@ function changeType() {
var level = present.level;
var sels = present.selections
var catDict = present.categoriesDict;
var type_t0 = present.type;
var str_type_t0 = type_t0.map(Number).join("|")
......@@ -94,7 +93,7 @@ function changeType() {
if(present.level) { //If level=Global, fill all {X}-component
for(var nid in TW.Nodes) {
if(type_t1[catDict[TW.Nodes[nid].type]])
if(type_t1[TW.catDict[TW.Nodes[nid].type]])
add1Elem(nid)
}
for(var eid in TW.Edges) {
......@@ -262,8 +261,6 @@ function changeType() {
TW.partialGraph.states[avantlastpos].selections = selsbackup;
TW.partialGraph.states[avantlastpos].type = present.type;
TW.partialGraph.states[avantlastpos].opposites = present.opposites;
TW.partialGraph.states[avantlastpos].categories = present.categories;//to_del
TW.partialGraph.states[avantlastpos].categoriesDict = present.categoriesDict;//to_del
TW.partialGraph.states[lastpos].setState({
type: nextState,
......@@ -271,9 +268,6 @@ function changeType() {
sels: Object.keys(selections).map(Number),
oppos: []
})
TW.partialGraph.states[lastpos].categories = present.categories;//to_del
TW.partialGraph.states[lastpos].categoriesDict = catDict;//to_del
fa2enabled=true; TW.partialGraph.zoomTo(TW.partialGraph._core.width / 2, TW.partialGraph._core.height / 2, 0.8).draw();//.startForceAtlas2();
}
......@@ -302,7 +296,6 @@ function changeLevel() {
var level = present.level;
var sels = present.selections;//[144, 384, 543]//TW.partialGraph.states.selections;
var catDict = present.categoriesDict;
// type "grammar"
......@@ -374,7 +367,7 @@ function changeLevel() {
// var t0 = performance.now()
for(var nid in TW.Nodes) {
if(type_t0[catDict[TW.Nodes[nid].type]])
if(type_t0[TW.catDict[TW.Nodes[nid].type]])
// we add 1 by 1
add1Elem(nid)
}
......@@ -408,8 +401,6 @@ function changeLevel() {
TW.partialGraph.states[avantlastpos].selections = present.selections;
TW.partialGraph.states[avantlastpos].type = present.type;
TW.partialGraph.states[avantlastpos].opposites = present.opposites;
TW.partialGraph.states[avantlastpos].categories = present.categories;//to_del
TW.partialGraph.states[avantlastpos].categoriesDict = present.categoriesDict;//to_del
TW.partialGraph.states[lastpos].setState({
type: present.type,
......@@ -417,8 +408,6 @@ function changeLevel() {
sels: Object.keys(selections).map(Number),
oppos: []
})
TW.partialGraph.states[lastpos].categories = present.categories;//to_del
TW.partialGraph.states[lastpos].categoriesDict = catDict;//to_del
TW.partialGraph.camera.goTo({x:0, y:0, ratio:1.2, angle: 0})
TW.partialGraph.refresh()
......
......@@ -302,21 +302,26 @@ if (! inFormat || ! inData) {
}
else {
console.log("parsing the data")
var start = new ParseCustom( inFormat , inData );
var categories = start.scanFile(); //user should choose the order of categories
let start = new ParseCustom( inFormat , inData );
let catsInfos = start.scanFile(); //user should choose the order of categories
TW.categories = catsInfos.categories
console.log("Categories: ")
console.log(categories)
console.log(TW.categories)
if (! categories) {
// reverse lookup: category name => category indice
TW.catDict = catsInfos.lookup_dict
if (! TW.categories) {
console.warn ('ParseCustom scanFile found no categories!!')
categories = []
TW.categories = []
TW.catDict = {}
}
var possibleStates = makeSystemStates( categories )
var initialState = buildInitialState( categories ) //[true,false]//
var possibleStates = makeSystemStates( TW.categories )
var initialState = buildInitialState( TW.categories ) //[true,false]//
// XML parsing from ParseCustom
var dicts = start.makeDicts(categories); // > parse json or gexf, dictfy
var dicts = start.makeDicts(TW.categories); // > parse json or gexf, dictfy
console.warn("parsing result:", dicts)
TW.Nodes = dicts.nodes;
......@@ -363,11 +368,7 @@ else {
console.error("== currently unhandled categorization of node types ==", TW.categories)
}
// FIXME generalize the use of these two TW.* variants instead of window-scoped 'categories' and 'catDict'
TW.categories = categories;
TW.categoriesIndex = catDict;
for(var i in categories) {
for(var i in TW.categories) {
TW.Filters[i] = {}
TW.Filters[i]["#slidercat"+i+"edgesweight"] = true;
}
......@@ -394,8 +395,7 @@ else {
// preparing the data and settings
TW.graphData = {nodes: [], edges: []}
TW.graphData = sigma_utils.FillGraph( initialState , catDict , TW.Nodes , TW.Edges , TW.graphData );
TW.graphData = sigma_utils.FillGraph( initialState , TW.catDict , TW.Nodes , TW.Edges , TW.graphData );
// // ----------- TEST stock parse gexf and use nodes to replace TW's ---------
......@@ -518,9 +518,12 @@ else {
TW.partialGraph.states = []
TW.partialGraph.states[0] = false;
TW.partialGraph.states[1] = TW.SystemStates;
TW.partialGraph.states[1].categories = categories
TW.partialGraph.states[1].categoriesDict = catDict;
console.log("!? initialState => states[1].type")
// can be COMMENTED OUT: in specifications categories never change so states shouldn't need them
// TW.partialGraph.states[1].categories = TW.categories
// TW.partialGraph.states[1].categoriesDict = TW.catDict;
// here 'type' means: the categorie(s) that is (are) currently displayed
TW.partialGraph.states[1].type = initialState;
TW.partialGraph.states[1].LouvainFait = false;
// [ / Poblating the Sigma-Graph ]
......@@ -678,7 +681,7 @@ else {
// REFA new sigma.js
TW.partialGraph.camera.goTo({x:0, y:0, ratio:0.5, angle: 0})
twjs_.initListeners( categories , TW.partialGraph);
twjs_.initListeners(TW.categories , TW.partialGraph);
// run fa2 if settings_explorerjs.fa2enabled == true
if (fa2enabled) {
......@@ -688,7 +691,7 @@ else {
});
}
if( categories.length==1 ) {
if( TW.categories.length==1 ) {
$("#changetype").hide();
$("#taboppos").remove();
......
......@@ -85,10 +85,6 @@ function cancelSelection (fromTagCloud, settings) {
function getCurrentType() {
// type grammar overly complicated: it's absurd to have to do 10 lines
// to retrieve the tina type when other times
// there's so many window-scoped vars !!!
// TODO expose current type more accessibly
let currentTypeName
let currentTypeIdx
let typeIdxs = Object.keys(TW.partialGraph.states.slice(-1)[0].type)
......@@ -99,7 +95,7 @@ function getCurrentType() {
}
}
currentTypeName = window.categories[currentTypeIdx]
currentTypeName = TW.categories[currentTypeIdx]
return currentTypeName
}
......
......@@ -5,9 +5,6 @@
// Level-01
ParseCustom = function ( format , data ) {
console.debug("ParseCustom init format, data", format, data)
if (format == 'gexf') {
this.data = $.parseXML(data)
}
......@@ -44,6 +41,7 @@ ParseCustom = function ( format , data ) {
// Level-02
ParseCustom.prototype.scanFile = function() {
let catInfos = {'categories':[], 'lookup_dict': {}}
switch (this.format) {
case "api.json":
console.log("scanFile: "+this.format)
......@@ -53,13 +51,13 @@ ParseCustom.prototype.scanFile = function() {
break;
case "json":
console.log("scanFile: "+this.format)
categories = this.getJSONCategories( this.data );
return categories;
catInfos = this.getJSONCategories( this.data );
return catInfos;
break;
case "gexf":
console.log("scanFile: "+this.format)
categories = this.getGEXFCategories( this.data );
return categories;
catInfos = this.getGEXFCategories( this.data );
return catInfos;
break;
default:
console.log("scanFile jsaispas: "+this.format)
......@@ -166,7 +164,7 @@ function gexfCheckAttributesMap (someXMLContent) {
// Level-00
function scanGexf(gexfContent) {
console.log("ParseCustom : scanGexf ======= ")
console.debug("ParseCustom : scanGexf ======= ")
var categoriesDict={};
// adding gexfCheckAttributesMap call
......@@ -259,7 +257,7 @@ function sortNodeTypes(observedTypesDict) {
}
observedTypes = newcats;
}
return {'categories': observedTypes, 'reverse_dict': catDict}
return {'categories': observedTypes, 'lookup_dict': catDict}
}
// Level-00
......@@ -297,7 +295,7 @@ function dictfyGexf( gexf , categories ){
// let sizeStats = {'mean':null, 'median':null, 'max':0, 'min':1000000000}
// if scanClusters, we'll also use:
var tmpVals = {} // to build reverse index attval => nodes
var tmpVals = {} // to build inverted index attval => nodes
// (to inventory subclasses for a given attr)
// if < maxDiscreteValues: keep all in legend
// else: show intervals in legend
......@@ -391,8 +389,6 @@ function dictfyGexf( gexf , categories ){
}
node.attributes = atts;
// £TODO copy this logic in json case
// nodew=parseInt(attributes["weight"]);
if ( atts["category"] ) {
node_cat = atts["category"];
......@@ -440,7 +436,7 @@ function dictfyGexf( gexf , categories ){
if (!tmpVals[node_cat][at].map[someval]) tmpVals[node_cat][at].map[someval] = []
tmpVals[node_cat][at].vals.push(someval) // for ordered scale
tmpVals[node_cat][at].map[someval].push(node.id) // reverse index
tmpVals[node_cat][at].map[someval].push(node.id) // inverted index
}
}
}
......@@ -449,7 +445,7 @@ function dictfyGexf( gexf , categories ){
}
// console.warn ('parseCustom output nodes', nodes)
// console.warn ('parseCustom reverse index: vals to ids', tmpVals)
// console.warn ('parseCustom inverted index: vals to ids', tmpVals)
// -------------- debug: for local stats ----------------
// allSizes.sort();
......@@ -552,7 +548,7 @@ function dictfyGexf( gexf , categories ){
})
// (enhanced intervalsInventory)
// => creates bin, binlabels, reverse index per bins
// => creates bin, binlabels, inverted index per bins
var legendRefTicks = []
// how many bins for this attribute ?
......
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