referHelper.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  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. /**
  41. * Helper for model references.
  42. * There are many manners to refer axis/coordSys.
  43. */
  44. // TODO
  45. // merge relevant logic to this file?
  46. // check: "modelHelper" of tooltip and "BrushTargetManager".
  47. import { createHashMap, retrieve, each } from 'zrender/lib/core/util.js';
  48. import { SINGLE_REFERRING } from '../util/model.js';
  49. /**
  50. * @class
  51. * For example:
  52. * {
  53. * coordSysName: 'cartesian2d',
  54. * coordSysDims: ['x', 'y', ...],
  55. * axisMap: HashMap({
  56. * x: xAxisModel,
  57. * y: yAxisModel
  58. * }),
  59. * categoryAxisMap: HashMap({
  60. * x: xAxisModel,
  61. * y: undefined
  62. * }),
  63. * // The index of the first category axis in `coordSysDims`.
  64. * // `null/undefined` means no category axis exists.
  65. * firstCategoryDimIndex: 1,
  66. * // To replace user specified encode.
  67. * }
  68. */
  69. var CoordSysInfo = /** @class */function () {
  70. function CoordSysInfo(coordSysName) {
  71. this.coordSysDims = [];
  72. this.axisMap = createHashMap();
  73. this.categoryAxisMap = createHashMap();
  74. this.coordSysName = coordSysName;
  75. }
  76. return CoordSysInfo;
  77. }();
  78. export function getCoordSysInfoBySeries(seriesModel) {
  79. var coordSysName = seriesModel.get('coordinateSystem');
  80. var result = new CoordSysInfo(coordSysName);
  81. var fetch = fetchers[coordSysName];
  82. if (fetch) {
  83. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  84. return result;
  85. }
  86. }
  87. // TODO: refactor them to static member of each coord sys, rather than hard code here.
  88. var fetchers = {
  89. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  90. var xAxisModel = seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  91. var yAxisModel = seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  92. if (process.env.NODE_ENV !== 'production') {
  93. if (!xAxisModel) {
  94. throw new Error('xAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('xAxisId'), 0) + '" not found');
  95. }
  96. if (!yAxisModel) {
  97. throw new Error('yAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('yAxisId'), 0) + '" not found');
  98. }
  99. }
  100. result.coordSysDims = ['x', 'y'];
  101. axisMap.set('x', xAxisModel);
  102. axisMap.set('y', yAxisModel);
  103. if (isCategory(xAxisModel)) {
  104. categoryAxisMap.set('x', xAxisModel);
  105. result.firstCategoryDimIndex = 0;
  106. }
  107. if (isCategory(yAxisModel)) {
  108. categoryAxisMap.set('y', yAxisModel);
  109. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  110. }
  111. },
  112. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  113. var singleAxisModel = seriesModel.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
  114. if (process.env.NODE_ENV !== 'production') {
  115. if (!singleAxisModel) {
  116. throw new Error('singleAxis should be specified.');
  117. }
  118. }
  119. result.coordSysDims = ['single'];
  120. axisMap.set('single', singleAxisModel);
  121. if (isCategory(singleAxisModel)) {
  122. categoryAxisMap.set('single', singleAxisModel);
  123. result.firstCategoryDimIndex = 0;
  124. }
  125. },
  126. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  127. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  128. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  129. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  130. if (process.env.NODE_ENV !== 'production') {
  131. if (!angleAxisModel) {
  132. throw new Error('angleAxis option not found');
  133. }
  134. if (!radiusAxisModel) {
  135. throw new Error('radiusAxis option not found');
  136. }
  137. }
  138. result.coordSysDims = ['radius', 'angle'];
  139. axisMap.set('radius', radiusAxisModel);
  140. axisMap.set('angle', angleAxisModel);
  141. if (isCategory(radiusAxisModel)) {
  142. categoryAxisMap.set('radius', radiusAxisModel);
  143. result.firstCategoryDimIndex = 0;
  144. }
  145. if (isCategory(angleAxisModel)) {
  146. categoryAxisMap.set('angle', angleAxisModel);
  147. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  148. }
  149. },
  150. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  151. result.coordSysDims = ['lng', 'lat'];
  152. },
  153. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  154. var ecModel = seriesModel.ecModel;
  155. var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  156. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  157. each(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  158. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  159. var axisDim = coordSysDims[index];
  160. axisMap.set(axisDim, axisModel);
  161. if (isCategory(axisModel)) {
  162. categoryAxisMap.set(axisDim, axisModel);
  163. if (result.firstCategoryDimIndex == null) {
  164. result.firstCategoryDimIndex = index;
  165. }
  166. }
  167. });
  168. },
  169. matrix: function (seriesModel, result, axisMap, categoryAxisMap) {
  170. var matrixModel = seriesModel.getReferringComponents('matrix', SINGLE_REFERRING).models[0];
  171. if (process.env.NODE_ENV !== 'production') {
  172. if (!matrixModel) {
  173. throw new Error('matrix coordinate system should be specified.');
  174. }
  175. }
  176. result.coordSysDims = ['x', 'y'];
  177. var xModel = matrixModel.getDimensionModel('x');
  178. var yModel = matrixModel.getDimensionModel('y');
  179. axisMap.set('x', xModel);
  180. axisMap.set('y', yModel);
  181. categoryAxisMap.set('x', xModel);
  182. categoryAxisMap.set('y', yModel);
  183. }
  184. };
  185. function isCategory(axisModel) {
  186. return axisModel.get('type') === 'category';
  187. }