UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

468 lines (465 loc) • 16 kB
/** * DevExtreme (cjs/__internal/viz/series/points/base_point.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Point = void 0; var _m_common = require("../../../core/utils/m_common"); var _m_extend = require("../../../core/utils/m_extend"); var _m_type = require("../../../core/utils/m_type"); var _consts = _interopRequireDefault(require("../../../viz/components/consts")); var _utils = require("../../../viz/core/utils"); var _bar_point = _interopRequireDefault(require("../../../viz/series/points/bar_point")); var _bubble_point = _interopRequireDefault(require("../../../viz/series/points/bubble_point")); var _candlestick_point = _interopRequireDefault(require("../../../viz/series/points/candlestick_point")); var _pie_point = _interopRequireDefault(require("../../../viz/series/points/pie_point")); var _polar_point = require("../../../viz/series/points/polar_point"); var _range_bar_point = _interopRequireDefault(require("../../../viz/series/points/range_bar_point")); var _range_symbol_point = _interopRequireDefault(require("../../../viz/series/points/range_symbol_point")); var _stock_point = _interopRequireDefault(require("../../../viz/series/points/stock_point")); var _symbol_point = _interopRequireDefault(require("../../../viz/series/points/symbol_point")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const mixins = {}; const _extend = _m_extend.extend; const statesConsts = _consts.default.states; const SYMBOL_POINT = "symbolPoint"; const POLAR_SYMBOL_POINT = "polarSymbolPoint"; const BAR_POINT = "barPoint"; const POLAR_BAR_POINT = "polarBarPoint"; const PIE_POINT = "piePoint"; const SELECTED_STATE = statesConsts.selectedMark; const HOVER_STATE = statesConsts.hoverMark; const NORMAL_STATE = statesConsts.normalMark; const HOVER = statesConsts.hover; const NORMAL = statesConsts.normal; const SELECTION = statesConsts.selection; const pointTypes = { chart: { scatter: SYMBOL_POINT, line: SYMBOL_POINT, spline: SYMBOL_POINT, stepline: SYMBOL_POINT, stackedline: SYMBOL_POINT, fullstackedline: SYMBOL_POINT, stackedspline: SYMBOL_POINT, fullstackedspline: SYMBOL_POINT, stackedsplinearea: SYMBOL_POINT, fullstackedsplinearea: SYMBOL_POINT, area: SYMBOL_POINT, splinearea: SYMBOL_POINT, steparea: SYMBOL_POINT, stackedarea: SYMBOL_POINT, fullstackedarea: SYMBOL_POINT, rangearea: "rangeSymbolPoint", bar: BAR_POINT, stackedbar: BAR_POINT, fullstackedbar: BAR_POINT, rangebar: "rangeBarPoint", bubble: "bubblePoint", stock: "stockPoint", candlestick: "candlestickPoint" }, pie: { pie: PIE_POINT, doughnut: PIE_POINT, donut: PIE_POINT }, polar: { scatter: "polarSymbolPoint", line: "polarSymbolPoint", area: "polarSymbolPoint", bar: "polarBarPoint", stackedbar: "polarBarPoint" } }; function isNoneMode(mode) { return "none" === (0, _utils.normalizeEnum)(mode) } let Point = exports.Point = class { constructor(series, dataItem, options) { this.fullState = NORMAL_STATE; this.series = series; this.update(dataItem, options); this._viewCounters = { hover: 0, selection: 0 }; this._emptySettings = { fill: null, stroke: null, dashStyle: null, filter: null } } getColor() { if (!this.hasValue() && !this._styles.usePointCustomOptions) { this.series.customizePoint(this, this._dataItem) } return this._styles.normal.fill || this.series.getColor() } _getStyle() { return this._styles[this._currentStyle || "normal"] } update(dataItem, options) { this.updateOptions(options); this.updateData(dataItem) } updateData(dataItem) { const argumentWasChanged = this.argument !== dataItem.argument; this.argument = this.initialArgument = this.originalArgument = dataItem.argument; this.tag = dataItem.tag; this.index = dataItem.index; this._dataItem = dataItem; this.data = dataItem.data; this.lowError = dataItem.lowError; this.highError = dataItem.highError; this.aggregationInfo = dataItem.aggregationInfo; this._updateData(dataItem, argumentWasChanged); !this.hasValue() && this.setInvisibility(); this._fillStyle(); this._updateLabelData() } deleteMarker() { if (this.graphic) { this.graphic.dispose() } this.graphic = null } draw(renderer, groups, animationEnabled, firstDrawing) { if (this._needDeletingOnDraw || this.series.autoHidePointMarkers && !this.isSelected()) { this.deleteMarker(); this._needDeletingOnDraw = false } if (this._needClearingOnDraw) { this.clearMarker(); this._needClearingOnDraw = false } if (!this._hasGraphic()) { this.getMarkerVisibility() && !this.series.autoHidePointMarkers && this._drawMarker(renderer, groups.markers, animationEnabled, firstDrawing) } else { this._updateMarker(animationEnabled, this._getStyle(), groups.markers) } this._drawLabel(); this._drawErrorBar(renderer, groups.errorBars); return this } _getViewStyle() { let state = NORMAL_STATE; let fullState = this.fullState; const styles = [NORMAL, HOVER, SELECTION, SELECTION]; if (this._viewCounters.hover) { state |= HOVER_STATE } if (this._viewCounters.selection) { state |= SELECTED_STATE } if (isNoneMode(this.getOptions().selectionMode)) { fullState &= ~SELECTED_STATE } if (isNoneMode(this.getOptions().hoverMode)) { fullState &= ~HOVER_STATE } state |= fullState; return styles[state] } applyView(legendCallback) { const style = this._getViewStyle(); this._currentStyle = style; if (!this.graphic && this.getMarkerVisibility() && this.series.autoHidePointMarkers && (style === SELECTION || style === HOVER)) { this._drawMarker(this.series.getRenderer(), this.series.getMarkersGroup()) } if (this.graphic) { if (this.series.autoHidePointMarkers && style !== SELECTION && style !== HOVER) { this.deleteMarker() } else { if ("normal" === style) { this.clearMarker() } else { this.graphic.toForeground() } this._updateMarker(true, this._styles[style], void 0, legendCallback) } } } setView(style) { this._viewCounters[style]++; this.applyView() } resetView(style) { const viewCounters = this._viewCounters; --viewCounters[style]; if (viewCounters[style] < 0) { viewCounters[style] = 0 } this.applyView() } releaseHoverState() { if (this.graphic && !this.isSelected()) { this.graphic.toBackground() } } select() { this.series.selectPoint(this) } clearSelection() { this.series.deselectPoint(this) } hover() { this.series.hoverPoint(this) } clearHover() { this.series.clearPointHover() } showTooltip() { this.series.showPointTooltip(this) } hideTooltip() { this.series.hidePointTooltip(this) } _checkLabelsChanging(oldType, newType) { const isNewRange = ~newType.indexOf("range"); const isOldRange = ~oldType.indexOf("range"); return isOldRange && !isNewRange || !isOldRange && isNewRange } updateOptions(newOptions) { if (!newOptions) { return } const oldOptions = this._options; const widgetType = newOptions.widgetType; const oldType = oldOptions && oldOptions.type; const newType = newOptions.type; const newPointTypeMixin = pointTypes[widgetType][newType]; if (oldType !== newType) { this._needDeletingOnDraw = true; this._needClearingOnDraw = false; if (oldType) { this._checkLabelsChanging(oldType, newType) && this.deleteLabel(); this._resetType(mixins[pointTypes[widgetType][oldType]]) } this._setType(mixins[newPointTypeMixin]) } else { this._needDeletingOnDraw = this._needDeletingOnDraw || this._checkSymbol(oldOptions, newOptions); this._needClearingOnDraw = this._checkCustomize(oldOptions, newOptions) } this._options = newOptions; this._fillStyle(); this._updateLabelOptions() } translate() { if (this.hasValue()) { this._translate(); this.translated = true } } _checkCustomize(oldOptions, newOptions) { return oldOptions.styles.usePointCustomOptions && !newOptions.styles.usePointCustomOptions } _getCustomLabelVisibility() { return this._styles.useLabelCustomOptions ? !!this._options.label.visible : null } getBoundingRect() { return this._getGraphicBBox() } _resetType(methods) { for (const methodName in methods) { delete this[methodName] } } _setType(methods) { for (const methodName in methods) { this[methodName] = methods[methodName] } } isInVisibleArea() { return this.inVisibleArea } isSelected() { return !!(this.fullState & SELECTED_STATE) } isHovered() { return !!(this.fullState & HOVER_STATE) } getOptions() { return this._options } animate(complete, settings, partitionDuration) { if (!this.graphic) { complete && complete(); return } this.graphic.animate(settings, { partitionDuration: partitionDuration }, complete) } getCoords(min) { if (!min) { return { x: this.x, y: this.y } } if (!this._options.rotated) { return { x: this.x, y: this.minY + (this.y - this.minY ? 0 : 1) } } return { x: this.minX - (this.x - this.minX ? 0 : 1), y: this.y } } getDefaultCoords() { return !this._options.rotated ? { x: this.x, y: this.defaultY } : { x: this.defaultX, y: this.y } } setDefaultCoords() { const coords = this.getDefaultCoords(); this.x = coords.x; this.y = coords.y } _getVisibleArea() { return this.series.getVisibleArea() } _getArgTranslator() { return this.series.getArgumentAxis().getTranslator() } _getValTranslator() { return this.series.getValueAxis().getTranslator() } isArgumentCorrect() { return this.series._argumentChecker(this.argument) } isValueCorrect() { const valueChecker = this.series._valueChecker; return valueChecker(this.getMinValue()) && valueChecker(this.getMaxValue()) } hasValue() { return null !== this.value && null !== this.minValue && this.isArgumentCorrect() && this.isValueCorrect() } dispose() { this.deleteMarker(); this.deleteLabel(); this._errorBar && this._errorBar.dispose(); this._options = this._styles = this.series = this._errorBar = null } getTooltipFormatObject(tooltip, stackPoints) { const tooltipFormatObject = this._getFormatObject(tooltip); const sharedTooltipValuesArray = []; const tooltipStackPointsFormatObject = []; if (stackPoints) { stackPoints.forEach(point => { if (!point.isVisible()) { return } const formatObject = point._getFormatObject(tooltip); tooltipStackPointsFormatObject.push(formatObject); sharedTooltipValuesArray.push(`${formatObject.seriesName}: ${formatObject.valueText}`) }); _extend(tooltipFormatObject, { points: tooltipStackPointsFormatObject, valueText: sharedTooltipValuesArray.join("\n"), stackName: this.series.getStackName() || null }) } const aggregationInfo = this.aggregationInfo; if (aggregationInfo) { const axis = this.series.getArgumentAxis(); const rangeText = axis.formatRange(aggregationInfo.intervalStart, aggregationInfo.intervalEnd, aggregationInfo.aggregationInterval, tooltip.getOptions().argumentFormat); if (rangeText) { tooltipFormatObject.valueText += `\n${rangeText}` } } return tooltipFormatObject } setHole(holeValue, position) { const minValue = isFinite(this.minValue) ? this.minValue : 0; if ((0, _m_type.isDefined)(holeValue)) { if ("left" === position) { this.leftHole = this.value - holeValue; this.minLeftHole = minValue - holeValue } else { this.rightHole = this.value - holeValue; this.minRightHole = minValue - holeValue } } } resetHoles() { this.leftHole = null; this.minLeftHole = null; this.rightHole = null; this.minRightHole = null } getLabel() { return this._label } getLabels() { return [this._label] } getCenterCoord() { return { x: this.x, y: this.y } } }; mixins.symbolPoint = _symbol_point.default; mixins.barPoint = _bar_point.default; mixins.bubblePoint = _bubble_point.default; mixins.piePoint = _pie_point.default; mixins.rangeSymbolPoint = _range_symbol_point.default; mixins.rangeBarPoint = _range_bar_point.default; mixins.candlestickPoint = _candlestick_point.default; mixins.stockPoint = _stock_point.default; mixins.polarSymbolPoint = _polar_point.polarSymbolPoint; mixins.polarBarPoint = _polar_point.polarBarPoint; Object.assign(Point.prototype, { hasCoords: _m_common.noop, correctPosition: _m_common.noop, correctRadius: _m_common.noop, correctLabelRadius: _m_common.noop, getCrosshairData: _m_common.noop, getPointRadius: _m_common.noop, _populatePointShape: _m_common.noop, _checkSymbol: _m_common.noop, getMarkerCoords: _m_common.noop, hide: _m_common.noop, show: _m_common.noop, hideMarker: _m_common.noop, setInvisibility: _m_common.noop, clearVisibility: _m_common.noop, isVisible: _m_common.noop, resetCorrection: _m_common.noop, correctValue: _m_common.noop, resetValue: _m_common.noop, setPercentValue: _m_common.noop, correctCoordinates: _m_common.noop, coordsIn: _m_common.noop, getTooltipParams: _m_common.noop, applyWordWrap: _m_common.noop, setLabelTrackerData: _m_common.noop, updateLabelCoord: _m_common.noop, drawLabel: _m_common.noop, correctLabelPosition: _m_common.noop, getMinValue: _m_common.noop, getMaxValue: _m_common.noop, _drawErrorBar: _m_common.noop, getMarkerVisibility: _m_common.noop });