1

Simpler animation handling

This commit is contained in:
Alex Yatskov 2014-11-09 12:31:52 +09:00
parent 305e6d96ec
commit 205ab5c662
2 changed files with 13 additions and 22 deletions

View File

@ -27,8 +27,7 @@
(function(hscd) { (function(hscd) {
'use strict'; 'use strict';
var _custom = '[custom]'; var _ctx = { log: [] };
var _ctx = { log: [] };
function onAdjust(name, value) { function onAdjust(name, value) {
_ctx.query.features[name] = value; _ctx.query.features[name] = value;
@ -212,20 +211,13 @@
$(document).on({ $(document).on({
ajaxStart: function() { ajaxStart: function() {
if (_.has(_ctx, 'grapher')) {
_ctx.grapher.enable(false);
}
$('#spinner').show(); $('#spinner').show();
}, },
ajaxStop: function() { ajaxStop: function() {
if (_.has(_ctx, 'grapher')) {
_ctx.grapher.enable(true);
}
$('#spinner').hide(); $('#spinner').hide();
}, },
ready: onReady() ready: onReady()
}); });
}(window.hscd = window.hscd || {})); }(window.hscd = window.hscd || {}));

View File

@ -91,7 +91,7 @@
var _width = 125; var _width = 125;
var _easeTime = 200; var _easeTime = 200;
var _enabled = true; var _animation = null;
var _canvas = params.canvas; var _canvas = params.canvas;
var _data = params.data; var _data = params.data;
var _index = params.index; var _index = params.index;
@ -226,7 +226,15 @@
} }
function animateIndicator(valueOld, valueNew) { function animateIndicator(valueOld, valueNew) {
Snap.animate( if (valueOld === valueNew) {
return;
}
if (_animation !== null) {
_animation.stop();
}
_animation = Snap.animate(
valueOld, valueOld,
valueNew, valueNew,
function(value) { function(value) {
@ -236,6 +244,7 @@
mina.linear, mina.linear,
function() { function() {
updateDensity(); updateDensity();
_animation = null;
} }
); );
} }
@ -271,7 +280,7 @@
} }
function clicked(event, x, y) { function clicked(event, x, y) {
if (_enabled) { if (_animation === null) {
var rect = _canvas.node.getBoundingClientRect(); var rect = _canvas.node.getBoundingClientRect();
updateValue(indicatorToValue(y - rect.top)); updateValue(indicatorToValue(y - rect.top));
} }
@ -284,10 +293,6 @@
animateIndicator(_valueAnimated, _data.value); animateIndicator(_valueAnimated, _data.value);
}; };
this.enable = function(enable) {
_enabled = enable;
};
createShapes(); createShapes();
} }
@ -373,11 +378,5 @@
this.setColumns(_data); this.setColumns(_data);
} }
}; };
this.enable = function(enable) {
for (var name in _columns) {
_columns[name].enable(enable);
}
};
}; };
}(window.grapher = window.grapher || {})); }(window.grapher = window.grapher || {}));