polar_point.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /**
  2. * DevExtreme (viz/series/points/polar_point.js)
  3. * Version: 19.1.16
  4. * Build date: Tue Oct 18 2022
  5. *
  6. * Copyright (c) 2012 - 2022 Developer Express Inc. ALL RIGHTS RESERVED
  7. * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
  8. */
  9. "use strict";
  10. var extend = require("../../../core/utils/extend").extend;
  11. var _extend = extend;
  12. var symbolPoint = require("./symbol_point");
  13. var barPoint = require("./bar_point");
  14. var piePoint = require("./pie_point");
  15. var isDefined = require("../../../core/utils/type").isDefined;
  16. var vizUtils = require("../../core/utils");
  17. var normalizeAngle = vizUtils.normalizeAngle;
  18. var _math = Math;
  19. var _max = _math.max;
  20. var RADIAL_LABEL_INDENT = require("../../components/consts").radialLabelIndent;
  21. var ERROR_BARS_ANGLE_OFFSET = 90;
  22. var CANVAS_POSITION_END = "canvas_position_end";
  23. var CANVAS_POSITION_DEFAULT = "canvas_position_default";
  24. exports.polarSymbolPoint = _extend({}, symbolPoint, {
  25. _getLabelCoords: piePoint._getLabelCoords,
  26. _moveLabelOnCanvas: barPoint._moveLabelOnCanvas,
  27. _getLabelPosition: function() {
  28. return "outside"
  29. },
  30. _getCoords: function(argument, value) {
  31. var axis = this.series.getValueAxis();
  32. var startAngle = axis.getAngles()[0];
  33. var angle = this._getArgTranslator().translate(argument);
  34. var radius = this._getValTranslator().translate(value);
  35. var coords = vizUtils.convertPolarToXY(axis.getCenter(), axis.getAngles()[0], angle, radius);
  36. coords.angle = angle + startAngle - 90, coords.radius = radius;
  37. return coords
  38. },
  39. _translate: function() {
  40. var that = this;
  41. var center = that.series.getValueAxis().getCenter();
  42. var coord = that._getCoords(that.argument, that.value);
  43. that.vx = normalizeAngle(coord.angle);
  44. that.vy = that.radiusOuter = that.radiusLabels = coord.radius;
  45. that.radiusLabels += RADIAL_LABEL_INDENT;
  46. that.radius = coord.radius;
  47. that.middleAngle = -coord.angle;
  48. that.angle = -coord.angle;
  49. that.x = coord.x;
  50. that.y = coord.y;
  51. that.defaultX = that.centerX = center.x;
  52. that.defaultY = that.centerY = center.y;
  53. that._translateErrorBars();
  54. that.inVisibleArea = true
  55. },
  56. _translateErrorBars: function() {
  57. var that = this;
  58. var errorBars = that._options.errorBars;
  59. var translator = that._getValTranslator();
  60. if (!errorBars) {
  61. return
  62. }
  63. isDefined(that.lowError) && (that._lowErrorCoord = that.centerY - translator.translate(that.lowError));
  64. isDefined(that.highError) && (that._highErrorCoord = that.centerY - translator.translate(that.highError));
  65. that._errorBarPos = that.centerX;
  66. that._baseErrorBarPos = "stdDeviation" === errorBars.type ? that._lowErrorCoord + (that._highErrorCoord - that._lowErrorCoord) / 2 : that.centerY - that.radius
  67. },
  68. _getTranslates: function(animationEnabled) {
  69. return animationEnabled ? this.getDefaultCoords() : {
  70. x: this.x,
  71. y: this.y
  72. }
  73. },
  74. getDefaultCoords: function() {
  75. var cosSin = vizUtils.getCosAndSin(-this.angle);
  76. var radius = this._getValTranslator().translate(CANVAS_POSITION_DEFAULT);
  77. var x = this.defaultX + radius * cosSin.cos;
  78. var y = this.defaultY + radius * cosSin.sin;
  79. return {
  80. x: x,
  81. y: y
  82. }
  83. },
  84. _addLabelAlignmentAndOffset: function(label, coord) {
  85. return coord
  86. },
  87. _checkLabelPosition: function(label, coord) {
  88. var that = this;
  89. var visibleArea = that._getVisibleArea();
  90. var graphicBBox = that._getGraphicBBox();
  91. if (that._isPointInVisibleArea(visibleArea, graphicBBox)) {
  92. coord = that._moveLabelOnCanvas(coord, visibleArea, label.getBoundingRect())
  93. }
  94. return coord
  95. },
  96. _getErrorBarSettings: function(errorBarOptions, animationEnabled) {
  97. var settings = symbolPoint._getErrorBarSettings.call(this, errorBarOptions, animationEnabled);
  98. settings.rotate = ERROR_BARS_ANGLE_OFFSET - this.angle;
  99. settings.rotateX = this.centerX;
  100. settings.rotateY = this.centerY;
  101. return settings
  102. },
  103. getCoords: function(min) {
  104. return min ? this.getDefaultCoords() : {
  105. x: this.x,
  106. y: this.y
  107. }
  108. }
  109. });
  110. exports.polarBarPoint = _extend({}, barPoint, {
  111. _translateErrorBars: exports.polarSymbolPoint._translateErrorBars,
  112. _getErrorBarSettings: exports.polarSymbolPoint._getErrorBarSettings,
  113. _moveLabelOnCanvas: barPoint._moveLabelOnCanvas,
  114. _getLabelCoords: piePoint._getLabelCoords,
  115. _getLabelConnector: piePoint._getLabelConnector,
  116. getTooltipParams: piePoint.getTooltipParams,
  117. _getLabelPosition: piePoint._getLabelPosition,
  118. _getCoords: exports.polarSymbolPoint._getCoords,
  119. _translate: function() {
  120. var that = this;
  121. var translator = that._getValTranslator();
  122. var maxRadius = translator.translate(CANVAS_POSITION_END);
  123. that.radiusInner = translator.translate(that.minValue);
  124. exports.polarSymbolPoint._translate.call(that);
  125. if (null === that.radiusInner) {
  126. that.radiusInner = that.radius = maxRadius
  127. } else {
  128. if (null === that.radius) {
  129. this.radius = this.value >= 0 ? maxRadius : 0
  130. }
  131. }
  132. that.radiusOuter = that.radiusLabels = _max(that.radiusInner, that.radius);
  133. that.radiusLabels += RADIAL_LABEL_INDENT;
  134. that.radiusInner = that.defaultRadius = _math.min(that.radiusInner, that.radius);
  135. that.middleAngle = that.angle = -normalizeAngle(that.middleAngleCorrection - that.angle)
  136. },
  137. _getErrorBarBaseEdgeLength: function() {
  138. var coord = this.getMarkerCoords();
  139. return _math.PI * coord.outerRadius * _math.abs(coord.startAngle - coord.endAngle) / 180
  140. },
  141. getMarkerCoords: function() {
  142. return {
  143. x: this.centerX,
  144. y: this.centerY,
  145. outerRadius: this.radiusOuter,
  146. innerRadius: this.defaultRadius,
  147. startAngle: this.middleAngle - this.interval / 2,
  148. endAngle: this.middleAngle + this.interval / 2
  149. }
  150. },
  151. _drawMarker: function(renderer, group, animationEnabled) {
  152. var that = this;
  153. var styles = that._getStyle();
  154. var coords = that.getMarkerCoords();
  155. var innerRadius = coords.innerRadius;
  156. var outerRadius = coords.outerRadius;
  157. var start = that._getCoords(that.argument, CANVAS_POSITION_DEFAULT);
  158. var x = coords.x;
  159. var y = coords.y;
  160. if (animationEnabled) {
  161. innerRadius = 0;
  162. outerRadius = 0;
  163. x = start.x;
  164. y = start.y
  165. }
  166. that.graphic = renderer.arc(x, y, innerRadius, outerRadius, coords.startAngle, coords.endAngle).attr(styles).data({
  167. "chart-data-point": that
  168. }).append(group)
  169. },
  170. _checkLabelPosition: function(label, coord) {
  171. var that = this;
  172. var visibleArea = that._getVisibleArea();
  173. var angleFunctions = vizUtils.getCosAndSin(that.middleAngle);
  174. var x = that.centerX + that.defaultRadius * angleFunctions.cos;
  175. var y = that.centerY - that.defaultRadius * angleFunctions.sin;
  176. if (x > visibleArea.minX && x < visibleArea.maxX && y > visibleArea.minY && y < visibleArea.maxY) {
  177. coord = that._moveLabelOnCanvas(coord, visibleArea, label.getBoundingRect())
  178. }
  179. return coord
  180. },
  181. _addLabelAlignmentAndOffset: function(label, coord) {
  182. return coord
  183. },
  184. correctCoordinates: function(correctOptions) {
  185. this.middleAngleCorrection = correctOptions.offset;
  186. this.interval = correctOptions.width
  187. },
  188. coordsIn: function(x, y) {
  189. var val = vizUtils.convertXYToPolar(this.series.getValueAxis().getCenter(), x, y);
  190. var coords = this.getMarkerCoords();
  191. var isBetweenAngles = coords.startAngle < coords.endAngle ? -val.phi >= coords.startAngle && -val.phi <= coords.endAngle : -val.phi <= coords.startAngle && -val.phi >= coords.endAngle;
  192. return val.r >= coords.innerRadius && val.r <= coords.outerRadius && isBetweenAngles
  193. }
  194. });