Skip to content

Commit 0c64e71

Browse files
committed
Experimenting with a new version
1 parent c9252b5 commit 0c64e71

File tree

4 files changed

+98
-1
lines changed

4 files changed

+98
-1
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"description": "A JavaScript library dedicated to graph drawing.",
55
"homepage": "http://sigmajs.org",
66
"bugs": "http://github.com/jacomyal/sigma.js/issues",
7+
"main": "dist/sigma.js",
78
"repository": {
89
"type": "git",
910
"url": "http://github.com/jacomyal/sigma.js.git"
@@ -19,8 +20,8 @@
1920
}
2021
],
2122
"license": "MIT",
22-
"main": "build/sigma.require.js",
2323
"devDependencies": {
24+
"graphology": "0.0.4",
2425
"mocha": "^3.0.2"
2526
},
2627
"keywords": [

src/camera.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/**
2+
* Sigma.js Camera Class
3+
* ======================
4+
*
5+
* Class designed to store camera information & used to update it.
6+
*/
7+
8+
/**
9+
* Camera class
10+
*
11+
* @constructor
12+
*/
13+
export default class Camera {
14+
constructor() {
15+
16+
// Properties
17+
this.x = 0;
18+
this.y = 0;
19+
this.angle = 0;
20+
this.ratio = 0;
21+
}
22+
}

src/sigma.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/**
2+
* Sigma.js Core Class
3+
* ====================
4+
*
5+
* Core class holding state for the bound graph and using a combination of
6+
* a renderer & camera to display the bound graph on screen.
7+
*/
8+
import Camera from './camera';
9+
import {isGraph} from './utils';
10+
11+
// TODO: possibility to pass a camera
12+
13+
/**
14+
* Sigma class
15+
*
16+
* @constructor
17+
* @param {Graph} graph - A graphology Graph instance.
18+
*/
19+
export default class Sigma {
20+
constructor(graph) {
21+
22+
// Checking the arguments
23+
if (!isGraph(graph))
24+
throw new Error('Sigma.constructor: given graph is not an instance of a graphology implementation.');
25+
26+
// Properties
27+
this.graph = graph;
28+
this.camera = new Camera();
29+
}
30+
31+
/**---------------------------------------------------------------------------
32+
* Getters
33+
**---------------------------------------------------------------------------
34+
*/
35+
36+
/**
37+
* Method returning the graph bound to the instance.
38+
*
39+
* @return {Graph} - The bound graph.
40+
*/
41+
getGraph() {
42+
return this.graph;
43+
}
44+
45+
/**
46+
* Method returning the instance's camera.
47+
*
48+
* @return {Camera} - The instance's graph.
49+
*/
50+
getCamera() {
51+
return this.camera;
52+
}
53+
}

src/utils.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Sigma.js Utils
3+
* ===============
4+
*
5+
* Various helper functions & classes used throughout the library.
6+
*/
7+
8+
/**
9+
* Function returning whether the given value is a graphology Graph instance.
10+
*
11+
* @param {any} value - Target value.
12+
* @return {boolean}
13+
*/
14+
export function isGraph(value) {
15+
return (
16+
value &&
17+
typeof value === 'object' &&
18+
typeof value.addUndirectedEdgeWithKey === 'function' &&
19+
typeof value.dropNodes === 'function'
20+
);
21+
}

0 commit comments

Comments
 (0)