2015-06-15 02:09:45 +02:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//Declare root variable - window in the browser, global on the server
|
|
|
|
var root = this,
|
2015-10-22 18:47:45 +02:00
|
|
|
Chart = root.Chart,
|
2015-06-15 02:09:45 +02:00
|
|
|
helpers = Chart.helpers;
|
|
|
|
|
2015-06-15 22:36:02 +02:00
|
|
|
Chart.elements = {};
|
2015-06-15 02:09:45 +02:00
|
|
|
|
|
|
|
Chart.Element = function(configuration) {
|
|
|
|
helpers.extend(this, configuration);
|
|
|
|
this.initialize.apply(this, arguments);
|
|
|
|
};
|
|
|
|
helpers.extend(Chart.Element.prototype, {
|
|
|
|
initialize: function() {},
|
|
|
|
pivot: function() {
|
|
|
|
if (!this._view) {
|
|
|
|
this._view = helpers.clone(this._model);
|
|
|
|
}
|
|
|
|
this._start = helpers.clone(this._view);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
transition: function(ease) {
|
|
|
|
if (!this._view) {
|
|
|
|
this._view = helpers.clone(this._model);
|
|
|
|
}
|
2016-01-15 13:06:03 +01:00
|
|
|
|
|
|
|
// No animation -> No Transition
|
|
|
|
if (ease === 1) {
|
|
|
|
this._view = this._model;
|
|
|
|
this._start = null;
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2015-06-15 02:09:45 +02:00
|
|
|
if (!this._start) {
|
|
|
|
this.pivot();
|
|
|
|
}
|
|
|
|
|
|
|
|
helpers.each(this._model, function(value, key) {
|
|
|
|
|
|
|
|
if (key[0] === '_' || !this._model.hasOwnProperty(key)) {
|
|
|
|
// Only non-underscored properties
|
|
|
|
}
|
|
|
|
|
|
|
|
// Init if doesn't exist
|
2016-01-15 13:06:03 +01:00
|
|
|
else if (!this._view.hasOwnProperty(key)) {
|
|
|
|
if (typeof value === 'number' && !isNaN(this._view[key])) {
|
2015-06-15 02:09:45 +02:00
|
|
|
this._view[key] = value * ease;
|
|
|
|
} else {
|
2016-01-15 13:06:03 +01:00
|
|
|
this._view[key] = value;
|
2015-06-15 02:09:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No unnecessary computations
|
2016-01-15 13:06:03 +01:00
|
|
|
else if (value === this._view[key]) {
|
2015-06-15 02:09:45 +02:00
|
|
|
// It's the same! Woohoo!
|
|
|
|
}
|
|
|
|
|
|
|
|
// Color transitions if possible
|
|
|
|
else if (typeof value === 'string') {
|
|
|
|
try {
|
|
|
|
var color = helpers.color(this._start[key]).mix(helpers.color(this._model[key]), ease);
|
|
|
|
this._view[key] = color.rgbString();
|
|
|
|
} catch (err) {
|
|
|
|
this._view[key] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Number transitions
|
|
|
|
else if (typeof value === 'number') {
|
2015-11-15 04:49:53 +01:00
|
|
|
var startVal = this._start[key] !== undefined && isNaN(this._start[key]) === false ? this._start[key] : 0;
|
2015-06-15 02:09:45 +02:00
|
|
|
this._view[key] = ((this._model[key] - startVal) * ease) + startVal;
|
|
|
|
}
|
|
|
|
// Everything else
|
|
|
|
else {
|
|
|
|
this._view[key] = value;
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
tooltipPosition: function() {
|
|
|
|
return {
|
|
|
|
x: this._model.x,
|
|
|
|
y: this._model.y
|
|
|
|
};
|
|
|
|
},
|
|
|
|
hasValue: function() {
|
|
|
|
return helpers.isNumber(this._model.x) && helpers.isNumber(this._model.y);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Chart.Element.extend = helpers.inherits;
|
|
|
|
|
|
|
|
}).call(this);
|