RadiusAxisView.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  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. import { __extends } from "tslib";
  41. import * as zrUtil from 'zrender/lib/core/util.js';
  42. import * as graphic from '../../util/graphic.js';
  43. import AxisBuilder from './AxisBuilder.js';
  44. import AxisView from './AxisView.js';
  45. var selfBuilderAttrs = ['splitLine', 'splitArea', 'minorSplitLine'];
  46. var RadiusAxisView = /** @class */function (_super) {
  47. __extends(RadiusAxisView, _super);
  48. function RadiusAxisView() {
  49. var _this = _super !== null && _super.apply(this, arguments) || this;
  50. _this.type = RadiusAxisView.type;
  51. _this.axisPointerClass = 'PolarAxisPointer';
  52. return _this;
  53. }
  54. RadiusAxisView.prototype.render = function (radiusAxisModel, ecModel, api) {
  55. this.group.removeAll();
  56. if (!radiusAxisModel.get('show')) {
  57. return;
  58. }
  59. var oldAxisGroup = this._axisGroup;
  60. var newAxisGroup = this._axisGroup = new graphic.Group();
  61. this.group.add(newAxisGroup);
  62. var radiusAxis = radiusAxisModel.axis;
  63. var polar = radiusAxis.polar;
  64. var angleAxis = polar.getAngleAxis();
  65. var ticksCoords = radiusAxis.getTicksCoords();
  66. var minorTicksCoords = radiusAxis.getMinorTicksCoords();
  67. var axisAngle = angleAxis.getExtent()[0];
  68. var radiusExtent = radiusAxis.getExtent();
  69. var layout = layoutAxis(polar, radiusAxisModel, axisAngle);
  70. var axisBuilder = new AxisBuilder(radiusAxisModel, api, layout);
  71. axisBuilder.build();
  72. newAxisGroup.add(axisBuilder.group);
  73. graphic.groupTransition(oldAxisGroup, newAxisGroup, radiusAxisModel);
  74. zrUtil.each(selfBuilderAttrs, function (name) {
  75. if (radiusAxisModel.get([name, 'show']) && !radiusAxis.scale.isBlank()) {
  76. axisElementBuilders[name](this.group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords, minorTicksCoords);
  77. }
  78. }, this);
  79. };
  80. RadiusAxisView.type = 'radiusAxis';
  81. return RadiusAxisView;
  82. }(AxisView);
  83. var axisElementBuilders = {
  84. splitLine: function (group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  85. var splitLineModel = radiusAxisModel.getModel('splitLine');
  86. var lineStyleModel = splitLineModel.getModel('lineStyle');
  87. var lineColors = lineStyleModel.get('color');
  88. var lineCount = 0;
  89. var angleAxis = polar.getAngleAxis();
  90. var RADIAN = Math.PI / 180;
  91. var angleExtent = angleAxis.getExtent();
  92. var shapeType = Math.abs(angleExtent[1] - angleExtent[0]) === 360 ? 'Circle' : 'Arc';
  93. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  94. var splitLines = [];
  95. for (var i = 0; i < ticksCoords.length; i++) {
  96. var colorIndex = lineCount++ % lineColors.length;
  97. splitLines[colorIndex] = splitLines[colorIndex] || [];
  98. splitLines[colorIndex].push(new graphic[shapeType]({
  99. shape: {
  100. cx: polar.cx,
  101. cy: polar.cy,
  102. // ensure circle radius >= 0
  103. r: Math.max(ticksCoords[i].coord, 0),
  104. startAngle: -angleExtent[0] * RADIAN,
  105. endAngle: -angleExtent[1] * RADIAN,
  106. clockwise: angleAxis.inverse
  107. }
  108. }));
  109. }
  110. // Simple optimization
  111. // Batching the lines if color are the same
  112. for (var i = 0; i < splitLines.length; i++) {
  113. group.add(graphic.mergePath(splitLines[i], {
  114. style: zrUtil.defaults({
  115. stroke: lineColors[i % lineColors.length],
  116. fill: null
  117. }, lineStyleModel.getLineStyle()),
  118. silent: true
  119. }));
  120. }
  121. },
  122. minorSplitLine: function (group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords, minorTicksCoords) {
  123. if (!minorTicksCoords.length) {
  124. return;
  125. }
  126. var minorSplitLineModel = radiusAxisModel.getModel('minorSplitLine');
  127. var lineStyleModel = minorSplitLineModel.getModel('lineStyle');
  128. var lines = [];
  129. for (var i = 0; i < minorTicksCoords.length; i++) {
  130. for (var k = 0; k < minorTicksCoords[i].length; k++) {
  131. lines.push(new graphic.Circle({
  132. shape: {
  133. cx: polar.cx,
  134. cy: polar.cy,
  135. r: minorTicksCoords[i][k].coord
  136. }
  137. }));
  138. }
  139. }
  140. group.add(graphic.mergePath(lines, {
  141. style: zrUtil.defaults({
  142. fill: null
  143. }, lineStyleModel.getLineStyle()),
  144. silent: true
  145. }));
  146. },
  147. splitArea: function (group, radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  148. if (!ticksCoords.length) {
  149. return;
  150. }
  151. var splitAreaModel = radiusAxisModel.getModel('splitArea');
  152. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  153. var areaColors = areaStyleModel.get('color');
  154. var lineCount = 0;
  155. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  156. var splitAreas = [];
  157. var prevRadius = ticksCoords[0].coord;
  158. for (var i = 1; i < ticksCoords.length; i++) {
  159. var colorIndex = lineCount++ % areaColors.length;
  160. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  161. splitAreas[colorIndex].push(new graphic.Sector({
  162. shape: {
  163. cx: polar.cx,
  164. cy: polar.cy,
  165. r0: prevRadius,
  166. r: ticksCoords[i].coord,
  167. startAngle: 0,
  168. endAngle: Math.PI * 2
  169. },
  170. silent: true
  171. }));
  172. prevRadius = ticksCoords[i].coord;
  173. }
  174. // Simple optimization
  175. // Batching the lines if color are the same
  176. for (var i = 0; i < splitAreas.length; i++) {
  177. group.add(graphic.mergePath(splitAreas[i], {
  178. style: zrUtil.defaults({
  179. fill: areaColors[i % areaColors.length]
  180. }, areaStyleModel.getAreaStyle()),
  181. silent: true
  182. }));
  183. }
  184. }
  185. };
  186. /**
  187. * @inner
  188. */
  189. function layoutAxis(polar, radiusAxisModel, axisAngle) {
  190. return {
  191. position: [polar.cx, polar.cy],
  192. rotation: axisAngle / 180 * Math.PI,
  193. labelDirection: -1,
  194. tickDirection: -1,
  195. nameDirection: 1,
  196. labelRotate: radiusAxisModel.getModel('axisLabel').get('rotate'),
  197. // Over splitLine and splitArea
  198. z2: 1
  199. };
  200. }
  201. export default RadiusAxisView;