Commit baa586a0 authored by Romain Loth's avatar Romain Loth

more settings harmonization (presentation, sourcefile, sigma drawing params)

parent eceb74e3
...@@ -13,7 +13,6 @@ TW.conf = (function(TW){ ...@@ -13,7 +13,6 @@ TW.conf = (function(TW){
// TINA POSSIBLE DATA SOURCES // TINA POSSIBLE DATA SOURCES
// ========================== // ==========================
// Graph data source // Graph data source
// ----------------- // -----------------
// the graph input depends on TWConf.sourcemode (or manual url arg 'sourcemode') // the graph input depends on TWConf.sourcemode (or manual url arg 'sourcemode')
...@@ -42,18 +41,16 @@ TW.conf = (function(TW){ ...@@ -42,18 +41,16 @@ TW.conf = (function(TW){
// TWConf.relatedDocsType // TWConf.relatedDocsType
// =========== // =======================
// DATA FACETS // DATA FACETS AND LEGENDS
// =========== // =======================
// to process node attributes values from data
// => colors (continuous numeric attributes)
// => clusters (discrete numeric or str attributes),
// create facets ? // create facets ?
TWConf.scanClusters = true TWConf.scanClusters = true
// to handle node attributes from data
// => clusters (discrete numeric or str vars),
// => colors (continuous numeric vars)
// for continuous attrvalues/colors (cf. clustersBy), how many levels in legend? // for continuous attrvalues/colors (cf. clustersBy), how many levels in legend?
TWConf.legendsBins = 7 ; TWConf.legendsBins = 7 ;
...@@ -67,7 +64,7 @@ TW.conf = (function(TW){ ...@@ -67,7 +64,7 @@ TW.conf = (function(TW){
'growth_rate': 12 'growth_rate': 12
} }
// default clustering (used to show as initial color) // default clustering attribute (<---> used for initial node colors)
TWConf.nodeClusAtt = "modularity_class" TWConf.nodeClusAtt = "modularity_class"
...@@ -121,7 +118,7 @@ TW.conf = (function(TW){ ...@@ -121,7 +118,7 @@ TW.conf = (function(TW){
// if fa2Available, the auto-run config: // if fa2Available, the auto-run config:
TWConf.fa2Enabled= false; // fa2 auto-run at start and after graph modified ? TWConf.fa2Enabled= true; // fa2 auto-run at start and after graph modified ?
TWConf.fa2Milliseconds=5000; // duration of auto-run TWConf.fa2Milliseconds=5000; // duration of auto-run
TWConf.minNodesForAutoFA2 = 5 // graph size threshold to auto-run TWConf.minNodesForAutoFA2 = 5 // graph size threshold to auto-run
...@@ -133,86 +130,81 @@ TW.conf = (function(TW){ ...@@ -133,86 +130,81 @@ TW.conf = (function(TW){
TWConf.strSearchBar = "Select topics"; TWConf.strSearchBar = "Select topics";
// ======================= // ===================
// TINA RENDERING SETTINGS // RENDERING SETTINGS
// ======================= // ===================
TWConf.overSampling = true // costly hi-def rendering (true => pixelRatio x 2) TWConf.twRendering = true ; // false: use sigma "stock" rendering
// true: use our rendering customizations
// relative sizes (iff graph display with both nodetypes) // (nodes with borders,
TWConf.sizeMult = []; // edges with curves,
TWConf.sizeMult[0] = 1.5; // ie for node type 0 // better labels, etc)
TWConf.sizeMult[1] = 1.0; // ie for node type 1
// circle selection cursor
TWConf.circleSizeMin = 0;
TWConf.circleSizeMax = 100;
// size range for neighbor nodes "tagcloud"
TWConf.tagcloudFontsizeMin = 12;
TWConf.tagcloudFontsizeMax = 24;
TWConf.tagcloudSameLimit = 50 // display at most how many neighbors of the same type
TWConf.tagcloudOpposLimit = 10 // display at most how many neighbors of the opposite type
TWConf.defaultNodeColor = "rgb(40,40,40)" TWConf.overSampling = true // hi-def rendering (true => pixelRatio x 2)
// selected/deselected rendering // sigma rendering settings
TWConf.nodesGreyBorderColor = "rgba(100, 100, 100, 0.5)"; // not selected nodes // ------------------------
TWConf.sigmaJsDrawingProperties = {
// nodes
TWConf.selectedColor = "default" // "node" for a background like the node's color, defaultNodeColor: "#333",
// "default" for note-like yellow twNodeRendBorderSize: 1, // node borders (only iff ourRendering)
twNodeRendBorderColor: "#eee",
// edges
minEdgeSize: 2, // in fact used in tina as edge size
defaultEdgeType: 'curve', // 'curve' or 'line' (curve only iff ourRendering)
twEdgeDefaultOpacity: 0.4, // initial opacity added to src/tgt colors
// labels
font: "Droid Sans", // font params
fontStyle: "bold",
defaultLabelColor: '#000', // labels text color
labelSizeRatio: 1, // initial label size (on the slider)
labelThreshold: 5, // min node cam size to start showing label
// (old tina: showLabelsIfZoom)
TWConf.edgeDefaultOpacity = 0.4 // opacity when true_color // hovered nodes
TWConf.edgeGreyColor = "rgba(150, 150, 150, 0.5)"; // not selected edges defaultHoverLabelBGColor: '#fff',
defaultHoverLabelColor: '#000',
borderSize: 2.5, // for ex, bigger border when hover
nodeBorderColor: "node", // choices: 'default' color vs. node color
defaultNodeBorderColor: "black", // <- if nodeBorderColor = 'default'
// ======================== // selected nodes <=> special label
// SIGMA RENDERING SETTINGS twSelectedColor: "node", // "node" for a label bg like the node color,
// ======================== // "default" for note-like yellow
// triggers overriding sigma.canvas renderers: nodes.def, labels.def, edges.def
TWConf.ourRendering = true ;
// not selected <=> grey
twNodesGreyOpacity: .35, // smaller value: more grey
twBorderGreyColor: "rgba(100, 100, 100, 0.5)",
twEdgeGreyColor: "rgba(150, 150, 150, 0.5)",
};
// NB: sigmaJsDrawingProperties are available as 'settings' in all renderers
// cf. https://github.com/jacomyal/sigma.js/wiki/Settings#renderers-settings
TWConf.sigmaJsDrawingProperties = {
defaultLabelColor: 'black',
defaultLabelSize: 30, // in fact usually overridden by node data...
labelSizeRatio: 1, // ...but this ratio allows truly adjusting the sizes
labelThreshold: 5, // <- replaces deprecated showLabelsIfZoom // tina environment rendering settings
// -----------------------------------
// mouse captor zoom limits
TWConf.zoomMin = .015625 // for zoom IN (ex: 1/64 to allow zoom x64)
TWConf.zoomMax = 2 // for zoom OUT
defaultEdgeType: 'curve', // 'curve' or 'line' // circle selection cursor
TWConf.circleSizeMin = 0;
TWConf.circleSizeMax = 100;
defaultBorderView: "always", // size range for neighbor nodes "tagcloud"
TWConf.tagcloudFontsizeMin = 12;
TWConf.tagcloudFontsizeMax = 24;
// new sigma.js only for hover + new settingnames TWConf.tagcloudSameLimit = 50 // max displayed neighbors of the same type
defaultHoverLabelBGColor: '#fff', TWConf.tagcloudOpposLimit = 10 // max displayed neighbors of the opposite type
defaultHoverLabelColor: '#000',
borderSize: 2.5, // (only for hovered nodes)
defaultNodeBorderColor: "black",
nodeBorderColor: "default", // vs. node
// for custom TW node renderer with borders
twNodeRendBorderSize: 1, // (for all normal nodes, iff TWConf.nodeRendBorder)
twNodeRendBorderColor: "#222",
// twNodeRendBorderColor: "#eee",
font: "Droid Sans",
// font: "Crete Round",
// font: "Ubuntu Condensed",
fontStyle: "bold",
};
TWConf.sigmaJsGraphProperties = { // relative sizes (iff ChangeType == both nodetypes)
minEdgeSize: 3, TWConf.sizeMult = [];
// maxEdgeSize: 10 TWConf.sizeMult[0] = 1.5; // ie for node type 0
}; TWConf.sizeMult[1] = 1.0; // ie for node type 1
TWConf.sigmaJsMouseProperties = {
minRatio: .03125, // 1/32 pour permettre zoom x32
maxRatio: 2
};
// =========== // ===========
......
...@@ -873,7 +873,7 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -873,7 +873,7 @@ TinaWebJS = function ( sigmacanvas ) {
// to init local, instance-related listeners (need to run at new sigma instance) // to init local, instance-related listeners (need to run at new sigma instance)
// args: @partialGraph = a sigma instance // args: @partialGraph = a sigma instance
this.SigmaListeners = function(partialGraph, initialActivetypes) { this.initSigmaListeners = function(partialGraph, initialActivetypes) {
var SelInst = new SelectionEngine(); var SelInst = new SelectionEngine();
...@@ -1009,8 +1009,8 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -1009,8 +1009,8 @@ TinaWebJS = function ( sigmacanvas ) {
// new sigma.js current zoom ratio // new sigma.js current zoom ratio
value: partialGraph.camera.ratio, value: partialGraph.camera.ratio,
min: 1 / TW.conf.sigmaJsMouseProperties.maxRatio, // ex x.5 min: 1 / TW.conf.zoomMax, // ex x.5
max: 1 / TW.conf.sigmaJsMouseProperties.minRatio, // ex x32 max: 1 / TW.conf.zoomMin, // ex x32
// range: true, // range: true,
step: .2, step: .2,
value: 1, value: 1,
...@@ -1098,6 +1098,16 @@ TinaWebJS = function ( sigmacanvas ) { ...@@ -1098,6 +1098,16 @@ TinaWebJS = function ( sigmacanvas ) {
} }
// clears the graph instance
this.clearSigma = function() {
if (TW.partialGraph && TW.partialGraph.graph) {
TW.partialGraph.graph.clear()
TW.partialGraph.refresh()
selections = []
}
}
this.initialActivetypes = function( categories ) { this.initialActivetypes = function( categories ) {
var firstActivetypes = [] var firstActivetypes = []
for(var i=0; i<categories.length ; i++) { for(var i=0; i<categories.length ; i++) {
......
...@@ -52,11 +52,7 @@ function createFilechooserEl () { ...@@ -52,11 +52,7 @@ function createFilechooserEl () {
} }
else { else {
// we might have a previous graph opened // we might have a previous graph opened
if (TW.partialGraph && TW.partialGraph.graph) { TW.instance.clearSigma()
TW.partialGraph.graph.clear()
TW.partialGraph.refresh()
selections = []
}
// run // run
if (theFormat == 'json') if (theFormat == 'json')
...@@ -978,7 +974,11 @@ function jsActionOnGexfSelector(gexfBasename){ ...@@ -978,7 +974,11 @@ function jsActionOnGexfSelector(gexfBasename){
if (pathcomponents[i] != 'explorerjs.html') if (pathcomponents[i] != 'explorerjs.html')
serverPrefix += '/'+pathcomponents[i] serverPrefix += '/'+pathcomponents[i]
} }
var newDataRes = AjaxSync({ URL: window.location.origin+serverPrefix+'/'+gexfPath }); var newDataRes = AjaxSync({ URL: window.location.origin+serverPrefix+gexfPath });
// remove any previous instance
TW.instance.clearSigma()
mainStartGraph(newDataRes["format"], newDataRes["data"], TW.instance) mainStartGraph(newDataRes["format"], newDataRes["data"], TW.instance)
writeLabel(gexfBasename) writeLabel(gexfBasename)
} }
......
...@@ -104,11 +104,13 @@ if (window.location.protocol == 'file:' ...@@ -104,11 +104,13 @@ if (window.location.protocol == 'file:'
let inputDiv = document.getElementById('localInput') let inputDiv = document.getElementById('localInput')
inputDiv.style.display = 'block' inputDiv.style.display = 'block'
var remark = document.createElement("p") if (window.location.protocol == 'file:') {
remark.innerHTML = `You're running project explorer as a local html file (no syncing).` var remark = document.createElement("p")
remark.classList.add('comment') remark.innerHTML = `You're running project explorer as a local html file (no syncing).`
remark.classList.add('centered') remark.classList.add('comment')
inputDiv.appendChild(remark) remark.classList.add('centered')
inputDiv.appendChild(remark)
}
// user can open a gexf or json from his fs // user can open a gexf or json from his fs
var graphFileInput = createFilechooserEl() var graphFileInput = createFilechooserEl()
...@@ -263,11 +265,11 @@ function syncRemoteGraphData () { ...@@ -263,11 +265,11 @@ function syncRemoteGraphData () {
// menufile case : a list of source files in ./db.json // menufile case : a list of source files in ./db.json
if (sourcemode == 'servermenu') { if (sourcemode == 'servermenu') {
console.log("no @file arg nor TW.mainfile: trying FILEMENU TW.conf.sourceMenu") console.log("reading from FILEMENU TW.conf.sourceMenu")
// we'll first retrieve the menu of available files in db.json, then get the real data in a second ajax // we'll first retrieve the menu of available files in db.json, then get the real data in a second ajax
var infofile = TW.conf.sourceMenu var infofile = TW.conf.sourceMenu
if (TW.conf.debug.logFetchers) console.info(`attempting to load infofile ${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, DT:"json" });
if (preRES['OK'] && preRES.data) { if (preRES['OK'] && preRES.data) {
...@@ -323,7 +325,6 @@ function syncRemoteGraphData () { ...@@ -323,7 +325,6 @@ function syncRemoteGraphData () {
files_selector += '<option '+cssFileSelected+'>'+gexfBasename+'</option>' files_selector += '<option '+cssFileSelected+'>'+gexfBasename+'</option>'
} }
// console.log( files_selector ) // console.log( files_selector )
break;
} }
files_selector += "</select>" files_selector += "</select>"
console.log("files_selector HTML", files_selector) console.log("files_selector HTML", files_selector)
...@@ -336,7 +337,7 @@ function syncRemoteGraphData () { ...@@ -336,7 +337,7 @@ function syncRemoteGraphData () {
} }
// direct file fallback case: specified file in settings_explorer // direct file fallback case: specified file in settings_explorer
else if (TW.conf.sourceFile && linkCheck(TW.conf.sourceFile)) { else if (TW.conf.sourceFile && linkCheck(TW.conf.sourceFile)) {
console.log("no @file arg: trying TW.mainfile from settings") console.log("no @file arg: trying TW.conf.sourceFile from settings")
the_file = TW.conf.sourceFile; the_file = TW.conf.sourceFile;
} }
else { else {
...@@ -495,15 +496,13 @@ function mainStartGraph(inFormat, inData, twInstance) { ...@@ -495,15 +496,13 @@ function mainStartGraph(inFormat, inData, twInstance) {
// our final sigma params (cf github.com/jacomyal/sigma.js/wiki/Settings) // our final sigma params (cf github.com/jacomyal/sigma.js/wiki/Settings)
TW.customSettings = Object.assign( TW.customSettings = Object.assign(
// 1) default values // 1) optimal low-level values (was: "developer settings")
{ {
drawEdges: true, drawEdges: true,
drawNodes: true, drawNodes: true,
drawLabels: true, drawLabels: true,
labelSize: "proportional", labelSize: "proportional",
// font: "Ubuntu Condensed", // overridden by settings_explorer.js
// labelColor: "node",
// nodesPowRatio: .3, // nodesPowRatio: .3,
batchEdgesDrawing: false, batchEdgesDrawing: false,
...@@ -520,13 +519,14 @@ function mainStartGraph(inFormat, inData, twInstance) { ...@@ -520,13 +519,14 @@ function mainStartGraph(inFormat, inData, twInstance) {
touchEnabled: false, touchEnabled: false,
animationsTime:150, animationsTime:150,
mouseZoomDuration:250 mouseZoomDuration:250,
zoomMin: TW.conf.zoomMin,
zoomMax: TW.conf.zoomMax
}, },
// 2) settings_explorer values // 2) user-configurable values (cf. settings_explorer)
TW.conf.sigmaJsDrawingProperties, TW.conf.sigmaJsDrawingProperties,
TW.conf.sigmaJsGraphProperties,
TW.conf.sigmaJsMouseProperties
) )
...@@ -574,7 +574,7 @@ function mainStartGraph(inFormat, inData, twInstance) { ...@@ -574,7 +574,7 @@ function mainStartGraph(inFormat, inData, twInstance) {
// (new graph => new categories combinations => new array) // (new graph => new categories combinations => new array)
// now that we have a sigma instance, let's bind our click handlers to it // now that we have a sigma instance, let's bind our click handlers to it
TW.instance.SigmaListeners(TW.partialGraph, initialActivetypes) TW.instance.initSigmaListeners(TW.partialGraph, initialActivetypes)
// [ / Poblating the Sigma-Graph ] // [ / Poblating the Sigma-Graph ]
......
...@@ -735,15 +735,15 @@ function prepareNodesRenderingProperties(nodesDict) { ...@@ -735,15 +735,15 @@ function prepareNodesRenderingProperties(nodesDict) {
n.color = `rgb(${rgbStr})` n.color = `rgb(${rgbStr})`
} }
else { else {
n.color = TW.conf.defaultNodeColor n.color = TW.conf.sigmaJsDrawingProperties.defaultNodeColor
rgbStr = TW.conf.defaultNodeColor.split(',').splice(0, 3).join(','); rgbStr = n.color.split(',').splice(0, 3).join(',');
} }
n.customAttrs = { n.customAttrs = {
grey: false, grey: false,
highlight: false, highlight: false,
true_color : n.color, true_color : n.color,
defgrey_color : "rgba("+rgbStr+",.35)" defgrey_color : "rgba("+rgbStr+","+TW.conf.sigmaJsDrawingProperties.twNodesGreyOpacity+")"
} }
// POSS n.type: distinguish rendtype and twtype // POSS n.type: distinguish rendtype and twtype
...@@ -770,7 +770,7 @@ function prepareEdgesRenderingProperties(edgesDict, nodesDict) { ...@@ -770,7 +770,7 @@ function prepareEdgesRenderingProperties(edgesDict, nodesDict) {
var rgbStr = sigmaTools.edgeRGB(nodesDict[e.source].color, nodesDict[e.target].color) var rgbStr = sigmaTools.edgeRGB(nodesDict[e.source].color, nodesDict[e.target].color)
e.color = "rgba("+rgbStr+","+TW.conf.edgeDefaultOpacity+")" e.color = "rgba("+rgbStr+","+TW.conf.sigmaJsDrawingProperties.twEdgeDefaultOpacity+")"
e.customAttrs = { e.customAttrs = {
grey: false, grey: false,
activeEdge : false, activeEdge : false,
......
...@@ -110,7 +110,7 @@ SigmaUtils = function () { ...@@ -110,7 +110,7 @@ SigmaUtils = function () {
context.beginPath(); context.beginPath();
if (TW.conf.nodesGreyBorderColor == "node") if (settings('twSelectedColor') == "node")
context.fillStyle = TW.handpickedcolor? node.customAttrs.alt_color : node.color; // node's context.fillStyle = TW.handpickedcolor? node.customAttrs.alt_color : node.color; // node's
else else
context.fillStyle = "#F7E521"; // yellow context.fillStyle = "#F7E521"; // yellow
...@@ -203,11 +203,11 @@ SigmaUtils = function () { ...@@ -203,11 +203,11 @@ SigmaUtils = function () {
// console.debug(`t=${tstamp()} curve render activeedge: ${edgeInfos(edge)})`) // console.debug(`t=${tstamp()} curve render activeedge: ${edgeInfos(edge)})`)
} }
else if (edge.customAttrs.grey) { else if (edge.customAttrs.grey) {
color = TW.conf.edgeGreyColor color = settings('twEdgeGreyColor')
size = 1 size = 1
} }
else { else {
color = "rgba( "+baseRGB+" , "+TW.conf.edgeDefaultOpacity+")"; color = "rgba( "+baseRGB+" , "+TW.conf.sigmaJsDrawingProperties.twEdgeDefaultOpacity+")";
size = defSize size = defSize
} }
...@@ -255,11 +255,11 @@ SigmaUtils = function () { ...@@ -255,11 +255,11 @@ SigmaUtils = function () {
color = 'rgba('+rgb.join()+',.7)' color = 'rgba('+rgb.join()+',.7)'
} }
else if (edge.customAttrs.grey) { else if (edge.customAttrs.grey) {
color = TW.conf.edgeGreyColor color = settings('twEdgeGreyColor')
size = 1 size = 1
} }
else { else {
// color = "rgba( "+rgb.join()+" , "+TW.conf.edgeDefaultOpacity+")"; // color = "rgba( "+rgb.join()+" , "+TW.conf.sigmaJsDrawingProperties.twEdgeDefaultOpacity+")";
color = edge.customAttrs.true_color color = edge.customAttrs.true_color
size = defSize size = defSize
} }
...@@ -293,7 +293,7 @@ SigmaUtils = function () { ...@@ -293,7 +293,7 @@ SigmaUtils = function () {
// mode variants // mode variants
if (TW.selectionActive) { if (TW.selectionActive) {
// passive nodes should blend in the grey of TW.conf.edgeGreyColor // passive nodes should blend in the grey of twEdgeGreyColor
// cf settings_explorerjs, defgrey_color and greyEverything() // cf settings_explorerjs, defgrey_color and greyEverything()
if (node.customAttrs.grey) { if (node.customAttrs.grey) {
if (! TW.handpickedcolor) { if (! TW.handpickedcolor) {
...@@ -309,7 +309,7 @@ SigmaUtils = function () { ...@@ -309,7 +309,7 @@ SigmaUtils = function () {
nodeColor = node.customAttrs.altgrey_color nodeColor = node.customAttrs.altgrey_color
} }
// nice looking uniform grey // nice looking uniform grey
borderColor = TW.conf.nodesGreyBorderColor borderColor = TW.conf.sigmaJsDrawingProperties.twBorderGreyColor
} }
// neighbor nodes <=> (highlight flag AND selectionActive) // neighbor nodes <=> (highlight flag AND selectionActive)
else if(node.customAttrs.highlight) { else if(node.customAttrs.highlight) {
......
...@@ -45,7 +45,7 @@ sigmaTools = (function(stools) { ...@@ -45,7 +45,7 @@ sigmaTools = (function(stools) {
var rawEdge = rawGexfEdges[i] var rawEdge = rawGexfEdges[i]
var rgbStr = sigmaTools.edgeRGB(newNodes[rawEdge.source].color, newNodes[rawEdge.target].color) var rgbStr = sigmaTools.edgeRGB(newNodes[rawEdge.source].color, newNodes[rawEdge.target].color)
var leColor = "rgba("+rgbStr+","+TW.conf.edgeDefaultOpacity+")" var leColor = "rgba("+rgbStr+","+TW.conf.sigmaJsDrawingProperties.twEdgeDefaultOpacity+")"
var newEid = rawEdge.source+";"+rawEdge.target; var newEid = rawEdge.source+";"+rawEdge.target;
var newEdge = { var newEdge = {
......
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