polar_axes.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /**
  2. * DevExtreme (viz/axes/polar_axes.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 vizUtils = require("../core/utils");
  11. var isDefined = require("../../core/utils/type").isDefined;
  12. var extend = require("../../core/utils/extend").extend;
  13. var constants = require("./axes_constants");
  14. var xyAxesLinear = require("./xy_axes").linear;
  15. var tick = require("./tick").tick;
  16. var _map = vizUtils.map;
  17. var baseAxisModule = require("./base_axis");
  18. var _math = Math;
  19. var _abs = _math.abs;
  20. var _round = _math.round;
  21. var convertPolarToXY = vizUtils.convertPolarToXY;
  22. var _extend = extend;
  23. var _noop = require("../../core/utils/common").noop;
  24. var HALF_PI_ANGLE = 90;
  25. function getPolarQuarter(angle) {
  26. var quarter;
  27. angle = vizUtils.normalizeAngle(angle);
  28. if (angle >= 315 && angle <= 360 || angle < 45 && angle >= 0) {
  29. quarter = 1
  30. } else {
  31. if (angle >= 45 && angle < 135) {
  32. quarter = 2
  33. } else {
  34. if (angle >= 135 && angle < 225) {
  35. quarter = 3
  36. } else {
  37. if (angle >= 225 && angle < 315) {
  38. quarter = 4
  39. }
  40. }
  41. }
  42. }
  43. return quarter
  44. }
  45. var polarAxes = exports;
  46. var circularAxes = polarAxes.circular = {
  47. _calculateValueMargins: function(ticks) {
  48. var _this$_getViewportRan = this._getViewportRange(),
  49. minVisible = _this$_getViewportRan.minVisible,
  50. maxVisible = _this$_getViewportRan.maxVisible;
  51. if (ticks && ticks.length > 1) {
  52. minVisible = minVisible < ticks[0].value ? minVisible : ticks[0].value;
  53. maxVisible = minVisible > ticks[ticks.length - 1].value ? maxVisible : ticks[ticks.length - 1].value
  54. }
  55. return {
  56. minValue: minVisible,
  57. maxValue: maxVisible
  58. }
  59. },
  60. applyMargins: function() {
  61. var margins = this._calculateValueMargins(this._majorTicks);
  62. var br = this._translator.getBusinessRange();
  63. br.addRange({
  64. minVisible: margins.minValue,
  65. maxVisible: margins.maxValue,
  66. interval: this._calculateRangeInterval(br.interval)
  67. });
  68. this._translator.updateBusinessRange(br)
  69. },
  70. _getTranslatorOptions: function() {
  71. return {
  72. isHorizontal: true,
  73. conversionValue: true,
  74. addSpiderCategory: this._getSpiderCategoryOption(),
  75. stick: this._getStick()
  76. }
  77. },
  78. getCenter: function() {
  79. return this._center
  80. },
  81. getRadius: function() {
  82. return this._radius
  83. },
  84. getAngles: function() {
  85. var options = this._options;
  86. return [options.startAngle, options.endAngle]
  87. },
  88. _updateRadius: function(canvas) {
  89. var rad = Math.min(canvas.width - canvas.left - canvas.right, canvas.height - canvas.top - canvas.bottom) / 2;
  90. this._radius = rad < 0 ? 0 : rad
  91. },
  92. _updateCenter: function(canvas) {
  93. this._center = {
  94. x: canvas.left + (canvas.width - canvas.right - canvas.left) / 2,
  95. y: canvas.top + (canvas.height - canvas.top - canvas.bottom) / 2
  96. }
  97. },
  98. _processCanvas: function(canvas) {
  99. this._updateRadius(canvas);
  100. this._updateCenter(canvas);
  101. return {
  102. left: 0,
  103. right: 0,
  104. width: this._getScreenDelta()
  105. }
  106. },
  107. _createAxisElement: function() {
  108. return this._renderer.circle()
  109. },
  110. _updateAxisElementPosition: function() {
  111. var center = this.getCenter();
  112. this._axisElement.attr({
  113. cx: center.x,
  114. cy: center.y,
  115. r: this.getRadius()
  116. })
  117. },
  118. _boundaryTicksVisibility: {
  119. min: true
  120. },
  121. _getSpiderCategoryOption: function() {
  122. return this._options.firstPointOnStartAngle
  123. },
  124. _validateOptions: function(options) {
  125. var that = this;
  126. var originValue = options.originValue;
  127. var wholeRange = options.wholeRange = {};
  128. var period = options.period;
  129. if (isDefined(originValue)) {
  130. originValue = that.validateUnit(originValue)
  131. }
  132. if (period > 0 && options.argumentType === constants.numeric) {
  133. originValue = originValue || 0;
  134. wholeRange.endValue = originValue + period;
  135. that._viewport = vizUtils.getVizRangeObject([originValue, wholeRange.endValue])
  136. }
  137. if (isDefined(originValue)) {
  138. wholeRange.startValue = originValue
  139. }
  140. },
  141. getMargins: function() {
  142. var tickOptions = this._options.tick;
  143. var tickOuterLength = Math.max(tickOptions.visible ? tickOptions.length / 2 + tickOptions.shift : 0, 0);
  144. var radius = this.getRadius();
  145. var _this$_center = this._center,
  146. x = _this$_center.x,
  147. y = _this$_center.y;
  148. var labelBoxes = this._majorTicks.map(function(t) {
  149. return t.label && t.label.getBBox()
  150. }).filter(function(b) {
  151. return b
  152. });
  153. var canvas = extend({}, this._canvas, {
  154. left: x - radius,
  155. top: y - radius,
  156. right: this._canvas.width - (x + radius),
  157. bottom: this._canvas.height - (y + radius)
  158. });
  159. var margins = baseAxisModule.calculateCanvasMargins(labelBoxes, canvas);
  160. Object.keys(margins).forEach(function(k) {
  161. return margins[k] = margins[k] < tickOuterLength ? tickOuterLength : margins[k]
  162. });
  163. return margins
  164. },
  165. updateSize: function() {
  166. var that = this;
  167. baseAxisModule.Axis.prototype.updateSize.apply(that, arguments);
  168. baseAxisModule.measureLabels(that._majorTicks);
  169. that._adjustLabelsCoord(0, 0, true);
  170. this._checkBoundedLabelsOverlapping(this._majorTicks, this._majorTicks.map(function(t) {
  171. return t.labelBBox
  172. }))
  173. },
  174. _setVisualRange: _noop,
  175. allowToExtendVisualRange: function(isEnd) {
  176. return true
  177. },
  178. _getStick: function() {
  179. return this._options.firstPointOnStartAngle || this._options.type !== constants.discrete
  180. },
  181. _getTranslatedCoord: function(value, offset) {
  182. return this._translator.translate(value, offset) - HALF_PI_ANGLE
  183. },
  184. _getCanvasStartEnd: function() {
  185. return {
  186. start: 0 - HALF_PI_ANGLE,
  187. end: 360 - HALF_PI_ANGLE
  188. }
  189. },
  190. _getStripGraphicAttributes: function(fromAngle, toAngle) {
  191. var center = this.getCenter();
  192. var angle = this.getAngles()[0];
  193. var r = this.getRadius();
  194. return {
  195. x: center.x,
  196. y: center.y,
  197. innerRadius: 0,
  198. outerRadius: r,
  199. startAngle: -toAngle - angle,
  200. endAngle: -fromAngle - angle
  201. }
  202. },
  203. _createStrip: function(coords) {
  204. return this._renderer.arc(coords.x, coords.y, coords.innerRadius, coords.outerRadius, coords.startAngle, coords.endAngle)
  205. },
  206. _getStripLabelCoords: function(from, to) {
  207. var that = this;
  208. var coords = that._getStripGraphicAttributes(from, to);
  209. var angle = coords.startAngle + (coords.endAngle - coords.startAngle) / 2;
  210. var cosSin = vizUtils.getCosAndSin(angle);
  211. var halfRad = that.getRadius() / 2;
  212. var center = that.getCenter();
  213. var x = _round(center.x + halfRad * cosSin.cos);
  214. var y = _round(center.y - halfRad * cosSin.sin);
  215. return {
  216. x: x,
  217. y: y,
  218. align: constants.center
  219. }
  220. },
  221. _getConstantLineGraphicAttributes: function(value) {
  222. var center = this.getCenter();
  223. var r = this.getRadius();
  224. return {
  225. points: [center.x, center.y, center.x + r, center.y]
  226. }
  227. },
  228. _createConstantLine: function(value, attr) {
  229. return this._createPathElement(this._getConstantLineGraphicAttributes(value).points, attr)
  230. },
  231. _rotateConstantLine: function(line, value) {
  232. var _this$getCenter = this.getCenter(),
  233. x = _this$getCenter.x,
  234. y = _this$getCenter.y;
  235. line.rotate(value + this.getAngles()[0], x, y)
  236. },
  237. _getConstantLineLabelsCoords: function(value) {
  238. var that = this;
  239. var cosSin = vizUtils.getCosAndSin(-value - that.getAngles()[0]);
  240. var halfRad = that.getRadius() / 2;
  241. var center = that.getCenter();
  242. var x = _round(center.x + halfRad * cosSin.cos);
  243. var y = _round(center.y - halfRad * cosSin.sin);
  244. return {
  245. x: x,
  246. y: y
  247. }
  248. },
  249. _checkAlignmentConstantLineLabels: _noop,
  250. _adjustDivisionFactor: function(val) {
  251. return 180 * val / (this.getRadius() * Math.PI)
  252. },
  253. _getScreenDelta: function() {
  254. var angles = this.getAngles();
  255. return _math.abs(angles[0] - angles[1])
  256. },
  257. _getTickMarkPoints: function(coords, length, _ref) {
  258. var _ref$shift = _ref.shift,
  259. shift = void 0 === _ref$shift ? 0 : _ref$shift;
  260. var center = this.getCenter();
  261. var corrections = {
  262. inside: -1,
  263. center: -.5,
  264. outside: 0
  265. };
  266. var radiusWithTicks = this.getRadius() + length * corrections[this._options.tickOrientation || "center"];
  267. return [center.x + radiusWithTicks + shift, center.y, center.x + radiusWithTicks + length + shift, center.y]
  268. },
  269. _getLabelAdjustedCoord: function(tick, _offset, _maxWidth, checkCanvas) {
  270. var that = this;
  271. var labelCoords = tick.labelCoords;
  272. var labelY = labelCoords.y;
  273. var labelAngle = labelCoords.angle;
  274. var cosSin = vizUtils.getCosAndSin(labelAngle);
  275. var cos = cosSin.cos;
  276. var sin = cosSin.sin;
  277. var box = tick.labelBBox;
  278. var halfWidth = box.width / 2;
  279. var halfHeight = box.height / 2;
  280. var indentFromAxis = that._options.label.indentFromAxis || 0;
  281. var x = labelCoords.x + indentFromAxis * cos;
  282. var y = labelY + (labelY - box.y - halfHeight) + indentFromAxis * sin;
  283. var shiftX = 0;
  284. var shiftY = 0;
  285. switch (getPolarQuarter(labelAngle)) {
  286. case 1:
  287. shiftX = halfWidth;
  288. shiftY = halfHeight * sin;
  289. break;
  290. case 2:
  291. shiftX = halfWidth * cos;
  292. shiftY = halfHeight;
  293. break;
  294. case 3:
  295. shiftX = -halfWidth;
  296. shiftY = halfHeight * sin;
  297. break;
  298. case 4:
  299. shiftX = halfWidth * cos;
  300. shiftY = -halfHeight
  301. }
  302. if (checkCanvas) {
  303. var canvas = that._canvas;
  304. var boxShiftX = x - labelCoords.x + shiftX;
  305. var boxShiftY = y - labelCoords.y + shiftY;
  306. if (box.x + boxShiftX < canvas.originalLeft) {
  307. shiftX -= box.x + boxShiftX - canvas.originalLeft
  308. }
  309. if (box.x + box.width + boxShiftX > canvas.width - canvas.originalRight) {
  310. shiftX -= box.x + box.width + boxShiftX - (canvas.width - canvas.originalRight)
  311. }
  312. if (box.y + boxShiftY < canvas.originalTop) {
  313. shiftY -= box.y + boxShiftY - canvas.originalTop
  314. }
  315. if (box.y + box.height + boxShiftY > canvas.height - canvas.originalBottom) {
  316. shiftY -= box.y + box.height + boxShiftY - (canvas.height - canvas.originalBottom)
  317. }
  318. }
  319. return {
  320. x: x + shiftX,
  321. y: y + shiftY
  322. }
  323. },
  324. _getGridLineDrawer: function() {
  325. var that = this;
  326. return function(tick, gridStyle) {
  327. var center = that.getCenter();
  328. return that._createPathElement(that._getGridPoints().points, gridStyle).rotate(tick.coords.angle, center.x, center.y)
  329. }
  330. },
  331. _getGridPoints: function() {
  332. var r = this.getRadius();
  333. var center = this.getCenter();
  334. return {
  335. points: [center.x, center.y, center.x + r, center.y]
  336. }
  337. },
  338. _getTranslatedValue: function(value, offset) {
  339. var startAngle = this.getAngles()[0];
  340. var angle = this._translator.translate(value, -offset);
  341. var coords = convertPolarToXY(this.getCenter(), startAngle, angle, this.getRadius());
  342. return {
  343. x: coords.x,
  344. y: coords.y,
  345. angle: angle + startAngle - HALF_PI_ANGLE
  346. }
  347. },
  348. _getAdjustedStripLabelCoords: function(strip) {
  349. var box = strip.labelBBox;
  350. return {
  351. translateY: strip.label.attr("y") - box.y - box.height / 2
  352. }
  353. },
  354. coordsIn: function(x, y) {
  355. return vizUtils.convertXYToPolar(this.getCenter(), x, y).r > this.getRadius()
  356. },
  357. _rotateTick: function(element, coords) {
  358. var center = this.getCenter();
  359. element.rotate(coords.angle, center.x, center.y)
  360. },
  361. _validateOverlappingMode: function(mode) {
  362. return constants.validateOverlappingMode(mode)
  363. },
  364. _validateDisplayMode: function() {
  365. return "standard"
  366. },
  367. _getStep: function(boxes) {
  368. var that = this;
  369. var radius = that.getRadius() + (that._options.label.indentFromAxis || 0);
  370. var maxLabelBox = boxes.reduce(function(prevValue, box) {
  371. var curValue = prevValue;
  372. if (prevValue.width < box.width) {
  373. curValue.width = box.width
  374. }
  375. if (prevValue.height < box.height) {
  376. curValue.height = box.height
  377. }
  378. return curValue
  379. }, {
  380. width: 0,
  381. height: 0
  382. });
  383. var angle1 = _abs(2 * _math.atan(maxLabelBox.height / (2 * radius - maxLabelBox.width)) * 180 / _math.PI);
  384. var angle2 = _abs(2 * _math.atan(maxLabelBox.width / (2 * radius - maxLabelBox.height)) * 180 / _math.PI);
  385. return constants.getTicksCountInRange(that._majorTicks, "angle", _math.max(angle1, angle2))
  386. },
  387. _checkBoundedLabelsOverlapping: function(majorTicks, boxes, mode) {
  388. var labelOpt = this._options.label;
  389. mode = mode || this._validateOverlappingMode(labelOpt.overlappingBehavior);
  390. if ("hide" !== mode) {
  391. return
  392. }
  393. var lastVisibleLabelIndex = majorTicks.reduce(function(lastVisibleLabelIndex, tick, index) {
  394. return tick.label ? index : lastVisibleLabelIndex
  395. }, null);
  396. if (!lastVisibleLabelIndex) {
  397. return
  398. }
  399. if (constants.areLabelsOverlap(boxes[0], boxes[lastVisibleLabelIndex], labelOpt.minSpacing, constants.center)) {
  400. "first" === labelOpt.hideFirstOrLast ? majorTicks[0].label.remove() : majorTicks[lastVisibleLabelIndex].label.remove()
  401. }
  402. },
  403. shift: function(margins) {
  404. this._axisGroup.attr({
  405. translateX: margins.right,
  406. translateY: margins.bottom
  407. })
  408. }
  409. };
  410. polarAxes.circularSpider = _extend({}, circularAxes, {
  411. _createAxisElement: function() {
  412. return this._renderer.path([], "area")
  413. },
  414. _updateAxisElementPosition: function() {
  415. this._axisElement.attr({
  416. points: _map(this.getSpiderTicks(), function(tick) {
  417. return {
  418. x: tick.coords.x,
  419. y: tick.coords.y
  420. }
  421. })
  422. })
  423. },
  424. _getStick: function() {
  425. return true
  426. },
  427. _getSpiderCategoryOption: function() {
  428. return true
  429. },
  430. getSpiderTicks: function() {
  431. var that = this;
  432. var ticks = that.getFullTicks();
  433. that._spiderTicks = ticks.map(tick(that, that.renderer, {}, {}, that._getSkippedCategory(ticks), true));
  434. that._spiderTicks.forEach(function(tick) {
  435. tick.initCoords()
  436. });
  437. return that._spiderTicks
  438. },
  439. _getStripGraphicAttributes: function(fromAngle, toAngle) {
  440. var center = this.getCenter();
  441. var spiderTicks = this.getSpiderTicks();
  442. var firstTick;
  443. var lastTick;
  444. var points = [];
  445. var i = 0;
  446. var len = spiderTicks.length;
  447. while (i < len) {
  448. var _tick = spiderTicks[i].coords;
  449. if (_tick.angle >= fromAngle && _tick.angle <= toAngle) {
  450. if (!firstTick) {
  451. firstTick = (spiderTicks[i - 1] || spiderTicks[spiderTicks.length - 1]).coords;
  452. points.push((_tick.x + firstTick.x) / 2, (_tick.y + firstTick.y) / 2)
  453. }
  454. points.push(_tick.x, _tick.y);
  455. var nextTick = (spiderTicks[i + 1] || spiderTicks[0]).coords;
  456. lastTick = {
  457. x: (_tick.x + nextTick.x) / 2,
  458. y: (_tick.y + nextTick.y) / 2
  459. }
  460. }
  461. i++
  462. }
  463. points.push(lastTick.x, lastTick.y);
  464. points.push(center.x, center.y);
  465. return {
  466. points: points
  467. }
  468. },
  469. _createStrip: function(_ref2) {
  470. var points = _ref2.points;
  471. return this._renderer.path(points, "area")
  472. },
  473. _getTranslatedCoord: function(value, offset) {
  474. return this._translator.translate(value, offset) - HALF_PI_ANGLE
  475. },
  476. _setTickOffset: function() {
  477. this._tickOffset = false
  478. }
  479. });
  480. polarAxes.linear = {
  481. applyMargins: circularAxes.applyMargins,
  482. _resetMargins: function() {
  483. this._reinitTranslator(this._getViewportRange())
  484. },
  485. _setVisualRange: _noop,
  486. _getStick: xyAxesLinear._getStick,
  487. _getSpiderCategoryOption: _noop,
  488. _getTranslatorOptions: function() {
  489. return {
  490. isHorizontal: true,
  491. stick: this._getStick()
  492. }
  493. },
  494. _updateRadius: circularAxes._updateRadius,
  495. getRadius: circularAxes.getRadius,
  496. getCenter: circularAxes.getCenter,
  497. getAngles: circularAxes.getAngles,
  498. _updateCenter: circularAxes._updateCenter,
  499. _processCanvas: function(canvas) {
  500. this._updateRadius(canvas);
  501. this._updateCenter(canvas);
  502. return {
  503. left: 0,
  504. right: 0,
  505. width: this.getRadius()
  506. }
  507. },
  508. _createAxisElement: xyAxesLinear._createAxisElement,
  509. _updateAxisElementPosition: function() {
  510. var centerCoord = this.getCenter();
  511. this._axisElement.attr({
  512. points: [centerCoord.x, centerCoord.y, centerCoord.x + this.getRadius(), centerCoord.y]
  513. }).rotate(this.getAngles()[0] - HALF_PI_ANGLE, centerCoord.x, centerCoord.y)
  514. },
  515. _getScreenDelta: function() {
  516. return this.getRadius()
  517. },
  518. _getTickMarkPoints: function(coords, length) {
  519. return [coords.x - length / 2, coords.y, coords.x + length / 2, coords.y]
  520. },
  521. _getLabelAdjustedCoord: function(tick) {
  522. var that = this;
  523. var labelCoords = tick.labelCoords;
  524. var labelY = labelCoords.y;
  525. var cosSin = vizUtils.getCosAndSin(labelCoords.angle);
  526. var indentFromAxis = that._options.label.indentFromAxis || 0;
  527. var box = tick.labelBBox;
  528. var x = labelCoords.x - _abs(indentFromAxis * cosSin.sin) + _abs(box.width / 2 * cosSin.cos) - box.width / 2;
  529. var y = labelY + (labelY - box.y) - _abs(box.height / 2 * cosSin.sin) + _abs(indentFromAxis * cosSin.cos);
  530. return {
  531. x: x,
  532. y: y
  533. }
  534. },
  535. _getGridLineDrawer: function() {
  536. var that = this;
  537. return function(tick, gridStyle) {
  538. var grid = that._getGridPoints(tick.coords);
  539. return that._renderer.circle(grid.cx, grid.cy, grid.r).attr(gridStyle).sharp()
  540. }
  541. },
  542. _getGridPoints: function(coords) {
  543. var pos = this.getCenter();
  544. var radius = vizUtils.getDistance(pos.x, pos.y, coords.x, coords.y);
  545. if (radius > this.getRadius()) {
  546. return {
  547. cx: null,
  548. cy: null,
  549. r: null
  550. }
  551. }
  552. return {
  553. cx: pos.x,
  554. cy: pos.y,
  555. r: radius
  556. }
  557. },
  558. _getTranslatedValue: function(value, offset) {
  559. var startAngle = this.getAngles()[0];
  560. var xy = convertPolarToXY(this.getCenter(), startAngle, 0, this._translator.translate(value, offset));
  561. return {
  562. x: xy.x,
  563. y: xy.y,
  564. angle: startAngle - HALF_PI_ANGLE
  565. }
  566. },
  567. _getTranslatedCoord: function(value, offset) {
  568. return this._translator.translate(value, offset)
  569. },
  570. _getCanvasStartEnd: function() {
  571. return {
  572. start: 0,
  573. end: this.getRadius()
  574. }
  575. },
  576. _getStripGraphicAttributes: function(fromPoint, toPoint) {
  577. var center = this.getCenter();
  578. return {
  579. x: center.x,
  580. y: center.y,
  581. innerRadius: fromPoint,
  582. outerRadius: toPoint
  583. }
  584. },
  585. _createStrip: function(attrs) {
  586. return this._renderer.arc(attrs.x, attrs.y, attrs.innerRadius, attrs.outerRadius, 0, 360)
  587. },
  588. _getAdjustedStripLabelCoords: circularAxes._getAdjustedStripLabelCoords,
  589. _getStripLabelCoords: function(from, to) {
  590. var that = this;
  591. var labelPos = from + (to - from) / 2;
  592. var center = that.getCenter();
  593. var y = _round(center.y - labelPos);
  594. return {
  595. x: center.x,
  596. y: y,
  597. align: constants.center
  598. }
  599. },
  600. _getConstantLineGraphicAttributes: function(value) {
  601. var center = this.getCenter();
  602. return {
  603. cx: center.x,
  604. cy: center.y,
  605. r: value
  606. }
  607. },
  608. _createConstantLine: function(value, attr) {
  609. var attrs = this._getConstantLineGraphicAttributes(value);
  610. return this._renderer.circle(attrs.cx, attrs.cy, attrs.r).attr(attr).sharp()
  611. },
  612. _getConstantLineLabelsCoords: function(value) {
  613. var that = this;
  614. var center = that.getCenter();
  615. var y = _round(center.y - value);
  616. return {
  617. x: center.x,
  618. y: y
  619. }
  620. },
  621. _checkAlignmentConstantLineLabels: _noop,
  622. _rotateTick: function(element, coords, isGridLine) {
  623. !isGridLine && element.rotate(coords.angle + HALF_PI_ANGLE, coords.x, coords.y)
  624. },
  625. _validateOverlappingMode: circularAxes._validateOverlappingMode,
  626. _validateDisplayMode: circularAxes._validateDisplayMode,
  627. _getStep: function(boxes) {
  628. var quarter = getPolarQuarter(this.getAngles()[0]);
  629. var spacing = this._options.label.minSpacing;
  630. var func = 2 === quarter || 4 === quarter ? function(box) {
  631. return box.width + spacing
  632. } : function(box) {
  633. return box.height
  634. };
  635. var maxLabelLength = boxes.reduce(function(prevValue, box) {
  636. return _math.max(prevValue, func(box))
  637. }, 0);
  638. return constants.getTicksCountInRange(this._majorTicks, 2 === quarter || 4 === quarter ? "x" : "y", maxLabelLength)
  639. }
  640. };
  641. polarAxes.linearSpider = _extend({}, polarAxes.linear, {
  642. _createPathElement: function(points, attr) {
  643. return this._renderer.path(points, "area").attr(attr).sharp()
  644. },
  645. setSpiderTicks: function(ticks) {
  646. this._spiderTicks = ticks
  647. },
  648. _getGridLineDrawer: function() {
  649. var that = this;
  650. return function(tick, gridStyle, element) {
  651. return that._createPathElement(that._getGridPoints(tick.coords).points, gridStyle)
  652. }
  653. },
  654. _getGridPoints: function(coords) {
  655. var pos = this.getCenter();
  656. var radius = vizUtils.getDistance(pos.x, pos.y, coords.x, coords.y);
  657. return this._getGridPointsByRadius(radius)
  658. },
  659. _getGridPointsByRadius: function(radius) {
  660. var pos = this.getCenter();
  661. if (radius > this.getRadius()) {
  662. return {
  663. points: null
  664. }
  665. }
  666. return {
  667. points: _map(this._spiderTicks, function(tick) {
  668. var cosSin = vizUtils.getCosAndSin(tick.coords.angle);
  669. return {
  670. x: _round(pos.x + radius * cosSin.cos),
  671. y: _round(pos.y + radius * cosSin.sin)
  672. }
  673. })
  674. }
  675. },
  676. _getStripGraphicAttributes: function(fromPoint, toPoint) {
  677. var innerPoints = this._getGridPointsByRadius(toPoint).points;
  678. var outerPoints = this._getGridPointsByRadius(fromPoint).points;
  679. return {
  680. points: [outerPoints, innerPoints.reverse()]
  681. }
  682. },
  683. _createStrip: polarAxes.circularSpider._createStrip,
  684. _getConstantLineGraphicAttributes: function(value) {
  685. return this._getGridPointsByRadius(value)
  686. },
  687. _createConstantLine: function(value, attr) {
  688. return this._createPathElement(this._getConstantLineGraphicAttributes(value).points, attr)
  689. }
  690. });