Chart.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. var zrUtil = require("zrender/lib/core/util");
  2. var Group = require("zrender/lib/container/Group");
  3. var componentUtil = require("../util/component");
  4. var clazzUtil = require("../util/clazz");
  5. var modelUtil = require("../util/model");
  6. function Chart() {
  7. /**
  8. * @type {module:zrender/container/Group}
  9. * @readOnly
  10. */
  11. this.group = new Group();
  12. /**
  13. * @type {string}
  14. * @readOnly
  15. */
  16. this.uid = componentUtil.getUID('viewChart');
  17. }
  18. Chart.prototype = {
  19. type: 'chart',
  20. /**
  21. * Init the chart
  22. * @param {module:echarts/model/Global} ecModel
  23. * @param {module:echarts/ExtensionAPI} api
  24. */
  25. init: function (ecModel, api) {},
  26. /**
  27. * Render the chart
  28. * @param {module:echarts/model/Series} seriesModel
  29. * @param {module:echarts/model/Global} ecModel
  30. * @param {module:echarts/ExtensionAPI} api
  31. * @param {Object} payload
  32. */
  33. render: function (seriesModel, ecModel, api, payload) {},
  34. /**
  35. * Highlight series or specified data item
  36. * @param {module:echarts/model/Series} seriesModel
  37. * @param {module:echarts/model/Global} ecModel
  38. * @param {module:echarts/ExtensionAPI} api
  39. * @param {Object} payload
  40. */
  41. highlight: function (seriesModel, ecModel, api, payload) {
  42. toggleHighlight(seriesModel.getData(), payload, 'emphasis');
  43. },
  44. /**
  45. * Downplay series or specified data item
  46. * @param {module:echarts/model/Series} seriesModel
  47. * @param {module:echarts/model/Global} ecModel
  48. * @param {module:echarts/ExtensionAPI} api
  49. * @param {Object} payload
  50. */
  51. downplay: function (seriesModel, ecModel, api, payload) {
  52. toggleHighlight(seriesModel.getData(), payload, 'normal');
  53. },
  54. /**
  55. * Remove self
  56. * @param {module:echarts/model/Global} ecModel
  57. * @param {module:echarts/ExtensionAPI} api
  58. */
  59. remove: function (ecModel, api) {
  60. this.group.removeAll();
  61. },
  62. /**
  63. * Dispose self
  64. * @param {module:echarts/model/Global} ecModel
  65. * @param {module:echarts/ExtensionAPI} api
  66. */
  67. dispose: function () {}
  68. /**
  69. * The view contains the given point.
  70. * @interface
  71. * @param {Array.<number>} point
  72. * @return {boolean}
  73. */
  74. // containPoint: function () {}
  75. };
  76. var chartProto = Chart.prototype;
  77. chartProto.updateView = chartProto.updateLayout = chartProto.updateVisual = function (seriesModel, ecModel, api, payload) {
  78. this.render(seriesModel, ecModel, api, payload);
  79. };
  80. /**
  81. * Set state of single element
  82. * @param {module:zrender/Element} el
  83. * @param {string} state
  84. */
  85. function elSetState(el, state) {
  86. if (el) {
  87. el.trigger(state);
  88. if (el.type === 'group') {
  89. for (var i = 0; i < el.childCount(); i++) {
  90. elSetState(el.childAt(i), state);
  91. }
  92. }
  93. }
  94. }
  95. /**
  96. * @param {module:echarts/data/List} data
  97. * @param {Object} payload
  98. * @param {string} state 'normal'|'emphasis'
  99. * @inner
  100. */
  101. function toggleHighlight(data, payload, state) {
  102. var dataIndex = modelUtil.queryDataIndex(data, payload);
  103. if (dataIndex != null) {
  104. zrUtil.each(modelUtil.normalizeToArray(dataIndex), function (dataIdx) {
  105. elSetState(data.getItemGraphicEl(dataIdx), state);
  106. });
  107. } else {
  108. data.eachItemGraphicEl(function (el) {
  109. elSetState(el, state);
  110. });
  111. }
  112. } // Enable Chart.extend.
  113. clazzUtil.enableClassExtend(Chart, ['dispose']); // Add capability of registerClass, getClass, hasClass, registerSubTypeDefaulter and so on.
  114. clazzUtil.enableClassManagement(Chart, {
  115. registerWhenExtend: true
  116. });
  117. var _default = Chart;
  118. module.exports = _default;