polarCreator.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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(); // Reset scale
  74. angleAxis.scale.setExtent(Infinity, -Infinity);
  75. radiusAxis.scale.setExtent(Infinity, -Infinity);
  76. ecModel.eachSeries(function (seriesModel) {
  77. if (seriesModel.coordinateSystem === polar) {
  78. var data_1 = seriesModel.getData();
  79. zrUtil.each(getDataDimensionsOnAxis(data_1, 'radius'), function (dim) {
  80. radiusAxis.scale.unionExtentFromData(data_1, dim);
  81. });
  82. zrUtil.each(getDataDimensionsOnAxis(data_1, 'angle'), function (dim) {
  83. angleAxis.scale.unionExtentFromData(data_1, dim);
  84. });
  85. }
  86. });
  87. niceScaleExtent(angleAxis.scale, angleAxis.model);
  88. niceScaleExtent(radiusAxis.scale, radiusAxis.model); // Fix extent of category angle axis
  89. if (angleAxis.type === 'category' && !angleAxis.onBand) {
  90. var extent = angleAxis.getExtent();
  91. var diff = 360 / angleAxis.scale.count();
  92. angleAxis.inverse ? extent[1] += diff : extent[1] -= diff;
  93. angleAxis.setExtent(extent[0], extent[1]);
  94. }
  95. }
  96. function isAngleAxisModel(axisModel) {
  97. return axisModel.mainType === 'angleAxis';
  98. }
  99. /**
  100. * Set common axis properties
  101. */
  102. function setAxis(axis, axisModel) {
  103. axis.type = axisModel.get('type');
  104. axis.scale = createScaleByModel(axisModel);
  105. axis.onBand = axisModel.get('boundaryGap') && axis.type === 'category';
  106. axis.inverse = axisModel.get('inverse');
  107. if (isAngleAxisModel(axisModel)) {
  108. axis.inverse = axis.inverse !== axisModel.get('clockwise');
  109. var startAngle = axisModel.get('startAngle');
  110. axis.setExtent(startAngle, startAngle + (axis.inverse ? -360 : 360));
  111. } // Inject axis instance
  112. axisModel.axis = axis;
  113. axis.model = axisModel;
  114. }
  115. var polarCreator = {
  116. dimensions: polarDimensions,
  117. create: function (ecModel, api) {
  118. var polarList = [];
  119. ecModel.eachComponent('polar', function (polarModel, idx) {
  120. var polar = new Polar(idx + ''); // Inject resize and update method
  121. polar.update = updatePolarScale;
  122. var radiusAxis = polar.getRadiusAxis();
  123. var angleAxis = polar.getAngleAxis();
  124. var radiusAxisModel = polarModel.findAxisModel('radiusAxis');
  125. var angleAxisModel = polarModel.findAxisModel('angleAxis');
  126. setAxis(radiusAxis, radiusAxisModel);
  127. setAxis(angleAxis, angleAxisModel);
  128. resizePolar(polar, polarModel, api);
  129. polarList.push(polar);
  130. polarModel.coordinateSystem = polar;
  131. polar.model = polarModel;
  132. }); // Inject coordinateSystem to series
  133. ecModel.eachSeries(function (seriesModel) {
  134. if (seriesModel.get('coordinateSystem') === 'polar') {
  135. var polarModel = seriesModel.getReferringComponents('polar', SINGLE_REFERRING).models[0];
  136. if (process.env.NODE_ENV !== 'production') {
  137. if (!polarModel) {
  138. throw new Error('Polar "' + zrUtil.retrieve(seriesModel.get('polarIndex'), seriesModel.get('polarId'), 0) + '" not found');
  139. }
  140. }
  141. seriesModel.coordinateSystem = polarModel.coordinateSystem;
  142. }
  143. });
  144. return polarList;
  145. }
  146. };
  147. export default polarCreator;