Chart.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. /**
  20. * AUTO-GENERATED FILE. DO NOT MODIFY.
  21. */
  22. /*
  23. * Licensed to the Apache Software Foundation (ASF) under one
  24. * or more contributor license agreements. See the NOTICE file
  25. * distributed with this work for additional information
  26. * regarding copyright ownership. The ASF licenses this file
  27. * to you under the Apache License, Version 2.0 (the
  28. * "License"); you may not use this file except in compliance
  29. * with the License. You may obtain a copy of the License at
  30. *
  31. * http://www.apache.org/licenses/LICENSE-2.0
  32. *
  33. * Unless required by applicable law or agreed to in writing,
  34. * software distributed under the License is distributed on an
  35. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  36. * KIND, either express or implied. See the License for the
  37. * specific language governing permissions and limitations
  38. * under the License.
  39. */
  40. import { each } from 'zrender/lib/core/util.js';
  41. import Group from 'zrender/lib/graphic/Group.js';
  42. import * as componentUtil from '../util/component.js';
  43. import * as clazzUtil from '../util/clazz.js';
  44. import * as modelUtil from '../util/model.js';
  45. import { enterEmphasis, leaveEmphasis, getHighlightDigit, isHighDownDispatcher } from '../util/states.js';
  46. import { createTask } from '../core/task.js';
  47. import createRenderPlanner from '../chart/helper/createRenderPlanner.js';
  48. import { traverseElements } from '../util/graphic.js';
  49. import { error } from '../util/log.js';
  50. var inner = modelUtil.makeInner();
  51. var renderPlanner = createRenderPlanner();
  52. var ChartView = /** @class */function () {
  53. function ChartView() {
  54. this.group = new Group();
  55. this.uid = componentUtil.getUID('viewChart');
  56. this.renderTask = createTask({
  57. plan: renderTaskPlan,
  58. reset: renderTaskReset
  59. });
  60. this.renderTask.context = {
  61. view: this
  62. };
  63. }
  64. ChartView.prototype.init = function (ecModel, api) {};
  65. ChartView.prototype.render = function (seriesModel, ecModel, api, payload) {
  66. if (process.env.NODE_ENV !== 'production') {
  67. throw new Error('render method must been implemented');
  68. }
  69. };
  70. /**
  71. * Highlight series or specified data item.
  72. */
  73. ChartView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  74. var data = seriesModel.getData(payload && payload.dataType);
  75. if (!data) {
  76. if (process.env.NODE_ENV !== 'production') {
  77. error("Unknown dataType " + payload.dataType);
  78. }
  79. return;
  80. }
  81. toggleHighlight(data, payload, 'emphasis');
  82. };
  83. /**
  84. * Downplay series or specified data item.
  85. */
  86. ChartView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  87. var data = seriesModel.getData(payload && payload.dataType);
  88. if (!data) {
  89. if (process.env.NODE_ENV !== 'production') {
  90. error("Unknown dataType " + payload.dataType);
  91. }
  92. return;
  93. }
  94. toggleHighlight(data, payload, 'normal');
  95. };
  96. /**
  97. * `remove` only occurs when series is filtered out, typically by legend.
  98. * And theirafter the view can only be rendered again via
  99. * `ChartView['render']` or `ChartView['incrementalPrepareRender']`.
  100. */
  101. ChartView.prototype.remove = function (ecModel, api) {
  102. this.group.removeAll();
  103. };
  104. /**
  105. * Dispose self.
  106. */
  107. ChartView.prototype.dispose = function (ecModel, api) {};
  108. ChartView.prototype.updateView = function (seriesModel, ecModel, api, payload) {
  109. this.render(seriesModel, ecModel, api, payload);
  110. };
  111. // FIXME never used?
  112. // updateLayout(seriesModel: SeriesModel, ecModel: GlobalModel, api: ExtensionAPI, payload: Payload): void {
  113. // this.render(seriesModel, ecModel, api, payload);
  114. // }
  115. // FIXME never used?
  116. ChartView.prototype.updateVisual = function (seriesModel, ecModel, api, payload) {
  117. this.render(seriesModel, ecModel, api, payload);
  118. };
  119. /**
  120. * Traverse the new rendered elements.
  121. *
  122. * It will traverse the new added element in progressive rendering.
  123. * And traverse all in normal rendering.
  124. */
  125. ChartView.prototype.eachRendered = function (cb) {
  126. traverseElements(this.group, cb);
  127. };
  128. ChartView.markUpdateMethod = function (payload, methodName) {
  129. inner(payload).updateMethod = methodName;
  130. };
  131. ChartView.protoInitialize = function () {
  132. var proto = ChartView.prototype;
  133. proto.type = 'chart';
  134. }();
  135. return ChartView;
  136. }();
  137. ;
  138. /**
  139. * Set state of single element
  140. */
  141. function elSetState(el, state, highlightDigit) {
  142. if (el && isHighDownDispatcher(el)) {
  143. (state === 'emphasis' ? enterEmphasis : leaveEmphasis)(el, highlightDigit);
  144. }
  145. }
  146. function toggleHighlight(data, payload, state) {
  147. var dataIndex = modelUtil.queryDataIndex(data, payload);
  148. var highlightDigit = payload && payload.highlightKey != null ? getHighlightDigit(payload.highlightKey) : null;
  149. if (dataIndex != null) {
  150. each(modelUtil.normalizeToArray(dataIndex), function (dataIdx) {
  151. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  152. });
  153. } else {
  154. // In progressive mode, `data._graphicEls` has typically no items,
  155. // thereby skipping this hover style changing.
  156. // PENDING: more robust approaches?
  157. data.eachItemGraphicEl(function (el) {
  158. elSetState(el, state, highlightDigit);
  159. });
  160. }
  161. }
  162. clazzUtil.enableClassExtend(ChartView, ['dispose']);
  163. clazzUtil.enableClassManagement(ChartView);
  164. function renderTaskPlan(context) {
  165. return renderPlanner(context.model);
  166. }
  167. function renderTaskReset(context) {
  168. var seriesModel = context.model;
  169. var ecModel = context.ecModel;
  170. var api = context.api;
  171. var payload = context.payload;
  172. // FIXME: remove updateView updateVisual
  173. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  174. var view = context.view;
  175. var updateMethod = payload && inner(payload).updateMethod;
  176. var methodName = progressiveRender ? 'incrementalPrepareRender' : updateMethod && view[updateMethod] ? updateMethod
  177. // `appendData` is also supported when data amount
  178. // is less than progressive threshold.
  179. : 'render';
  180. if (methodName !== 'render') {
  181. view[methodName](seriesModel, ecModel, api, payload);
  182. }
  183. return progressMethodMap[methodName];
  184. }
  185. var progressMethodMap = {
  186. incrementalPrepareRender: {
  187. progress: function (params, context) {
  188. context.view.incrementalRender(params, context.model, context.ecModel, context.api, context.payload);
  189. }
  190. },
  191. render: {
  192. // Put view.render in `progress` to support appendData. But in this case
  193. // view.render should not be called in reset, otherwise it will be called
  194. // twise. Use `forceFirstProgress` to make sure that view.render is called
  195. // in any cases.
  196. forceFirstProgress: true,
  197. progress: function (params, context) {
  198. context.view.render(context.model, context.ecModel, context.api, context.payload);
  199. }
  200. }
  201. };
  202. export default ChartView;