Skip to content

Commit ebc05e1

Browse files
committed
Merge branch 'master' of https://github.com/Raibaz/sigma.js into devel
2 parents cd71892 + dd5fdcb commit ebc05e1

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

plugins/sigma.parseGexf.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ sigma.publicPrototype.parseGexf = function(gexfPath) {
131131
var source = edgeNode.getAttribute('source');
132132
var target = edgeNode.getAttribute('target');
133133
var label = edgeNode.getAttribute('label');
134+
var weight_val = parseFloat(edgeNode.getAttribute('weight'));
134135
var edge = {id:j, sourceID:source, targetID:target,label:label, attributes:[]};
135136
var attvalueNodes = edgeNode.getElementsByTagName('attvalue');
136137
for(k=0; k<attvalueNodes.length; k++){
@@ -140,7 +141,7 @@ sigma.publicPrototype.parseGexf = function(gexfPath) {
140141
edge.attributes.push({attr:attr, val:val});
141142
}
142143

143-
sigmaInstance.addEdge(edgeId++,source,target,edge);
144+
sigmaInstance.addEdge(edgeId++,source,target,edge,weight_val);
144145
}
145146
}
146147
};

src/core/graph.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ function Graph() {
223223
* of the edge.
224224
* @return {Graph} Returns itself.
225225
*/
226-
function addEdge(id, source, target, params) {
226+
function addEdge(id, source, target, params, weight) {
227227
if (self.edgesIndex[id]) {
228228
throw new Error('Edge "' + id + '" already exists.');
229229
}
@@ -238,16 +238,21 @@ function Graph() {
238238
throw new Error(s);
239239
}
240240

241+
if(!weight) {
242+
weight = 1;
243+
}
244+
241245
params = params || {};
242246
var e = {
243247
'source': self.nodesIndex[source],
244248
'target': self.nodesIndex[target],
245249
'size': 1,
246-
'weight': 1,
250+
'weight': weight,
247251
'displaySize': 0.5,
248252
'label': id.toString(),
249253
'id': id.toString(),
250-
'attr': {}
254+
'attr': {},
255+
'hidden': false
251256
};
252257

253258
e['source']['degree']++;
@@ -261,6 +266,9 @@ function Graph() {
261266
case 'source':
262267
case 'target':
263268
break;
269+
case 'hidden':
270+
e[k] = !!params[k];
271+
break;
264272
case 'size':
265273
e[k] = +params[k];
266274
break;
@@ -328,6 +336,9 @@ function Graph() {
328336
case 'target':
329337
edge[k] = self.nodesIndex[k] || edge[k];
330338
break;
339+
case 'hidden':
340+
edge[k] = !!copy[k];
341+
break;
331342
case 'color':
332343
case 'label':
333344
case 'type':

src/core/plotter.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -207,9 +207,11 @@ function Plotter(nodesCtx, edgesCtx, labelsCtx, hoverCtx, graph, w, h) {
207207
var s, t, i = 0;
208208

209209
while (i++< self.p.edgesSpeed && self.currentEdgeIndex < c) {
210-
s = graph.edges[self.currentEdgeIndex]['source'];
211-
t = graph.edges[self.currentEdgeIndex]['target'];
212-
if (s['hidden'] ||
210+
e = graph.edges[self.currentEdgeIndex];
211+
s = e['source'];
212+
t = e['target'];
213+
if (e['hidden'] ||
214+
s['hidden'] ||
213215
t['hidden'] ||
214216
(!self.isOnScreen(s) && !self.isOnScreen(t))) {
215217
self.currentEdgeIndex++;

src/core/sigmapublic.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ function SigmaPublic(sigmaInstance) {
124124
return self;
125125
};
126126

127-
this.addEdge = function(id, source, target, params) {
128-
s.graph.addEdge(id, source, target, params);
127+
this.addEdge = function(id, source, target, params, weight) {
128+
s.graph.addEdge(id, source, target, params, weight);
129129
return self;
130130
}
131131

0 commit comments

Comments
 (0)