helper.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  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. export var DATA_ZOOM_AXIS_DIMENSIONS = ['x', 'y', 'radius', 'angle', 'single']; // Supported coords.
  42. // FIXME: polar has been broken (but rarely used).
  43. var SERIES_COORDS = ['cartesian2d', 'polar', 'singleAxis'];
  44. export function isCoordSupported(seriesModel) {
  45. var coordType = seriesModel.get('coordinateSystem');
  46. return indexOf(SERIES_COORDS, coordType) >= 0;
  47. }
  48. export function getAxisMainType(axisDim) {
  49. if (process.env.NODE_ENV !== 'production') {
  50. assert(axisDim);
  51. }
  52. return axisDim + 'Axis';
  53. }
  54. export function getAxisIndexPropName(axisDim) {
  55. if (process.env.NODE_ENV !== 'production') {
  56. assert(axisDim);
  57. }
  58. return axisDim + 'AxisIndex';
  59. }
  60. export function getAxisIdPropName(axisDim) {
  61. if (process.env.NODE_ENV !== 'production') {
  62. assert(axisDim);
  63. }
  64. return axisDim + 'AxisId';
  65. }
  66. /**
  67. * If two dataZoomModels has the same axis controlled, we say that they are 'linked'.
  68. * This function finds all linked dataZoomModels start from the given payload.
  69. */
  70. export function findEffectedDataZooms(ecModel, payload) {
  71. // Key: `DataZoomAxisDimension`
  72. var axisRecords = createHashMap();
  73. var effectedModels = []; // Key: uid of dataZoomModel
  74. var effectedModelMap = createHashMap(); // Find the dataZooms specified by payload.
  75. ecModel.eachComponent({
  76. mainType: 'dataZoom',
  77. query: payload
  78. }, function (dataZoomModel) {
  79. if (!effectedModelMap.get(dataZoomModel.uid)) {
  80. addToEffected(dataZoomModel);
  81. }
  82. }); // Start from the given dataZoomModels, travel the graph to find
  83. // all of the linked dataZoom models.
  84. var foundNewLink;
  85. do {
  86. foundNewLink = false;
  87. ecModel.eachComponent('dataZoom', processSingle);
  88. } while (foundNewLink);
  89. function processSingle(dataZoomModel) {
  90. if (!effectedModelMap.get(dataZoomModel.uid) && isLinked(dataZoomModel)) {
  91. addToEffected(dataZoomModel);
  92. foundNewLink = true;
  93. }
  94. }
  95. function addToEffected(dataZoom) {
  96. effectedModelMap.set(dataZoom.uid, true);
  97. effectedModels.push(dataZoom);
  98. markAxisControlled(dataZoom);
  99. }
  100. function isLinked(dataZoomModel) {
  101. var isLink = false;
  102. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  103. var axisIdxArr = axisRecords.get(axisDim);
  104. if (axisIdxArr && axisIdxArr[axisIndex]) {
  105. isLink = true;
  106. }
  107. });
  108. return isLink;
  109. }
  110. function markAxisControlled(dataZoomModel) {
  111. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  112. (axisRecords.get(axisDim) || axisRecords.set(axisDim, []))[axisIndex] = true;
  113. });
  114. }
  115. return effectedModels;
  116. }
  117. /**
  118. * Find the first target coordinate system.
  119. * Available after model built.
  120. *
  121. * @return Like {
  122. * grid: [
  123. * {model: coord0, axisModels: [axis1, axis3], coordIndex: 1},
  124. * {model: coord1, axisModels: [axis0, axis2], coordIndex: 0},
  125. * ...
  126. * ], // cartesians must not be null/undefined.
  127. * polar: [
  128. * {model: coord0, axisModels: [axis4], coordIndex: 0},
  129. * ...
  130. * ], // polars must not be null/undefined.
  131. * singleAxis: [
  132. * {model: coord0, axisModels: [], coordIndex: 0}
  133. * ]
  134. * }
  135. */
  136. export function collectReferCoordSysModelInfo(dataZoomModel) {
  137. var ecModel = dataZoomModel.ecModel;
  138. var coordSysInfoWrap = {
  139. infoList: [],
  140. infoMap: createHashMap()
  141. };
  142. dataZoomModel.eachTargetAxis(function (axisDim, axisIndex) {
  143. var axisModel = ecModel.getComponent(getAxisMainType(axisDim), axisIndex);
  144. if (!axisModel) {
  145. return;
  146. }
  147. var coordSysModel = axisModel.getCoordSysModel();
  148. if (!coordSysModel) {
  149. return;
  150. }
  151. var coordSysUid = coordSysModel.uid;
  152. var coordSysInfo = coordSysInfoWrap.infoMap.get(coordSysUid);
  153. if (!coordSysInfo) {
  154. coordSysInfo = {
  155. model: coordSysModel,
  156. axisModels: []
  157. };
  158. coordSysInfoWrap.infoList.push(coordSysInfo);
  159. coordSysInfoWrap.infoMap.set(coordSysUid, coordSysInfo);
  160. }
  161. coordSysInfo.axisModels.push(axisModel);
  162. });
  163. return coordSysInfoWrap;
  164. }