polarCreator.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. // TODO Axis scale
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import Polar, { polarDimensions } from './Polar.js';
  43. import { parsePercent } from '../../util/number.js';
  44. import { createScaleByModel, niceScaleExtent, getDataDimensionsOnAxis } from '../../coord/axisHelper.js';
  45. import { SINGLE_REFERRING } from '../../util/model.js';
  46. /**
  47. * Resize method bound to the polar
  48. */
  49. function resizePolar(polar, polarModel, api) {
  50. var center = polarModel.get('center');
  51. var width = api.getWidth();
  52. var height = api.getHeight();
  53. polar.cx = parsePercent(center[0], width);
  54. polar.cy = parsePercent(center[1], height);
  55. var radiusAxis = polar.getRadiusAxis();
  56. var size = Math.min(width, height) / 2;
  57. var radius = polarModel.get('radius');
  58. if (radius == null) {
  59. radius = [0, '100%'];
  60. } else if (!zrUtil.isArray(radius)) {
  61. // r0 = 0
  62. radius = [0, radius];
  63. }
  64. var parsedRadius = [parsePercent(radius[0], size), parsePercent(radius[1], size)];
  65. radiusAxis.inverse ? radiusAxis.setExtent(parsedRadius[1], parsedRadius[0]) : radiusAxis.setExtent(parsedRadius[0], parsedRadius[1]);
  66. }
  67. /**
  68. * Update polar
  69. */
  70. function updatePolarScale(ecModel, api) {
  71. var polar = this;
  72. var angleAxis = polar.getAngleAxis();
  73. var radiusAxis = polar.getRadiusAxis();
  74. // Reset scale
  75. angleAxis.scale.setExtent(Infinity, -Infinity);
  76. radiusAxis.scale.setExtent(Infinity, -Infinity);
  77. ecModel.eachSeries(function (seriesModel) {
  78. if (seriesModel.coordinateSystem === polar) {
  79. var data_1 = seriesModel.getData();
  80. zrUtil.each(getDataDimensionsOnAxis(data_1, 'radius'), function (dim) {
  81. radiusAxis.scale.unionExtentFromData(data_1, dim);
  82. });
  83. zrUtil.each(getDataDimensionsOnAxis(data_1, 'angle'), function (dim) {
  84. angleAxis.scale.unionExtentFromData(data_1, dim);
  85. });
  86. }
  87. });
  88. niceScaleExtent(angleAxis.scale, angleAxis.model);
  89. niceScaleExtent(radiusAxis.scale, radiusAxis.model);
  90. // Fix extent of category angle axis
  91. if (angleAxis.type === 'category' && !angleAxis.onBand) {
  92. var extent = angleAxis.getExtent();
  93. var diff = 360 / angleAxis.scale.count();
  94. angleAxis.inverse ? extent[1] += diff : extent[1] -= diff;
  95. angleAxis.setExtent(extent[0], extent[1]);
  96. }
  97. }
  98. function isAngleAxisModel(axisModel) {
  99. return axisModel.mainType === 'angleAxis';
  100. }
  101. /**
  102. * Set common axis properties
  103. */
  104. function setAxis(axis, axisModel) {
  105. var _a;
  106. axis.type = axisModel.get('type');
  107. axis.scale = createScaleByModel(axisModel);
  108. axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
  109. axis.inverse = axisModel.get('inverse');
  110. if (isAngleAxisModel(axisModel)) {
  111. axis.inverse = axis.inverse !== axisModel.get('clockwise');
  112. var startAngle = axisModel.get('startAngle');
  113. var endAngle = (_a = axisModel.get('endAngle')) !== null && _a !== void 0 ? _a : startAngle + (axis.inverse ? -360 : 360);
  114. axis.setExtent(startAngle, endAngle);
  115. }
  116. // Inject axis instance
  117. axisModel.axis = axis;
  118. axis.model = axisModel;
  119. }
  120. var polarCreator = {
  121. dimensions: polarDimensions,
  122. create: function (ecModel, api) {
  123. var polarList = [];
  124. ecModel.eachComponent('polar', function (polarModel, idx) {
  125. var polar = new Polar(idx + '');
  126. // Inject resize and update method
  127. polar.update = updatePolarScale;
  128. var radiusAxis = polar.getRadiusAxis();
  129. var angleAxis = polar.getAngleAxis();
  130. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  131. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  132. setAxis(radiusAxis, radiusAxisModel);
  133. setAxis(angleAxis, angleAxisModel);
  134. resizePolar(polar, polarModel, api);
  135. polarList.push(polar);
  136. polarModel.coordinateSystem = polar;
  137. polar.model = polarModel;
  138. });
  139. // Inject coordinateSystem to series
  140. ecModel.eachSeries(function (seriesModel) {
  141. if (seriesModel.get('coordinateSystem') === 'polar') {
  142. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  143. if (process.env.NODE_ENV !== 'production') {
  144. if (!polarModel) {
  145. throw new Error('Polar "' + zrUtil.retrieve(seriesModel.get('polarIndex'), seriesModel.get('polarId'), 0) + '" not found');
  146. }
  147. }
  148. seriesModel.coordinateSystem = polarModel.coordinateSystem;
  149. }
  150. });
  151. return polarList;
  152. }
  153. };
  154. export default polarCreator;