UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

349 lines (347 loc) • 14 kB
/** * DevExtreme (cjs/viz/series/points/candlestick_point.js) * Version: 24.2.6 * Build date: Mon Mar 17 2025 * * Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ "use strict"; exports.default = void 0; var _extend2 = require("../../../core/utils/extend"); var _symbol_point = _interopRequireDefault(require("./symbol_point")); var _bar_point = _interopRequireDefault(require("./bar_point")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e } } const _math = Math; const _abs = _math.abs; const _min = _math.min; const _max = _math.max; const _round = _math.round; const DEFAULT_FINANCIAL_TRACKER_MARGIN = 2; var _default = exports.default = (0, _extend2.extend)({}, _bar_point.default, { _calculateVisibility: _symbol_point.default._calculateVisibility, _getContinuousPoints: function(openCoord, closeCoord) { const that = this; const x = that.x; const createPoint = that._options.rotated ? function(x, y) { return [y, x] } : function(x, y) { return [x, y] }; const width = that.width; const highCoord = that.highY; const max = _abs(highCoord - openCoord) < _abs(highCoord - closeCoord) ? openCoord : closeCoord; const min = max === closeCoord ? openCoord : closeCoord; let points; if (min === max) { points = [].concat(createPoint(x, that.highY)).concat(createPoint(x, that.lowY)).concat(createPoint(x, that.closeY)).concat(createPoint(x - width / 2, that.closeY)).concat(createPoint(x + width / 2, that.closeY)).concat(createPoint(x, that.closeY)) } else { points = [].concat(createPoint(x, that.highY)).concat(createPoint(x, max)).concat(createPoint(x + width / 2, max)).concat(createPoint(x + width / 2, min)).concat(createPoint(x, min)).concat(createPoint(x, that.lowY)).concat(createPoint(x, min)).concat(createPoint(x - width / 2, min)).concat(createPoint(x - width / 2, max)).concat(createPoint(x, max)) } return points }, _getCrockPoints: function(y) { const x = this.x; const createPoint = this._options.rotated ? function(x, y) { return [y, x] } : function(x, y) { return [x, y] }; return [].concat(createPoint(x, this.highY)).concat(createPoint(x, this.lowY)).concat(createPoint(x, y)).concat(createPoint(x - this.width / 2, y)).concat(createPoint(x + this.width / 2, y)).concat(createPoint(x, y)) }, _getPoints: function() { const that = this; let points; const closeCoord = that.closeY; const openCoord = that.openY; if (null !== closeCoord && null !== openCoord) { points = that._getContinuousPoints(openCoord, closeCoord) } else if (openCoord === closeCoord) { points = [that.x, that.highY, that.x, that.lowY] } else { points = that._getCrockPoints(null !== openCoord ? openCoord : closeCoord) } return points }, getColor: function() { return this._isReduction ? this._options.reduction.color : this._styles.normal.stroke || this.series.getColor() }, _drawMarkerInGroup: function(group, attributes, renderer) { this.graphic = renderer.path(this._getPoints(), "area").attr({ "stroke-linecap": "square" }).attr(attributes).data({ "chart-data-point": this }).sharp().append(group) }, _fillStyle: function() { const that = this; const styles = that._options.styles; if (that._isReduction && that._isPositive) { that._styles = styles.reductionPositive } else if (that._isReduction) { that._styles = styles.reduction } else if (that._isPositive) { that._styles = styles.positive } else { that._styles = styles } }, _getMinTrackerWidth: function() { return 2 + 2 * this._styles.normal["stroke-width"] }, correctCoordinates: function(correctOptions) { const minWidth = this._getMinTrackerWidth(); let width = correctOptions.width; width = width < minWidth ? minWidth : width > 10 ? 10 : width; this.width = width + width % 2; this.xCorrection = correctOptions.offset }, _getMarkerGroup: function(group) { let markerGroup; if (this._isReduction && this._isPositive) { markerGroup = group.reductionPositiveMarkersGroup } else if (this._isReduction) { markerGroup = group.reductionMarkersGroup } else if (this._isPositive) { markerGroup = group.defaultPositiveMarkersGroup } else { markerGroup = group.defaultMarkersGroup } return markerGroup }, _drawMarker: function(renderer, group) { this._drawMarkerInGroup(this._getMarkerGroup(group), this._getStyle(), renderer) }, _getSettingsForTracker: function() { const that = this; let highY = that.highY; let lowY = that.lowY; const rotated = that._options.rotated; let x; let y; let width; let height; if (highY === lowY) { highY = rotated ? highY + 2 : highY - 2; lowY = rotated ? lowY - 2 : lowY + 2 } if (rotated) { x = _min(lowY, highY); y = that.x - that.width / 2; width = _abs(lowY - highY); height = that.width } else { x = that.x - that.width / 2; y = _min(lowY, highY); width = that.width; height = _abs(lowY - highY) } return { x: x, y: y, width: width, height: height } }, _getGraphicBBox: function(location) { const that = this; const rotated = that._options.rotated; const x = that.x; const width = that.width; let lowY = that.lowY; let highY = that.highY; if (location) { const valVisibleArea = that.series.getValueAxis().getVisibleArea(); highY = that._truncateCoord(highY, valVisibleArea); lowY = that._truncateCoord(lowY, valVisibleArea) } const bBox = { x: !rotated ? x - _round(width / 2) : lowY, y: !rotated ? highY : x - _round(width / 2), width: !rotated ? width : highY - lowY, height: !rotated ? lowY - highY : width }; if (location) { const isTop = "top" === location; if (!this._options.rotated) { bBox.y = isTop ? bBox.y : bBox.y + bBox.height; bBox.height = 0 } else { bBox.x = isTop ? bBox.x + bBox.width : bBox.x; bBox.width = 0 } } return bBox }, getTooltipParams: function(location) { const that = this; if (that.graphic) { const minValue = _min(that.lowY, that.highY); const maxValue = _max(that.lowY, that.highY); const visibleArea = that._getVisibleArea(); const rotated = that._options.rotated; const minVisible = rotated ? visibleArea.minX : visibleArea.minY; const maxVisible = rotated ? visibleArea.maxX : visibleArea.maxY; const min = _max(minVisible, minValue); const max = _min(maxVisible, maxValue); const centerCoord = that.getCenterCoord(); if ("edge" === location) { centerCoord[rotated ? "x" : "y"] = rotated ? max : min } centerCoord.offset = 0; return centerCoord } }, getCenterCoord() { if (this.graphic) { const that = this; let x; let y; const minValue = _min(that.lowY, that.highY); const maxValue = _max(that.lowY, that.highY); const visibleArea = that._getVisibleArea(); const rotated = that._options.rotated; const minVisible = rotated ? visibleArea.minX : visibleArea.minY; const maxVisible = rotated ? visibleArea.maxX : visibleArea.maxY; const min = _max(minVisible, minValue); const max = _min(maxVisible, maxValue); const center = min + (max - min) / 2; if (rotated) { y = that.x; x = center } else { x = that.x; y = center } return { x: x, y: y } } }, hasValue: function() { return null !== this.highValue && null !== this.lowValue }, hasCoords: function() { return null !== this.x && null !== this.lowY && null !== this.highY }, _translate: function() { const rotated = this._options.rotated; const valTranslator = this._getValTranslator(); const x = this._getArgTranslator().translate(this.argument); this.vx = this.vy = this.x = null === x ? x : x + (this.xCorrection || 0); this.openY = null !== this.openValue ? valTranslator.translate(this.openValue) : null; this.highY = valTranslator.translate(this.highValue); this.lowY = valTranslator.translate(this.lowValue); this.closeY = null !== this.closeValue ? valTranslator.translate(this.closeValue) : null; const centerValue = _min(this.lowY, this.highY) + _abs(this.lowY - this.highY) / 2; this._calculateVisibility(!rotated ? this.x : centerValue, !rotated ? centerValue : this.x) }, getCrosshairData: function(x, y) { const that = this; const rotated = that._options.rotated; const origY = rotated ? x : y; let yValue; const argument = that.argument; let coords; let coord = "low"; if (_abs(that.lowY - origY) < _abs(that.closeY - origY)) { yValue = that.lowY } else { yValue = that.closeY; coord = "close" } if (_abs(yValue - origY) >= _abs(that.openY - origY)) { yValue = that.openY; coord = "open" } if (_abs(yValue - origY) >= _abs(that.highY - origY)) { yValue = that.highY; coord = "high" } if (rotated) { coords = { y: that.vy, x: yValue, xValue: that[coord + "Value"], yValue: argument } } else { coords = { x: that.vx, y: yValue, xValue: argument, yValue: that[coord + "Value"] } } coords.axis = that.series.axis; return coords }, _updateData: function(data) { const label = this._label; const reductionColor = this._options.reduction.color; this.value = this.initialValue = data.reductionValue; this.originalValue = data.value; this.lowValue = this.originalLowValue = data.lowValue; this.highValue = this.originalHighValue = data.highValue; this.openValue = this.originalOpenValue = data.openValue; this.closeValue = this.originalCloseValue = data.closeValue; this._isPositive = data.openValue < data.closeValue; this._isReduction = data.isReduction; if (this._isReduction) { label.setColor(reductionColor) } }, _updateMarker: function(animationEnabled, style, group) { const graphic = this.graphic; graphic.attr({ points: this._getPoints() }).smartAttr(style).sharp(); group && graphic.append(this._getMarkerGroup(group)) }, _getLabelFormatObject: function() { return { openValue: this.openValue, highValue: this.highValue, lowValue: this.lowValue, closeValue: this.closeValue, reductionValue: this.initialValue, argument: this.initialArgument, value: this.initialValue, seriesName: this.series.name, originalOpenValue: this.originalOpenValue, originalCloseValue: this.originalCloseValue, originalLowValue: this.originalLowValue, originalHighValue: this.originalHighValue, originalArgument: this.originalArgument, point: this } }, _getFormatObject: function(tooltip) { const highValue = tooltip.formatValue(this.highValue); const openValue = tooltip.formatValue(this.openValue); const closeValue = tooltip.formatValue(this.closeValue); const lowValue = tooltip.formatValue(this.lowValue); const symbolMethods = _symbol_point.default; const formatObject = symbolMethods._getFormatObject.call(this, tooltip); return (0, _extend2.extend)({}, formatObject, { valueText: "h: " + highValue + ("" !== openValue ? " o: " + openValue : "") + ("" !== closeValue ? " c: " + closeValue : "") + " l: " + lowValue, highValueText: highValue, openValueText: openValue, closeValueText: closeValue, lowValueText: lowValue }) }, getMaxValue: function() { return this.highValue }, getMinValue: function() { return this.lowValue } }); module.exports = exports.default; module.exports.default = exports.default;