Test Failed
Push — master ( def0c6...dd5863 )
by
unknown
06:55
created

docs/_includes/DataProjector.js   F

Complexity

Total Complexity 388
Complexity/F 2.18

Size

Lines of Code 2037
Function Count 178

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 0
dl 0
loc 2037
rs 2.4
wmc 388
mnd 4
bc 284
fnc 178
bpm 1.5955
cpm 2.1797
noi 120

How to fix   Complexity   

Complexity

Complex classes like docs/_includes/DataProjector.js often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

1
;(function(e,t,n){function i(n,s){if(!t[n]){if(!e[n]){var o=typeof require=="function"&&require;if(!s&&o)return o(n,!0);if(r)return r(n,!0);throw new Error("Cannot find module '"+n+"'")}var u=t[n]={exports:{}};e[n][0].call(u.exports,function(t){var r=e[n][1][t];return i(r?r:t)},u,u.exports)}return t[n].exports}var r=typeof require=="function"&&require;for(var s=0;s<n.length;s++)i(n[s]);return i})({1:[function(require,module,exports){
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Unused Code introduced by
The parameter module is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter exports is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
2
var DataProjector, Info, Menu, Observer, Palette, Projector, Storage, Subject, Toolbar, Utility, dataProjector,
3
  __hasProp = {}.hasOwnProperty,
4
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
5
6
Subject = require('./Subject.coffee');
0 ignored issues
show
Unused Code introduced by
The variable Subject seems to be never used. Consider removing it.
Loading history...
7
8
Observer = require('./Observer.coffee');
9
10
Utility = require('./Utility.coffee');
11
12
Palette = require('./Palette.coffee');
13
14
Storage = require('./Storage.coffee');
15
16
Toolbar = require('./Toolbar.coffee');
17
18
Menu = require('./Menu.coffee');
19
20
Info = require('./Info.coffee');
21
22
Projector = require('./Projector.coffee');
23
24
DataProjector = (function(_super) {
25
  __extends(DataProjector, _super);
26
27
  DataProjector.prototype.storage = null;
28
29
  DataProjector.prototype.toolbar = null;
30
31
  DataProjector.prototype.menu = null;
32
33
  DataProjector.prototype.info = null;
34
35
  DataProjector.prototype.projector = null;
36
37
  DataProjector.prototype.palette = null;
38
39
  DataProjector.prototype.colors = null;
40
41
  function DataProjector() {
42
    this.storage = new Storage();
43
    this.storage.attach(this);
44
    this.storage.requestData();
45
    this.toolbar = new Toolbar('#toolbar');
46
    this.toolbar.attach(this);
47
    this.menu = new Menu('#menu');
48
    this.menu.attach(this);
49
    this.info = new Info('#info');
50
    this.info.attach(this);
51
    this.projector = new Projector();
52
    this.projector.attach(this);
53
  }
54
55
  DataProjector.prototype.update = function(subject, type, data) {
56
    if (subject instanceof Storage) {
57
      this.onStorageEvent(type, data);
58
    }
59
    if (subject instanceof Toolbar) {
60
      this.onToolbarEvent(type, data);
61
    }
62
    if (subject instanceof Menu) {
63
      this.onMenuEvent(type, data);
64
    }
65
    if (subject instanceof Projector) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if subject instanceof Projector is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
66
      return this.onProjectorEvent(type, data);
67
    }
68
  };
69
70
  DataProjector.prototype.onStorageEvent = function(type, data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
71
    switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
72
      case Storage.EVENT_DATA_READY:
0 ignored issues
show
Bug introduced by
The variable Storage seems to be never declared. If this is a global, consider adding a /** global: Storage */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
73
        this.info.display("Processed " + (this.storage.getPoints()) + " points.");
74
        this.info.display("Found " + (this.storage.getClusters()) + " clusters.");
75
        return this.initialize();
76
      case Storage.EVENT_SCREENSHOT_OK:
77
        return this.info.display("Screenshot " + (this.storage.getSaved()) + " saved.");
78
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
79
  };
80
81
  DataProjector.prototype.onToolbarEvent = function(type, data) {
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
82
    var state;
83
    switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
84
      case Toolbar.EVENT_MENU:
0 ignored issues
show
Bug introduced by
The variable Toolbar seems to be never declared. If this is a global, consider adding a /** global: Toolbar */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
85
        state = this.menu.toggle();
86
        return this.toolbar.setMenuButtonSelected(state);
87
      case Toolbar.EVENT_INFO:
88
        state = this.info.toggle();
89
        return this.toolbar.setInfoButtonSelected(state);
90
      case Toolbar.EVENT_PERSPECTIVE:
91
        this.projector.setMode(Projector.VIEW.PERSPECTIVE);
92
        return this.toolbar.setCameraButtonSelected(true, false, false);
93
      case Toolbar.EVENT_ORTHOGRAPHIC:
94
        this.projector.setMode(Projector.VIEW.ORTHOGRAPHIC);
95
        return this.toolbar.setCameraButtonSelected(false, true, false);
96
      case Toolbar.EVENT_DUAL:
97
        this.projector.setMode(Projector.VIEW.DUAL);
98
        return this.toolbar.setCameraButtonSelected(false, false, true);
99
      case Toolbar.EVENT_RESET:
100
        this.projector.resetCamera(true);
101
        return this.toolbar.blinkResetButton();
102
      case Toolbar.EVENT_CLEAR:
103
        this.info.clear();
104
        return this.toolbar.blinkClearButton();
105
      case Toolbar.EVENT_BOX:
106
        state = this.projector.toggleBox();
107
        return this.toolbar.setBoxButtonSelected(state);
108
      case Toolbar.EVENT_VIEWPORT:
109
        state = this.projector.toggleViewport();
110
        return this.toolbar.setViewportButtonSelected(state);
111
      case Toolbar.EVENT_SELECT:
112
        state = this.projector.toggleSelector();
113
        return this.toolbar.setSelectButtonSelected(state);
114
      case Toolbar.EVENT_VIEW_TOP:
115
        this.projector.changeView(Utility.DIRECTION.TOP);
116
        return this.toolbar.setViewButtonSelected(true, false, false);
117
      case Toolbar.EVENT_VIEW_FRONT:
118
        this.projector.changeView(Utility.DIRECTION.FRONT);
119
        return this.toolbar.setViewButtonSelected(false, true, false);
120
      case Toolbar.EVENT_VIEW_SIDE:
121
        this.projector.changeView(Utility.DIRECTION.SIDE);
122
        return this.toolbar.setViewButtonSelected(false, false, true);
123
      case Toolbar.EVENT_SPIN_LEFT:
124
        this.projector.setSpin(Projector.SPIN.LEFT);
125
        return this.toolbar.setSpinButtonSelected(true, false, false);
126
      case Toolbar.EVENT_SPIN_STOP:
127
        this.projector.setSpin(Projector.SPIN.NONE);
128
        return this.toolbar.setSpinButtonSelected(false, true, false);
129
      case Toolbar.EVENT_SPIN_RIGHT:
130
        this.projector.setSpin(Projector.SPIN.RIGHT);
131
        return this.toolbar.setSpinButtonSelected(false, false, true);
132
      case Toolbar.EVENT_ANIMATE:
133
        state = this.projector.toggleAnimation();
134
        return this.toolbar.setAnimateButtonSelected(state);
135
      case Toolbar.EVENT_PRINT:
136
        this.storage.saveImage(this.projector.getImage());
137
        return this.toolbar.blinkPrintButton();
138
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
139
  };
140
141
  DataProjector.prototype.onMenuEvent = function(type, data) {
142
    switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
143
      case Menu.EVENT_TOGGLE_ALL_ON:
0 ignored issues
show
Bug introduced by
The variable Menu seems to be never declared. If this is a global, consider adding a /** global: Menu */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
144
        return this.projector.setAllClustersVisible(true);
145
      case Menu.EVENT_TOGGLE_ALL_OFF:
146
        return this.projector.setAllClustersVisible(false);
147
      case Menu.EVENT_TOGGLE_ID:
148
        return this.projector.toggleClusterVisibility(data.id);
149
      case Menu.EVENT_CLUSTER_ID:
150
        return this.projector.toggleClusterSelection(data.id);
151
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
152
  };
153
154
  DataProjector.prototype.onProjectorEvent = function(type, data) {
155
    console.log("DataProjector.onProjectorEvent " + type + " : " + data);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
156
    switch (type) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
157
      case Projector.EVENT_DATA_LOADED:
0 ignored issues
show
Bug introduced by
The variable Projector seems to be never declared. If this is a global, consider adding a /** global: Projector */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
158
        return console.log("DataProjector.onProjectorEvent " + type);
159
      case Projector.EVENT_POINTS_SELECTED:
160
        return this.info.display("Selected " + data.points + " points.");
161
      case Projector.EVENT_CLUSTER_SELECTED:
162
        if (data.id > -1) {
163
          return this.info.display("Cluster " + data.id + " selected");
164
        } else {
165
          return this.info.display("No cluster selected");
166
        }
167
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
168
  };
169
170
  DataProjector.prototype.initialize = function() {
171
    this.palette = new Palette(this.storage.getClusters());
172
    this.colors = this.palette.getColors();
173
    this.menu.create(this.storage.getClusters(), this.palette.getColors());
174
    this.projector.setColors(this.colors);
175
    this.projector.load(this.storage);
176
    return this.onToolbarEvent(Toolbar.EVENT_SPIN_RIGHT);
177
  };
178
179
  return DataProjector;
180
181
})(Observer);
182
183
dataProjector = new DataProjector();
0 ignored issues
show
Unused Code introduced by
The variable dataProjector seems to be never used. Consider removing it.
Loading history...
184
185
186
},{"./Info.coffee":2,"./Menu.coffee":3,"./Observer.coffee":4,"./Palette.coffee":5,"./Projector.coffee":7,"./Storage.coffee":9,"./Subject.coffee":10,"./Toolbar.coffee":11,"./Utility.coffee":12}],2:[function(require,module,exports){
187
var Info, Panel,
188
  __hasProp = {}.hasOwnProperty,
189
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
190
191
Panel = require('./Panel.coffee');
192
193
Info = (function(_super) {
194
  __extends(Info, _super);
195
196
  function Info(id) {
197
    Info.__super__.constructor.call(this, id);
198
  }
199
200
  Info.prototype.display = function(message) {
201
    return $('#message').append(message + "<br/>");
202
  };
203
204
  Info.prototype.clear = function() {
205
    return $('#message').text("");
206
  };
207
208
  return Info;
209
210
})(Panel);
211
212
module.exports = Info;
213
214
215
},{"./Panel.coffee":6}],3:[function(require,module,exports){
216
var Menu, Panel,
217
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
218
  __hasProp = {}.hasOwnProperty,
219
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
220
221
Panel = require('./Panel.coffee');
222
223
Menu = (function(_super) {
224
  __extends(Menu, _super);
225
226
  Menu.EVENT_TOGGLE_ALL_ON = "EVENT_TOGGLE_ALL_ON";
227
228
  Menu.EVENT_TOGGLE_ALL_OFF = "EVENT_TOGGLE_ALL_OFF";
229
230
  Menu.EVENT_TOGGLE_ID = "EVENT_TOGGLE_ID";
231
232
  Menu.EVENT_CLUSTER_ID = "EVENT_CLUSTER_ID";
233
234
  Menu.TOGGLE_ON = "[+]";
235
236
  Menu.TOGGLE_OFF = "[-]";
237
238
  Menu.TOGGLE_MIX = "[/]";
239
240
  Menu.prototype.clusters = 0;
241
242
  Menu.prototype.selected = -1;
243
244
  Menu.prototype.colors = null;
245
246
  function Menu(id) {
247
    this.onCluster = __bind(this.onCluster, this);
248
    this.onToggle = __bind(this.onToggle, this);
249
    this.onToggleAll = __bind(this.onToggleAll, this);
250
    Menu.__super__.constructor.call(this, id);
251
  }
252
253
  Menu.prototype.onToggleAll = function(event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
254
    var i, state, _i, _j, _ref, _ref1;
255
    state = $("#toggleAll").text();
256
    switch (state) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
257
      case Menu.TOGGLE_OFF:
0 ignored issues
show
Bug introduced by
The variable Menu seems to be never declared. If this is a global, consider adding a /** global: Menu */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
258
      case Menu.TOGGLE_MIX:
259
        $("#toggleAll").text(Menu.TOGGLE_ON);
260
        for (i = _i = 0, _ref = this.clusters; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
261
          $("#t" + String(i)).text(Menu.TOGGLE_ON);
262
        }
263
        return this.notify(Menu.EVENT_TOGGLE_ALL_ON);
264
      case Menu.TOGGLE_ON:
265
        $("#toggleAll").text(Menu.TOGGLE_OFF);
266
        for (i = _j = 0, _ref1 = this.clusters; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
267
          $("#t" + String(i)).text(Menu.TOGGLE_OFF);
268
        }
269
        return this.notify(Menu.EVENT_TOGGLE_ALL_OFF);
270
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
271
  };
272
273
  Menu.prototype.onToggle = function(event) {
274
    var id, identifier, index;
275
    identifier = event.target.id;
276
    id = identifier.replace("t", "");
277
    index = parseInt(id);
278
    this.doToggle(index);
279
    return this.notify(Menu.EVENT_TOGGLE_ID, {
280
      id: index
281
    });
282
  };
283
284
  Menu.prototype.onCluster = function(event) {
285
    var index;
286
    index = parseInt(event.target.id.replace("b", ""));
287
    if (this.selected === index) {
288
      this.selected = -1;
289
    } else {
290
      this.selected = index;
291
    }
292
    this.updateSwatches();
293
    this.updateButtons();
294
    return this.notify(Menu.EVENT_CLUSTER_ID, {
295
      id: index
296
    });
297
  };
298
299
  Menu.prototype.doToggle = function(index) {
300
    var state, tag;
301
    tag = "#t" + String(index);
302
    state = $(tag).text();
303
    switch (state) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
304
      case Menu.TOGGLE_ON:
0 ignored issues
show
Bug introduced by
The variable Menu seems to be never declared. If this is a global, consider adding a /** global: Menu */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
305
        $(tag).text(Menu.TOGGLE_OFF);
306
        break;
307
      case Menu.TOGGLE_OFF:
308
        $(tag).text(Menu.TOGGLE_ON);
309
    }
310
    return this.updateMasterToggle();
311
  };
312
313
  Menu.prototype.create = function(clusters, colors) {
314
    var html, i, _i, _j, _ref, _ref1;
315
    this.clusters = clusters;
316
    this.colors = colors;
317
    for (i = _i = 0, _ref = this.clusters; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
318
      html = "<span class='toggle' id='t" + i + "'>[+]</span><span class='button' id='b" + i + "'> Cluster</span><span class='color' id='c" + i + "'> " + i + " </span><br/>";
319
      $("#menu").append(html);
320
    }
321
    $("#toggleAll").click(this.onToggleAll);
322
    for (i = _j = 0, _ref1 = this.clusters; 0 <= _ref1 ? _j < _ref1 : _j > _ref1; i = 0 <= _ref1 ? ++_j : --_j) {
323
      $("#t" + String(i)).click(this.onToggle);
324
      $("#b" + String(i)).click(this.onCluster);
325
    }
326
    return this.updateSwatches();
327
  };
328
329
  Menu.prototype.togglesOn = function() {
330
    var i, result, state, tag, _i, _ref;
331
    result = 0;
332
    for (i = _i = 0, _ref = this.clusters; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
333
      tag = "#t" + String(i);
334
      state = $(tag).text();
335
      if (state === Menu.TOGGLE_ON) {
336
        result++;
337
      }
338
    }
339
    return result;
340
  };
341
342
  Menu.prototype.updateMasterToggle = function() {
343
    var shown;
344
    shown = this.togglesOn();
345
    switch (shown) {
346
      case 0:
347
        return $("#toggleAll").text(Menu.TOGGLE_OFF);
348
      case this.clusters:
349
        return $("#toggleAll").text(Menu.TOGGLE_ON);
350
      default:
351
        return $("#toggleAll").text(Menu.TOGGLE_MIX);
352
    }
353
  };
354
355
  Menu.prototype.updateSwatches = function() {
356
    var i, _i, _ref, _results;
357
    _results = [];
358
    for (i = _i = 0, _ref = this.clusters; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
359
      if (i === this.selected) {
360
        _results.push($("#c" + String(i)).css('color', Palette.HIGHLIGHT.getStyle()));
0 ignored issues
show
Bug introduced by
The variable Palette seems to be never declared. If this is a global, consider adding a /** global: Palette */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
361
      } else {
362
        _results.push($("#c" + String(i)).css('color', this.colors[i].getStyle()));
363
      }
364
    }
365
    return _results;
366
  };
367
368
  Menu.prototype.updateButtons = function() {
369
    var i, _i, _ref, _results;
370
    _results = [];
371
    for (i = _i = 0, _ref = this.clusters; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
372
      if (i === this.selected) {
373
        _results.push($("#b" + String(i)).css('color', Palette.HIGHLIGHT.getStyle()));
0 ignored issues
show
Bug introduced by
The variable Palette seems to be never declared. If this is a global, consider adding a /** global: Palette */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
374
      } else {
375
        _results.push($("#b" + String(i)).css('color', Palette.BUTTON.getStyle()));
376
      }
377
    }
378
    return _results;
379
  };
380
381
  return Menu;
382
383
})(Panel);
384
385
module.exports = Menu;
386
387
388
},{"./Panel.coffee":6}],4:[function(require,module,exports){
389
var Observer;
390
391
Observer = (function() {
392
  function Observer() {}
393
394
  Observer.prototype.update = function(subject, type, data) {};
0 ignored issues
show
Unused Code introduced by
The parameter data is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter type is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter subject is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
395
396
  return Observer;
397
398
})();
399
400
module.exports = Observer;
401
402
403
},{}],5:[function(require,module,exports){
404
var Palette;
405
406
Palette = (function() {
407
  Palette.BACKGROUND = new THREE.Color(0x202020);
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
408
409
  Palette.HIGHLIGHT = new THREE.Color(0xFFFFFF);
410
411
  Palette.SELECTOR = new THREE.Color(0xCC0000);
412
413
  Palette.BUTTON = new THREE.Color(0xCCCCCC);
414
415
  Palette.BUTTON_SELECTED = new THREE.Color(0xFF9C00);
416
417
  Palette.prototype.colors = null;
418
419
  function Palette(size) {
420
    this.colors = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
421
    this.generate(size);
422
  }
423
424
  Palette.prototype.generate = function(size) {
425
    var color, hue, i, lightness, saturation, step, _i, _results;
426
    hue = 0;
0 ignored issues
show
Unused Code introduced by
The assignment to variable hue seems to be never used. Consider removing it.
Loading history...
427
    saturation = 0.7;
428
    lightness = 0.45;
429
    step = 1 / size;
430
    _results = [];
431
    for (i = _i = 0; 0 <= size ? _i < size : _i > size; i = 0 <= size ? ++_i : --_i) {
432
      hue = (i + 1) * step;
433
      color = new THREE.Color();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
434
      color.setHSL(hue, saturation, lightness);
435
      _results.push(this.colors.push(color));
436
    }
437
    return _results;
438
  };
439
440
  Palette.prototype.getColors = function() {
441
    return this.colors;
442
  };
443
444
  Palette.prototype.print = function() {
445
    var c, css, hsl, hue, i, lightness, saturation, _i, _len, _ref, _results;
446
    i = 0;
447
    _ref = this.colors;
448
    _results = [];
449
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
450
      c = _ref[_i];
451
      css = c.getStyle();
452
      hsl = c.getHSL();
453
      hue = hsl.h.toFixed(1);
454
      saturation = hsl.s.toFixed(1);
455
      lightness = hsl.l.toFixed(1);
456
      _results.push(console.log(i++ + " > " + hue + " : " + saturation + " : " + lightness + " | " + css));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
457
    }
458
    return _results;
459
  };
460
461
  return Palette;
462
463
})();
464
465
module.exports = Palette;
466
467
468
},{}],6:[function(require,module,exports){
469
var Panel, Subject,
470
  __hasProp = {}.hasOwnProperty,
471
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
472
473
Subject = require('./Subject.coffee');
474
475
Panel = (function(_super) {
476
  __extends(Panel, _super);
477
478
  Panel.EVENT_PANEL_SHOWN = "EVENT_PANEL_SHOWN";
479
480
  Panel.EVENT_PANEL_HIDDEN = "EVENT_PANEL_HIDDEN";
481
482
  Panel.prototype.visible = true;
483
484
  function Panel(id) {
485
    this.id = id;
486
    Panel.__super__.constructor.call(this);
487
  }
488
489
  Panel.prototype.show = function() {
490
    $(this.id).show();
491
    this.visible = true;
492
    return this.notify(Panel.EVENT_PANEL_SHOWN);
493
  };
494
495
  Panel.prototype.hide = function() {
496
    $(this.id).hide();
497
    this.visible = false;
498
    return this.notify(Panel.EVENT_PANEL_HIDDEN);
499
  };
500
501
  Panel.prototype.toggle = function() {
502
    if (this.visible) {
503
      this.hide();
504
    } else {
505
      this.show();
506
    }
507
    return this.visible;
508
  };
509
510
  return Panel;
511
512
})(Subject);
513
514
module.exports = Panel;
515
516
517
},{"./Subject.coffee":10}],7:[function(require,module,exports){
518
var Palette, Projector, Selector, Subject, Utility,
519
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
520
  __hasProp = {}.hasOwnProperty,
521
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
0 ignored issues
show
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
522
523
Subject = require('./Subject.coffee');
524
525
Utility = require('./Utility.coffee');
526
527
Palette = require('./Palette.coffee');
528
529
Selector = require('./Selector.coffee');
530
531
Projector = (function(_super) {
532
  __extends(Projector, _super);
533
534
  Projector.EVENT_DATA_LOADED = "EVENT_DATA_LOADED";
535
536
  Projector.EVENT_POINTS_SELECTED = "EVENT_POINTS_SELECTED";
537
538
  Projector.EVENT_CLUSTER_SELECTED = "EVENT_CLUSTER_SELECTED";
539
540
  Projector.VIEW = {
541
    NONE: -1,
542
    PERSPECTIVE: 0,
543
    ORTHOGRAPHIC: 1,
544
    DUAL: 2
545
  };
546
547
  Projector.SPIN = {
548
    LEFT: -1,
549
    NONE: 0,
550
    RIGHT: +1
551
  };
552
553
  Projector.SPIN_STEP = Utility.DEGREE / 10;
554
555
  Projector.prototype.SCREEN_WIDTH = window.innerWidth;
556
557
  Projector.prototype.SCREEN_HEIGHT = window.innerHeight;
558
559
  Projector.prototype.mode = Projector.VIEW.PERSPECTIVE;
560
561
  Projector.prototype.storage = null;
562
563
  Projector.prototype.colors = null;
564
565
  Projector.prototype.scene = null;
566
567
  Projector.prototype.cameraPerspective = null;
568
569
  Projector.prototype.cameraOrthographic = null;
570
571
  Projector.prototype.renderer = null;
572
573
  Projector.prototype.mouse = new THREE.Vector3();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
574
575
  Projector.prototype.mouseStart = new THREE.Vector3();
576
577
  Projector.prototype.mouseEnd = new THREE.Vector3();
578
579
  Projector.prototype.dragging = false;
580
581
  Projector.prototype.selector = null;
582
583
  Projector.prototype.box = null;
584
585
  Projector.prototype.viewport = null;
586
587
  Projector.prototype.direction = Utility.DIRECTION.ALL;
588
589
  Projector.prototype.view1 = null;
590
591
  Projector.prototype.view2 = null;
592
593
  Projector.prototype.view3 = null;
594
595
  Projector.prototype.points = null;
596
597
  Projector.prototype.particles = null;
598
599
  Projector.prototype.clusters = null;
600
601
  Projector.prototype.selected = -1;
602
603
  Projector.prototype.controls = null;
604
605
  Projector.prototype.timeStamp = 0;
606
607
  function Projector() {
608
    this.clustersVisible = __bind(this.clustersVisible, this);
609
    this.startTimer = __bind(this.startTimer, this);
610
    this.updatePoints = __bind(this.updatePoints, this);
611
    this.toggleClusterSelection = __bind(this.toggleClusterSelection, this);
612
    this.setAllClustersVisible = __bind(this.setAllClustersVisible, this);
613
    this.toggleClusterVisibility = __bind(this.toggleClusterVisibility, this);
614
    this.getSpinStep = __bind(this.getSpinStep, this);
615
    this.spinCamera = __bind(this.spinCamera, this);
616
    this.setSpin = __bind(this.setSpin, this);
617
    this.toggleAnimation = __bind(this.toggleAnimation, this);
618
    this.changeView = __bind(this.changeView, this);
619
    this.setViewsVisible = __bind(this.setViewsVisible, this);
620
    this.updateView = __bind(this.updateView, this);
621
    this.resetCamera = __bind(this.resetCamera, this);
622
    this.updateMouse3D = __bind(this.updateMouse3D, this);
623
    this.updateSelection = __bind(this.updateSelection, this);
624
    this.render = __bind(this.render, this);
625
    this.animate = __bind(this.animate, this);
626
    this.processPoint = __bind(this.processPoint, this);
627
    this.load = __bind(this.load, this);
628
    this.createRenderingEngine = __bind(this.createRenderingEngine, this);
629
    this.createViews = __bind(this.createViews, this);
630
    this.createBox = __bind(this.createBox, this);
631
    this.createControls = __bind(this.createControls, this);
632
    this.createOrthographicCamera = __bind(this.createOrthographicCamera, this);
633
    this.createPerspectiveCamera = __bind(this.createPerspectiveCamera, this);
634
    this.addUIListeners = __bind(this.addUIListeners, this);
635
    this.getImage = __bind(this.getImage, this);
636
    this.toggleSelector = __bind(this.toggleSelector, this);
637
    this.toggleViewport = __bind(this.toggleViewport, this);
638
    this.toggleBox = __bind(this.toggleBox, this);
639
    this.setColors = __bind(this.setColors, this);
640
    this.setMode = __bind(this.setMode, this);
641
    this.onTimer = __bind(this.onTimer, this);
642
    this.onMouseUp = __bind(this.onMouseUp, this);
643
    this.onMouseMove = __bind(this.onMouseMove, this);
644
    this.onMouseDown = __bind(this.onMouseDown, this);
645
    this.onWindowResize = __bind(this.onWindowResize, this);
646
    Projector.__super__.constructor.call(this);
647
    this.addUIListeners();
648
    this.scene = new THREE.Scene();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
649
    this.createPerspectiveCamera();
650
    this.createOrthographicCamera();
651
    this.createControls();
652
    this.createBox();
653
    this.cameraPerspective.lookAt(this.box.position);
654
    this.cameraOrthographic.lookAt(this.box.position);
655
    this.createViews();
656
    this.updateView(true);
657
    this.selector = new Selector(this.box);
658
    this.createRenderingEngine();
659
    this.onWindowResize(null);
660
    this.animate();
661
  }
662
663
  Projector.prototype.onWindowResize = function(event) {
0 ignored issues
show
Unused Code introduced by
The parameter event is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
664
    this.SCREEN_WIDTH = window.innerWidth;
665
    this.SCREEN_HEIGHT = window.innerHeight;
666
    console.log("Screen " + this.SCREEN_WIDTH + " x " + this.SCREEN_HEIGHT);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
667
    if (this.renderer != null) {
668
      this.renderer.setSize(this.SCREEN_WIDTH, this.SCREEN_HEIGHT);
669
      switch (this.mode) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
670
        case Projector.VIEW.PERSPECTIVE:
0 ignored issues
show
Bug introduced by
The variable Projector seems to be never declared. If this is a global, consider adding a /** global: Projector */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
671
          this.cameraPerspective.aspect = this.SCREEN_WIDTH / this.SCREEN_HEIGHT;
672
          this.cameraPerspective.updateProjectionMatrix();
673
          break;
674
        case Projector.VIEW.ORTHOGRAPHIC:
675
          this.cameraOrthographic.left = -(this.SCREEN_WIDTH / 8);
676
          this.cameraOrthographic.right = +(this.SCREEN_WIDTH / 8);
677
          this.cameraOrthographic.top = +(this.SCREEN_HEIGHT / 8);
678
          this.cameraOrthographic.bottom = -(this.SCREEN_HEIGHT / 8);
679
          this.cameraOrthographic.updateProjectionMatrix();
680
          break;
681
        case Projector.VIEW.DUAL:
682
          this.cameraPerspective.aspect = 0.5 * this.SCREEN_WIDTH / this.SCREEN_HEIGHT;
683
          this.cameraPerspective.updateProjectionMatrix();
684
          this.cameraOrthographic.left = -(this.SCREEN_WIDTH / 10);
685
          this.cameraOrthographic.right = +(this.SCREEN_WIDTH / 10);
686
          this.cameraOrthographic.top = +(this.SCREEN_HEIGHT / 5);
687
          this.cameraOrthographic.bottom = -(this.SCREEN_HEIGHT / 5);
688
          this.cameraOrthographic.updateProjectionMatrix();
689
      }
690
    }
691
    return this.controls.handleResize();
692
  };
693
694
  Projector.prototype.onMouseDown = function(event) {
695
    if (this.mode === Projector.VIEW.DUAL) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.mode === Projector.VIEW.DUAL is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
696
      event.preventDefault();
697
      if (event.shiftKey) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if event.shiftKey is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
698
        this.dragging = true;
699
        this.updateMouse3D();
700
        this.mouseStart.copy(this.mouse);
701
        this.selector.start(this.mouseStart.clone());
702
        return event.stopPropagation();
703
      }
704
    }
705
  };
706
707
  Projector.prototype.onMouseMove = function(event) {
708
    if (this.mode === Projector.VIEW.DUAL) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.mode === Projector.VIEW.DUAL is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
709
      event.preventDefault();
710
      if (this.dragging) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.dragging is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
711
        this.updateMouse3D();
712
        this.selector.update(this.mouse);
713
        return event.stopPropagation();
714
      }
715
    }
