RadiusAxisView.js 7.1 KB

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