Skip to content

Commit e8f941e

Browse files
authored
Merge pull request #14 from davidpiegza/add-grunt-and-js-lint
Add grunt and js lint
2 parents 6feb7b9 + 42eb5a1 commit e8f941e

File tree

11 files changed

+173
-113
lines changed

11 files changed

+173
-113
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.DS_Store
1+
.DS_Store
2+
node_modules

Graph.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,16 @@
2121
2222
Edges:
2323
Connects to nodes together.
24-
24+
2525
Example:
2626
edge = new Edge(node1, node2);
2727
2828
An edge can also be extended with the data attribute. E.g. set a
29-
type like "friends", different types can then be draw in differnt ways.
29+
type like "friends", different types can then be draw in differnt ways.
3030
3131
3232
Graph:
33-
33+
3434
Parameters:
3535
options = {
3636
limit: <int>, maximum number of nodes
@@ -43,7 +43,7 @@
4343
addEdge(node1, node2) - adds an edge for node1 and node2. Returns true if the
4444
edge has been added, otherwise false (e.g.) when the
4545
edge between these nodes already exist.
46-
46+
4747
reached_limit() - returns true if the limit has been reached, otherwise false
4848
4949
*/
@@ -53,11 +53,11 @@ function Graph(options) {
5353
this.nodeSet = {};
5454
this.nodes = [];
5555
this.edges = [];
56-
this.layout;
56+
this.layout = undefined;
5757
}
5858

5959
Graph.prototype.addNode = function(node) {
60-
if(this.nodeSet[node.id] == undefined && !this.reached_limit()) {
60+
if(this.nodeSet[node.id] === undefined && !this.reached_limit()) {
6161
this.nodeSet[node.id] = node;
6262
this.nodes.push(node);
6363
return true;
@@ -79,7 +79,7 @@ Graph.prototype.addEdge = function(source, target) {
7979
};
8080

8181
Graph.prototype.reached_limit = function() {
82-
if(this.options.limit != undefined)
82+
if(this.options.limit !== undefined)
8383
return this.options.limit <= this.nodes.length;
8484
else
8585
return false;

Gruntfile.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
module.exports = function(grunt) {
2+
grunt.initConfig({
3+
pkg: grunt.file.readJSON('package.json'),
4+
jshint: {
5+
all: ['Gruntfile.js', 'Graph.js', 'drawings/*.js', 'layouts/*.js', 'utils/Label.js', 'utils/ObjectSelection.js']
6+
},
7+
uglify: {
8+
options: {
9+
banner: '/*! <%= pkg.name %> <%= pkg.version %> */\n'
10+
},
11+
graphVisualization: {
12+
files: {
13+
'build/graph.min.js': ['Graph.js', 'webgl-frameworks/three.min.js', 'utils/*.js', 'layouts/*.js', 'drawings/*.js']
14+
}
15+
}
16+
}
17+
});
18+
19+
grunt.loadNpmTasks('grunt-contrib-jshint');
20+
grunt.loadNpmTasks('grunt-contrib-uglify');
21+
22+
grunt.registerTask('default', ['jshint', 'uglify']);
23+
};

README.markdown

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,26 @@
1-
Graph-Visualization
2-
===================
1+
# Graph-Visualization
32

43
This project is about 3D graph visualization with WebGL. The aim of this project is to evaluate the possibilities of graph drawing in WebGL.
54

65
This project uses Three.js for drawing and currently supports a force directed layout.
76

87

9-
### Run the example ###
8+
### Run the example
109

1110
1. Clone or download the project
1211
2. Open the index_sample.html in a WebGL-compatible browser
1312

1413
You may copy the index_sample.html to index.html and customize it.
1514

16-
Project Description
17-
-------------------
15+
## Project Description
1816

1917
The project consists of
2018

2119
- a graph structure
2220
- a graph layout implementation
2321
- and a graph drawing implementation
2422

25-
### Graph Structure ###
23+
### Graph Structure
2624

2725
This is implemented in graph-visualization/Graph.js.
2826

@@ -47,7 +45,7 @@ A node has the properties
4745

4846
For more details have a look at the [source code](https://github.com/davidpiegza/Graph-Visualization/blob/master/Graph.js).
4947

50-
### Graph Layout ###
48+
### Graph Layout
5149

5250
A graph layout has the basic structure:
5351

@@ -71,7 +69,20 @@ The graph layout may extend the nodes and edges with custom properties in the da
7169
See [force-based-layout.js](https://github.com/davidpiegza/Graph-Visualization/blob/master/layouts/force-based-layout.js) for example usage.
7270

7371

74-
Changelog
75-
-------------------
72+
## Contribution
73+
74+
This project uses [Grunt](http://gruntjs.com/) to run several tasks in development. You should have `npm` and `grunt` installed. To install `grunt` run
75+
76+
npm install -g grunt-cli
77+
78+
And to install all dependencies run
79+
80+
npm install
81+
82+
For more info check the [Grunt - Getting started guide](http://gruntjs.com/getting-started).
83+
84+
If you added some changes, run `grunt` to check the code.
85+
86+
## Changelog
7687

7788
See [releases](https://github.com/davidpiegza/Graph-Visualization/releases).

build/graph.min.js

Lines changed: 18 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

drawings/simple_graph.js

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
var Drawing = Drawing || {};
5050

5151
Drawing.SimpleGraph = function(options) {
52-
var options = options || {};
52+
options = options || {};
5353

5454
this.layout = options.layout || "2d";
5555
this.layout_options = options.graphLayout || {};
@@ -115,7 +115,7 @@ Drawing.SimpleGraph = function(options) {
115115
domElement: renderer.domElement,
116116
selected: function(obj) {
117117
// display info
118-
if(obj != null) {
118+
if(obj !== null) {
119119
info_text.select = "Object " + obj.id;
120120
} else {
121121
delete info_text.select;
@@ -163,8 +163,8 @@ Drawing.SimpleGraph = function(options) {
163163
nodes.push(node);
164164

165165
var steps = 1;
166-
while(nodes.length != 0 && steps < that.nodes_count) {
167-
var node = nodes.shift();
166+
while(nodes.length !== 0 && steps < that.nodes_count) {
167+
node = nodes.shift();
168168

169169
var numEdges = randomFromTo(1, that.edges_count);
170170
for(var i=1; i <= numEdges; i++) {
@@ -198,12 +198,13 @@ Drawing.SimpleGraph = function(options) {
198198
*/
199199
function drawNode(node) {
200200
var draw_object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: Math.random() * 0xffffff, opacity: 0.5 } ) );
201+
var label_object;
201202

202203
if(that.show_labels) {
203-
if(node.data.title != undefined) {
204-
var label_object = new THREE.Label(node.data.title);
204+
if(node.data.title !== undefined) {
205+
label_object = new THREE.Label(node.data.title);
205206
} else {
206-
var label_object = new THREE.Label(node.id);
207+
label_object = new THREE.Label(node.id);
207208
}
208209
node.data.label_object = label_object;
209210
scene.add( node.data.label_object );
@@ -259,6 +260,8 @@ Drawing.SimpleGraph = function(options) {
259260

260261

261262
function render() {
263+
var i, length, node;
264+
262265
// Generate layout if not finished
263266
if(!graph.layout.finished) {
264267
info_text.calc = "<span style='color: red'>Calculating layout...</span>";
@@ -268,37 +271,38 @@ Drawing.SimpleGraph = function(options) {
268271
}
269272

270273
// Update position of lines (edges)
271-
for(var i=0; i<geometries.length; i++) {
274+
for(i=0; i<geometries.length; i++) {
272275
geometries[i].verticesNeedUpdate = true;
273276
}
274277

275278

276279
// Show labels if set
277280
// It creates the labels when this options is set during visualization
278281
if(that.show_labels) {
279-
var length = graph.nodes.length;
280-
for(var i=0; i<length; i++) {
281-
var node = graph.nodes[i];
282-
if(node.data.label_object != undefined) {
282+
length = graph.nodes.length;
283+
for(i=0; i<length; i++) {
284+
node = graph.nodes[i];
285+
if(node.data.label_object !== undefined) {
283286
node.data.label_object.position.x = node.data.draw_object.position.x;
284287
node.data.label_object.position.y = node.data.draw_object.position.y - 100;
285288
node.data.label_object.position.z = node.data.draw_object.position.z;
286289
node.data.label_object.lookAt(camera.position);
287290
} else {
288-
if(node.data.title != undefined) {
289-
var label_object = new THREE.Label(node.data.title, node.data.draw_object);
291+
var label_object;
292+
if(node.data.title !== undefined) {
293+
label_object = new THREE.Label(node.data.title, node.data.draw_object);
290294
} else {
291-
var label_object = new THREE.Label(node.id, node.data.draw_object);
295+
label_object = new THREE.Label(node.id, node.data.draw_object);
292296
}
293297
node.data.label_object = label_object;
294298
scene.add( node.data.label_object );
295299
}
296300
}
297301
} else {
298-
var length = graph.nodes.length;
299-
for(var i=0; i<length; i++) {
300-
var node = graph.nodes[i];
301-
if(node.data.label_object != undefined) {
302+
length = graph.nodes.length;
303+
for(i=0; i<length; i++) {
304+
node = graph.nodes[i];
305+
if(node.data.label_object !== undefined) {
302306
scene.remove( node.data.label_object );
303307
node.data.label_object = undefined;
304308
}
@@ -325,7 +329,7 @@ Drawing.SimpleGraph = function(options) {
325329
function printInfo(text) {
326330
var str = '';
327331
for(var index in info_text) {
328-
if(str != '' && info_text[index] != '') {
332+
if(str !== '' && info_text[index] !== '') {
329333
str += " - ";
330334
}
331335
str += info_text[index];
@@ -341,5 +345,5 @@ Drawing.SimpleGraph = function(options) {
341345
// Stop layout calculation
342346
this.stop_calculating = function() {
343347
graph.layout.stop_calculating();
344-
}
345-
}
348+
};
349+
};

drawings/sphere_graph.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
var Drawing = Drawing || {};
5151

5252
Drawing.SphereGraph = function(options) {
53-
var options = options || {};
53+
options = options || {};
5454

5555
this.layout = options.layout || "2d";
5656
this.show_stats = options.showStats || false;
@@ -93,7 +93,7 @@ Drawing.SphereGraph = function(options) {
9393
controls.zoomSpeed = 5.2;
9494
controls.panSpeed = 1;
9595

96-
controls.noZoom = false
96+
controls.noZoom = false;
9797
controls.noPan = false;
9898

9999
controls.staticMoving = false;
@@ -120,7 +120,7 @@ Drawing.SphereGraph = function(options) {
120120
domElement: renderer.domElement,
121121
selected: function(obj) {
122122
// display info
123-
if(obj != null) {
123+
if(obj !== null) {
124124
info_text.select = "Object " + obj.id;
125125
} else {
126126
delete info_text.select;
@@ -164,8 +164,8 @@ Drawing.SphereGraph = function(options) {
164164
nodes.push(node);
165165

166166
var steps = 1;
167-
while(nodes.length != 0 && steps < that.nodes_count) {
168-
var node = nodes.shift();
167+
while(nodes.length !== 0 && steps < that.nodes_count) {
168+
node = nodes.shift();
169169

170170
var numEdges = randomFromTo(1, that.edges_count);
171171
for(var i=1; i <= numEdges; i++) {
@@ -229,7 +229,7 @@ Drawing.SphereGraph = function(options) {
229229

230230
draw_object.id = node.id;
231231
node.data.draw_object = draw_object;
232-
node.layout = {}
232+
node.layout = {};
233233
node.layout.max_X = 90;
234234
node.layout.min_X = -90;
235235
node.layout.max_Y = 180;
@@ -271,6 +271,8 @@ Drawing.SphereGraph = function(options) {
271271

272272

273273
function render() {
274+
var i;
275+
274276
// Generate layout if not finished
275277
if(!graph.layout.finished) {
276278
info_text.calc = "<span style='color: red'>Calculating layout...</span>";
@@ -280,12 +282,12 @@ Drawing.SphereGraph = function(options) {
280282
}
281283

282284
// Update position of lines (edges)
283-
for(var i=0; i<geometries.length; i++) {
285+
for(i=0; i<geometries.length; i++) {
284286
geometries[i].verticesNeedUpdate = true;
285287
}
286288

287289
// set lookat of nodes to camera
288-
for(var i=0; i<graph.nodes.length; i++) {
290+
for(i=0; i<graph.nodes.length; i++) {
289291
graph.nodes[i].data.draw_object.lookAt(camera.position);
290292
}
291293

@@ -310,7 +312,7 @@ Drawing.SphereGraph = function(options) {
310312
function printInfo(text) {
311313
var str = '';
312314
for(var index in info_text) {
313-
if(str != '' && info_text[index] != '') {
315+
if(str !== '' && info_text[index] !== '') {
314316
str += " - ";
315317
}
316318
str += info_text[index];
@@ -327,5 +329,5 @@ Drawing.SphereGraph = function(options) {
327329
// Stop layout calculation
328330
this.stop_calculating = function() {
329331
graph.layout.stop_calculating();
330-
}
331-
}
332+
};
333+
};

0 commit comments

Comments
 (0)