716
  };
717
718
  Projector.prototype.onMouseUp = function(event) {
719
    if (this.mode === Projector.VIEW.DUAL) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.mode === Projector.VIEW.DUAL is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
720
      event.preventDefault();
721
      if (this.dragging) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.dragging is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
722
        this.dragging = false;
723
        this.updateMouse3D();
724
        this.mouseEnd.copy(this.mouse);
725
        this.selector.end(this.mouseEnd.clone());
726
        this.updateSelection();
727
        return event.stopPropagation();
728
      }
729
    }
730
  };
731
732
  Projector.prototype.onTimer = function(index) {
733
    this.toggleClusterVisibility(index);
734
    if (++index === this.storage.getClusters()) {
735
      index = 0;
736
    }
737
    if (this.animateOn) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if this.animateOn is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
738
      return this.startTimer(index);
739
    }
740
  };
741
742
  Projector.prototype.setMode = function(mode) {
743
    this.mode = mode;
744
    return this.onWindowResize(null);
745
  };
746
747
  Projector.prototype.setColors = function(colors) {
748
    this.colors = colors;
749
  };
750
751
  Projector.prototype.toggleBox = function() {
752
    return (this.box.visible = !this.box.visible);
753
  };
754
755
  Projector.prototype.toggleViewport = function() {
756
    return this.updateView(!this.viewport.visible);
757
  };
