RadiusAxisView.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. var zrUtil = require("zrender/lib/core/util");
  2. var graphic = require("../../util/graphic");
  3. var AxisBuilder = require("./AxisBuilder");
  4. var AxisView = require("./AxisView");
  5. var axisBuilderAttrs = ['axisLine', 'axisTickLabel', 'axisName'];
  6. var selfBuilderAttrs = ['splitLine', 'splitArea'];
  7. var _default = AxisView.extend({
  8. type: 'radiusAxis',
  9. axisPointerClass: 'PolarAxisPointer',
  10. render: function (radiusAxisModel, ecModel) {
  11. this.group.removeAll();
  12. if (!radiusAxisModel.get('show')) {
  13. return;
  14. }
  15. var radiusAxis = radiusAxisModel.axis;
  16. var polar = radiusAxis.polar;
  17. var angleAxis = polar.getAngleAxis();
  18. var ticksCoords = radiusAxis.getTicksCoords();
  19. var axisAngle = angleAxis.getExtent()[0];
  20. var radiusExtent = radiusAxis.getExtent();
  21. var layout = layoutAxis(polar, radiusAxisModel, axisAngle);
  22. var axisBuilder = new AxisBuilder(radiusAxisModel, layout);
  23. zrUtil.each(axisBuilderAttrs, axisBuilder.add, axisBuilder);
  24. this.group.add(axisBuilder.getGroup());
  25. zrUtil.each(selfBuilderAttrs, function (name) {
  26. if (radiusAxisModel.get(name + '.show') && !radiusAxis.scale.isBlank()) {
  27. this['_' + name](radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords);
  28. }
  29. }, this);
  30. },
  31. /**
  32. * @private
  33. */
  34. _splitLine: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  35. var splitLineModel = radiusAxisModel.getModel('splitLine');
  36. var lineStyleModel = splitLineModel.getModel('lineStyle');
  37. var lineColors = lineStyleModel.get('color');
  38. var lineCount = 0;
  39. lineColors = lineColors instanceof Array ? lineColors : [lineColors];
  40. var splitLines = [];
  41. for (var i = 0; i < ticksCoords.length; i++) {
  42. var colorIndex = lineCount++ % lineColors.length;
  43. splitLines[colorIndex] = splitLines[colorIndex] || [];
  44. splitLines[colorIndex].push(new graphic.Circle({
  45. shape: {
  46. cx: polar.cx,
  47. cy: polar.cy,
  48. r: ticksCoords[i]
  49. },
  50. silent: true
  51. }));
  52. } // Simple optimization
  53. // Batching the lines if color are the same
  54. for (var i = 0; i < splitLines.length; i++) {
  55. this.group.add(graphic.mergePath(splitLines[i], {
  56. style: zrUtil.defaults({
  57. stroke: lineColors[i % lineColors.length],
  58. fill: null
  59. }, lineStyleModel.getLineStyle()),
  60. silent: true
  61. }));
  62. }
  63. },
  64. /**
  65. * @private
  66. */
  67. _splitArea: function (radiusAxisModel, polar, axisAngle, radiusExtent, ticksCoords) {
  68. var splitAreaModel = radiusAxisModel.getModel('splitArea');
  69. var areaStyleModel = splitAreaModel.getModel('areaStyle');
  70. var areaColors = areaStyleModel.get('color');
  71. var lineCount = 0;
  72. areaColors = areaColors instanceof Array ? areaColors : [areaColors];
  73. var splitAreas = [];
  74. var prevRadius = ticksCoords[0];
  75. for (var i = 1; i < ticksCoords.length; i++) {
  76. var colorIndex = lineCount++ % areaColors.length;
  77. splitAreas[colorIndex] = splitAreas[colorIndex] || [];
  78. splitAreas[colorIndex].push(new graphic.Sector({
  79. shape: {
  80. cx: polar.cx,
  81. cy: polar.cy,
  82. r0: prevRadius,
  83. r: ticksCoords[i],
  84. startAngle: 0,
  85. endAngle: Math.PI * 2
  86. },
  87. silent: true
  88. }));
  89. prevRadius = ticksCoords[i];
  90. } // Simple optimization
  91. // Batching the lines if color are the same
  92. for (var i = 0; i < splitAreas.length; i++) {
  93. this.group.add(graphic.mergePath(splitAreas[i], {
  94. style: zrUtil.defaults({
  95. fill: areaColors[i % areaColors.length]
  96. }, areaStyleModel.getAreaStyle()),
  97. silent: true
  98. }));
  99. }
  100. }
  101. });
  102. /**
  103. * @inner
  104. */
  105. function layoutAxis(polar, radiusAxisModel, axisAngle) {
  106. return {
  107. position: [polar.cx, polar.cy],
  108. rotation: axisAngle / 180 * Math.PI,
  109. labelDirection: -1,
  110. tickDirection: -1,
  111. nameDirection: 1,
  112. labelRotate: radiusAxisModel.getModel('axisLabel').get('rotate'),
  113. // Over splitLine and splitArea
  114. z2: 1
  115. };
  116. }
  117. module.exports = _default;