referHelper.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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 =
  70. /** @class */
  71. function () {
  72. function CoordSysInfo(coordSysName) {
  73. this.coordSysDims = [];
  74. this.axisMap = createHashMap();
  75. this.categoryAxisMap = createHashMap();
  76. this.coordSysName = coordSysName;
  77. }
  78. return CoordSysInfo;
  79. }();
  80. export function getCoordSysInfoBySeries(seriesModel) {
  81. var coordSysName = seriesModel.get('coordinateSystem');
  82. var result = new CoordSysInfo(coordSysName);
  83. var fetch = fetchers[coordSysName];
  84. if (fetch) {
  85. fetch(seriesModel, result, result.axisMap, result.categoryAxisMap);
  86. return result;
  87. }
  88. }
  89. var fetchers = {
  90. cartesian2d: function (seriesModel, result, axisMap, categoryAxisMap) {
  91. var xAxisModel = seriesModel.getReferringComponents('xAxis', SINGLE_REFERRING).models[0];
  92. var yAxisModel = seriesModel.getReferringComponents('yAxis', SINGLE_REFERRING).models[0];
  93. if (process.env.NODE_ENV !== 'production') {
  94. if (!xAxisModel) {
  95. throw new Error('xAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('xAxisId'), 0) + '" not found');
  96. }
  97. if (!yAxisModel) {
  98. throw new Error('yAxis "' + retrieve(seriesModel.get('xAxisIndex'), seriesModel.get('yAxisId'), 0) + '" not found');
  99. }
  100. }
  101. result.coordSysDims = ['x', 'y'];
  102. axisMap.set('x', xAxisModel);
  103. axisMap.set('y', yAxisModel);
  104. if (isCategory(xAxisModel)) {
  105. categoryAxisMap.set('x', xAxisModel);
  106. result.firstCategoryDimIndex = 0;
  107. }
  108. if (isCategory(yAxisModel)) {
  109. categoryAxisMap.set('y', yAxisModel);
  110. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  111. }
  112. },
  113. singleAxis: function (seriesModel, result, axisMap, categoryAxisMap) {
  114. var singleAxisModel = seriesModel.getReferringComponents('singleAxis', SINGLE_REFERRING).models[0];
  115. if (process.env.NODE_ENV !== 'production') {
  116. if (!singleAxisModel) {
  117. throw new Error('singleAxis should be specified.');
  118. }
  119. }
  120. result.coordSysDims = ['single'];
  121. axisMap.set('single', singleAxisModel);
  122. if (isCategory(singleAxisModel)) {
  123. categoryAxisMap.set('single', singleAxisModel);
  124. result.firstCategoryDimIndex = 0;
  125. }
  126. },
  127. polar: function (seriesModel, result, axisMap, categoryAxisMap) {
  128. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  129. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  130. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  131. if (process.env.NODE_ENV !== 'production') {
  132. if (!angleAxisModel) {
  133. throw new Error('angleAxis option not found');
  134. }
  135. if (!radiusAxisModel) {
  136. throw new Error('radiusAxis option not found');
  137. }
  138. }
  139. result.coordSysDims = ['radius', 'angle'];
  140. axisMap.set('radius', radiusAxisModel);
  141. axisMap.set('angle', angleAxisModel);
  142. if (isCategory(radiusAxisModel)) {
  143. categoryAxisMap.set('radius', radiusAxisModel);
  144. result.firstCategoryDimIndex = 0;
  145. }
  146. if (isCategory(angleAxisModel)) {
  147. categoryAxisMap.set('angle', angleAxisModel);
  148. result.firstCategoryDimIndex == null && (result.firstCategoryDimIndex = 1);
  149. }
  150. },
  151. geo: function (seriesModel, result, axisMap, categoryAxisMap) {
  152. result.coordSysDims = ['lng', 'lat'];
  153. },
  154. parallel: function (seriesModel, result, axisMap, categoryAxisMap) {
  155. var ecModel = seriesModel.ecModel;
  156. var parallelModel = ecModel.getComponent('parallel', seriesModel.get('parallelIndex'));
  157. var coordSysDims = result.coordSysDims = parallelModel.dimensions.slice();
  158. each(parallelModel.parallelAxisIndex, function (axisIndex, index) {
  159. var axisModel = ecModel.getComponent('parallelAxis', axisIndex);
  160. var axisDim = coordSysDims[index];
  161. axisMap.set(axisDim, axisModel);
  162. if (isCategory(axisModel)) {
  163. categoryAxisMap.set(axisDim, axisModel);
  164. if (result.firstCategoryDimIndex == null) {
  165. result.firstCategoryDimIndex = index;
  166. }
  167. }
  168. });
  169. }
  170. };
  171. function isCategory(axisModel) {
  172. return axisModel.get('type') === 'category';
  173. }