758
759
  Projector.prototype.toggleSelector = function() {
760
    var state;
761
    state = this.selector.toggle();
762
    this.updateSelection();
763
    return state;
764
  };
765
766
  Projector.prototype.getImage = function() {
767
    return document.getElementById("renderer").toDataURL("image/png");
768
  };
769
770
  Projector.prototype.addUIListeners = function() {
771
    window.addEventListener('resize', this.onWindowResize, false);
772
    $('#container').mousedown(this.onMouseDown);
773
    $('#container').mousemove(this.onMouseMove);
774
    return $('#container').mouseup(this.onMouseUp);
775
  };
776
777
  Projector.prototype.createPerspectiveCamera = function() {
778
    this.cameraPerspective = new THREE.PerspectiveCamera(50, 0.5 * this.SCREEN_WIDTH / this.SCREEN_HEIGHT, 150, 1000);
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
779
    this.cameraPerspective.position.set(0, 0, 550);
780
    return this.scene.add(this.cameraPerspective);
781
  };
782
783
  Projector.prototype.createOrthographicCamera = function() {
784
    this.cameraOrthographic = new THREE.OrthographicCamera(-(this.SCREEN_WIDTH / 8), +(this.SCREEN_WIDTH / 8), +(this.SCREEN_HEIGHT / 4), -(this.SCREEN_HEIGHT / 4), 250, 750);
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
785
    this.cameraOrthographic.position.set(0, 500, 0);
786
    return this.scene.add(this.cameraOrthographic);
787
  };
788
789
  Projector.prototype.createControls = function() {
790
    this.controls = new THREE.TrackballControls(this.cameraPerspective);
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
791
    this.controls.rotateSpeed = 1.0;
792
    this.controls.zoomSpeed = 1.0;
793
    this.controls.panSpeed = 0.8;
794
    this.controls.noZoom = false;
795
    this.controls.noPan = false;
796
    this.controls.staticMoving = true;
797
    this.controls.dynamicDampingFactor = 0.3;
798
    return this.controls.addEventListener('change', this.render);
799
  };
800
801
  Projector.prototype.createBox = function() {
802
    this.box = new THREE.Mesh(new THREE.CubeGeometry(200, 200, 200), new THREE.MeshBasicMaterial({
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
803
      color: 0x404040,
804
      wireframe: true
805
    }));
806
    return this.scene.add(this.box);
807
  };
