/* * * * (c) 2010-2021 Torstein Honsi * * License: www.highcharts.com/license * * !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!! * * */ 'use strict'; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import OHLCPoint from './OHLCPoint.js'; import SeriesRegistry from '../../Core/Series/SeriesRegistry.js'; var Series = SeriesRegistry.series, HLCSeries = SeriesRegistry.seriesTypes.hlc; import U from '../../Core/Utilities.js'; var addEvent = U.addEvent, extend = U.extend, merge = U.merge; /** * The ohlc series type. * * @private * @class * @name Highcharts.seriesTypes.ohlc * * @augments Highcharts.Series */ var OHLCSeries = /** @class */ (function (_super) { __extends(OHLCSeries, _super); function OHLCSeries() { /* * * * Static Properties * * */ var _this = _super !== null && _super.apply(this, arguments) || this; /* * * * Properties * * */ _this.data = void 0; _this.options = void 0; _this.points = void 0; return _this; } /* * * * Functions * * */ OHLCSeries.prototype.getPointPath = function (point, graphic) { var path = _super.prototype.getPointPath.call(this, point, graphic), strokeWidth = graphic.strokeWidth(), crispCorr = (strokeWidth % 2) / 2, crispX = Math.round(point.plotX) - crispCorr, halfWidth = Math.round(point.shapeArgs.width / 2); var plotOpen = point.plotOpen; // crisp vector coordinates if (point.open !== null) { plotOpen = Math.round(point.plotOpen) + crispCorr; path.push(['M', crispX, plotOpen], ['L', crispX - halfWidth, plotOpen]); _super.prototype.extendStem.call(this, path, strokeWidth / 2, plotOpen); } return path; }; /* eslint-disable valid-jsdoc */ /** * Postprocess mapping between options and SVG attributes * @private */ OHLCSeries.prototype.pointAttribs = function (point, state) { var attribs = _super.prototype.pointAttribs.call(this, point, state), options = this.options; delete attribs.fill; if (!point.options.color && options.upColor && point.open < point.close) { attribs.stroke = options.upColor; } return attribs; }; OHLCSeries.prototype.toYData = function (point) { // return a plain array for speedy calculation return [point.open, point.high, point.low, point.close]; }; /** * An OHLC chart is a style of financial chart used to describe price * movements over time. It displays open, high, low and close values per * data point. * * @sample stock/demo/ohlc/ * OHLC chart * * @extends plotOptions.hlc * @product highstock * @optionparent plotOptions.ohlc */ /** * The parameter allows setting line series type and use OHLC indicators. * Data in OHLC format is required. * * @sample {highstock} stock/indicators/use-ohlc-data * Use OHLC data format to plot line chart * * @type {boolean} * @product highstock * @apioption plotOptions.line.useOhlcData */ OHLCSeries.defaultOptions = merge(HLCSeries.defaultOptions, { /** * @type {Highcharts.DataGroupingApproximationValue|Function} * @default ohlc * @product highstock * @apioption plotOptions.ohlc.dataGrouping.approximation */ tooltip: { pointFormat: '\u25CF ' + ' {series.name}
' + 'Open: {point.open}
' + 'High: {point.high}
' + 'Low: {point.low}
' + 'Close: {point.close}
' } /** * Determines which one of `open`, `high`, `low`, `close` values should * be represented as `point.y`, which is later used to set dataLabel * position and [compare](#plotOptions.series.compare). * * @default close * @validvalue ["open", "high", "low", "close"] * @product highstock * @apioption plotOptions.ohlc.pointValKey */ /** * Line color for up points. * * @type {Highcharts.ColorString|Highcharts.GradientColorObject|Highcharts.PatternObject} * @product highstock * @apioption plotOptions.ohlc.upColor */ }); return OHLCSeries; }(HLCSeries)); extend(OHLCSeries.prototype, { pointArrayMap: ['open', 'high', 'low', 'close'] }); OHLCSeries.prototype.pointClass = OHLCPoint; SeriesRegistry.registerSeriesType('ohlc', OHLCSeries); /* * * * Default Export * * */ export default OHLCSeries; // Add useOhlcData option addEvent(Series, 'init', function (eventOptions) { // eslint-disable-next-line no-invalid-this var series = this, options = eventOptions.options; if (options.useOhlcData && options.id !== 'highcharts-navigator-series') { extend(series, { pointValKey: OHLCSeries.prototype.pointValKey, // keys: ohlcProto.keys, // @todo potentially nonsense pointArrayMap: OHLCSeries.prototype.pointArrayMap, toYData: OHLCSeries.prototype.toYData }); } }); addEvent(Series, 'afterSetOptions', function (e) { var options = e.options, dataGrouping = options.dataGrouping; if (dataGrouping && options.useOhlcData && options.id !== 'highcharts-navigator-series') { dataGrouping.approximation = 'ohlc'; } }); /* * * * API Options * * */ /** * A `ohlc` series. If the [type](#series.ohlc.type) option is not * specified, it is inherited from [chart.type](#chart.type). * * @extends series,plotOptions.ohlc * @excluding dataParser, dataURL * @product highstock * @apioption series.ohlc */ /** * An array of data points for the series. For the `ohlc` series type, * points can be given in the following ways: * * 1. An array of arrays with 5 or 4 values. In this case, the values correspond * to `x,open,high,low,close`. If the first value is a string, it is applied * as the name of the point, and the `x` value is inferred. The `x` value can * also be omitted, in which case the inner arrays should be of length 4\. * Then the `x` value is automatically calculated, either starting at 0 and * incremented by 1, or from `pointStart` and `pointInterval` given in the * series options. * ```js * data: [ * [0, 6, 5, 6, 7], * [1, 9, 4, 8, 2], * [2, 6, 3, 4, 10] * ] * ``` * * 2. An array of objects with named values. The following snippet shows only a * few settings, see the complete options set below. If the total number of * data points exceeds the series' * [turboThreshold](#series.ohlc.turboThreshold), this option is not * available. * ```js * data: [{ * x: 1, * open: 3, * high: 4, * low: 5, * close: 2, * name: "Point2", * color: "#00FF00" * }, { * x: 1, * open: 4, * high: 3, * low: 6, * close: 7, * name: "Point1", * color: "#FF00FF" * }] * ``` * * @type {Array|Array<(number|string),number,number,number,number>|*>} * @extends series.arearange.data * @excluding y, marker * @product highstock * @apioption series.ohlc.data */ /** * The closing value of each data point. * * @type {number} * @product highstock * @apioption series.ohlc.data.close */ /** * The opening value of each data point. * * @type {number} * @product highstock * @apioption series.ohlc.data.open */ ''; // adds doclets above to transpilat