1

Fixes to lint correctly

This commit is contained in:
Alex Yatskov 2014-09-28 16:58:56 +09:00
parent 826638e984
commit c14b5d1419
2 changed files with 75 additions and 65 deletions

View File

@ -1,7 +1,6 @@
'use strict';
(function(hscd) { (function(hscd) {
'use strict';
var ctx = {}; var ctx = {};
function onAdjust(name, value) { function onAdjust(name, value) {
@ -179,3 +178,12 @@
}); });
}(window.hscd = window.hscd || {})); }(window.hscd = window.hscd || {}));
/*
global
$,
Handlebars,
document,
grapher,
window,
*/

View File

@ -1,7 +1,6 @@
'use strict';
(function(grapher) { (function(grapher) {
'use strict';
// //
// Coord // Coord
// //
@ -71,7 +70,7 @@
} }
return value; return value;
} };
} }
@ -86,7 +85,7 @@
}); });
this.shapes = []; this.shapes = [];
} };
this.updateShapes = function(final) { this.updateShapes = function(final) {
this.columnBounds = this.getColumnBounds(this.bounds); this.columnBounds = this.getColumnBounds(this.bounds);
@ -163,7 +162,7 @@
} }
this.canvas.renderAll(); this.canvas.renderAll();
} };
this.updateRect = function(name, args) { this.updateRect = function(name, args) {
if (name in this) { if (name in this) {
@ -175,19 +174,19 @@
this.shapes.push(rect); this.shapes.push(rect);
this[name] = rect; this[name] = rect;
} }
} };
this.updateText = function(name, text, args) { this.updateText = function(name, str, args) {
if (name in this) { if (name in this) {
this[name].set(args); this[name].set(args);
} }
else { else {
var text = new fabric.Text(text, args); var text = new fabric.Text(str, args);
this.canvas.add(text); this.canvas.add(text);
this.shapes.push(text); this.shapes.push(text);
this[name] = text; this[name] = text;
} }
} };
this.updateLine = function(name, points, args) { this.updateLine = function(name, points, args) {
if (name in this) { if (name in this) {
@ -199,7 +198,7 @@
this.shapes.push(line); this.shapes.push(line);
this[name] = line; this[name] = line;
} }
} };
this.decimateHints = function(steps, scale) { this.decimateHints = function(steps, scale) {
var groups = this.groupHints(steps); var groups = this.groupHints(steps);
@ -219,7 +218,7 @@
}); });
return colorStops; return colorStops;
} };
this.groupHints = function(steps) { this.groupHints = function(steps) {
var stepSize = this.range.getLength() / steps; var stepSize = this.range.getLength() / steps;
@ -230,17 +229,18 @@
var stepMin = stepMax - stepSize; var stepMin = stepMax - stepSize;
var hintCount = 0; var hintCount = 0;
_.each(this.hints, function(hint) { for (var j = 0, count = this.hints.length; j < count; ++j) {
var hint = this.hints[j];
if (hint.sample > stepMin && hint.sample <= stepMax) { if (hint.sample > stepMin && hint.sample <= stepMax) {
hintCount += hint.count; hintCount += hint.count;
} }
}); }
hintGroups.push(hintCount); hintGroups.push(hintCount);
} }
return hintGroups; return hintGroups;
} };
this.setClampedValue = function(value, final) { this.setClampedValue = function(value, final) {
this.value = this.range.clamp(value); this.value = this.range.clamp(value);
@ -249,13 +249,13 @@
if (this.onValueChanged && final) { if (this.onValueChanged && final) {
this.onValueChanged(this.name, this.value); this.onValueChanged(this.name, this.value);
} }
} };
this.setHints = function(hints, scale) { this.setHints = function(hints, scale) {
this.hints = hints; this.hints = hints;
this.scale = scale; this.scale = scale;
this.updateShapes(true); this.updateShapes(true);
} };
this.getLabelBounds = function(bounds) { this.getLabelBounds = function(bounds) {
return new Rect( return new Rect(
@ -264,7 +264,7 @@
bounds.width, bounds.width,
this.labelSize this.labelSize
); );
} };
this.getColumnBounds = function(bounds) { this.getColumnBounds = function(bounds) {
return new Rect( return new Rect(
@ -273,7 +273,7 @@
bounds.width - this.tickLength, bounds.width - this.tickLength,
bounds.height - this.labelSize bounds.height - this.labelSize
); );
} };
this.getHintBounds = function(bounds) { this.getHintBounds = function(bounds) {
return new Rect( return new Rect(
@ -282,7 +282,7 @@
this.hintSize, this.hintSize,
bounds.height bounds.height
); );
} };
this.getFillBounds = function(bounds) { this.getFillBounds = function(bounds) {
var y1 = this.getPosFromValue(0.0); var y1 = this.getPosFromValue(0.0);
@ -293,7 +293,7 @@
bounds.width - this.hintSize, bounds.width - this.hintSize,
Math.abs(y1 - y2) Math.abs(y1 - y2)
); );
} };
this.getHandleBounds = function(bounds, fillBounds) { this.getHandleBounds = function(bounds, fillBounds) {
var handleBounds = new Rect( var handleBounds = new Rect(
@ -304,7 +304,7 @@
); );
handleBounds.intersection(bounds); handleBounds.intersection(bounds);
return handleBounds; return handleBounds;
} };
this.valueColorAdjust = function(color, offset) { this.valueColorAdjust = function(color, offset) {
var colorObj = tinycolor(color); var colorObj = tinycolor(color);
@ -313,30 +313,30 @@
var rangeRat = (this.value - rangeMid) / (rangeEnd - rangeMid); var rangeRat = (this.value - rangeMid) / (rangeEnd - rangeMid);
var desatVal = Math.max(0.0, 1.0 - rangeRat + offset) * 100.0; var desatVal = Math.max(0.0, 1.0 - rangeRat + offset) * 100.0;
return colorObj.desaturate(desatVal).toHexString(); return colorObj.desaturate(desatVal).toHexString();
} };
this.getFillColor = function() { this.getFillColor = function() {
var color = this.value >= 0.0 ? this.fillColorPos : this.fillColorNeg; var color = this.value >= 0.0 ? this.fillColorPos : this.fillColorNeg;
return this.valueColorAdjust(color, this.desatOffset); return this.valueColorAdjust(color, this.desatOffset);
} };
this.getHandleColor = function() { this.getHandleColor = function() {
var color = this.value >= 0.0 ? this.handleColorPos : this.handleColorNeg; var color = this.value >= 0.0 ? this.handleColorPos : this.handleColorNeg;
return this.valueColorAdjust(color, this.desatOffset); return this.valueColorAdjust(color, this.desatOffset);
} };
this.mouseDown = function(position) { this.mouseDown = function(position) {
if (this.isGrabbing(position)) { if (this.isGrabbing(position)) {
this.stateTransition(this.State.DRAG, position); this.stateTransition(this.State.DRAG, position);
} }
} };
this.mouseUp = function(position) { this.mouseUp = function(position) {
this.stateTransition( this.stateTransition(
this.isHovering(position) ? this.State.HOVER : this.State.NORMAL, this.isHovering(position) ? this.State.HOVER : this.State.NORMAL,
position position
); );
} };
this.mouseMove = function(position) { this.mouseMove = function(position) {
switch (this.state) { switch (this.state) {
@ -353,40 +353,40 @@
} }
this.stateUpdate(position); this.stateUpdate(position);
} };
this.mouseOut = function(position) { this.mouseOut = function(position) {
this.mouseUp(position); this.mouseUp(position);
} };
this.mouseDoubleClick = function(position) { this.mouseDoubleClick = function(position) {
if (this.isContained(position)) { if (this.isContained(position)) {
this.setClampedValue(this.getValueFromPos(position.y), true); this.setClampedValue(this.getValueFromPos(position.y), true);
} }
} };
this.getValueFromPos = function(position) { this.getValueFromPos = function(position) {
var percent = 1.0 - (position - this.columnBounds.top) / this.columnBounds.height; var percent = 1.0 - (position - this.columnBounds.top) / this.columnBounds.height;
return this.range.start + this.range.getLength() * percent; return this.range.start + this.range.getLength() * percent;
} };
this.getPosFromValue = function(value) { this.getPosFromValue = function(value) {
var percent = 1.0 - (value - this.range.start) / this.range.getLength(); var percent = 1.0 - (value - this.range.start) / this.range.getLength();
var range = new Range(this.columnBounds.top, this.columnBounds.top + this.columnBounds.height); var range = new Range(this.columnBounds.top, this.columnBounds.top + this.columnBounds.height);
return range.clamp(this.columnBounds.top + this.columnBounds.height * percent); return range.clamp(this.columnBounds.top + this.columnBounds.height * percent);
} };
this.isHovering = function(position) { this.isHovering = function(position) {
return this.isGrabbing(position); return this.isGrabbing(position);
} };
this.isGrabbing = function(position) { this.isGrabbing = function(position) {
return this.handleBounds.contains(position); return this.handleBounds.contains(position);
} };
this.isContained = function(position) { this.isContained = function(position) {
return this.columnBounds.contains(position); return this.columnBounds.contains(position);
} };
this.stateUpdate = function(position) { this.stateUpdate = function(position) {
switch (this.state) { switch (this.state) {
@ -394,7 +394,7 @@
this.setClampedValue(this.getValueFromPos(position.y) + this.dragDelta, false); this.setClampedValue(this.getValueFromPos(position.y) + this.dragDelta, false);
break; break;
} }
} };
this.stateTransition = function(state, position) { this.stateTransition = function(state, position) {
if (state == this.state) { if (state == this.state) {
@ -404,23 +404,25 @@
switch (this.state) { switch (this.state) {
case this.State.DRAG: case this.State.DRAG:
this.setClampedValue(this.getValueFromPos(position.y) + this.dragDelta, true); this.setClampedValue(this.getValueFromPos(position.y) + this.dragDelta, true);
/* falls through */
case this.State.HOVER: case this.State.HOVER:
if (state == this.State.NORMAL) { if (state == this.State.NORMAL) {
this.canvas.contextContainer.canvas.style.cursor = 'default'; this.canvas.contextContainer.canvas.style.cursor = 'default';
} }
break; break;
} }
switch (state) { switch (state) {
case this.State.DRAG: case this.State.DRAG:
this.dragDelta = this.value - this.getValueFromPos(position.y); this.dragDelta = this.value - this.getValueFromPos(position.y);
/* falls through */
case this.State.HOVER: case this.State.HOVER:
this.canvas.contextContainer.canvas.style.cursor = 'ns-resize'; this.canvas.contextContainer.canvas.style.cursor = 'ns-resize';
break; break;
} }
this.state = state; this.state = state;
} };
this.State = { this.State = {
NORMAL: 0, NORMAL: 0,
@ -488,7 +490,7 @@
that.columns.push(new Column(that.canvas, columnName, columnValue, scale, that.range, columnBounds)); that.columns.push(new Column(that.canvas, columnName, columnValue, scale, that.range, columnBounds));
that.indexMap[columnName] = index++; that.indexMap[columnName] = index++;
}); });
} };
this.clearColumns = function() { this.clearColumns = function() {
_.each(this.columns, function(column) { _.each(this.columns, function(column) {
@ -497,7 +499,7 @@
this.columns = []; this.columns = [];
this.indexMap = {}; this.indexMap = {};
} };
this.setColumnHints = function(hintData) { this.setColumnHints = function(hintData) {
var scale = 0; var scale = 0;
@ -516,21 +518,21 @@
that.columns[index].setHints(hints, scale); that.columns[index].setHints(hints, scale);
}); });
} };
this.setUseLocalScale = function(useLocalScale) { this.setUseLocalScale = function(useLocalScale) {
if (useLocalScale != this.useLocalScale) { if (useLocalScale != this.useLocalScale) {
this.useLocalScale = useLocalScale; this.useLocalScale = useLocalScale;
this.invalidateHints(); this.invalidateHints();
} }
} };
this.setUseRelativeScale = function(useRelativeScale) { this.setUseRelativeScale = function(useRelativeScale) {
if (useRelativeScale != this.useRelativeScale) { if (useRelativeScale != this.useRelativeScale) {
this.useRelativeScale = useRelativeScale; this.useRelativeScale = useRelativeScale;
this.invalidateHints(); this.invalidateHints();
} }
} };
this.invalidateHints = function() { this.invalidateHints = function() {
var hintData = {}; var hintData = {};
@ -539,19 +541,19 @@
}); });
this.setColumnHints(hintData); this.setColumnHints(hintData);
} };
this.setValueChangedListener = function(listener) { this.setValueChangedListener = function(listener) {
_.each(this.columns, function(column) { _.each(this.columns, function(column) {
column.onValueChanged = listener; column.onValueChanged = listener;
}); });
} };
this.getLocalScale = function(hints) { this.getLocalScale = function(hints) {
var counts = _.pluck(hints, 'count'); var counts = _.pluck(hints, 'count');
var min = this.useRelativeScale ? _.min(counts) : 0; var min = this.useRelativeScale ? _.min(counts) : 0;
return new Range(min, _.max(counts)); return new Range(min, _.max(counts));
} };
this.getGlobalScale = function(hintData) { this.getGlobalScale = function(hintData) {
var that = this; var that = this;
@ -568,32 +570,32 @@
}); });
return globalScale; return globalScale;
} };
this.getColumnCount = function() { this.getColumnCount = function() {
return this.columns.length; return this.columns.length;
} };
this.getColumnIndex = function(name) { this.getColumnIndex = function(name) {
console.assert(name in this.indexMap); console.assert(name in this.indexMap);
return this.indexMap[name]; return this.indexMap[name];
} };
this.getColumnName = function(index) { this.getColumnName = function(index) {
return this.columns[index].name; return this.columns[index].name;
} };
this.getColumnNames = function() { this.getColumnNames = function() {
return _.pluck(this.columns, 'name'); return _.pluck(this.columns, 'name');
} };
this.getCanvasBounds = function() { this.getCanvasBounds = function() {
return new Rect(0, 0, this.canvas.width - 1, this.canvas.height - 1); return new Rect(0, 0, this.canvas.width - 1, this.canvas.height - 1);
} };
this.getGraphBounds = function(bounds) { this.getGraphBounds = function(bounds) {
return this.getCanvasBounds(); return this.getCanvasBounds();
} };
this.getColumnBounds = function(bounds, index, count) { this.getColumnBounds = function(bounds, index, count) {
var width = this.columnWidth + this.padding * 2; var width = this.columnWidth + this.padding * 2;
@ -603,47 +605,47 @@
this.columnWidth, this.columnWidth,
bounds.height bounds.height
); );
} };
this.getMousePos = function(e) { this.getMousePos = function(e) {
var rect = e.target.getBoundingClientRect(); var rect = e.target.getBoundingClientRect();
return new Coord(e.clientX - rect.left, e.clientY - rect.top); return new Coord(e.clientX - rect.left, e.clientY - rect.top);
} };
this.mouseDown = function(e) { this.mouseDown = function(e) {
var position = this.grapher.getMousePos(e); var position = this.grapher.getMousePos(e);
_.each(this.grapher.columns, function(column) { _.each(this.grapher.columns, function(column) {
column.mouseDown(position); column.mouseDown(position);
}); });
} };
this.mouseUp = function(e) { this.mouseUp = function(e) {
var position = this.grapher.getMousePos(e); var position = this.grapher.getMousePos(e);
_.each(this.grapher.columns, function(column) { _.each(this.grapher.columns, function(column) {
column.mouseUp(position); column.mouseUp(position);
}); });
} };
this.mouseMove = function(e) { this.mouseMove = function(e) {
var position = this.grapher.getMousePos(e); var position = this.grapher.getMousePos(e);
_.each(this.grapher.columns, function(column) { _.each(this.grapher.columns, function(column) {
column.mouseMove(position); column.mouseMove(position);
}); });
} };
this.mouseOut = function(e) { this.mouseOut = function(e) {
var position = this.grapher.getMousePos(e); var position = this.grapher.getMousePos(e);
_.each(this.grapher.columns, function(column) { _.each(this.grapher.columns, function(column) {
column.mouseOut(position); column.mouseOut(position);
}); });
} };
this.mouseDoubleClick = function(e) { this.mouseDoubleClick = function(e) {
var position = this.grapher.getMousePos(e); var position = this.grapher.getMousePos(e);
_.each(this.grapher.columns, function(column) { _.each(this.grapher.columns, function(column) {
column.mouseDoubleClick(position); column.mouseDoubleClick(position);
}); });
} };
this.useLocalScale = useLocalScale; this.useLocalScale = useLocalScale;
this.useRelativeScale = useRelativeScale; this.useRelativeScale = useRelativeScale;
@ -661,5 +663,5 @@
c.addEventListener('mouseout', this.mouseOut, false); c.addEventListener('mouseout', this.mouseOut, false);
c.addEventListener('dblclick', this.mouseDoubleClick, false); c.addEventListener('dblclick', this.mouseDoubleClick, false);
c.grapher = this; c.grapher = this;
} };
}(window.grapher = window.grapher || {})); }(window.grapher = window.grapher || {}));