808
809
  Projector.prototype.createViews = function() {
810
    var geometry1, geometry2, geometry3;
811
    this.viewport = new THREE.Object3D();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
812
    geometry1 = new THREE.Geometry();
813
    geometry1.vertices.push(new THREE.Vector3(+100, +101, +100));
814
    geometry1.vertices.push(new THREE.Vector3(-100, +101, +100));
815
    geometry1.vertices.push(new THREE.Vector3(-100, +101, -100));
816
    geometry1.vertices.push(new THREE.Vector3(+100, +101, -100));
817
    geometry1.vertices.push(new THREE.Vector3(+100, +101, +100));
818
    this.view1 = new THREE.Line(geometry1, new THREE.LineBasicMaterial(), THREE.LineStrip);
819
    geometry2 = new THREE.Geometry();
820
    geometry2.vertices.push(new THREE.Vector3(+100, +100, +101));
821
    geometry2.vertices.push(new THREE.Vector3(-100, +100, +101));
822
    geometry2.vertices.push(new THREE.Vector3(-100, -100, +101));
823
    geometry2.vertices.push(new THREE.Vector3(+100, -100, +101));
824
    geometry2.vertices.push(new THREE.Vector3(+100, +100, +101));
825
    this.view2 = new THREE.Line(geometry2, new THREE.LineBasicMaterial(), THREE.LineStrip);
826
    geometry3 = new THREE.Geometry();
827
    geometry3.vertices.push(new THREE.Vector3(+101, +100, +100));
828
    geometry3.vertices.push(new THREE.Vector3(+101, -100, +100));
829
    geometry3.vertices.push(new THREE.Vector3(+101, -100, -100));
830
    geometry3.vertices.push(new THREE.Vector3(+101, +100, -100));
831
    geometry3.vertices.push(new THREE.Vector3(+101, +100, +100));
832
    this.view3 = new THREE.Line(geometry3, new THREE.LineBasicMaterial(), THREE.LineStrip);
833
    this.viewport.add(this.view1);
834
    this.viewport.add(this.view2);
835
    this.viewport.add(this.view3);
836
    return this.box.add(this.viewport);
837
  };
838
839
  Projector.prototype.createRenderingEngine = function() {
840
    var container;
841
    this.renderer = new THREE.WebGLRenderer({
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
842
      antialias: true,
843
      preserveDrawingBuffer: true
844
    });
845
    this.renderer.setSize(this.SCREEN_WIDTH, this.SCREEN_HEIGHT);
846
    this.renderer.setClearColor(Palette.BACKGROUND.getHex(), 1);
847
    this.renderer.domElement.style.position = "relative";
848
    this.renderer.domElement.id = "renderer";
849
    this.renderer.autoClear = false;
850
    container = $('#container').get(0);
851
    return container.appendChild(this.renderer.domElement);
852
  };
853
854
  Projector.prototype.load = function(storage) {
855
    var c, clusters, data, material, p, _i, _j;
856
    this.storage = storage;
857
    data = this.storage.getData();
858
    clusters = this.storage.getClusters();
859
    this.points = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
860
    for (c = _i = 0; 0 <= clusters ? _i < clusters : _i > clusters; c = 0 <= clusters ? ++_i : --_i) {
861
      this.points[c] = new THREE.Geometry();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
862
      this.points[c].colorsNeedUpdate = true;
863
    }
864
    $.each(data.points, this.processPoint);
865
    this.particles = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
866
    for (p = _j = 0; 0 <= clusters ? _j < clusters : _j > clusters; p = 0 <= clusters ? ++_j : --_j) {
867
      material = new THREE.ParticleBasicMaterial({
868
        size: 15.0,
869
        sizeAttenuation: false,
870
        vertexColors: true
871
      });
872
      this.particles[p] = new THREE.ParticleSystem(this.points[p], material);
873
      this.box.add(this.particles[p]);
874
    }
875
    return this.notify(Projector.EVENT_DATA_LOADED);
876
  };
877
878
  Projector.prototype.processPoint = function(nodeName, nodeData) {
879
    var color, index, vertex;
880
    index = parseInt(nodeData.cid);
881
    vertex = new THREE.Vector3();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
882
    vertex.x = parseFloat(nodeData.x);
883
    vertex.y = parseFloat(nodeData.y);
884
    vertex.z = parseFloat(nodeData.z);
885
    this.points[index].vertices.push(vertex);
886
    color = this.colors[index].clone();
887
    return this.points[index].colors.push(color);
888
  };
889
890
  Projector.prototype.animate = function() {
891
    requestAnimationFrame(this.animate);
892
    this.controls.update();
893
    return this.render();
894
  };
895
896
  Projector.prototype.render = function() {
897
    this.renderer.clear();
898
    switch (this.mode) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
899
      case Projector.VIEW.PERSPECTIVE:
0 ignored issues
show
Bug introduced by
The variable Projector seems to be never declared. If this is a global, consider adding a /** global: Projector */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
900
        if (this.spin !== Projector.SPIN.NONE) {
901
          this.spinCamera();
902
        }
903
        this.cameraPerspective.lookAt(this.box.position);
904
        this.renderer.setViewport(0, 0, this.SCREEN_WIDTH, this.SCREEN_HEIGHT);
905
        return this.renderer.render(this.scene, this.cameraPerspective);
906
      case Projector.VIEW.ORTHOGRAPHIC:
907
        this.cameraOrthographic.rotation.z = 0;
908
        this.renderer.setViewport(0, 0, this.SCREEN_WIDTH, this.SCREEN_HEIGHT);
909
        return this.renderer.render(this.scene, this.cameraOrthographic);
910
      case Projector.VIEW.DUAL:
911
        if (this.spin !== Projector.SPIN.NONE) {
912
          this.spinCamera();
913
        }
914
        this.cameraPerspective.lookAt(this.box.position);
915
        this.renderer.setViewport(0, 0, this.SCREEN_WIDTH / 2, this.SCREEN_HEIGHT);
916
        this.renderer.render(this.scene, this.cameraPerspective);
917
        this.cameraOrthographic.rotation.z = 0;
918
        this.renderer.setViewport(this.SCREEN_WIDTH / 2, 0, this.SCREEN_WIDTH / 2, this.SCREEN_HEIGHT);
919
        return this.renderer.render(this.scene, this.cameraOrthographic);
920
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
921
  };
922
923
  Projector.prototype.updateSelection = function() {
924
    var all, cloud, color, counter, i, j, vertex, _i, _j, _ref;
925
    counter = 0;
926
    for (i = _i = 0, _ref = this.storage.getClusters(); 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
927
      if (this.particles[i].visible) {
928
        cloud = this.points[i];
929
        all = cloud.vertices.length;
930
        for (j = _j = 0; 0 <= all ? _j < all : _j > all; j = 0 <= all ? ++_j : --_j) {
931
          vertex = cloud.vertices[j];
932
          color = cloud.colors[j];
933
          if (this.selector.isActive() && this.selector.contains(vertex, Utility.DIRECTION.ALL)) {
934
            color.setHex(Palette.HIGHLIGHT.getHex());
935
            counter++;
936
          } else {
937
            color.setHex(this.colors[i].getHex());
938
          }
939
        }
940
        cloud.colorsNeedUpdate = true;
941
      }
942
    }
943
    return this.notify(Projector.EVENT_POINTS_SELECTED, {
944
      points: counter
945
    });
946
  };
947
948
  Projector.prototype.updateMouse3D = function() {
949
    var ratio;
950
    ratio = 100 / 250;
951
    switch (this.direction) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
952
      case Utility.DIRECTION.TOP:
0 ignored issues
show
Bug introduced by
The variable Utility seems to be never declared. If this is a global, consider adding a /** global: Utility */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
953
        this.mouse.x = (event.pageX - (3 * this.SCREEN_WIDTH / 4)) * ratio;
0 ignored issues
show
Bug introduced by
The variable event seems to be never declared. If this is a global, consider adding a /** global: event */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
954
        this.mouse.y = 100;
955
        return this.mouse.z = (event.pageY - (this.SCREEN_HEIGHT / 2)) * ratio;
956
      case Utility.DIRECTION.FRONT:
957
        this.mouse.x = (event.pageX - (3 * this.SCREEN_WIDTH / 4)) * ratio;
958
        this.mouse.y = -(event.pageY - (this.SCREEN_HEIGHT / 2)) * ratio;
959
        return this.mouse.z = 100;
960
      case Utility.DIRECTION.SIDE:
961
        this.mouse.x = 100;
962
        this.mouse.y = -(event.pageY - (this.SCREEN_HEIGHT / 2)) * ratio;
963
        return this.mouse.z = -(event.pageX - (3 * this.SCREEN_WIDTH / 4)) * ratio;
964
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
965
  };
966
967
  Projector.prototype.resetCamera = function(location) {
968
    if (location) {
969
      TweenLite.to(this.cameraPerspective.position, 1, {
0 ignored issues
show
Bug introduced by
The variable TweenLite seems to be never declared. If this is a global, consider adding a /** global: TweenLite */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
970
        x: 0,
971
        y: 0,
972
        z: 550
973
      });
974
    }
975
    TweenLite.to(this.cameraPerspective.rotation, 1, {
976
      x: 0,
977
      y: 0,
978
      z: 0
979
    });
980
    return TweenLite.to(this.cameraPerspective.up, 1, {
981
      x: 0,
982
      y: 1,
983
      z: 0
984
    });
985
  };
986
987
  Projector.prototype.updateView = function(visible) {
988
    this.viewport.visible = visible;
989
    if (this.viewport.visible) {
990
      switch (this.direction) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
991
        case Utility.DIRECTION.TOP:
0 ignored issues
show
Bug introduced by
The variable Utility seems to be never declared. If this is a global, consider adding a /** global: Utility */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
992
          this.setViewsVisible(true, false, false);
993
          this.cameraOrthographic.position.set(0, 500, 0);
994
          break;
995
        case Utility.DIRECTION.FRONT:
996
          this.setViewsVisible(false, true, false);
997
          this.cameraOrthographic.position.set(0, 0, 500);
998
          break;
999
        case Utility.DIRECTION.SIDE:
1000
          this.setViewsVisible(false, false, true);
1001
          this.cameraOrthographic.position.set(500, 0, 0);
1002
      }
1003
      this.cameraOrthographic.lookAt(this.box.position);
1004
    } else {
1005
      this.setViewsVisible(false, false, false);
1006
    }
1007
    return this.viewport.visible;
1008
  };
1009
1010
  Projector.prototype.setViewsVisible = function(top, front, side) {
1011
    this.view1.visible = top;
1012
    this.view2.visible = front;
1013
    return this.view3.visible = side;
1014
  };
1015
1016
  Projector.prototype.changeView = function(direction) {
1017
    this.direction = direction;
1018
    this.updateView(this.viewport.visible);
1019
    return this.selector.setDirection(this.direction);
1020
  };
1021
1022
  Projector.prototype.toggleAnimation = function() {
1023
    this.animateOn = !this.animateOn;
1024
    if (this.animateOn) {
1025
      this.setAllClustersVisible(false);
1026
      this.startTimer(0);
1027
    } else {
1028
      this.setAllClustersVisible(true);
1029
    }
1030
    return this.animateOn;
1031
  };
