Chart.js 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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 =
  53. /** @class */
  54. function () {
  55. function ChartView() {
  56. this.group = new Group();
  57. this.uid = componentUtil.getUID('viewChart');
  58. this.renderTask = createTask({
  59. plan: renderTaskPlan,
  60. reset: renderTaskReset
  61. });
  62. this.renderTask.context = {
  63. view: this
  64. };
  65. }
  66. ChartView.prototype.init = function (ecModel, api) {};
  67. ChartView.prototype.render = function (seriesModel, ecModel, api, payload) {
  68. if (process.env.NODE_ENV !== 'production') {
  69. throw new Error('render method must been implemented');
  70. }
  71. };
  72. /**
  73. * Highlight series or specified data item.
  74. */
  75. ChartView.prototype.highlight = function (seriesModel, ecModel, api, payload) {
  76. var data = seriesModel.getData(payload && payload.dataType);
  77. if (!data) {
  78. if (process.env.NODE_ENV !== 'production') {
  79. error("Unknown dataType " + payload.dataType);
  80. }
  81. return;
  82. }
  83. toggleHighlight(data, payload, 'emphasis');
  84. };
  85. /**
  86. * Downplay series or specified data item.
  87. */
  88. ChartView.prototype.downplay = function (seriesModel, ecModel, api, payload) {
  89. var data = seriesModel.getData(payload && payload.dataType);
  90. if (!data) {
  91. if (process.env.NODE_ENV !== 'production') {
  92. error("Unknown dataType " + payload.dataType);
  93. }
  94. return;
  95. }
  96. toggleHighlight(data, payload, 'normal');
  97. };
  98. /**
  99. * Remove self.
  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. }; // FIXME never used?
  111. ChartView.prototype.updateLayout = function (seriesModel, ecModel, api, payload) {
  112. this.render(seriesModel, ecModel, api, payload);
  113. }; // FIXME never used?
  114. ChartView.prototype.updateVisual = function (seriesModel, ecModel, api, payload) {
  115. this.render(seriesModel, ecModel, api, payload);
  116. };
  117. /**
  118. * Traverse the new rendered elements.
  119. *
  120. * It will traverse the new added element in progressive rendering.
  121. * And traverse all in normal rendering.
  122. */
  123. ChartView.prototype.eachRendered = function (cb) {
  124. traverseElements(this.group, cb);
  125. };
  126. ChartView.markUpdateMethod = function (payload, methodName) {
  127. inner(payload).updateMethod = methodName;
  128. };
  129. ChartView.protoInitialize = function () {
  130. var proto = ChartView.prototype;
  131. proto.type = 'chart';
  132. }();
  133. return ChartView;
  134. }();
  135. ;
  136. /**
  137. * Set state of single element
  138. */
  139. function elSetState(el, state, highlightDigit) {
  140. if (el && isHighDownDispatcher(el)) {
  141. (state === 'emphasis' ? enterEmphasis : leaveEmphasis)(el, highlightDigit);
  142. }
  143. }
  144. function toggleHighlight(data, payload, state) {
  145. var dataIndex = modelUtil.queryDataIndex(data, payload);
  146. var highlightDigit = payload && payload.highlightKey != null ? getHighlightDigit(payload.highlightKey) : null;
  147. if (dataIndex != null) {
  148. each(modelUtil.normalizeToArray(dataIndex), function (dataIdx) {
  149. elSetState(data.getItemGraphicEl(dataIdx), state, highlightDigit);
  150. });
  151. } else {
  152. data.eachItemGraphicEl(function (el) {
  153. elSetState(el, state, highlightDigit);
  154. });
  155. }
  156. }
  157. clazzUtil.enableClassExtend(ChartView, ['dispose']);
  158. clazzUtil.enableClassManagement(ChartView);
  159. function renderTaskPlan(context) {
  160. return renderPlanner(context.model);
  161. }
  162. function renderTaskReset(context) {
  163. var seriesModel = context.model;
  164. var ecModel = context.ecModel;
  165. var api = context.api;
  166. var payload = context.payload; // FIXME: remove updateView updateVisual
  167. var progressiveRender = seriesModel.pipelineContext.progressiveRender;
  168. var view = context.view;
  169. var updateMethod = payload && inner(payload).updateMethod;
  170. var methodName = progressiveRender ? 'incrementalPrepareRender' : updateMethod && view[updateMethod] ? updateMethod // `appendData` is also supported when data amount
  171. // is less than progressive threshold.
  172. : 'render';
  173. if (methodName !== 'render') {
  174. view[methodName](seriesModel, ecModel, api, payload);
  175. }
  176. return progressMethodMap[methodName];
  177. }
  178. var progressMethodMap = {
  179. incrementalPrepareRender: {
  180. progress: function (params, context) {
  181. context.view.incrementalRender(params, context.model, context.ecModel, context.api, context.payload);
  182. }
  183. },
  184. render: {
  185. // Put view.render in `progress` to support appendData. But in this case
  186. // view.render should not be called in reset, otherwise it will be called
  187. // twise. Use `forceFirstProgress` to make sure that view.render is called
  188. // in any cases.
  189. forceFirstProgress: true,
  190. progress: function (params, context) {
  191. context.view.render(context.model, context.ecModel, context.api, context.payload);
  192. }
  193. }
  194. };
  195. export default ChartView;