devextreme
Version:
JavaScript/TypeScript Component Suite for Responsive Web Development
353 lines (351 loc) • 13.8 kB
JavaScript
/**
* DevExtreme (cjs/__internal/viz/series/points/candlestick_point.js)
* Version: 25.2.5
* Build date: Fri Feb 20 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.default = void 0;
var _extend2 = require("../../../../core/utils/extend");
var _bar_point = _interopRequireDefault(require("../../../viz/series/points/bar_point"));
var _symbol_point = _interopRequireDefault(require("../../../viz/series/points/symbol_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, {
_getContinuousPoints(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(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() {
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() {
return this._isReduction ? this._options.reduction.color : this._styles.normal.stroke || this.series.getColor()
},
_drawMarkerInGroup(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() {
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() {
return 2 + 2 * this._styles.normal["stroke-width"]
},
correctCoordinates(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(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(renderer, group) {
this._drawMarkerInGroup(this._getMarkerGroup(group), this._getStyle(), renderer)
},
_getSettingsForTracker() {
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(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(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() {
return null !== this.highValue && null !== this.lowValue
},
hasCoords() {
return null !== this.x && null !== this.lowY && null !== this.highY
},
_translate() {
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 minValue = Math.min(this.lowY, this.highY);
const height = Math.abs(this.lowY - this.highY);
if (this._options.rotated) {
this._calculateVisibility(minValue, this.x, height, 0)
} else {
this._calculateVisibility(this.x, minValue, 0, height)
}
},
getCrosshairData(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(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(animationEnabled, style, group) {
const graphic = this.graphic;
graphic.attr({
points: this._getPoints()
}).smartAttr(style).sharp();
group && graphic.append(this._getMarkerGroup(group))
},
_getLabelFormatObject() {
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(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() {
return this.highValue
},
getMinValue() {
return this.lowValue
}
});