1

More cleanup

This commit is contained in:
Alex Yatskov 2014-10-31 11:15:51 +09:00
parent e18efdf0a2
commit 0abb488acd

View File

@ -109,32 +109,34 @@
// Column // Column
// //
function Column(canvas, name, params, scale, range) { function Column(params) {
this.updateShapes = function(final) { this.updateShapes = function() {
}; };
this.decimateHints = function(steps, scale) { this.decimateHints = function(hints, steps, scale) {
var groups = this.groupHints(steps); var groups = this.groupHints(hints, steps);
var colorStops = {}; var colorStops = {};
_.each(groups, function(count, index) { for (var i = 0, count = groups.length; i < count; ++i) {
var groupSize = groups[i];
var colorPercent = 0; var colorPercent = 0;
if (scale.getLength() > 0) { if (scale.getLength() > 0) {
colorPercent = Math.max(0, count - scale.start) / scale.getLength(); colorPercent = Math.max(0, groupSize - scale.start) / scale.getLength();
} }
var colorByte = 0xff - Math.min(0xff, Math.round(0xff * colorPercent)); var colorByte = 0xff - Math.min(0xff, Math.round(0xff * colorPercent));
var colorObj = tinycolor({ r: colorByte, g: colorByte, b: colorByte }); var colorObj = tinycolor({ r: colorByte, g: colorByte, b: colorByte });
var colorStr = colorObj.toHexString(); var colorStr = colorObj.toHexString();
colorStops[index / steps] = colorStr; colorStops[i / steps] = colorStr;
}); }
return colorStops; return colorStops;
}; };
this.groupHints = function(steps) { this.groupHints = function(hints, steps) {
var stepSize = this.range.getLength() / steps; var stepSize = this.range.getLength() / steps;
var hintGroups = []; var hintGroups = [];
@ -143,7 +145,7 @@
var stepMin = stepMax - stepSize; var stepMin = stepMax - stepSize;
var hintCount = 0; var hintCount = 0;
for (var j = 0, count = this.hints.length; j < count; ++j) { for (var j = 0, count = hints.length; j < count; ++j) {
var hint = this.hints[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;
@ -165,10 +167,8 @@
} }
}; };
this.updateParams = function(params, scale) { this.update = function(data, scale) {
this.hints = params.hints; this.data = data;
this.value = params.value;
this.steps = params.steps;
this.scale = scale; this.scale = scale;
this.updateShapes(true); this.updateShapes(true);
}; };
@ -182,12 +182,12 @@
return colorObj.desaturate(desatVal).toHexString(); return colorObj.desaturate(desatVal).toHexString();
}; };
this.getFillColor = function() { this.computeFillColor = 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.computeHandleColor = 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);
}; };
@ -212,18 +212,14 @@
this.handleColorNeg = '#204a87'; this.handleColorNeg = '#204a87';
this.handleColorPos = '#a40000'; this.handleColorPos = '#a40000';
this.canvas = canvas; this.canvas = params.canvas;
this.shapes = []; this.name = params.name;
this.name = name; this.data = params.data;
this.value = params.value; this.scale = params.scale;
this.hints = params.hints; this.range = params.range;
this.steps = params.steps;
this.scale = scale;
this.range = range;
this.bounds = bounds;
this.state = this.State.NORMAL; this.state = this.State.NORMAL;
this.updateShapes(true); this.updateShapes();
} }
@ -247,10 +243,7 @@
var column = this.columns[name]; var column = this.columns[name];
if (column) { if (column) {
column.update({ column.update(data, scale);
data: data,
scale: scale
});
} }
else { else {
this.columns.push(new Column({ this.columns.push(new Column({