CoordinateSystem.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. define(function(require) {
  2. 'use strict';
  3. var zrUtil = require('zrender/core/util');
  4. /**
  5. * Interface of Coordinate System Class
  6. *
  7. * create:
  8. * @param {module:echarts/model/Global} ecModel
  9. * @param {module:echarts/ExtensionAPI} api
  10. * @return {Object} coordinate system instance
  11. *
  12. * update:
  13. * @param {module:echarts/model/Global} ecModel
  14. * @param {module:echarts/ExtensionAPI} api
  15. *
  16. * convertToPixel:
  17. * convertFromPixel:
  18. * These two methods is also responsible for determine whether this
  19. * coodinate system is applicable to the given `finder`.
  20. * Each coordinate system will be tried, util one returns none
  21. * null/undefined value.
  22. * @param {module:echarts/model/Global} ecModel
  23. * @param {Object} finder
  24. * @param {Array|number} value
  25. * @return {Array|number} convert result.
  26. *
  27. * containPoint:
  28. * @param {Array.<number>} point In pixel coordinate system.
  29. * @return {boolean}
  30. */
  31. var coordinateSystemCreators = {};
  32. function CoordinateSystemManager() {
  33. this._coordinateSystems = [];
  34. }
  35. CoordinateSystemManager.prototype = {
  36. constructor: CoordinateSystemManager,
  37. create: function (ecModel, api) {
  38. var coordinateSystems = [];
  39. zrUtil.each(coordinateSystemCreators, function (creater, type) {
  40. var list = creater.create(ecModel, api);
  41. coordinateSystems = coordinateSystems.concat(list || []);
  42. });
  43. this._coordinateSystems = coordinateSystems;
  44. },
  45. update: function (ecModel, api) {
  46. zrUtil.each(this._coordinateSystems, function (coordSys) {
  47. // FIXME MUST have
  48. coordSys.update && coordSys.update(ecModel, api);
  49. });
  50. },
  51. getCoordinateSystems: function () {
  52. return this._coordinateSystems.slice();
  53. }
  54. };
  55. CoordinateSystemManager.register = function (type, coordinateSystemCreator) {
  56. coordinateSystemCreators[type] = coordinateSystemCreator;
  57. };
  58. CoordinateSystemManager.get = function (type) {
  59. return coordinateSystemCreators[type];
  60. };
  61. return CoordinateSystemManager;
  62. });