linear_indicators.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. /**
  2. * DevExtreme (viz/gauges/linear_indicators.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 baseIndicatorsModule = require("./base_indicators");
  11. var BaseIndicator = baseIndicatorsModule.BaseIndicator;
  12. var BaseTextCloudMarker = baseIndicatorsModule.BaseTextCloudMarker;
  13. var BaseRangeBar = baseIndicatorsModule.BaseRangeBar;
  14. var _Number = Number;
  15. var _normalizeEnum = require("../core/utils").normalizeEnum;
  16. var SimpleIndicator = BaseIndicator.inherit({
  17. _move: function() {
  18. var that = this;
  19. var delta = that._actualPosition - that._zeroPosition;
  20. that._rootElement.move(that.vertical ? 0 : delta, that.vertical ? delta : 0);
  21. that._trackerElement && that._trackerElement.move(that.vertical ? 0 : delta, that.vertical ? delta : 0)
  22. },
  23. _isEnabled: function() {
  24. this.vertical = this._options.vertical;
  25. return this._options.length > 0 && this._options.width > 0
  26. },
  27. _isVisible: function() {
  28. return true
  29. },
  30. _getTrackerSettings: function() {
  31. var options = this._options;
  32. var x1;
  33. var x2;
  34. var y1;
  35. var y2;
  36. var width = options.width / 2;
  37. var length = options.length / 2;
  38. var p = this._zeroPosition;
  39. width > 10 || (width = 10);
  40. length > 10 || (length = 10);
  41. if (this.vertical) {
  42. x1 = options.x - length;
  43. x2 = options.x + length;
  44. y1 = p + width;
  45. y2 = p - width
  46. } else {
  47. x1 = p - width;
  48. x2 = p + width;
  49. y1 = options.y + length;
  50. y2 = options.y - length
  51. }
  52. return {
  53. points: [x1, y1, x1, y2, x2, y2, x2, y1]
  54. }
  55. },
  56. _render: function() {
  57. var that = this;
  58. that._zeroPosition = that._translator.getCodomainStart()
  59. },
  60. _clear: function() {
  61. delete this._element
  62. },
  63. measure: function(layout) {
  64. var p = this.vertical ? layout.x : layout.y;
  65. return {
  66. min: p - this._options.length / 2,
  67. max: p + this._options.length / 2
  68. }
  69. },
  70. getTooltipParameters: function() {
  71. var that = this;
  72. var options = that._options;
  73. var p = that._actualPosition;
  74. var parameters = {
  75. x: p,
  76. y: p,
  77. value: that._currentValue,
  78. color: options.color,
  79. offset: options.width / 2
  80. };
  81. that.vertical ? parameters.x = options.x : parameters.y = options.y;
  82. return parameters
  83. }
  84. });
  85. var rectangle = SimpleIndicator.inherit({
  86. _render: function() {
  87. var that = this;
  88. var options = that._options;
  89. var x1;
  90. var x2;
  91. var y1;
  92. var y2;
  93. that.callBase();
  94. var p = that._zeroPosition;
  95. if (that.vertical) {
  96. x1 = options.x - options.length / 2;
  97. x2 = options.x + options.length / 2;
  98. y1 = p + options.width / 2;
  99. y2 = p - options.width / 2
  100. } else {
  101. x1 = p - options.width / 2;
  102. x2 = p + options.width / 2;
  103. y1 = options.y + options.length / 2;
  104. y2 = options.y - options.length / 2
  105. }
  106. that._element = that._element || that._renderer.path([], "area").append(that._rootElement);
  107. that._element.attr({
  108. points: [x1, y1, x1, y2, x2, y2, x2, y1]
  109. })
  110. }
  111. });
  112. var rhombus = SimpleIndicator.inherit({
  113. _render: function() {
  114. var that = this;
  115. var options = that._options;
  116. var x;
  117. var y;
  118. var dx;
  119. var dy;
  120. that.callBase();
  121. if (that.vertical) {
  122. x = options.x;
  123. y = that._zeroPosition;
  124. dx = options.length / 2 || 0;
  125. dy = options.width / 2 || 0
  126. } else {
  127. x = that._zeroPosition;
  128. y = options.y;
  129. dx = options.width / 2 || 0;
  130. dy = options.length / 2 || 0
  131. }
  132. that._element = that._element || that._renderer.path([], "area").append(that._rootElement);
  133. that._element.attr({
  134. points: [x - dx, y, x, y - dy, x + dx, y, x, y + dy]
  135. })
  136. }
  137. });
  138. var circle = SimpleIndicator.inherit({
  139. _render: function() {
  140. var that = this;
  141. var options = that._options;
  142. var x;
  143. var y;
  144. that.callBase();
  145. if (that.vertical) {
  146. x = options.x;
  147. y = that._zeroPosition
  148. } else {
  149. x = that._zeroPosition;
  150. y = options.y
  151. }
  152. var r = options.length / 2 || 0;
  153. that._element = that._element || that._renderer.circle().append(that._rootElement);
  154. that._element.attr({
  155. cx: x,
  156. cy: y,
  157. r: r
  158. })
  159. }
  160. });
  161. var triangleMarker = SimpleIndicator.inherit({
  162. _isEnabled: function() {
  163. var that = this;
  164. that.vertical = that._options.vertical;
  165. that._inverted = that.vertical ? "right" === _normalizeEnum(that._options.horizontalOrientation) : "bottom" === _normalizeEnum(that._options.verticalOrientation);
  166. return that._options.length > 0 && that._options.width > 0
  167. },
  168. _isVisible: function() {
  169. return true
  170. },
  171. _render: function() {
  172. var that = this;
  173. var options = that._options;
  174. var x1;
  175. var x2;
  176. var y1;
  177. var y2;
  178. var settings = {
  179. stroke: "none",
  180. "stroke-width": 0,
  181. "stroke-linecap": "square"
  182. };
  183. that.callBase();
  184. if (that.vertical) {
  185. x1 = options.x;
  186. y1 = that._zeroPosition;
  187. x2 = x1 + _Number(that._inverted ? options.length : -options.length);
  188. settings.points = [x1, y1, x2, y1 - options.width / 2, x2, y1 + options.width / 2]
  189. } else {
  190. y1 = options.y;
  191. x1 = that._zeroPosition;
  192. y2 = y1 + _Number(that._inverted ? options.length : -options.length);
  193. settings.points = [x1, y1, x1 - options.width / 2, y2, x1 + options.width / 2, y2]
  194. }
  195. if (options.space > 0) {
  196. settings["stroke-width"] = Math.min(options.space, options.width / 4) || 0;
  197. settings.stroke = settings["stroke-width"] > 0 ? options.containerBackgroundColor || "none" : "none"
  198. }
  199. that._element = that._element || that._renderer.path([], "area").append(that._rootElement);
  200. that._element.attr(settings).sharp()
  201. },
  202. _getTrackerSettings: function() {
  203. var that = this;
  204. var options = that._options;
  205. var width = options.width / 2;
  206. var length = _Number(options.length);
  207. var x1;
  208. var x2;
  209. var y1;
  210. var y2;
  211. var result;
  212. width > 10 || (width = 10);
  213. length > 20 || (length = 20);
  214. if (that.vertical) {
  215. x1 = x2 = options.x;
  216. x2 = x1 + (that._inverted ? length : -length);
  217. y1 = that._zeroPosition + width;
  218. y2 = that._zeroPosition - width;
  219. result = [x1, y1, x2, y1, x2, y2, x1, y2]
  220. } else {
  221. y1 = options.y;
  222. y2 = y1 + (that._inverted ? length : -length);
  223. x1 = that._zeroPosition - width;
  224. x2 = that._zeroPosition + width;
  225. result = [x1, y1, x1, y2, x2, y2, x2, y1]
  226. }
  227. return {
  228. points: result
  229. }
  230. },
  231. measure: function(layout) {
  232. var that = this;
  233. var length = _Number(that._options.length);
  234. var minBound;
  235. var maxBound;
  236. if (that.vertical) {
  237. minBound = maxBound = layout.x;
  238. if (that._inverted) {
  239. maxBound = minBound + length
  240. } else {
  241. minBound = maxBound - length
  242. }
  243. } else {
  244. minBound = maxBound = layout.y;
  245. if (that._inverted) {
  246. maxBound = minBound + length
  247. } else {
  248. minBound = maxBound - length
  249. }
  250. }
  251. return {
  252. min: minBound,
  253. max: maxBound,
  254. indent: that._options.width / 2
  255. }
  256. },
  257. getTooltipParameters: function() {
  258. var that = this;
  259. var options = that._options;
  260. var s = (that._inverted ? options.length : -options.length) / 2;
  261. var parameters = that.callBase();
  262. that.vertical ? parameters.x += s : parameters.y += s;
  263. parameters.offset = options.length / 2;
  264. return parameters
  265. }
  266. });
  267. var textCloud = BaseTextCloudMarker.inherit({
  268. _isEnabled: function() {
  269. var that = this;
  270. that.vertical = that._options.vertical;
  271. that._inverted = that.vertical ? "right" === _normalizeEnum(that._options.horizontalOrientation) : "bottom" === _normalizeEnum(that._options.verticalOrientation);
  272. return true
  273. },
  274. _isVisible: function() {
  275. return true
  276. },
  277. _getTextCloudOptions: function() {
  278. var that = this;
  279. var x = that._actualPosition;
  280. var y = that._actualPosition;
  281. var type;
  282. if (that.vertical) {
  283. x = that._options.x;
  284. type = that._inverted ? "top-left" : "top-right"
  285. } else {
  286. y = that._options.y;
  287. type = that._inverted ? "right-top" : "right-bottom"
  288. }
  289. return {
  290. x: x,
  291. y: y,
  292. type: type
  293. }
  294. },
  295. measure: function(layout) {
  296. var that = this;
  297. var minBound;
  298. var maxBound;
  299. var arrowLength = _Number(that._options.arrowLength) || 0;
  300. var indent;
  301. that._measureText();
  302. if (that.vertical) {
  303. indent = that._textFullHeight;
  304. if (that._inverted) {
  305. minBound = layout.x;
  306. maxBound = layout.x + arrowLength + that._textFullWidth
  307. } else {
  308. minBound = layout.x - arrowLength - that._textFullWidth;
  309. maxBound = layout.x
  310. }
  311. } else {
  312. indent = that._textFullWidth;
  313. if (that._inverted) {
  314. minBound = layout.y;
  315. maxBound = layout.y + arrowLength + that._textFullHeight
  316. } else {
  317. minBound = layout.y - arrowLength - that._textFullHeight;
  318. maxBound = layout.y
  319. }
  320. }
  321. return {
  322. min: minBound,
  323. max: maxBound,
  324. indent: indent
  325. }
  326. }
  327. });
  328. var rangeBar = BaseRangeBar.inherit({
  329. _isEnabled: function() {
  330. var that = this;
  331. that.vertical = that._options.vertical;
  332. that._inverted = that.vertical ? "right" === _normalizeEnum(that._options.horizontalOrientation) : "bottom" === _normalizeEnum(that._options.verticalOrientation);
  333. return that._options.size > 0
  334. },
  335. _isVisible: function() {
  336. return true
  337. },
  338. _createBarItem: function() {
  339. return this._renderer.path([], "area").append(this._rootElement)
  340. },
  341. _createTracker: function() {
  342. return this._renderer.path([], "area")
  343. },
  344. _setBarSides: function() {
  345. var that = this;
  346. var options = that._options;
  347. var size = _Number(options.size);
  348. var minSide;
  349. var maxSide;
  350. if (that.vertical) {
  351. if (that._inverted) {
  352. minSide = options.x;
  353. maxSide = options.x + size
  354. } else {
  355. minSide = options.x - size;
  356. maxSide = options.x
  357. }
  358. } else {
  359. if (that._inverted) {
  360. minSide = options.y;
  361. maxSide = options.y + size
  362. } else {
  363. minSide = options.y - size;
  364. maxSide = options.y
  365. }
  366. }
  367. that._minSide = minSide;
  368. that._maxSide = maxSide;
  369. that._minBound = minSide;
  370. that._maxBound = maxSide
  371. },
  372. _getSpace: function() {
  373. var options = this._options;
  374. return options.space > 0 ? _Number(options.space) : 0
  375. },
  376. _isTextVisible: function() {
  377. var textOptions = this._options.text || {};
  378. return textOptions.indent > 0 || textOptions.indent < 0
  379. },
  380. _getTextAlign: function() {
  381. return this.vertical ? this._options.text.indent > 0 ? "left" : "right" : "center"
  382. },
  383. _setTextItemsSides: function() {
  384. var that = this;
  385. var indent = _Number(that._options.text.indent);
  386. if (indent > 0) {
  387. that._lineStart = that._maxSide;
  388. that._lineEnd = that._maxSide + indent;
  389. that._textPosition = that._lineEnd + (that.vertical ? 2 : that._textHeight / 2);
  390. that._maxBound = that._textPosition + (that.vertical ? that._textWidth : that._textHeight / 2)
  391. } else {
  392. if (indent < 0) {
  393. that._lineStart = that._minSide;
  394. that._lineEnd = that._minSide + indent;
  395. that._textPosition = that._lineEnd - (that.vertical ? 2 : that._textHeight / 2);
  396. that._minBound = that._textPosition - (that.vertical ? that._textWidth : that._textHeight / 2)
  397. }
  398. }
  399. },
  400. _getPositions: function() {
  401. var that = this;
  402. var startPosition = that._startPosition;
  403. var endPosition = that._endPosition;
  404. var space = that._space;
  405. var basePosition = that._basePosition;
  406. var actualPosition = that._actualPosition;
  407. var mainPosition1;
  408. var mainPosition2;
  409. var backPosition1;
  410. var backPosition2;
  411. if (startPosition < endPosition) {
  412. if (basePosition < actualPosition) {
  413. mainPosition1 = basePosition;
  414. mainPosition2 = actualPosition
  415. } else {
  416. mainPosition1 = actualPosition;
  417. mainPosition2 = basePosition
  418. }
  419. backPosition1 = mainPosition1 - space;
  420. backPosition2 = mainPosition2 + space
  421. } else {
  422. if (basePosition > actualPosition) {
  423. mainPosition1 = basePosition;
  424. mainPosition2 = actualPosition
  425. } else {
  426. mainPosition1 = actualPosition;
  427. mainPosition2 = basePosition
  428. }
  429. backPosition1 = mainPosition1 + space;
  430. backPosition2 = mainPosition2 - space
  431. }
  432. return {
  433. start: startPosition,
  434. end: endPosition,
  435. main1: mainPosition1,
  436. main2: mainPosition2,
  437. back1: backPosition1,
  438. back2: backPosition2
  439. }
  440. },
  441. _buildItemSettings: function(from, to) {
  442. var that = this;
  443. var side1 = that._minSide;
  444. var side2 = that._maxSide;
  445. var points = that.vertical ? [side1, from, side1, to, side2, to, side2, from] : [from, side1, from, side2, to, side2, to, side1];
  446. return {
  447. points: points
  448. }
  449. },
  450. _updateTextPosition: function() {
  451. var that = this;
  452. that._text.attr(that.vertical ? {
  453. x: that._textPosition,
  454. y: that._actualPosition + that._textVerticalOffset
  455. } : {
  456. x: that._actualPosition,
  457. y: that._textPosition + that._textVerticalOffset
  458. })
  459. },
  460. _updateLinePosition: function() {
  461. var that = this;
  462. var actualPosition = that._actualPosition;
  463. var side1;
  464. var side2;
  465. var points;
  466. if (that.vertical) {
  467. if (that._basePosition >= actualPosition) {
  468. side1 = actualPosition;
  469. side2 = actualPosition + 2
  470. } else {
  471. side1 = actualPosition - 2;
  472. side2 = actualPosition
  473. }
  474. points = [that._lineStart, side1, that._lineStart, side2, that._lineEnd, side2, that._lineEnd, side1]
  475. } else {
  476. if (that._basePosition <= actualPosition) {
  477. side1 = actualPosition - 2;
  478. side2 = actualPosition
  479. } else {
  480. side1 = actualPosition;
  481. side2 = actualPosition + 2
  482. }
  483. points = [side1, that._lineStart, side1, that._lineEnd, side2, that._lineEnd, side2, that._lineStart]
  484. }
  485. that._line.attr({
  486. points: points
  487. }).sharp()
  488. },
  489. _getTooltipPosition: function() {
  490. var that = this;
  491. var crossCenter = (that._minSide + that._maxSide) / 2;
  492. var alongCenter = (that._basePosition + that._actualPosition) / 2;
  493. return that.vertical ? {
  494. x: crossCenter,
  495. y: alongCenter
  496. } : {
  497. x: alongCenter,
  498. y: crossCenter
  499. }
  500. },
  501. measure: function(layout) {
  502. var that = this;
  503. var size = _Number(that._options.size);
  504. var textIndent = _Number(that._options.text.indent);
  505. var minBound;
  506. var maxBound;
  507. var indent;
  508. that._measureText();
  509. if (that.vertical) {
  510. minBound = maxBound = layout.x;
  511. if (that._inverted) {
  512. maxBound += size
  513. } else {
  514. minBound -= size
  515. }
  516. if (that._hasText) {
  517. indent = that._textHeight / 2;
  518. if (textIndent > 0) {
  519. maxBound += textIndent + that._textWidth
  520. }
  521. if (textIndent < 0) {
  522. minBound += textIndent - that._textWidth
  523. }
  524. }
  525. } else {
  526. minBound = maxBound = layout.y;
  527. if (that._inverted) {
  528. maxBound += size
  529. } else {
  530. minBound -= size
  531. }
  532. if (that._hasText) {
  533. indent = that._textWidth / 2;
  534. if (textIndent > 0) {
  535. maxBound += textIndent + that._textHeight
  536. }
  537. if (textIndent < 0) {
  538. minBound += textIndent - that._textHeight
  539. }
  540. }
  541. }
  542. return {
  543. min: minBound,
  544. max: maxBound,
  545. indent: indent
  546. }
  547. }
  548. });
  549. exports._default = rangeBar;
  550. exports.rectangle = rectangle;
  551. exports.rhombus = rhombus;
  552. exports.circle = circle;
  553. exports.trianglemarker = triangleMarker;
  554. exports.textcloud = textCloud;
  555. exports.rangebar = rangeBar;