Skip to content

Commit 386b181

Browse files
committed
Reshaping
1 parent 8d81ce9 commit 386b181

File tree

6 files changed

+23
-34
lines changed

6 files changed

+23
-34
lines changed

examples/basic.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import Sigma from '../src/sigma';
33
import CanvasRenderer from '../src/renderers/canvas';
44

55
const graph = new Graph();
6-
graph.addNode('John');
6+
graph.addNode('John', {x: 50, y: 50, color: 'blue', size: 10});
7+
graph.addNode('Martha', {x: 100, y: 100, color: 'red', size: 10});
78

89
const renderer = new CanvasRenderer(document.getElementById('container'));
910

package.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"bugs": "http://github.com/jacomyal/sigma.js/issues",
77
"main": "dist/sigma.js",
88
"scripts": {
9-
"examples": "webpack-dev-server --config ./examples/webpack.config.js --port 8000",
9+
"examples": "webpack-dev-server --config ./examples/webpack.config.js --port 8000 --progress",
1010
"lint": "eslint examples src test",
1111
"test": "mocha --compilers js:babel-core/register ./test/endpoint.js"
1212
},
@@ -31,14 +31,19 @@
3131
"babel-loader": "^6.2.5",
3232
"babel-preset-es2015": "^6.14.0",
3333
"eslint": "^3.5.0",
34-
"graphology": "0.0.4",
34+
"graphology": "0.4.1",
3535
"html-webpack-plugin": "^2.22.0",
3636
"mocha": "^3.0.2",
3737
"webpack": "^1.13.2",
3838
"webpack-dev-server": "^1.15.1"
3939
},
4040
"keywords": [
41-
"graph"
41+
"graph",
42+
"graphology",
43+
"renderer",
44+
"canvas",
45+
"webgl",
46+
"svg"
4247
],
4348
"babel": {
4449
"presets": [
@@ -47,5 +52,8 @@
4752
},
4853
"eslintConfig": {
4954
"extends": "@yomguithereal/eslint-config/es6"
55+
},
56+
"dependencies": {
57+
"graphology-utils": "^1.1.1"
5058
}
5159
}

src/reducers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@
1515
*/
1616
export function internalNodeReducer(controller, graph, node) {
1717
return {
18-
x: 50,
19-
y: 50,
20-
size: 15,
21-
color: 'red'
18+
x: graph.getNodeAttribute(node, 'x') || 1,
19+
y: graph.getNodeAttribute(node, 'y') || 1,
20+
size: graph.getNodeAttribute(node, 'size') || 1,
21+
color: graph.getNodeAttribute(node, 'color') || 'black'
2222
};
2323
}

src/renderers/canvas/index.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,9 @@ export default class CanvasRenderer extends Renderer {
4444
* @return {CanvasRenderer} - Returns itself for chaining.
4545
*/
4646
initialize(graph) {
47-
const map = graph.map;
4847

49-
this.map = map;
50-
this.nodesIndex = map ? new Map() : {};
51-
this.edgesIndex = map ? new Map() : {};
48+
this.nodesIndex = Object.create(null);
49+
this.edgesIndex = Object.create(null);
5250

5351
return this;
5452
}
@@ -63,10 +61,7 @@ export default class CanvasRenderer extends Renderer {
6361
updateNodeDisplayInformation(node, data) {
6462

6563
// TODO: for now, this is only saving raw
66-
if (this.map)
67-
this.nodesIndex.set(node, data);
68-
else
69-
this.nodesIndex[node] = data;
64+
this.nodesIndex[node] = data;
7065

7166
return this;
7267
}
@@ -79,7 +74,6 @@ export default class CanvasRenderer extends Renderer {
7974
render() {
8075

8176
// Rendering nodes
82-
// TODO: handle maps
8377
for (const k in this.nodesIndex) {
8478
const displayInformation = this.nodesIndex[k];
8579

src/sigma.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
* Core class holding state for the bound graph and using a combination of
66
* a renderer & camera to display the bound graph on screen.
77
*/
8+
import isGraph from 'graphology-utils/is-graph';
9+
810
import Camera from './camera';
911
import Renderer from './renderer';
1012
import {internalNodeReducer} from './reducers';
11-
import {assign, isGraph} from './utils';
13+
import {assign} from './utils';
1214

1315
// TODO: possibility to pass a camera
1416
// TODO: distinguish with events, full refresh vs. draw
@@ -38,7 +40,6 @@ export default class Sigma {
3840

3941
// Properties
4042
this.graph = graph;
41-
this.map = this.graph.map;
4243
this.camera = new Camera();
4344
this.renderer = renderer;
4445

src/utils.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,3 @@ export function assign(target, ...objects) {
2525

2626
return target;
2727
}
28-
29-
/**
30-
* Function returning whether the given value is a graphology Graph instance.
31-
*
32-
* @param {any} value - Target value.
33-
* @return {boolean}
34-
*/
35-
export function isGraph(value) {
36-
return (
37-
value &&
38-
typeof value === 'object' &&
39-
typeof value.addUndirectedEdgeWithKey === 'function' &&
40-
typeof value.dropNodes === 'function'
41-
);
42-
}

0 commit comments

Comments
 (0)