1032
1033
  Projector.prototype.setSpin = function(spin) {
1034
    this.spin = spin;
1035
    switch (this.spin) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1036
      case Projector.SPIN.LEFT:
0 ignored issues
show
Bug introduced by
The variable Projector seems to be never declared. If this is a global, consider adding a /** global: Projector */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1037
        return this.resetCamera(false);
1038
      case Projector.SPIN.NONE:
1039
        return this.timeStamp = 0;
1040
      case Projector.SPIN.RIGHT:
1041
        return this.resetCamera(false);
1042
    }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
1043
  };
1044
1045
  Projector.prototype.spinCamera = function() {
1046
    var STEP, cx, cy, radians, radius, x, y;
1047
    STEP = this.getSpinStep();
1048
    cx = this.cameraPerspective.position.x;
1049
    cy = -1 * this.cameraPerspective.position.z;
1050
    radians = Math.atan2(cy, cx);
1051
    radius = Math.sqrt(cx * cx + cy * cy);
1052
    switch (this.spin) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1053
      case Projector.SPIN.LEFT:
0 ignored issues
show
Bug introduced by
The variable Projector seems to be never declared. If this is a global, consider adding a /** global: Projector */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1054
        radians += STEP;
1055
        if (radians > Math.PI) {
1056
          radians = radians - (2 * Math.PI);
1057
        }
1058
        break;
1059
      case Projector.SPIN.RIGHT:
1060
        radians -= STEP;
1061
        if (radians < -Math.PI) {
1062
          radians = (2 * Math.PI) + radians;
1063
        }
1064
    }
1065
    x = radius * Math.cos(radians);
1066
    y = radius * Math.sin(radians);
1067
    this.cameraPerspective.position.x = x;
1068
    return this.cameraPerspective.position.z = -1 * y;
1069
  };
1070
1071
  Projector.prototype.getSpinStep = function() {
1072
    var date, delta, step, timeNow;
1073
    step = Projector.SPIN_STEP;
1074
    if (this.timeStamp !== 0) {
1075
      date = new Date();
1076
      timeNow = date.getTime();
1077
      delta = timeNow - this.timeStamp;
1078
      this.timeStamp = timeNow;
1079
      step = delta * step / 10;
1080
    }
1081
    return step;
1082
  };
1083
1084
  Projector.prototype.toggleClusterVisibility = function(index) {
1085
    return this.particles[index].visible = !this.particles[index].visible;
1086
  };
1087
1088
  Projector.prototype.setAllClustersVisible = function(visible) {
1089
    var p, _i, _len, _ref, _results;
1090
    _ref = this.particles;
1091
    _results = [];
1092
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1093
      p = _ref[_i];
1094
      _results.push(p.visible = visible);
1095
    }
1096
    return _results;
1097
  };
1098
1099
  Projector.prototype.toggleClusterSelection = function(index) {
1100
    var hexColor;
1101
    if (this.selected > -1) {
1102
      hexColor = this.colors[this.selected].getHex();
1103
      this.updatePoints(this.selected, hexColor);
1104
    }
1105
    if (this.selected === index) {
1106
      this.selected = -1;
1107
    } else {
1108
      this.selected = index;
1109
      this.updatePoints(this.selected, Palette.HIGHLIGHT.getHex());
1110
    }
1111
    if (this.selected > -1) {
1112
      return this.notify(Projector.EVENT_CLUSTER_SELECTED, {
1113
        id: index
1114
      });
1115
    } else {
1116
      return this.notify(Projector.EVENT_CLUSTER_SELECTED, {
1117
        id: -1
1118
      });
1119
    }
1120
  };
1121
1122
  Projector.prototype.updatePoints = function(index, color) {
1123
    var all, cloud, i, _i;
1124
    cloud = this.points[index];
1125
    all = cloud.vertices.length;
1126
    for (i = _i = 0; 0 <= all ? _i < all : _i > all; i = 0 <= all ? ++_i : --_i) {
1127
      cloud.colors[i].setHex(color);
1128
    }
1129
    return this.points[index].colorsNeedUpdate = true;
1130
  };
1131
1132
  Projector.prototype.startTimer = function(index) {
1133
    this.toggleClusterVisibility(index);
1134
    return window.setTimeout(this.onTimer, 2 * Utility.SECOND, index);
1135
  };
1136
1137
  Projector.prototype.clustersVisible = function() {
1138
    var cloud, result, _i, _len, _ref;
1139
    result = 0;
1140
    _ref = this.particles;
1141
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1142
      cloud = _ref[_i];
1143
      if (cloud.visible) {
1144
        result++;
1145
      }
1146
    }
1147
    return result;
1148
  };
1149
1150
  return Projector;
