Code simplification
This commit is contained in:
parent
8e30a32b1c
commit
f6452bc7fc
@ -161,26 +161,23 @@
|
|||||||
function updateDensity() {
|
function updateDensity() {
|
||||||
var fill = _backdropColor;
|
var fill = _backdropColor;
|
||||||
if (_data.hints.length > 0) {
|
if (_data.hints.length > 0) {
|
||||||
fill = _canvas.gradient(decimateHints());
|
fill = _canvas.gradient(blendHints());
|
||||||
}
|
}
|
||||||
|
|
||||||
_elements.density.attr({fill: fill});
|
_elements.density.attr({fill: fill});
|
||||||
}
|
}
|
||||||
|
|
||||||
function decimateHints() {
|
function blendHints() {
|
||||||
var colorStops = 'l(0,0,0,1)';
|
var colorStops = 'l(0,0,0,1)';
|
||||||
|
|
||||||
var groups = groupHints();
|
for (var i = 0, count = _data.hints.length; i < count; ++i) {
|
||||||
for (var i = 0, count = groups.length; i < count; ++i) {
|
|
||||||
var groupSize = groups[i];
|
|
||||||
|
|
||||||
var colorPercent = 0;
|
var colorPercent = 0;
|
||||||
if (_scale.length() > 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 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 += colorStr;
|
colorStops += colorStr;
|
||||||
@ -192,31 +189,6 @@
|
|||||||
return colorStops;
|
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) {
|
function updateValue(value) {
|
||||||
_data.value = _range.clamp(value);
|
_data.value = _range.clamp(value);
|
||||||
if (_onValueChanged) {
|
if (_onValueChanged) {
|
||||||
|
Loading…
Reference in New Issue
Block a user