helper.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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 { indexOf, createHashMap, assert } from 'zrender/lib/core/util.js';
  41. import { makeInner } from '../../util/model.js';
  42. import { getCachePerECPrepare } from '../../util/cycleCache.js';
  43. export var DATA_ZOOM_AXIS_DIMENSIONS = ['x', 'y', 'radius', 'angle', 'single'];
  44. var ecModelCacheInner = makeInner();
  45. // Supported coords.
  46. // FIXME: polar has been broken (but rarely used).
  47. var SERIES_COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  48. export function isCoordSupported(seriesModel) {
  49. var coordType = seriesModel.get('coordinateSystem');
  50. return indexOf(SERIES_COORDS, coordType) >= 0;
  51. }
  52. export function getAxisMainType(axisDim) {
  53. if (process.env.NODE_ENV !== 'production') {
  54. assert(axisDim);
  55. }
  56. return axisDim + 'Axis';
  57. }
  58. export function getAxisIndexPropName(axisDim) {
  59. if (process.env.NODE_ENV !== 'production') {
  60. assert(axisDim);
  61. }
  62. return axisDim + 'AxisIndex';
  63. }
  64. export function getAxisIdPropName(axisDim) {
  65. if (process.env.NODE_ENV !== 'production') {
  66. assert(axisDim);
  67. }
  68. return axisDim + 'AxisId';
  69. }
  70. /**
  71. * If two dataZoomModels has the same axis controlled, we say that they are 'linked'.
  72. * This function finds all linked dataZoomModels start from the given payload.
  73. */
  74. export function findEffectedDataZooms(ecModel, payload) {
  75. // Key: `DataZoomAxisDimension`
  76. var axisRecords = createHashMap();
  77. var effectedModels = [];
  78. // Key: uid of dataZoomModel
  79. var effectedModelMap = createHashMap();
  80. // Find the dataZooms specified by payload.
  81. ecModel.eachComponent({
  82. mainType: 'dataZoom',
  83. query: payload
  84. }, function (dataZoomModel) {
  85. if (!effectedModelMap.get(dataZoomModel.uid)) {
  86. addToEffected(dataZoomModel);
  87. }
  88. });
  89. // Start from the given dataZoomModels, travel the graph to find
  90. // all of the linked dataZoom models.
  91. var foundNewLink;
  92. do {
  93. foundNewLink = false;
  94. ecModel.eachComponent('dataZoom', processSingle);
  95. } while (foundNewLink);
  96. function processSingle(dataZoomModel) {
  97. if (!effectedModelMap.get(dataZoomModel.uid) && isLinked(dataZoomModel)) {
  98. addToEffected(dataZoomModel);
  99. foundNewLink = true;
  100. }
  101. }
  102. function addToEffected(dataZoom) {
  103. effectedModelMap.set(dataZoom.uid, true);
  104. effectedModels.push(dataZoom);
  105. markAxisControlled(dataZoom);
  106. }
  107. function isLinked(dataZoomModel) {
  108. var isLink = false;
  109. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  110. var axisIdxArr = axisRecords.get(axisDim);
  111. if (axisIdxArr && axisIdxArr[axisIndex]) {
  112. isLink = true;
  113. }
  114. });
  115. return isLink;
  116. }
  117. function markAxisControlled(dataZoomModel) {
  118. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  119. (axisRecords.get(axisDim) || axisRecords.set(axisDim, []))[axisIndex] = true;
  120. });
  121. }
  122. return effectedModels;
  123. }
  124. /**
  125. * Find the first target coordinate system.
  126. * Available after model built.
  127. *
  128. * @return Like {
  129. * grid: [
  130. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  131. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  132. * ...
  133. * ], // cartesians must not be null/undefined.
  134. * polar: [
  135. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  136. * ...
  137. * ], // polars must not be null/undefined.
  138. * singleAxis: [
  139. * {model: coord0, axisModels: [], coordIndex: 0}
  140. * ]
  141. * }
  142. */
  143. export function collectReferCoordSysModelInfo(dataZoomModel) {
  144. var ecModel = dataZoomModel.ecModel;
  145. var coordSysInfoWrap = {
  146. infoList: [],
  147. infoMap: createHashMap()
  148. };
  149. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  150. var axisModel = ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  151. if (!axisModel) {
  152. return;
  153. }
  154. var coordSysModel = axisModel.getCoordSysModel();
  155. if (!coordSysModel) {
  156. return;
  157. }
  158. var coordSysUid = coordSysModel.uid;
  159. var coordSysInfo = coordSysInfoWrap.infoMap.get(coordSysUid);
  160. if (!coordSysInfo) {
  161. coordSysInfo = {
  162. model: coordSysModel,
  163. axisModels: []
  164. };
  165. coordSysInfoWrap.infoList.push(coordSysInfo);
  166. coordSysInfoWrap.infoMap.set(coordSysUid, coordSysInfo);
  167. }
  168. coordSysInfo.axisModels.push(axisModel);
  169. });
  170. return coordSysInfoWrap;
  171. }
  172. function ensureAxisProxyMap(ecModel) {
  173. // Consider some axes may be deleted, and dataZoom options may be changed at and only at each run of
  174. // "ec prepare", we save axis proxies to a cache that is auto-cleared for each run of "ec prepare".
  175. var store = ecModelCacheInner(getCachePerECPrepare(ecModel));
  176. return store.axisProxyMap || (store.axisProxyMap = createHashMap());
  177. }
  178. export function getAxisProxyFromModel(axisModel) {
  179. if (!axisModel) {
  180. return;
  181. }
  182. if (process.env.NODE_ENV !== 'production') {
  183. assert(axisModel.ecModel);
  184. }
  185. return ensureAxisProxyMap(axisModel.ecModel).get(axisModel.uid);
  186. }
  187. export function setAxisProxyToModel(axisModel, axisProxy) {
  188. if (process.env.NODE_ENV !== 'production') {
  189. assert(axisModel.ecModel);
  190. }
  191. ensureAxisProxyMap(axisModel.ecModel).set(axisModel.uid, axisProxy);
  192. }
  193. /**
  194. * NOTICE: If `axis_a` aligns to `axis_b`, but they are not controlled by
  195. * the same `dataZoom`, do not consider `axis_b` as `alignTo` and
  196. * then do not input it into `AxisProxy#reset`.
  197. */
  198. export function getAlignTo(dataZoomModel, axisProxy) {
  199. var alignToAxis = axisProxy.getAxisModel().axis.__alignTo;
  200. return alignToAxis && dataZoomModel.getAxisProxy(alignToAxis.dim, alignToAxis.model.componentIndex) ? getAxisProxyFromModel(alignToAxis.model) : null;
  201. }