base_point.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. /**
  2. * DevExtreme (viz/series/points/base_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 mixins = {};
  11. var statesConsts = require("../../components/consts").states;
  12. var symbolPoint = require("./symbol_point");
  13. var barPoint = require("./bar_point");
  14. var bubblePoint = require("./bubble_point");
  15. var piePoint = require("./pie_point");
  16. var rangeSymbolPoint = require("./range_symbol_point");
  17. var rangeBarPoint = require("./range_bar_point");
  18. var candlestickPoint = require("./candlestick_point");
  19. var stockPoint = require("./stock_point");
  20. var polarPoints = require("./polar_point");
  21. var _normalizeEnum = require("../../core/utils").normalizeEnum;
  22. var extend = require("../../../core/utils/extend").extend;
  23. var each = require("../../../core/utils/iterator").each;
  24. var _each = each;
  25. var _extend = extend;
  26. var _isDefined = require("../../../core/utils/type").isDefined;
  27. var _noop = require("../../../core/utils/common").noop;
  28. var SYMBOL_POINT = "symbolPoint";
  29. var POLAR_SYMBOL_POINT = "polarSymbolPoint";
  30. var BAR_POINT = "barPoint";
  31. var POLAR_BAR_POINT = "polarBarPoint";
  32. var PIE_POINT = "piePoint";
  33. var SELECTED_STATE = statesConsts.selectedMark;
  34. var HOVER_STATE = statesConsts.hoverMark;
  35. var NORMAL_STATE = statesConsts.normalMark;
  36. var HOVER = statesConsts.hover;
  37. var NORMAL = statesConsts.normal;
  38. var SELECTION = statesConsts.selection;
  39. var pointTypes = {
  40. chart: {
  41. scatter: SYMBOL_POINT,
  42. line: SYMBOL_POINT,
  43. spline: SYMBOL_POINT,
  44. stepline: SYMBOL_POINT,
  45. stackedline: SYMBOL_POINT,
  46. fullstackedline: SYMBOL_POINT,
  47. stackedspline: SYMBOL_POINT,
  48. fullstackedspline: SYMBOL_POINT,
  49. stackedsplinearea: SYMBOL_POINT,
  50. fullstackedsplinearea: SYMBOL_POINT,
  51. area: SYMBOL_POINT,
  52. splinearea: SYMBOL_POINT,
  53. steparea: SYMBOL_POINT,
  54. stackedarea: SYMBOL_POINT,
  55. fullstackedarea: SYMBOL_POINT,
  56. rangearea: "rangeSymbolPoint",
  57. bar: BAR_POINT,
  58. stackedbar: BAR_POINT,
  59. fullstackedbar: BAR_POINT,
  60. rangebar: "rangeBarPoint",
  61. bubble: "bubblePoint",
  62. stock: "stockPoint",
  63. candlestick: "candlestickPoint"
  64. },
  65. pie: {
  66. pie: PIE_POINT,
  67. doughnut: PIE_POINT,
  68. donut: PIE_POINT
  69. },
  70. polar: {
  71. scatter: POLAR_SYMBOL_POINT,
  72. line: POLAR_SYMBOL_POINT,
  73. area: POLAR_SYMBOL_POINT,
  74. bar: POLAR_BAR_POINT,
  75. stackedbar: POLAR_BAR_POINT
  76. }
  77. };
  78. function isNoneMode(mode) {
  79. return "none" === _normalizeEnum(mode)
  80. }
  81. function Point(series, dataItem, options) {
  82. this.fullState = NORMAL_STATE;
  83. this.series = series;
  84. this.update(dataItem, options);
  85. this._viewCounters = {
  86. hover: 0,
  87. selection: 0
  88. };
  89. this._emptySettings = {
  90. fill: null,
  91. stroke: null,
  92. dashStyle: null
  93. }
  94. }
  95. exports.Point = Point;
  96. mixins.symbolPoint = symbolPoint;
  97. mixins.barPoint = barPoint;
  98. mixins.bubblePoint = bubblePoint;
  99. mixins.piePoint = piePoint;
  100. mixins.rangeSymbolPoint = rangeSymbolPoint;
  101. mixins.rangeBarPoint = rangeBarPoint;
  102. mixins.candlestickPoint = candlestickPoint;
  103. mixins.stockPoint = stockPoint;
  104. mixins.polarSymbolPoint = polarPoints.polarSymbolPoint;
  105. mixins.polarBarPoint = polarPoints.polarBarPoint;
  106. Point.prototype = {
  107. constructor: Point,
  108. getColor: function() {
  109. if (!this.hasValue() && !this._styles.usePointCustomOptions) {
  110. this.series.customizePoint(this, this._dataItem)
  111. }
  112. return this._styles.normal.fill || this.series.getColor()
  113. },
  114. _getStyle: function() {
  115. return this._styles[this._currentStyle || "normal"]
  116. },
  117. update: function(dataItem, options) {
  118. this.updateOptions(options);
  119. this.updateData(dataItem)
  120. },
  121. updateData: function(dataItem) {
  122. var that = this;
  123. var argumentWasChanged = that.argument !== dataItem.argument;
  124. that.argument = that.initialArgument = that.originalArgument = dataItem.argument;
  125. that.tag = dataItem.tag;
  126. that.index = dataItem.index;
  127. that._dataItem = dataItem;
  128. that.data = dataItem.data;
  129. that.lowError = dataItem.lowError;
  130. that.highError = dataItem.highError;
  131. that.aggregationInfo = dataItem.aggregationInfo;
  132. that._updateData(dataItem, argumentWasChanged);
  133. !that.hasValue() && that.setInvisibility();
  134. that._fillStyle();
  135. that._updateLabelData()
  136. },
  137. deleteMarker: function() {
  138. var that = this;
  139. if (that.graphic) {
  140. that.graphic.dispose()
  141. }
  142. that.graphic = null
  143. },
  144. draw: function(renderer, groups, animationEnabled, firstDrawing) {
  145. var that = this;
  146. if (that._needDeletingOnDraw || that.series.autoHidePointMarkers && !that.isSelected()) {
  147. that.deleteMarker();
  148. that._needDeletingOnDraw = false
  149. }
  150. if (that._needClearingOnDraw) {
  151. that.clearMarker();
  152. that._needClearingOnDraw = false
  153. }
  154. if (!that._hasGraphic()) {
  155. that.getMarkerVisibility() && !that.series.autoHidePointMarkers && that._drawMarker(renderer, groups.markers, animationEnabled, firstDrawing)
  156. } else {
  157. that._updateMarker(animationEnabled, this._getStyle(), groups.markers)
  158. }
  159. that._drawLabel();
  160. that._drawErrorBar(renderer, groups.errorBars, animationEnabled);
  161. return that
  162. },
  163. _getViewStyle: function() {
  164. var state = NORMAL_STATE;
  165. var fullState = this.fullState;
  166. var styles = [NORMAL, HOVER, SELECTION, SELECTION];
  167. if (this._viewCounters.hover) {
  168. state |= HOVER_STATE
  169. }
  170. if (this._viewCounters.selection) {
  171. state |= SELECTED_STATE
  172. }
  173. if (isNoneMode(this.getOptions().selectionMode)) {
  174. fullState &= ~SELECTED_STATE
  175. }
  176. if (isNoneMode(this.getOptions().hoverMode)) {
  177. fullState &= ~HOVER_STATE
  178. }
  179. state |= fullState;
  180. return styles[state]
  181. },
  182. applyView: function(legendCallback) {
  183. var style = this._getViewStyle();
  184. var that = this;
  185. that._currentStyle = style;
  186. if (!that.graphic && that.series.autoHidePointMarkers && (style === SELECTION || style === HOVER)) {
  187. that._drawMarker(that.series.getRenderer(), that.series.getMarkersGroup())
  188. }
  189. if (that.graphic) {
  190. if (that.series.autoHidePointMarkers && style !== SELECTION && style !== HOVER) {
  191. that.deleteMarker()
  192. } else {
  193. if ("normal" === style) {
  194. that.clearMarker()
  195. } else {
  196. that.graphic.toForeground()
  197. }
  198. that._updateMarker(true, that._styles[style], void 0, legendCallback)
  199. }
  200. }
  201. },
  202. setView: function(style) {
  203. this._viewCounters[style]++;
  204. this.applyView()
  205. },
  206. resetView: function(style) {
  207. var viewCounters = this._viewCounters;
  208. --viewCounters[style];
  209. if (viewCounters[style] < 0) {
  210. viewCounters[style] = 0
  211. }
  212. this.applyView()
  213. },
  214. releaseHoverState: function() {
  215. var that = this;
  216. if (that.graphic && !that.isSelected()) {
  217. that.graphic.toBackground()
  218. }
  219. },
  220. select: function() {
  221. this.series.selectPoint(this)
  222. },
  223. clearSelection: function() {
  224. this.series.deselectPoint(this)
  225. },
  226. hover: function() {
  227. this.series.hoverPoint(this)
  228. },
  229. clearHover: function() {
  230. this.series.clearPointHover()
  231. },
  232. showTooltip: function() {
  233. this.series.showPointTooltip(this)
  234. },
  235. hideTooltip: function() {
  236. this.series.hidePointTooltip(this)
  237. },
  238. _checkLabelsChanging: function(oldType, newType) {
  239. var isNewRange = ~newType.indexOf("range");
  240. var isOldRange = ~oldType.indexOf("range");
  241. return isOldRange && !isNewRange || !isOldRange && isNewRange
  242. },
  243. updateOptions: function(newOptions) {
  244. if (!newOptions) {
  245. return
  246. }
  247. var that = this;
  248. var oldOptions = that._options;
  249. var widgetType = newOptions.widgetType;
  250. var oldType = oldOptions && oldOptions.type;
  251. var newType = newOptions.type;
  252. var newPointTypeMixin = pointTypes[widgetType][newType];
  253. if (oldType !== newType) {
  254. that._needDeletingOnDraw = true;
  255. that._needClearingOnDraw = false;
  256. if (oldType) {
  257. that._checkLabelsChanging(oldType, newType) && that.deleteLabel();
  258. that._resetType(mixins[pointTypes[oldType]])
  259. }
  260. that._setType(mixins[newPointTypeMixin])
  261. } else {
  262. that._needDeletingOnDraw = that._checkSymbol(oldOptions, newOptions);
  263. that._needClearingOnDraw = that._checkCustomize(oldOptions, newOptions)
  264. }
  265. that._options = newOptions;
  266. that._fillStyle();
  267. that._updateLabelOptions(newPointTypeMixin)
  268. },
  269. translate: function() {
  270. if (this.hasValue()) {
  271. this._translate();
  272. this.translated = true
  273. }
  274. },
  275. _checkCustomize: function(oldOptions, newOptions) {
  276. return oldOptions.styles.usePointCustomOptions && !newOptions.styles.usePointCustomOptions
  277. },
  278. _getCustomLabelVisibility: function() {
  279. return this._styles.useLabelCustomOptions ? !!this._options.label.visible : null
  280. },
  281. getBoundingRect: function() {
  282. return this._getGraphicBBox()
  283. },
  284. _resetType: function(methods) {
  285. for (var methodName in methods) {
  286. delete this[methodName]
  287. }
  288. },
  289. _setType: function(methods) {
  290. for (var methodName in methods) {
  291. this[methodName] = methods[methodName]
  292. }
  293. },
  294. isInVisibleArea: function() {
  295. return this.inVisibleArea
  296. },
  297. isSelected: function() {
  298. return !!(this.fullState & SELECTED_STATE)
  299. },
  300. isHovered: function() {
  301. return !!(this.fullState & HOVER_STATE)
  302. },
  303. getOptions: function() {
  304. return this._options
  305. },
  306. animate: function(complete, settings, partitionDuration) {
  307. if (!this.graphic) {
  308. complete && complete();
  309. return
  310. }
  311. this.graphic.animate(settings, {
  312. partitionDuration: partitionDuration
  313. }, complete)
  314. },
  315. getCoords: function(min) {
  316. var that = this;
  317. if (!min) {
  318. return {
  319. x: that.x,
  320. y: that.y
  321. }
  322. }
  323. if (!that._options.rotated) {
  324. return {
  325. x: that.x,
  326. y: that.minY + (that.y - that.minY ? 0 : 1)
  327. }
  328. }
  329. return {
  330. x: that.minX - (that.x - that.minX ? 0 : 1),
  331. y: that.y
  332. }
  333. },
  334. getDefaultCoords: function() {
  335. var that = this;
  336. return !that._options.rotated ? {
  337. x: that.x,
  338. y: that.defaultY
  339. } : {
  340. x: that.defaultX,
  341. y: that.y
  342. }
  343. },
  344. setDefaultCoords: function() {
  345. var coords = this.getDefaultCoords();
  346. this.x = coords.x;
  347. this.y = coords.y
  348. },
  349. _getVisibleArea: function() {
  350. return this.series.getVisibleArea()
  351. },
  352. _getArgTranslator: function() {
  353. return this.series.getArgumentAxis().getTranslator()
  354. },
  355. _getValTranslator: function() {
  356. return this.series.getValueAxis().getTranslator()
  357. },
  358. _calculateVisibility: function(x, y, width, height) {
  359. var that = this;
  360. var visibleArea = that._getVisibleArea();
  361. var rotated = that._options.rotated;
  362. if (visibleArea.minX > x + (width || 0) || visibleArea.maxX < x || visibleArea.minY > y + (height || 0) || visibleArea.maxY < y || rotated && _isDefined(width) && 0 !== width && (visibleArea.minX === x + width || visibleArea.maxX === x) || !rotated && _isDefined(height) && 0 !== height && (visibleArea.minY === y + height || visibleArea.maxY === y)) {
  363. that.inVisibleArea = false
  364. } else {
  365. that.inVisibleArea = true
  366. }
  367. },
  368. hasValue: function() {
  369. return null !== this.value && null !== this.minValue
  370. },
  371. hasCoords: _noop,
  372. correctPosition: _noop,
  373. correctRadius: _noop,
  374. correctLabelRadius: _noop,
  375. getCrosshairData: _noop,
  376. getPointRadius: _noop,
  377. _populatePointShape: _noop,
  378. _checkSymbol: _noop,
  379. getMarkerCoords: _noop,
  380. hide: _noop,
  381. show: _noop,
  382. hideMarker: _noop,
  383. setInvisibility: _noop,
  384. clearVisibility: _noop,
  385. isVisible: _noop,
  386. resetCorrection: _noop,
  387. correctValue: _noop,
  388. resetValue: _noop,
  389. setPercentValue: _noop,
  390. correctCoordinates: _noop,
  391. coordsIn: _noop,
  392. getTooltipParams: _noop,
  393. applyWordWrap: _noop,
  394. setLabelTrackerData: _noop,
  395. updateLabelCoord: _noop,
  396. drawLabel: _noop,
  397. correctLabelPosition: _noop,
  398. getMinValue: _noop,
  399. getMaxValue: _noop,
  400. _drawErrorBar: _noop,
  401. getMarkerVisibility: _noop,
  402. dispose: function() {
  403. var that = this;
  404. that.deleteMarker();
  405. that.deleteLabel();
  406. that._errorBar && this._errorBar.dispose();
  407. that._options = that._styles = that.series = that._errorBar = null
  408. },
  409. getTooltipFormatObject: function(tooltip) {
  410. var that = this;
  411. var tooltipFormatObject = that._getFormatObject(tooltip);
  412. var sharedTooltipValuesArray = [];
  413. var tooltipStackPointsFormatObject = [];
  414. if (that.stackPoints) {
  415. _each(that.stackPoints, function(_, point) {
  416. if (!point.isVisible()) {
  417. return
  418. }
  419. var formatObject = point._getFormatObject(tooltip);
  420. tooltipStackPointsFormatObject.push(formatObject);
  421. sharedTooltipValuesArray.push(formatObject.seriesName + ": " + formatObject.valueText)
  422. });
  423. _extend(tooltipFormatObject, {
  424. points: tooltipStackPointsFormatObject,
  425. valueText: sharedTooltipValuesArray.join("\n"),
  426. stackName: that.stackPoints.stackName
  427. })
  428. }
  429. var aggregationInfo = that.aggregationInfo;
  430. if (aggregationInfo) {
  431. var axis = that.series.getArgumentAxis();
  432. var rangeText = axis.formatRange(aggregationInfo.intervalStart, aggregationInfo.intervalEnd, aggregationInfo.aggregationInterval);
  433. if (rangeText) {
  434. tooltipFormatObject.valueText += "\n".concat(rangeText)
  435. }
  436. }
  437. return tooltipFormatObject
  438. },
  439. setHole: function(holeValue, position) {
  440. var that = this;
  441. var minValue = isFinite(that.minValue) ? that.minValue : 0;
  442. if (_isDefined(holeValue)) {
  443. if ("left" === position) {
  444. that.leftHole = that.value - holeValue;
  445. that.minLeftHole = minValue - holeValue
  446. } else {
  447. that.rightHole = that.value - holeValue;
  448. that.minRightHole = minValue - holeValue
  449. }
  450. }
  451. },
  452. resetHoles: function() {
  453. this.leftHole = null;
  454. this.minLeftHole = null;
  455. this.rightHole = null;
  456. this.minRightHole = null
  457. },
  458. getLabel: function() {
  459. return this._label
  460. },
  461. getLabels: function() {
  462. return [this._label]
  463. },
  464. getCenterCoord: function() {
  465. return {
  466. x: this.x,
  467. y: this.y
  468. }
  469. }
  470. };