referHelper.js 6.4 KB

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