Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2 changes #22

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ setParams({
/*
Default zoom level. At zoom = 0, the graph should fill a 800x700px zone
*/
ctlZoomPosition : "left",
/*
Defines the position of the Zoom Control Buttons : "left" or "right"
this setting can't be changed from the User Interface
*/
curvedEdges : true,
/*
False for curved edges, true for straight edges
Expand All @@ -31,6 +36,14 @@ setParams({
minEdgeWidth : 1,
maxEdgeWidth : 50,
textDisplayThreshold: 9,
labelQuadraticFactor : 1,
/*
If more than 1, makes the big labels even bigger.
If 1, nothing changes.
If less than 1, makes the big labels smallers
If 0, every label has the same size
this setting can't be changed from the User Interface
*/
nodeSizeFactor : 1,
/*
Change this parameter for smaller or larger nodes
Expand All @@ -46,6 +59,11 @@ setParams({
Show the weight of edges in the list
this setting can't be changed from the User Interface
*/
showEdgesWhileDragging : false,
/*
Show edges when dragging the graph. If False, the display is much quicker
this setting can't be changed from the User Interface
*/
language: false
/*
Set to an ISO language code to switch the interface to that language.
Expand Down
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@
<h1><a href="http://gephi.org/" target="_blank" title="Made with Gephi">Gephi: JavaScript GEXF Viewer</a></h1>
</div>
<form id="recherche">
<input id="searchinput" class="grey" autocomplete="off" />
<input id="searchsubmit" type="submit" />
<input id="searchinput" class="grey" autocomplete="off"></input>
<input id="searchsubmit" type="submit"></input>
</form>
</div>
<ul id="autocomplete">
Expand Down
141 changes: 92 additions & 49 deletions js/gexfjs.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function strLang(_str) {

function replaceURLWithHyperlinks(text) {
if (GexfJS.params.replaceUrls) {
var _urlExp = /(\b(https?:\/\/)?[-A-Z0-9]+\.[-A-Z0-9.:]+(\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*)?)/ig,
var _urlExp = /(\b(https?:\/\/)?[-A-Z0-9]+\.[-A-Z0-9.:?=]+(\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*)?)/ig,
_protocolExp = /^https?:\/\//i;
return text.replace(_urlExp, function(_found) {
return '<a href="'
Expand Down Expand Up @@ -243,6 +243,19 @@ function updateWorkspaceBounds() {
top : $("#titlebar").height() + "px"
}
_elZC.css(_top);

var _ctl = $("#ctlzoom");
if(GexfJS.params.ctlZoomPosition == "right"){
_ctl.css({
bottom : $("#overviewzone").height()+5+"px" ,
right : "5px"
});
}else{
_ctl.css({
left: "5px",
bottom: "5px"
});
}

$("#leftcolumn").css(_top);
GexfJS.graphZone.width = _elZC.width();
Expand All @@ -252,20 +265,23 @@ function updateWorkspaceBounds() {
for (var i in GexfJS.graphZone) {
GexfJS.areParamsIdentical = GexfJS.areParamsIdentical && ( GexfJS.graphZone[i] == GexfJS.oldGraphZone[i] );
}
GexfJS.areParamsIdentical = GexfJS.areParamsIdentical && ( GexfJS.dragOn == GexfJS.oldDragOn );

if (!GexfJS.areParamsIdentical) {

$("#carte")
.attr({
width : GexfJS.graphZone.width,
height : GexfJS.graphZone.height
})
.css({
width : GexfJS.graphZone.width + "px",
height : GexfJS.graphZone.height + "px"
});
$("#carte")
.attr({
width : GexfJS.graphZone.width,
height : GexfJS.graphZone.height
})
.css({
width : GexfJS.graphZone.width + "px",
height : GexfJS.graphZone.height + "px"
});
for (var i in GexfJS.graphZone) {
GexfJS.oldGraphZone[i] = GexfJS.graphZone[i];
}
GexfJS.oldDragOn = GexfJS.dragOn;
}
}

Expand Down Expand Up @@ -392,6 +408,8 @@ function loadGraph() {
url: ( document.location.hash.length > 1 ? document.location.hash.substr(1) : GexfJS.params.graphFile ),
dataType: "xml",
success: function(data) {
var _minNodeSize = 99999;
var _maxNodeSize = -1;
var _s = new Date();
var _g = $(data).find("graph"),
_nodes = _g.children().filter("nodes").children(),
Expand Down Expand Up @@ -446,14 +464,19 @@ function loadGraph() {
r : _echelle * _size
}
}

if(_d.coords.base.r<_minNodeSize) _minNodeSize = _d.coords.base.r;
if(_d.coords.base.r>_maxNodeSize) _maxNodeSize = _d.coords.base.r;

_d.color = {
rgb : {
r : _r,
g : _g,
b : _b
},
base : "rgba(" + _r + "," + _g + "," + _b + ",.7)",
gris : "rgba(" + Math.floor(84 + .33 * _r) + "," + Math.floor(84 + .33 * _g) + "," + Math.floor(84 + .33 * _b) + ",.5)"
base : "rgba(" + _r + "," + _g + "," + _b + ",.7)",
baseDarker : "rgba(" + Math.floor(62 + .5 * _r) + "," + Math.floor(62 + .5 * _g) + "," + Math.floor(62 + .5 * _b) + ",1)",
gris : "rgba(" + Math.floor(84 + .33 * _r) + "," + Math.floor(84 + .33 * _g) + "," + Math.floor(84 + .33 * _b) + ",.5)"
}
_d.attributes = [];
$(_attr).each(function() {
Expand Down Expand Up @@ -505,6 +528,13 @@ function loadGraph() {
});
});

var _fact = Math.max(0,GexfJS.params.labelQuadraticFactor) ;
for(var _ii = 0 ; _ii < GexfJS.graph.nodeList.length ; _ii++) {
var _n = GexfJS.graph.nodeList[_ii];
_n.labelSize = (_fact == 0 ? 1 : ((_minNodeSize+ Math.pow(_n.coords.base.r-_minNodeSize,_fact))/_n.coords.base.r));
//alert("orig: "+_n.coords.base.r+ "\nafter: "+_n.labelSize)//+"\n\nMath.ceil(("+_minNodeSize+"+Math.pow("+_n.coords.base.r+"-"+_minNodeSize+","+_fact+"))/"+_n.coords.base.r+"))");
}//nnn

GexfJS.imageMini = GexfJS.ctxMini.getImageData(0, 0, GexfJS.overviewWidth, GexfJS.overviewHeight);

//changeNiveau(0);
Expand Down Expand Up @@ -603,9 +633,9 @@ function traceMap() {
GexfJS.ctxGraphe.closePath();
GexfJS.ctxGraphe.fill();
}

var _centralNode = ( ( GexfJS.params.activeNode != -1 ) ? GexfJS.params.activeNode : GexfJS.params.currentNode );

for (var i in GexfJS.graph.nodeList) {
var _d = GexfJS.graph.nodeList[i];
_d.coords.actual = {
Expand All @@ -622,41 +652,12 @@ function traceMap() {
if ( _centralNode != -1 ) {
_tagsMisEnValeur = [ _centralNode ];
}

var _displayEdges = ( GexfJS.params.showEdges && GexfJS.params.currentNode == -1 );

for (var i in GexfJS.graph.edgeList) {
var _d = GexfJS.graph.edgeList[i],
_six = _d.source,
_tix = _d.target,
_ds = GexfJS.graph.nodeList[_six],
_dt = GexfJS.graph.nodeList[_tix];
var _isLinked = false;
if (_centralNode != -1) {
if (_six == _centralNode) {
_tagsMisEnValeur.push(_tix);
_coulTag = _dt.color.base;
_isLinked = true;
_dt.visible = true;
}
if (_tix == _centralNode) {
_tagsMisEnValeur.push(_six);
_coulTag = _ds.color.base;
_isLinked = true;
_ds.visible = true;
}
}

if ( ( _isLinked || _displayEdges ) && ( _ds.withinFrame || _dt.withinFrame ) && _ds.visible && _dt.visible ) {
GexfJS.ctxGraphe.lineWidth = _edgeSizeFactor * _d.width;
var _coords = ( ( GexfJS.params.useLens && GexfJS.mousePosition ) ? calcCoord( GexfJS.mousePosition.x , GexfJS.mousePosition.y , _ds.coords.actual ) : _ds.coords.actual );
_coordt = ( (GexfJS.params.useLens && GexfJS.mousePosition) ? calcCoord( GexfJS.mousePosition.x , GexfJS.mousePosition.y , _dt.coords.actual ) : _dt.coords.actual );
GexfJS.ctxGraphe.strokeStyle = ( _isLinked ? _d.color : "rgba(100,100,100,0.2)" );
traceArc(GexfJS.ctxGraphe, _coords, _coordt);
}
if(!GexfJS.dragOn || GexfJS.params.showEdgesWhileDragging){
traceMap_edges(_centralNode,_sizeFactor,_tagsMisEnValeur);
}

GexfJS.ctxGraphe.lineWidth = 4;
GexfJS.ctxGraphe.strokeStyle = "rgba(0,100,0,0.8)";

if (_centralNode != -1) {
var _dnc = GexfJS.graph.nodeList[_centralNode];
Expand All @@ -682,7 +683,7 @@ function traceMap() {
var _d = GexfJS.graph.nodeList[i];
if (_d.visible && _d.withinFrame) {
if (i != _centralNode) {
var _fs = _d.coords.real.r * _textSizeFactor;
var _fs = _d.coords.real.r * _d.labelSize * _textSizeFactor;//nnn
if (_d.isTag) {
if (_centralNode != -1) {
var _dist = Math.sqrt( Math.pow( _d.coords.real.x - _dnc.coords.real.x, 2 ) + Math.pow( _d.coords.real.y - _dnc.coords.real.y, 2 ) );
Expand All @@ -705,13 +706,14 @@ function traceMap() {
}

if (_centralNode != -1) {
GexfJS.ctxGraphe.strokeStyle = _dnc.color.baseDarker;
GexfJS.ctxGraphe.fillStyle = _dnc.color.base;
GexfJS.ctxGraphe.beginPath();
GexfJS.ctxGraphe.arc( _dnc.coords.real.x , _dnc.coords.real.y , _dnc.coords.real.r , 0 , Math.PI*2 , true );
GexfJS.ctxGraphe.closePath();
GexfJS.ctxGraphe.fill();
GexfJS.ctxGraphe.stroke();
var _fs = Math.max(GexfJS.params.textDisplayThreshold + 2, _dnc.coords.real.r * _textSizeFactor) + 2;
var _fs = Math.max(GexfJS.params.textDisplayThreshold + 2, _dnc.coords.real.r * _dnc.labelSize * _textSizeFactor) + 2;
GexfJS.ctxGraphe.font = "bold " + Math.floor( _fs )+"px Arial";
GexfJS.ctxGraphe.textAlign = "center";
GexfJS.ctxGraphe.textBaseline = "middle";
Expand All @@ -720,6 +722,10 @@ function traceMap() {
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x + 2, _dnc.coords.real.y);
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x, _dnc.coords.real.y - 2);
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x, _dnc.coords.real.y + 2);
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x - 1, _dnc.coords.real.y +1);
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x + 1, _dnc.coords.real.y +1);
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x - 1, _dnc.coords.real.y -1);
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x + 1, _dnc.coords.real.y -1);
GexfJS.ctxGraphe.fillStyle = "rgb(0,0,0)";
GexfJS.ctxGraphe.fillText(_dnc.label, _dnc.coords.real.x, _dnc.coords.real.y);
}
Expand All @@ -739,6 +745,43 @@ function traceMap() {
GexfJS.ctxMini.strokeRect( _x, _y, _w, _h );
}

function traceMap_edges(_centralNode,_sizeFactor,_tagsMisEnValeur) {

var _displayEdges = ( GexfJS.params.showEdges && GexfJS.params.currentNode == -1 ),
_edgeSizeFactor = _sizeFactor * GexfJS.params.edgeWidthFactor;

for (var i in GexfJS.graph.edgeList) {
var _d = GexfJS.graph.edgeList[i],
_six = _d.source,
_tix = _d.target,
_ds = GexfJS.graph.nodeList[_six],
_dt = GexfJS.graph.nodeList[_tix];
var _isLinked = false;
if (_centralNode != -1) {
if (_six == _centralNode) {
_tagsMisEnValeur.push(_tix);
_coulTag = _dt.color.base;
_isLinked = true;
_dt.visible = true;
}
if (_tix == _centralNode) {
_tagsMisEnValeur.push(_six);
_coulTag = _ds.color.base;
_isLinked = true;
_ds.visible = true;
}
}

if ( ( _isLinked || _displayEdges ) && ( _ds.withinFrame || _dt.withinFrame ) && _ds.visible && _dt.visible ) {
GexfJS.ctxGraphe.lineWidth = _edgeSizeFactor * _d.width;
var _coords = ( ( GexfJS.params.useLens && GexfJS.mousePosition ) ? calcCoord( GexfJS.mousePosition.x , GexfJS.mousePosition.y , _ds.coords.actual ) : _ds.coords.actual );
_coordt = ( (GexfJS.params.useLens && GexfJS.mousePosition) ? calcCoord( GexfJS.mousePosition.x , GexfJS.mousePosition.y , _dt.coords.actual ) : _dt.coords.actual );
GexfJS.ctxGraphe.strokeStyle = ( _isLinked ? _d.color : "rgba(100,100,100,0.2)" );
traceArc(GexfJS.ctxGraphe, _coords, _coordt);
}
}
}

function hoverAC() {
$("#autocomplete li").removeClass("hover");
$("#liac_"+GexfJS.autoCompletePosition).addClass("hover");
Expand Down Expand Up @@ -814,9 +857,9 @@ $(document).ready(function() {

GexfJS.ctxGraphe = document.getElementById('carte').getContext('2d');
GexfJS.ctxMini = document.getElementById('overview').getContext('2d');
updateWorkspaceBounds();

initializeMap();
updateWorkspaceBounds(); // Hm... I don't really know why... maybe an intuition.

window.onhashchange = initializeMap;

Expand Down
2 changes: 1 addition & 1 deletion styles/gexfjs.css
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ h1 a {
/* ZOOM IN OUT */

#ctlzoom {
position: absolute; left: 5px; bottom: 5px; list-style: none; padding: 0; margin: 0;
position: absolute; list-style: none; padding: 0; margin: 0;
}

#ctlzoom li {
Expand Down