From f6452bc7fc2d25def3e5f17387bff2033279ef84 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sat, 18 Apr 2015 19:02:49 +0900 Subject: [PATCH] Code simplification --- static/scripts/grapher.js | 38 +++++--------------------------------- 1 file changed, 5 insertions(+), 33 deletions(-) diff --git a/static/scripts/grapher.js b/static/scripts/grapher.js index 90590b0..da5e70a 100644 --- a/static/scripts/grapher.js +++ b/static/scripts/grapher.js @@ -161,26 +161,23 @@ function updateDensity() { var fill = _backdropColor; if (_data.hints.length > 0) { - fill = _canvas.gradient(decimateHints()); + fill = _canvas.gradient(blendHints()); } _elements.density.attr({fill: fill}); } - function decimateHints() { + function blendHints() { var colorStops = 'l(0,0,0,1)'; - var groups = groupHints(); - for (var i = 0, count = groups.length; i < count; ++i) { - var groupSize = groups[i]; - + for (var i = 0, count = _data.hints.length; i < count; ++i) { var colorPercent = 0; if (_scale.length() > 0) { - colorPercent = Math.max(0, groupSize - _scale.min) / _scale.length(); + colorPercent = Math.max(0, _data.hints[i].rating - _scale.min) / _scale.length(); } 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(); colorStops += colorStr; @@ -192,31 +189,6 @@ return colorStops; } - function groupHints() { - var hintGroups = []; - - var stepCount = _data.hints.length; - if (stepCount > 0) { - var stepSize = _range.length() / stepCount; - for (var i = 0; i < stepCount; ++i) { - var stepMax = _range.max - stepSize * i; - var stepMin = stepMax - stepSize; - - var hintValue = 0; - for (var j = 0, count = _data.hints.length; j < count; ++j) { - var hint = _data.hints[j]; - if (hint.sample > stepMin && hint.sample <= stepMax) { - hintValue += hint.rating; - } - } - - hintGroups.push(hintValue); - } - } - - return hintGroups; - } - function updateValue(value) { _data.value = _range.clamp(value); if (_onValueChanged) {