1151
1152
})(Subject);
1153
1154
module.exports = Projector;
1155
1156
1157
},{"./Palette.coffee":5,"./Selector.coffee":8,"./Subject.coffee":10,"./Utility.coffee":12}],8:[function(require,module,exports){
1158
var Palette, Selector, Utility,
1159
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
1160
1161
Utility = require('./Utility.coffee');
1162
1163
Palette = require('./Palette.coffee');
1164
1165
Selector = (function() {
1166
  Selector.prototype.active = false;
1167
1168
  Selector.prototype.direction = Utility.DIRECTION.TOP;
1169
1170
  Selector.prototype.selectorTop = null;
1171
1172
  Selector.prototype.selectorFront = null;
1173
1174
  Selector.prototype.selectorSide = null;
1175
1176
  Selector.prototype.mouseStart = null;
1177
1178
  Selector.prototype.mouse = null;
1179
1180
  Selector.prototype.mouseEnd = null;
1181
1182
  Selector.prototype.min = null;
1183
1184
  Selector.prototype.max = null;
1185
1186
  function Selector(parent) {
1187
    this.toggle = __bind(this.toggle, this);
1188
    this.isActive = __bind(this.isActive, this);
1189
    this.mouseStart = new THREE.Vector3();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1190
    this.mouse = new THREE.Vector3();
1191
    this.mouseEnd = new THREE.Vector3();
1192
    this.min = new THREE.Vector3();
1193
    this.max = new THREE.Vector3();
1194
    this.selectorTop = this.createSelector(Utility.DIRECTION.TOP);
1195
    parent.add(this.selectorTop);
1196
    this.selectorFront = this.createSelector(Utility.DIRECTION.FRONT);
1197
    parent.add(this.selectorFront);
1198
    this.selectorSide = this.createSelector(Utility.DIRECTION.SIDE);
1199
    parent.add(this.selectorSide);
1200
    this.setActive(false);
1201
  }
1202
1203
  Selector.prototype.setActive = function(active) {
1204
    this.active = active;
1205
    this.selectorTop.visible = this.active;
1206
    this.selectorFront.visible = this.active;
1207
    this.selectorSide.visible = this.active;
1208
    return this.active;
1209
  };
1210
1211
  Selector.prototype.setDirection = function(direction) {
1212
    this.direction = direction;
1213
    return console.log("Selector.setDirection " + this.direction);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
1214
  };
1215
1216
  Selector.prototype.isActive = function() {
1217
    return this.active;
1218
  };
1219
1220
  Selector.prototype.toggle = function() {
1221
    return this.setActive(!this.active);
1222
  };
1223
1224
  Selector.prototype.start = function(mouse) {
1225
    this.mouse = mouse;
1226
    this.setActive(true);
1227
    if (!this.contains(mouse, this.direction)) {
1228
      return this.mouseStart = mouse;
1229
    } else {
1230
      switch (this.direction) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1231
        case Utility.DIRECTION.TOP:
0 ignored issues
show
Bug introduced by
The variable Utility seems to be never declared. If this is a global, consider adding a /** global: Utility */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1232
          return this.mouseStart = this.getStart(mouse, this.selectorTop);
1233
        case Utility.DIRECTION.FRONT:
1234
          return this.mouseStart = this.getStart(mouse, this.selectorFront);
1235
        case Utility.DIRECTION.SIDE:
1236
          return this.mouseStart = this.getStart(mouse, this.selectorSide);
1237
      }
0 ignored issues
show
Comprehensibility introduced by
There is no default case in this switch, so nothing gets returned when all cases fail. You might want to consider adding a default or return undefined explicitly.
Loading history...
1238
    }
1239
  };
1240
1241
  Selector.prototype.getStart = function(mouse, selector) {
1242
    var distanceTo0, distanceTo1, distanceTo2, distanceTo3, shortest, start;
1243
    distanceTo0 = mouse.distanceTo(selector.geometry.vertices[0]);
1244
    distanceTo1 = mouse.distanceTo(selector.geometry.vertices[1]);
1245
    distanceTo2 = mouse.distanceTo(selector.geometry.vertices[2]);
1246
    distanceTo3 = mouse.distanceTo(selector.geometry.vertices[3]);
1247
    shortest = Math.min(distanceTo0, distanceTo1, distanceTo2, distanceTo3);
1248
    if (shortest === distanceTo0) {
1249
      start = selector.geometry.vertices[2].clone();
1250
    }
1251
    if (shortest === distanceTo1) {
1252
      start = selector.geometry.vertices[3].clone();
1253
    }
1254
    if (shortest === distanceTo2) {
1255
      start = selector.geometry.vertices[0].clone();
1256
    }
1257
    if (shortest === distanceTo3) {
1258
      start = selector.geometry.vertices[1].clone();
1259
    }
1260
    return start;
0 ignored issues
show
Bug introduced by
The variable start does not seem to be initialized in case shortest === distanceTo0 on line 1248 is false. Are you sure this can never be the case?
Loading history...
1261
  };
1262
1263
  Selector.prototype.update = function(mouse) {
1264
    this.mouse = mouse;
1265
    switch (this.direction) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1266
      case Utility.DIRECTION.TOP:
0 ignored issues
show
Bug introduced by
The variable Utility seems to be never declared. If this is a global, consider adding a /** global: Utility */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1267
        this.selectorTop.geometry.vertices[0].x = this.mouseStart.x;
1268
        this.selectorTop.geometry.vertices[0].y = 100;
1269
        this.selectorTop.geometry.vertices[0].z = this.mouseStart.z;
1270
        this.selectorTop.geometry.vertices[1].x = this.mouse.x;
1271
        this.selectorTop.geometry.vertices[1].y = 100;
1272
        this.selectorTop.geometry.vertices[1].z = this.mouseStart.z;
1273
        this.selectorTop.geometry.vertices[2].x = this.mouse.x;
1274
        this.selectorTop.geometry.vertices[2].y = 100;
1275
        this.selectorTop.geometry.vertices[2].z = this.mouse.z;
1276
        this.selectorTop.geometry.vertices[3].x = this.mouseStart.x;
1277
        this.selectorTop.geometry.vertices[3].y = 100;
1278
        this.selectorTop.geometry.vertices[3].z = this.mouse.z;
1279
        this.selectorTop.geometry.vertices[4].x = this.mouseStart.x;
1280
        this.selectorTop.geometry.vertices[4].y = 100;
1281
        this.selectorTop.geometry.vertices[4].z = this.mouseStart.z;
1282
        this.selectorFront.geometry.vertices[0].x = this.mouseStart.x;
1283
        this.selectorFront.geometry.vertices[0].z = 100;
1284
        this.selectorFront.geometry.vertices[1].x = this.mouse.x;
1285
        this.selectorFront.geometry.vertices[1].z = 100;
1286
        this.selectorFront.geometry.vertices[2].x = this.mouse.x;
1287
        this.selectorFront.geometry.vertices[2].z = 100;
1288
        this.selectorFront.geometry.vertices[3].x = this.mouseStart.x;
1289
        this.selectorFront.geometry.vertices[3].z = 100;
1290
        this.selectorFront.geometry.vertices[4].x = this.mouseStart.x;
1291
        this.selectorFront.geometry.vertices[4].z = 100;
1292
        this.selectorSide.geometry.vertices[0].x = 100;
1293
        this.selectorSide.geometry.vertices[0].z = this.mouseStart.z;
1294
        this.selectorSide.geometry.vertices[1].x = 100;
1295
        this.selectorSide.geometry.vertices[1].z = this.mouseStart.z;
1296
        this.selectorSide.geometry.vertices[2].x = 100;
1297
        this.selectorSide.geometry.vertices[2].z = this.mouse.z;
1298
        this.selectorSide.geometry.vertices[3].x = 100;
1299
        this.selectorSide.geometry.vertices[3].z = this.mouse.z;
1300
        this.selectorSide.geometry.vertices[4].x = 100;
1301
        this.selectorSide.geometry.vertices[4].z = this.mouseStart.z;
1302
        break;
1303
      case Utility.DIRECTION.FRONT:
1304
        this.selectorFront.geometry.vertices[0].x = this.mouseStart.x;
1305
        this.selectorFront.geometry.vertices[0].y = this.mouseStart.y;
1306
        this.selectorFront.geometry.vertices[0].z = 100;
1307
        this.selectorFront.geometry.vertices[1].x = this.mouse.x;
1308
        this.selectorFront.geometry.vertices[1].y = this.mouseStart.y;
1309
        this.selectorFront.geometry.vertices[1].z = 100;
1310
        this.selectorFront.geometry.vertices[2].x = this.mouse.x;
1311
        this.selectorFront.geometry.vertices[2].y = this.mouse.y;
1312
        this.selectorFront.geometry.vertices[2].z = 100;
1313
        this.selectorFront.geometry.vertices[3].x = this.mouseStart.x;
1314
        this.selectorFront.geometry.vertices[3].y = this.mouse.y;
1315
        this.selectorFront.geometry.vertices[3].z = 100;
1316
        this.selectorFront.geometry.vertices[4].x = this.mouseStart.x;
1317
        this.selectorFront.geometry.vertices[4].y = this.mouseStart.y;
1318
        this.selectorFront.geometry.vertices[4].z = 100;
1319
        this.selectorTop.geometry.vertices[0].x = this.mouseStart.x;
1320
        this.selectorTop.geometry.vertices[0].y = 100;
1321
        this.selectorTop.geometry.vertices[1].x = this.mouse.x;
1322
        this.selectorTop.geometry.vertices[1].y = 100;
1323
        this.selectorTop.geometry.vertices[2].x = this.mouse.x;
1324
        this.selectorTop.geometry.vertices[2].y = 100;
1325
        this.selectorTop.geometry.vertices[3].x = this.mouseStart.x;
1326
        this.selectorTop.geometry.vertices[3].y = 100;
1327
        this.selectorTop.geometry.vertices[4].x = this.mouseStart.x;
1328
        this.selectorTop.geometry.vertices[4].y = 100;
1329
        this.selectorSide.geometry.vertices[0].x = 100;
1330
        this.selectorSide.geometry.vertices[0].y = this.mouseStart.y;
1331
        this.selectorSide.geometry.vertices[1].x = 100;
1332
        this.selectorSide.geometry.vertices[1].y = this.mouse.y;
1333
        this.selectorSide.geometry.vertices[2].x = 100;
1334
        this.selectorSide.geometry.vertices[2].y = this.mouse.y;
1335
        this.selectorSide.geometry.vertices[3].x = 100;
1336
        this.selectorSide.geometry.vertices[3].y = this.mouseStart.y;
1337
        this.selectorSide.geometry.vertices[4].x = 100;
1338
        this.selectorSide.geometry.vertices[4].y = this.mouseStart.y;
1339
        break;
1340
      case Utility.DIRECTION.SIDE:
1341
        this.selectorSide.geometry.vertices[0].x = 100;
1342
        this.selectorSide.geometry.vertices[0].y = this.mouseStart.y;
1343
        this.selectorSide.geometry.vertices[0].z = this.mouseStart.z;
1344
        this.selectorSide.geometry.vertices[1].x = 100;
1345
        this.selectorSide.geometry.vertices[1].y = this.mouse.y;
1346
        this.selectorSide.geometry.vertices[1].z = this.mouseStart.z;
1347
        this.selectorSide.geometry.vertices[2].x = 100;
1348
        this.selectorSide.geometry.vertices[2].y = this.mouse.y;
1349
        this.selectorSide.geometry.vertices[2].z = this.mouse.z;
1350
        this.selectorSide.geometry.vertices[3].x = 100;
1351
        this.selectorSide.geometry.vertices[3].y = this.mouseStart.y;
1352
        this.selectorSide.geometry.vertices[3].z = this.mouse.z;
1353
        this.selectorSide.geometry.vertices[4].x = 100;
1354
        this.selectorSide.geometry.vertices[4].y = this.mouseStart.y;
1355
        this.selectorSide.geometry.vertices[4].z = this.mouseStart.z;
1356
        this.selectorTop.geometry.vertices[0].y = 100;
1357
        this.selectorTop.geometry.vertices[0].z = this.mouseStart.z;
1358
        this.selectorTop.geometry.vertices[1].y = 100;
1359
        this.selectorTop.geometry.vertices[1].z = this.mouseStart.z;
1360
        this.selectorTop.geometry.vertices[2].y = 100;
1361
        this.selectorTop.geometry.vertices[2].z = this.mouse.z;
1362
        this.selectorTop.geometry.vertices[3].y = 100;
1363
        this.selectorTop.geometry.vertices[3].z = this.mouse.z;
1364
        this.selectorTop.geometry.vertices[4].y = 100;
1365
        this.selectorTop.geometry.vertices[4].z = this.mouseStart.z;
1366
        this.selectorFront.geometry.vertices[0].y = this.mouseStart.y;
1367
        this.selectorFront.geometry.vertices[0].z = 100;
1368
        this.selectorFront.geometry.vertices[1].y = this.mouseStart.y;
1369
        this.selectorFront.geometry.vertices[1].z = 100;
1370
        this.selectorFront.geometry.vertices[2].y = this.mouse.y;
1371
        this.selectorFront.geometry.vertices[2].z = 100;
1372
        this.selectorFront.geometry.vertices[3].y = this.mouse.y;
1373
        this.selectorFront.geometry.vertices[3].z = 100;
1374
        this.selectorFront.geometry.vertices[4].y = this.mouseStart.y;
1375
        this.selectorFront.geometry.vertices[4].z = 100;
1376
    }
1377
    this.selectorTop.geometry.verticesNeedUpdate = true;
1378
    this.selectorFront.geometry.verticesNeedUpdate = true;
1379
    return this.selectorSide.geometry.verticesNeedUpdate = true;
1380
  };
1381
1382
  Selector.prototype.end = function(mouseEnd) {
1383
    this.mouseEnd = mouseEnd;
1384
    return this.updateBounds();
1385
  };
1386
1387
  Selector.prototype.updateBounds = function() {
1388
    this.min.x = Math.min(this.getMinX(this.selectorTop), this.getMinX(this.selectorFront));
1389
    this.max.x = Math.max(this.getMaxX(this.selectorTop), this.getMaxX(this.selectorFront));
1390
    this.min.y = Math.min(this.getMinY(this.selectorFront), this.getMinY(this.selectorSide));
1391
    this.max.y = Math.max(this.getMaxY(this.selectorFront), this.getMaxY(this.selectorSide));
1392
    this.min.z = Math.min(this.getMinZ(this.selectorTop), this.getMinZ(this.selectorSide));
1393
    return this.max.z = Math.max(this.getMaxZ(this.selectorTop), this.getMaxZ(this.selectorSide));
1394
  };
1395
1396
  Selector.prototype.contains = function(point, direction) {
1397
    var inside;
1398
    inside = true;
1399
    switch (direction) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1400
      case Utility.DIRECTION.ALL:
0 ignored issues
show
Bug introduced by
The variable Utility seems to be never declared. If this is a global, consider adding a /** global: Utility */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1401
        if (point.x < this.min.x || point.x > this.max.x) {
1402
          inside = false;
1403
        }
1404
        if (point.y < this.min.y || point.y > this.max.y) {
1405
          inside = false;
1406
        }
1407
        if (point.z < this.min.z || point.z > this.max.z) {
1408
          inside = false;
1409
        }
1410
        break;
1411
      case Utility.DIRECTION.TOP:
1412
        if (point.x < this.min.x || point.x > this.max.x) {
1413
          inside = false;
1414
        }
1415
        if (point.z < this.min.z || point.z > this.max.z) {
1416
          inside = false;
1417
        }
1418
        break;
1419
      case Utility.DIRECTION.FRONT:
1420
        if (point.x < this.min.x || point.x > this.max.x) {
1421
          inside = false;
1422
        }
1423
        if (point.y < this.min.y || point.y > this.max.y) {
1424
          inside = false;
1425
        }
1426
        break;
1427
      case Utility.DIRECTION.SIDE:
1428
        if (point.z < this.min.z || point.z > this.max.z) {
1429
          inside = false;
1430
        }
1431
        if (point.y < this.min.y || point.y > this.max.y) {
1432
          inside = false;
1433
        }
1434
    }
1435
    return inside;
1436
  };
1437
1438
  Selector.prototype.getMinX = function(selector) {
1439
    var i, minX, vertices, _i;
1440
    vertices = selector.geometry.vertices;
1441
    minX = vertices[0].x;
1442
    for (i = _i = 1; _i <= 4; i = ++_i) {
1443
      if (vertices[i].x < minX) {
1444
        minX = vertices[i].x;
1445
      }
1446
    }
1447
    return minX;
1448
  };
1449
1450
  Selector.prototype.getMaxX = function(selector) {
1451
    var i, maxX, vertices, _i;
1452
    vertices = selector.geometry.vertices;
1453
    maxX = vertices[0].x;
1454
    for (i = _i = 1; _i <= 4; i = ++_i) {
1455
      if (vertices[i].x > maxX) {
1456
        maxX = vertices[i].x;
1457
      }
1458
    }
1459
    return maxX;
1460
  };
1461
1462
  Selector.prototype.getMinY = function(selector) {
1463
    var i, minY, vertices, _i;
1464
    vertices = selector.geometry.vertices;
1465
    minY = vertices[0].y;
1466
    for (i = _i = 1; _i <= 4; i = ++_i) {
1467
      if (vertices[i].y < minY) {
1468
        minY = vertices[i].y;
1469
      }
1470
    }
1471
    return minY;
1472
  };
1473
1474
  Selector.prototype.getMaxY = function(selector) {
1475
    var i, maxY, vertices, _i;
1476
    vertices = selector.geometry.vertices;
1477
    maxY = vertices[0].y;
1478
    for (i = _i = 1; _i <= 4; i = ++_i) {
1479
      if (vertices[i].y > maxY) {
1480
        maxY = vertices[i].y;
1481
      }
1482
    }
1483
    return maxY;
1484
  };
1485
1486
  Selector.prototype.getMinZ = function(selector) {
1487
    var i, minZ, vertices, _i;
1488
    vertices = selector.geometry.vertices;
1489
    minZ = vertices[0].z;
1490
    for (i = _i = 1; _i <= 4; i = ++_i) {
1491
      if (vertices[i].z < minZ) {
1492
        minZ = vertices[i].z;
1493
      }
1494
    }
1495
    return minZ;
1496
  };
1497
1498
  Selector.prototype.getMaxZ = function(selector) {
1499
    var i, maxZ, vertices, _i;
1500
    vertices = selector.geometry.vertices;
1501
    maxZ = vertices[0].z;
1502
    for (i = _i = 1; _i <= 4; i = ++_i) {
1503
      if (vertices[i].z > maxZ) {
1504
        maxZ = vertices[i].z;
1505
      }
1506
    }
1507
    return maxZ;
1508
  };
1509
1510
  Selector.prototype.createSelector = function(direction) {
1511
    var SIZE, geometry, selector;
1512
    SIZE = 100;
1513
    geometry = new THREE.Geometry();
0 ignored issues
show
Bug introduced by
The variable THREE seems to be never declared. If this is a global, consider adding a /** global: THREE */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1514
    switch (direction) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, switch statements should have a default case.
Loading history...
1515
      case Utility.DIRECTION.TOP:
0 ignored issues
show
Bug introduced by
The variable Utility seems to be never declared. If this is a global, consider adding a /** global: Utility */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
1516
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, +SIZE));
1517
        geometry.vertices.push(new THREE.Vector3(-SIZE, +SIZE, +SIZE));
