helper.js 5.8 KB

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