Commit afa38061 authored by Romain Loth's avatar Romain Loth

WIP adapting main to cases with input file second graph load

in other words we try to distinguish between what needs to be initialized once and what needs to be initialized each time we get new graph data... this use case wasn't covered before and will need some more re-designing, but it's convergent with modularising the app
parent 2d6ac920
......@@ -3,18 +3,21 @@ This is a stub for a future documentation for developers.
## Graph initialization
The main steps for any graph initialization messily use functions across several modules, so it can be useful to list them here together:
This will still evolve but the main steps for any graph initialization messily use functions across several modules, so it can be useful to list them here together:
1. [`main.js`] initial choice of data source from URL params or settings
2. [`sigma.parseCustom.js`] prepares the data
- read a source via ajax GET
1. [`main.js`] initializes the TinaWebJS object and runs its init which registers our rendering function to sigma module
2. [`main.js`] makes the initial choice of data source from URL protocol (local or remote) and URL params (when remote)
- then read a source via fileinput (when local) or ajax GET (when remote)
3. [`sigma.parseCustom.js`] prepares the data
- *"scan"*: loop once to list present node categories
- *"dictify"*: loop again to copy all nodes/edges information
- prepares TW.Relations: edges sorted by type (term-term, term-doc...)
- prepares TW.Clusters: bins and facet index (node attr vals => nodes)
3. [`main.js`] precomputes display properties (grey color, etc.)
4. [`sigmaUtils`] the function `FillGraph()` was a central point for filtering and preparing properties but now with 2 and 3 it just copies the nodes and edges to a new structure that groups them together
5. [`main.js`] Finally all sigma settings (user + defaults) are merged and we initialize the sigma instance (`new sigma` etc.)
4. [`main.js`] mainStartGraph() function runs all the rest
1. precomputes display properties (grey color, etc.)
2. calls [`sigmaUtils`] where the function `FillGraph()` was a central point for filtering and preparing properties but now with 2 and 3 it just copies the nodes and edges to a new structure that groups them together
3. back in [`main.js`], finally all sigma settings (user + defaults) are merged and we initialize the sigma instance (`new sigma` etc.)
4. finally a call to [`TinawebJS`] initializes the action listeners and this phase should crucially initialize items that need the sigma instance (because they may depend the displayed categories, the number of displayed nodes, etc)
#### About source data
......
......@@ -92,6 +92,12 @@ function jsActionOnGexfSelector(gexfBasename , db_json){
// NB this method-holding instance could be initialized just once or even removed?
var sigma_utils = new SigmaUtils();
// POSS: ideally this should take a TW.settings as parameter
TW.instance = new TinaWebJS('#sigma-contnr');
// add once our tw rendering and index customizations into sigma module
TW.instance.init()
// show the custom name of the app
writeBrand(TW.branding)
......@@ -115,7 +121,6 @@ if (window.location.protocol == 'file:') {
graphFileInput.onchange = function() {
if (this.files && this.files[0]) {
console.log(this.files[0])
let clientLocalGraphFile = this.files[0]
// determine the format
......@@ -126,6 +131,9 @@ if (window.location.protocol == 'file:') {
else if (/\.json$/.test(clientLocalGraphFile.name)) {
theFormat = 'json'
}
else {
alert('unrecognized file format')
}
// retrieving the content
let rdr = new FileReader()
......@@ -134,11 +142,19 @@ if (window.location.protocol == 'file:') {
if (! rdr.result || !rdr.result.length) {
alert('the selected file is not readable')
}
else if(! theFormat) {
alert('unrecognized file format')
}
else {
mainStartGraph(theFormat, rdr.result)
// we might have a previous graph opened
if (TW.partialGraph && TW.partialGraph.graph) {
TW.partialGraph.graph.clear()
TW.partialGraph.refresh()
selections = []
}
// run
if (theFormat == 'json')
mainStartGraph(theFormat, JSON.parse(rdr.result), TW.instance)
else
mainStartGraph(theFormat, rdr.result, TW.instance)
}
}
rdr.readAsText(clientLocalGraphFile)
......@@ -149,7 +165,7 @@ if (window.location.protocol == 'file:') {
else {
// NB it will use global urlParams and TW.settings to choose the source
var [inFormat, inData] = syncRemoteGraphData()
mainStartGraph(inFormat, inData)
mainStartGraph(inFormat, inData, TW.instance)
}
// === [ / what to do at start ] === //
......@@ -392,7 +408,7 @@ function syncRemoteGraphData () {
// 3 - starts the tinaweb instance
// 4 - finishes setting up the environment
// (NB inspired by Samuel's legacy bringTheNoise() function)
function mainStartGraph(inFormat, inData) {
function mainStartGraph(inFormat, inData, twInstance) {
if (! inFormat || ! inData) {
alert("error on data load")
......@@ -476,12 +492,6 @@ function mainStartGraph(inFormat, inData) {
// [ Initiating Sigma-Canvas ]
// POSS: ideally this should take a TW.settings as parameter
var twjs_ = new TinaWebJS('#sigma-contnr');
// add our tw rendering and index customizations into sigma module
twjs_.init()
// overriding pixelRatio is possible if we need very high definition
if (TW.overSampling) {
var realRatio = sigma.utils.getPixelRatio
......@@ -770,7 +780,7 @@ function mainStartGraph(inFormat, inData) {
// REFA new sigma.js
TW.partialGraph.camera.goTo({x:0, y:0, ratio:0.9, angle: 0})
twjs_.initListeners(TW.categories , TW.partialGraph);
twInstance.initListeners(TW.categories , TW.partialGraph);
// mostly json data are extracts provided by DB apis => no positions
if (inFormat == "json") TW.fa2enabled = true
......@@ -782,7 +792,7 @@ function mainStartGraph(inFormat, inData) {
// adapt the enviroment to monopartite vs. bipartite cases
if( TW.categories.length==1 ) {
$("#changetype").hide();
$("#taboppos").remove();
$("#taboppos").hide();
// if (TW.catSem && TW.catSoc) {
setTimeout(function () {
......@@ -793,6 +803,8 @@ function mainStartGraph(inFormat, inData) {
}
// for elements hidden by default (cf. css) but useful in bipartite case
else {
$("#changetype").show();
$("#taboppos").show();
$("#taboppos").css('display', 'inline-block');
}
......
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