1518
        geometry.vertices.push(new THREE.Vector3(-SIZE, +SIZE, -SIZE));
1519
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, -SIZE));
1520
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, +SIZE));
1521
        break;
1522
      case Utility.DIRECTION.FRONT:
1523
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, +SIZE));
1524
        geometry.vertices.push(new THREE.Vector3(-SIZE, +SIZE, +SIZE));
1525
        geometry.vertices.push(new THREE.Vector3(-SIZE, -SIZE, +SIZE));
1526
        geometry.vertices.push(new THREE.Vector3(+SIZE, -SIZE, +SIZE));
1527
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, +SIZE));
1528
        break;
1529
      case Utility.DIRECTION.SIDE:
1530
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, +SIZE));
1531
        geometry.vertices.push(new THREE.Vector3(+SIZE, -SIZE, +SIZE));
1532
        geometry.vertices.push(new THREE.Vector3(+SIZE, -SIZE, -SIZE));
1533
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, -SIZE));
1534
        geometry.vertices.push(new THREE.Vector3(+SIZE, +SIZE, +SIZE));
1535
    }
1536
    return selector = new THREE.Line(geometry, new THREE.LineBasicMaterial({
0 ignored issues
show
Comprehensibility introduced by
Are you sure you want to assign to selector here, or did you intend to make a comparison like selector === new THREE.L...())}), THREE.LineStrip)?
Loading history...
Unused Code introduced by
The variable selector seems to be never used. Consider removing it.
Loading history...
1537
      color: Palette.SELECTOR.getHex()
1538
    }), THREE.LineStrip);
1539
  };
1540
1541
  return Selector;
