Skip to content

Commit

Permalink
Add edge hovering
Browse files Browse the repository at this point in the history
  • Loading branch information
BrainBuzzer committed Jan 9, 2018
1 parent f662023 commit 4732b69
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
npm-debug.log
40 changes: 39 additions & 1 deletion dist/sigma-netjson.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sigma-netjson.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"version": "0.0.2",
"description": "NetJSON Plugin for Sigma.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "gulp"
},
"repository": {
"type": "git",
Expand Down
40 changes: 39 additions & 1 deletion src/sigma.parsers.netjson.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@
source: 'n' + link.source,
target: 'n' + link.target,
size: 1,
color: '#ccc'
color: '#ccc',
hover_color: '#000',
data: {
source: link.source,
target: link.target,
cost: link.cost
}
});
});

Expand All @@ -102,9 +108,20 @@
type: 'canvas'
}

sig.settings = {
minEdgeSize: 0.5,
maxEdgeSize: 4,
enableEdgeHovering: true,
edgeHoverSizeRatio: 1,
edgeHoverExtremities: true,
}


// Initiate Sigma
sig = new sigma(sig);

sig.refresh();

// Configure the Fruchterman-Reingold algorithm:
var frListener = sigma.layouts.fruchtermanReingold.configure(sig, {
iterations: 500,
Expand Down Expand Up @@ -141,11 +158,32 @@
// Returns an HTML string:
return Mustache.render(template, node);
}
},
edge: {
show: 'overEdge',
hide: 'outEdge',
cssClass: 'sigma-tooltip',
position: 'top',
template:
'<div class="arrow"></div>' +
' <div class="sigma-tooltip-header">label</div>' +
' <div class="sigma-tooltip-body">' +
' <table>' +
' <tr><th>Source:</th> <td>{{data.source}}</td></tr>' +
' <tr><th>Target:</th> <td>{{data.target}}</td></tr>' +
' <tr><th>Cost:</th> <td>{{data.cost}}</td></tr>' +
' </table>' +
' </div>',
renderer: function(edge, template) {
// Returns an HTML string:
return Mustache.render(template, edge);
}
}
};

// Instanciate the tooltips plugin with a Mustache renderer for node tooltips:
var tooltips = sigma.plugins.tooltips(sig, sig.renderers[0], config);
sig.refresh();
} else if (typeof sig === 'function') {
callback = sig;
sig = null;
Expand Down

0 comments on commit 4732b69

Please sign in to comment.