echarts
Version:
A powerful charting and visualization library for browser
76 lines (60 loc) • 2.31 kB
JavaScript
;
var zrUtil = require('zrender/lib/core/util');
/**
* Interface of Coordinate System Class
*
* create:
* @param {module:echarts/model/Global} ecModel
* @param {module:echarts/ExtensionAPI} api
* @return {Object} coordinate system instance
*
* update:
* @param {module:echarts/model/Global} ecModel
* @param {module:echarts/ExtensionAPI} api
*
* convertToPixel:
* convertFromPixel:
* These two methods is also responsible for determine whether this
* coodinate system is applicable to the given `finder`.
* Each coordinate system will be tried, util one returns none
* null/undefined value.
* @param {module:echarts/model/Global} ecModel
* @param {Object} finder
* @param {Array|number} value
* @return {Array|number} convert result.
*
* containPoint:
* @param {Array.<number>} point In pixel coordinate system.
* @return {boolean}
*/
var coordinateSystemCreators = {};
function CoordinateSystemManager() {
this._coordinateSystems = [];
}
CoordinateSystemManager.prototype = {
constructor: CoordinateSystemManager,
create: function (ecModel, api) {
var coordinateSystems = [];
zrUtil.each(coordinateSystemCreators, function (creater, type) {
var list = creater.create(ecModel, api);
coordinateSystems = coordinateSystems.concat(list || []);
});
this._coordinateSystems = coordinateSystems;
},
update: function (ecModel, api) {
zrUtil.each(this._coordinateSystems, function (coordSys) {
// FIXME MUST have
coordSys.update && coordSys.update(ecModel, api);
});
},
getCoordinateSystems: function () {
return this._coordinateSystems.slice();
}
};
CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
coordinateSystemCreators[type] = coordinateSystemCreator;
};
CoordinateSystemManager.get = function (type) {
return coordinateSystemCreators[type];
};
module.exports = CoordinateSystemManager;