1542
1543
})();
1544
1545
module.exports = Selector;
1546
1547
1548
},{"./Palette.coffee":5,"./Utility.coffee":12}],9:[function(require,module,exports){
1549
var Storage, Subject,
1550
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
1551
  __hasProp = {}.hasOwnProperty,
1552
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
1553
  __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
1554
1555
Subject = require('./Subject.coffee');
1556
1557
Storage = (function(_super) {
1558
  __extends(Storage, _super);
1559
1560
  Storage.EVENT_DATAFILE_READY = "EVENT_DATAFILE_READY";
1561
1562
  Storage.EVENT_JSON_READY = "EVENT_JSON_READY";
1563
1564
  Storage.EVENT_DATA_READY = "EVENT_DATA_READY";
1565
1566
  Storage.EVENT_SCREENSHOT_OK = "EVENT_SCREENSHOT_OK";
1567
1568
  Storage.prototype.datafile = null;
1569
1570
  Storage.prototype.data = null;
1571
1572
  Storage.prototype.points = 0;
1573
1574
  Storage.prototype.clusterIDs = null;
1575
1576
  Storage.prototype.clusters = 0;
1577
1578
  Storage.prototype.saved = 0;
1579
1580
  function Storage() {
1581
    this.processPoint = __bind(this.processPoint, this);
1582
    this.onSaveResponse = __bind(this.onSaveResponse, this);
1583
    this.onJSON = __bind(this.onJSON, this);
1584
    this.onDatafile = __bind(this.onDatafile, this);
1585
    Storage.__super__.constructor.call(this);
1586
    this.clusterIDs = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
1587
  }
1588
1589
  Storage.prototype.onDatafile = function(datafile) {
1590
    this.datafile = datafile;
1591
    this.notify(Storage.EVENT_DATAFILE_READY);
1592
    return this.requestJSON(this.datafile);
1593
  };
1594
1595
  Storage.prototype.onJSON = function(data) {
1596
    this.data = data;
1597
    this.notify(Storage.EVENT_JSON_READY);
1598
    $.each(this.data.points, this.processPoint);
1599
    return this.notify(Storage.EVENT_DATA_READY);
1600
  };
1601
1602
  Storage.prototype.onSaveResponse = function(message) {
1603
    console.log("DataProjector.onSaveResponse " + message);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
1604
    return this.notify(Storage.EVENT_SCREENSHOT_OK);
1605
  };
1606
1607
  Storage.prototype.requestData = function() {
1608
    return this.requestDatafile();
1609
  };
1610
1611
  Storage.prototype.requestDatafile = function() {
1612
    return this.onDatafile("{{ page.dataset | prepend: site.baseurl }}");
1613
  };
1614
1615
  Storage.prototype.requestJSON = function(datafile) {
1616
    var file;
1617
    this.datafile = datafile;
1618
    file = this.datafile + "?" + String(Math.round(Math.random() * 99999));
1619
    return $.getJSON(file, this.onJSON);
1620
  };
1621
1622
  Storage.prototype.saveImage = function(base64Image) {
1623
    return $.post('/upload', {
1624
      id: ++this.saved,
1625
      image: base64Image
1626
    }, this.onSaveResponse);
1627
  };
1628
1629
  Storage.prototype.processPoint = function(nodeName, nodeData) {
1630
    var _ref;
1631
    if (_ref = nodeData.cid, __indexOf.call(this.clusterIDs, _ref) < 0) {
0 ignored issues
show
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
1632
      this.clusterIDs.push(nodeData.cid);
1633
      this.clusters = this.clusterIDs.length;
1634
    }
1635
    return this.points++;
1636
  };
1637
1638
  Storage.prototype.getDatafile = function() {
1639
    return this.datafile;
1640
  };
1641
1642
  Storage.prototype.getData = function() {
1643
    return this.data;
1644
  };
1645
1646
  Storage.prototype.getClusters = function() {
1647
    return this.clusters;
1648
  };
1649
1650
  Storage.prototype.getPoints = function() {
1651
    return this.points;
1652
  };
1653
1654
  Storage.prototype.getSaved = function() {
1655
    return this.saved;
1656
  };
1657
1658
  return Storage;
1659
1660
})(Subject);
1661
1662
module.exports = Storage;
1663
1664
1665
},{"./Subject.coffee":10}],10:[function(require,module,exports){
1666
var Subject;
1667
1668
Subject = (function() {
1669
  Subject.prototype.observers = null;
1670
1671
  function Subject() {
1672
    this.observers = new Array();
0 ignored issues
show
Coding Style Best Practice introduced by
Using the Array constructor is generally discouraged. Consider using an array literal instead.
Loading history...
1673
  }
1674
1675
  Subject.prototype.attach = function(o) {
1676
    return this.observers.push(o);
1677
  };
1678
1679
  Subject.prototype.detach = function(o) {
1680
    var index;
1681
    index = this.observers.indexOf(o);
1682
    if (index >= 0) {
0 ignored issues
show
Complexity Best Practice introduced by
There is no return statement if index >= 0 is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
1683
      return this.observers.splice(index, 1);
1684
    }
1685
  };
1686
1687
  Subject.prototype.notify = function(type, data) {
1688
    var o, _i, _len, _ref, _results;
1689
    if (data == null) {
1690
      data = null;
1691
    }
1692
    _ref = this.observers;
1693
    _results = [];
1694
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1695
      o = _ref[_i];
1696
      _results.push(o.update(this, type, data));
1697
    }
1698
    return _results;
1699
  };
1700
1701
  return Subject;
1702
1703
})();
1704
1705
module.exports = Subject;
1706
1707
1708
},{}],11:[function(require,module,exports){
1709
var Palette, Panel, Toolbar, Utility,
1710
  __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; },
1711
  __hasProp = {}.hasOwnProperty,
1712
  __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
Coding Style Best Practice introduced by
By convention, constructors like ctor should be capitalized.
Loading history...
1713
1714
Utility = require('./Utility.coffee');
1715
1716
Panel = require('./Panel.coffee');
1717
1718
Palette = require('./Palette.coffee');
1719
1720
Toolbar = (function(_super) {
1721
  __extends(Toolbar, _super);
1722
1723
  Toolbar.EVENT_MENU = "EVENT_MENU";
1724
1725
  Toolbar.EVENT_INFO = "EVENT_INFO";
1726
1727
  Toolbar.EVENT_PERSPECTIVE = "EVENT_PERSPECTIVE";
1728
1729
  Toolbar.EVENT_ORTHOGRAPHIC = "EVENT_ORTHOGRAPHIC";
1730
1731
  Toolbar.EVENT_DUAL = "EVENT_DUAL";
1732
1733
  Toolbar.EVENT_RESET = "EVENT_RESET";
1734
1735
  Toolbar.EVENT_CLEAR = "EVENT_CLEAR";
1736
1737
  Toolbar.EVENT_BOX = "EVENT_BOX";
1738
1739
  Toolbar.EVENT_VIEWPORT = "EVENT_VIEWPORT";
1740
1741
  Toolbar.EVENT_SELECT = "EVENT_SELECT";
1742
1743
  Toolbar.EVENT_VIEW_TOP = "EVENT_VIEW_TOP";
1744
1745
  Toolbar.EVENT_VIEW_FRONT = "EVENT_VIEW_FRONT";
1746
1747
  Toolbar.EVENT_VIEW_SIDE = "EVENT_VIEW_SIDE";
1748
1749
  Toolbar.EVENT_SPIN_LEFT = "EVENT_SPIN_LEFT";
1750
1751
  Toolbar.EVENT_SPIN_STOP = "EVENT_SPIN_STOP";
1752
1753
  Toolbar.EVENT_SPIN_RIGHT = "EVENT_SPIN_RIGHT";
1754
1755
  Toolbar.EVENT_ANIMATE = "EVENT_ANIMATE";
1756
1757
  Toolbar.prototype.dispatcher = null;
1758
1759
  function Toolbar(id) {
1760
    this.setAnimateButtonSelected = __bind(this.setAnimateButtonSelected, this);
1761
    this.setSpinButtonSelected = __bind(this.setSpinButtonSelected, this);
1762
    this.setViewButtonSelected = __bind(this.setViewButtonSelected, this);
1763
    this.setSelectButtonSelected = __bind(this.setSelectButtonSelected, this);
1764
    this.setViewportButtonSelected = __bind(this.setViewportButtonSelected, this);
1765
    this.setBoxButtonSelected = __bind(this.setBoxButtonSelected, this);
1766
    this.blinkClearButton = __bind(this.blinkClearButton, this);
1767
    this.blinkResetButton = __bind(this.blinkResetButton, this);
1768
    this.setCameraButtonSelected = __bind(this.setCameraButtonSelected, this);
1769
    this.setInfoButtonSelected = __bind(this.setInfoButtonSelected, this);
1770
    this.setMenuButtonSelected = __bind(this.setMenuButtonSelected, this);
1771
    this.unblinkButton = __bind(this.unblinkButton, this);
1772
    this.blinkButton = __bind(this.blinkButton, this);
1773
    this.setButtonSelected = __bind(this.setButtonSelected, this);
1774
    this.initialize = __bind(this.initialize, this);
1775
    this.createDispatcher = __bind(this.createDispatcher, this);
1776
    this.onClick = __bind(this.onClick, this);
1777
    this.onKeyDown = __bind(this.onKeyDown, this);
1778
    var item, _i, _len, _ref;
1779
    Toolbar.__super__.constructor.call(this, id);
1780
    this.createDispatcher();
1781
    _ref = this.dispatcher;
1782
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1783
      item = _ref[_i];
1784
      $(item.id).click({
1785
        type: item.type
1786
      }, this.onClick);
1787
    }
1788
    document.addEventListener('keydown', this.onKeyDown, false);
1789
    this.initialize();
1790
  }
1791
1792
  Toolbar.prototype.onKeyDown = function(event) {
1793
    var item, modifier, _i, _len, _ref, _results;
1794
    modifier = Utility.NO_KEY;
1795
    if (event.shiftKey) {
1796
      modifier = Utility.SHIFT_KEY;
1797
    }
1798
    _ref = this.dispatcher;
1799
    _results = [];
1800
    for (_i = 0, _len = _ref.length; _i < _len; _i++) {
1801
      item = _ref[_i];
1802
      if ((item.key === event.keyCode) && (item.modifier === modifier)) {
1803
        _results.push(this.notify(item.type));
1804
      } else {
1805
        _results.push(void 0);
0 ignored issues
show
Coding Style introduced by
Consider using undefined instead of void(0). It is equivalent and more straightforward to read.
Loading history...
1806
      }
1807
    }
1808
    return _results;
1809
  };
1810
1811
  Toolbar.prototype.onClick = function(event) {
1812
    return this.notify(event.data.type);
1813
  };
1814
1815
  Toolbar.prototype.createDispatcher = function() {
1816
    return this.dispatcher = [
1817
      {
1818
        id: "#menuButton",
1819
        key: 77,
1820
        modifier: Utility.NO_KEY,
1821
        type: Toolbar.EVENT_MENU
1822
      }, {
1823
        id: "#infoButton",
1824
        key: 73,
1825
        modifier: Utility.NO_KEY,
1826
        type: Toolbar.EVENT_INFO
1827
      }, {
1828
        id: "#perspectiveButton",
1829
        key: 80,
1830
        modifier: Utility.NO_KEY,
1831
        type: Toolbar.EVENT_PERSPECTIVE
1832
      }, {
1833
        id: "#orthographicButton",
1834
        key: 79,
1835
        modifier: Utility.NO_KEY,
1836
        type: Toolbar.EVENT_ORTHOGRAPHIC
1837
      }, {
1838
        id: "#dualButton",
1839
        key: 68,
1840
        modifier: Utility.NO_KEY,
1841
        type: Toolbar.EVENT_DUAL
1842
      }, {
1843
        id: "#resetButton",
1844
        key: 82,
1845
        modifier: Utility.NO_KEY,
1846
        type: Toolbar.EVENT_RESET
1847
      }, {
1848
        id: "#clearButton",
1849
        key: 67,
1850
        modifier: Utility.NO_KEY,
1851
        type: Toolbar.EVENT_CLEAR
1852
      }, {
1853
        id: "#boxButton",
1854
        key: 66,
1855
        modifier: Utility.NO_KEY,
1856
        type: Toolbar.EVENT_BOX
1857
      }, {
1858
        id: "#viewportButton",
1859
        key: 86,
1860
        modifier: Utility.NO_KEY,
1861
        type: Toolbar.EVENT_VIEWPORT
1862
      }, {
1863
        id: "#selectButton",
1864
        key: 83,
1865
        modifier: Utility.NO_KEY,
1866
        type: Toolbar.EVENT_SELECT
1867
      }, {
1868
        id: "#viewTopButton",
1869
        key: 49,
1870
        modifier: Utility.NO_KEY,
1871
        type: Toolbar.EVENT_VIEW_TOP
1872
      }, {
1873
        id: "#viewFrontButton",
1874
        key: 50,
1875
        modifier: Utility.NO_KEY,
1876
        type: Toolbar.EVENT_VIEW_FRONT
1877
      }, {
1878
        id: "#viewSideButton",
1879
        key: 51,
1880
        modifier: Utility.NO_KEY,
1881
        type: Toolbar.EVENT_VIEW_SIDE
1882
      }, {
1883
        id: "#spinLeftButton",
1884
        key: 37,
1885
        modifier: Utility.NO_KEY,
1886
        type: Toolbar.EVENT_SPIN_LEFT
1887
      }, {
1888
        id: "#spinStopButton",
1889
        key: 32,
1890
        modifier: Utility.NO_KEY,
1891
        type: Toolbar.EVENT_SPIN_STOP
1892
      }, {
1893
        id: "#spinRightButton",
1894
        key: 39,
1895
        modifier: Utility.NO_KEY,
1896
        type: Toolbar.EVENT_SPIN_RIGHT
1897
      }, {
1898
        id: "#animateButton",
1899
        key: 65,
1900
        modifier: Utility.NO_KEY,
1901
        type: Toolbar.EVENT_ANIMATE
1902
      }
1903
    ];
1904
  };
1905
1906
  Toolbar.prototype.initialize = function() {
1907
    this.setButtonSelected("#menuButton", true);
1908
    this.setButtonSelected("#infoButton", false);
1909
    this.setButtonSelected("#perspectiveButton", true);
1910
    this.setButtonSelected("#orthographicButton", false);
1911
    this.setButtonSelected("#dualButton", false);
1912
    this.setButtonSelected("#boxButton", true);
1913
    this.setButtonSelected("#viewportButton", false);
1914
    this.setButtonSelected("#selectButton", false);
1915
    this.setButtonSelected("#viewTopButton", true);
1916
    this.setButtonSelected("#viewFrontButton", false);
1917
    this.setButtonSelected("#viewSideButton", false);
1918
    this.setButtonSelected("#spinLeftButton", false);
1919
    this.setButtonSelected("#spinStopButton", true);
1920
    this.setButtonSelected("#spinRightButton", false);
1921
    return this.setButtonSelected("#animateButton", false);
1922
  };
1923
1924
  Toolbar.prototype.setButtonSelected = function(id, selected) {
1925
    var color;
1926
    color = Palette.BUTTON.getStyle();
1927
    if (selected) {
1928
      color = Palette.BUTTON_SELECTED.getStyle();
1929
    }
1930
    return $(id).css('color', color);
1931
  };
1932
1933
  Toolbar.prototype.blinkButton = function(id) {
1934
    this.setButtonSelected(id, true);
1935
    return window.setTimeout(this.unblinkButton, 200, id);
1936
  };
1937
1938
  Toolbar.prototype.unblinkButton = function(id) {
1939
    console.log("Toolbar.unblinkButton " + id);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
1940
    return this.setButtonSelected(id, false);
1941
  };
1942
1943
  Toolbar.prototype.setMenuButtonSelected = function(selected) {
1944
    return this.setButtonSelected("#menuButton", selected);
1945
  };
1946
1947
  Toolbar.prototype.setInfoButtonSelected = function(selected) {
1948
    return this.setButtonSelected("#infoButton", selected);
1949
  };
1950
1951
  Toolbar.prototype.setCameraButtonSelected = function(selected1, selected2, selected3) {
1952
    this.setButtonSelected("#perspectiveButton", selected1);
1953
    this.setButtonSelected("#orthographicButton", selected2);
1954
    return this.setButtonSelected("#dualButton", selected3);
1955
  };
1956
1957
  Toolbar.prototype.blinkResetButton = function() {
1958
    return this.blinkButton("#resetButton");
1959
  };
1960
1961
  Toolbar.prototype.blinkClearButton = function() {
1962
    return this.blinkButton("#clearButton");
1963
  };
1964
1965
  Toolbar.prototype.setBoxButtonSelected = function(selected) {
1966
    return this.setButtonSelected("#boxButton", selected);
1967
  };
1968
1969
  Toolbar.prototype.setViewportButtonSelected = function(selected) {
1970
    return this.setButtonSelected("#viewportButton", selected);
1971
  };
1972
1973
  Toolbar.prototype.setSelectButtonSelected = function(selected) {
1974
    return this.setButtonSelected("#selectButton", selected);
1975
  };
1976
1977
  Toolbar.prototype.setViewButtonSelected = function(selected1, selected2, selected3) {
1978
    this.setButtonSelected("#viewTopButton", selected1);
1979
    this.setButtonSelected("#viewFrontButton", selected2);
1980
    return this.setButtonSelected("#viewSideButton", selected3);
1981
  };
1982
1983
  Toolbar.prototype.setSpinButtonSelected = function(selected1, selected2, selected3) {
1984
    this.setButtonSelected("#spinLeftButton", selected1);
1985
    this.setButtonSelected("#spinStopButton", selected2);
1986
    return this.setButtonSelected("#spinRightButton", selected3);
1987
  };
1988
1989
  Toolbar.prototype.setAnimateButtonSelected = function(selected) {
1990
    return this.setButtonSelected("#animateButton", selected);
1991
  };
1992
1993
  return Toolbar;
1994
1995
})(Panel);
1996
1997
module.exports = Toolbar;
1998
1999
2000
},{"./Palette.coffee":5,"./Panel.coffee":6,"./Utility.coffee":12}],12:[function(require,module,exports){
2001
var Utility;
2002
2003
Utility = (function() {
2004
  function Utility() {}
2005
2006
  Utility.DIRECTION = {
2007
    ALL: 0,
2008
    TOP: 1,
2009
    FRONT: 2,
2010
    SIDE: 3
2011
  };
2012
2013
  Utility.DEGREE = Math.PI / 180;
2014
2015
  Utility.SECOND = 1000;
2016
2017
  Utility.NO_KEY = "NO_KEY";
2018
2019
  Utility.SHIFT_KEY = "SHIFT_KEY";
2020
2021
  Utility.CTRL_KEY = "CTRL_KEY";
2022
2023
  Utility.ALT_KEY = "ALT_KEY";
2024
2025
  Utility.printVector3 = function(vector) {
2026
    return console.log(vector.x.toFixed(1) + " : " + vector.y.toFixed(1) + " : " + vector.z.toFixed(1));
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
2027
  };
2028
2029
  return Utility;
2030
2031
})();
2032
2033
module.exports = Utility;
2034
2035
2036
},{}]},{},[1])
2037
;
2038