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. ...@@ -3,18 +3,21 @@ This is a stub for a future documentation for developers.
## Graph initialization ## 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 1. [`main.js`] initializes the TinaWebJS object and runs its init which registers our rendering function to sigma module
2. [`sigma.parseCustom.js`] prepares the data 2. [`main.js`] makes the initial choice of data source from URL protocol (local or remote) and URL params (when remote)
- read a source via ajax GET - 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 - *"scan"*: loop once to list present node categories
- *"dictify"*: loop again to copy all nodes/edges information - *"dictify"*: loop again to copy all nodes/edges information
- prepares TW.Relations: edges sorted by type (term-term, term-doc...) - prepares TW.Relations: edges sorted by type (term-term, term-doc...)
- prepares TW.Clusters: bins and facet index (node attr vals => nodes) - prepares TW.Clusters: bins and facet index (node attr vals => nodes)
3. [`main.js`] precomputes display properties (grey color, etc.) 4. [`main.js`] mainStartGraph() function runs all the rest
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 1. precomputes display properties (grey color, etc.)
5. [`main.js`] Finally all sigma settings (user + defaults) are merged and we initialize the sigma instance (`new sigma` 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 #### About source data
......
...@@ -92,6 +92,12 @@ function jsActionOnGexfSelector(gexfBasename , db_json){ ...@@ -92,6 +92,12 @@ function jsActionOnGexfSelector(gexfBasename , db_json){
// 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?
var sigma_utils = new SigmaUtils(); 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 // show the custom name of the app
writeBrand(TW.branding) writeBrand(TW.branding)
...@@ -115,7 +121,6 @@ if (window.location.protocol == 'file:') { ...@@ -115,7 +121,6 @@ if (window.location.protocol == 'file:') {
graphFileInput.onchange = function() { graphFileInput.onchange = function() {
if (this.files && this.files[0]) { if (this.files && this.files[0]) {
console.log(this.files[0])
let clientLocalGraphFile = this.files[0] let clientLocalGraphFile = this.files[0]
// determine the format // determine the format
...@@ -126,6 +131,9 @@ if (window.location.protocol == 'file:') { ...@@ -126,6 +131,9 @@ if (window.location.protocol == 'file:') {
else if (/\.json$/.test(clientLocalGraphFile.name)) { else if (/\.json$/.test(clientLocalGraphFile.name)) {
theFormat = 'json' theFormat = 'json'
} }
else {
alert('unrecognized file format')
}
// retrieving the content // retrieving the content
let rdr = new FileReader() let rdr = new FileReader()
...@@ -134,11 +142,19 @@ if (window.location.protocol == 'file:') { ...@@ -134,11 +142,19 @@ if (window.location.protocol == 'file:') {
if (! rdr.result || !rdr.result.length) { if (! rdr.result || !rdr.result.length) {
alert('the selected file is not readable') alert('the selected file is not readable')
} }
else if(! theFormat) {
alert('unrecognized file format')
}
else { 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) rdr.readAsText(clientLocalGraphFile)
...@@ -149,7 +165,7 @@ if (window.location.protocol == 'file:') { ...@@ -149,7 +165,7 @@ if (window.location.protocol == 'file:') {
else { else {
// NB it will use global urlParams and TW.settings to choose the source // NB it will use global urlParams and TW.settings to choose the source
var [inFormat, inData] = syncRemoteGraphData() var [inFormat, inData] = syncRemoteGraphData()
mainStartGraph(inFormat, inData) mainStartGraph(inFormat, inData, TW.instance)
} }
// === [ / what to do at start ] === // // === [ / what to do at start ] === //
...@@ -392,7 +408,7 @@ function syncRemoteGraphData () { ...@@ -392,7 +408,7 @@ function syncRemoteGraphData () {
// 3 - starts the tinaweb instance // 3 - starts the tinaweb instance
// 4 - finishes setting up the environment // 4 - finishes setting up the environment
// (NB inspired by Samuel's legacy bringTheNoise() function) // (NB inspired by Samuel's legacy bringTheNoise() function)
function mainStartGraph(inFormat, inData) { function mainStartGraph(inFormat, inData, twInstance) {
if (! inFormat || ! inData) { if (! inFormat || ! inData) {
alert("error on data load") alert("error on data load")
...@@ -476,12 +492,6 @@ function mainStartGraph(inFormat, inData) { ...@@ -476,12 +492,6 @@ function mainStartGraph(inFormat, inData) {
// [ Initiating Sigma-Canvas ] // [ 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 // overriding pixelRatio is possible if we need very high definition
if (TW.overSampling) { if (TW.overSampling) {
var realRatio = sigma.utils.getPixelRatio var realRatio = sigma.utils.getPixelRatio
...@@ -770,7 +780,7 @@ function mainStartGraph(inFormat, inData) { ...@@ -770,7 +780,7 @@ function mainStartGraph(inFormat, inData) {
// REFA new sigma.js // REFA new sigma.js
TW.partialGraph.camera.goTo({x:0, y:0, ratio:0.9, angle: 0}) 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 // mostly json data are extracts provided by DB apis => no positions
if (inFormat == "json") TW.fa2enabled = true if (inFormat == "json") TW.fa2enabled = true
...@@ -782,7 +792,7 @@ function mainStartGraph(inFormat, inData) { ...@@ -782,7 +792,7 @@ function mainStartGraph(inFormat, inData) {
// adapt the enviroment to monopartite vs. bipartite cases // adapt the enviroment to monopartite vs. bipartite cases
if( TW.categories.length==1 ) { if( TW.categories.length==1 ) {
$("#changetype").hide(); $("#changetype").hide();
$("#taboppos").remove(); $("#taboppos").hide();
// if (TW.catSem && TW.catSoc) { // if (TW.catSem && TW.catSoc) {
setTimeout(function () { setTimeout(function () {
...@@ -793,6 +803,8 @@ function mainStartGraph(inFormat, inData) { ...@@ -793,6 +803,8 @@ function mainStartGraph(inFormat, inData) {
} }
// for elements hidden by default (cf. css) but useful in bipartite case // for elements hidden by default (cf. css) but useful in bipartite case
else { else {
$("#changetype").show();
$("#taboppos").show();
$("#taboppos").css('display', 'inline-block'); $("#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