RadiusAxisView.js 7.5 KB

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