highcharts
Version:
JavaScript charting framework
197 lines (185 loc) • 6.12 kB
JavaScript
/**
* @license Highstock JS v12.2.0 (2025-04-07)
* @module highcharts/indicators/momentum
* @requires highcharts
* @requires highcharts/modules/stock
*
* Indicator series type for Highcharts Stock
*
* (c) 2010-2025 Sebastian Bochan
*
* License: www.highcharts.com/license
*/
import * as __WEBPACK_EXTERNAL_MODULE__highcharts_src_js_8202131d__ from "../highcharts.src.js";
import * as __WEBPACK_EXTERNAL_MODULE__modules_stock_src_js_b3d80146__ from "../modules/stock.src.js";
/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/
/************************************************************************/
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => (module['default']) :
/******/ () => (module);
/******/ __webpack_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/
/************************************************************************/
;// external ["../highcharts.src.js","default"]
const external_highcharts_src_js_default_namespaceObject = __WEBPACK_EXTERNAL_MODULE__highcharts_src_js_8202131d__["default"];
var external_highcharts_src_js_default_default = /*#__PURE__*/__webpack_require__.n(external_highcharts_src_js_default_namespaceObject);
;// external "../modules/stock.src.js"
var x = (y) => {
var x = {}; __webpack_require__.d(x,
y); return x
}
var y = (x) => (() => (x))
const stock_src_js_namespaceObject = x({ });
;// external ["../highcharts.src.js","default","SeriesRegistry"]
const external_highcharts_src_js_default_SeriesRegistry_namespaceObject = __WEBPACK_EXTERNAL_MODULE__highcharts_src_js_8202131d__["default"].SeriesRegistry;
var external_highcharts_src_js_default_SeriesRegistry_default = /*#__PURE__*/__webpack_require__.n(external_highcharts_src_js_default_SeriesRegistry_namespaceObject);
;// ./code/es-modules/Stock/Indicators/Momentum/MomentumIndicator.js
/* *
*
* License: www.highcharts.com/license
*
* !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
*
* */
const { sma: SMAIndicator } = (external_highcharts_src_js_default_SeriesRegistry_default()).seriesTypes;
const { extend, isArray, merge } = (external_highcharts_src_js_default_default());
/* *
*
* Functions
*
* */
/**
* @private
*/
function populateAverage(xVal, yVal, i, period, index) {
const mmY = yVal[i - 1][index] - yVal[i - period - 1][index], mmX = xVal[i - 1];
return [mmX, mmY];
}
/* *
*
* Class
*
* */
/**
* The Momentum series type.
*
* @private
* @class
* @name Highcharts.seriesTypes.momentum
*
* @augments Highcharts.Series
*/
class MomentumIndicator extends SMAIndicator {
/* *
*
* Functions
*
* */
getValues(series, params) {
const period = params.period, index = params.index, xVal = series.xData, yVal = series.yData, yValLen = yVal ? yVal.length : 0, MM = [], xData = [], yData = [];
let i, MMPoint;
if (xVal.length <= period) {
return;
}
// Switch index for OHLC / Candlestick / Arearange
if (!isArray(yVal[0])) {
return;
}
// Calculate value one-by-one for each period in visible data
for (i = (period + 1); i < yValLen; i++) {
MMPoint = populateAverage(xVal, yVal, i, period, index);
MM.push(MMPoint);
xData.push(MMPoint[0]);
yData.push(MMPoint[1]);
}
MMPoint = populateAverage(xVal, yVal, i, period, index);
MM.push(MMPoint);
xData.push(MMPoint[0]);
yData.push(MMPoint[1]);
return {
values: MM,
xData: xData,
yData: yData
};
}
}
/* *
*
* Static Properties
*
* */
/**
* Momentum. This series requires `linkedTo` option to be set.
*
* @sample stock/indicators/momentum
* Momentum indicator
*
* @extends plotOptions.sma
* @since 6.0.0
* @product highstock
* @requires stock/indicators/indicators
* @requires stock/indicators/momentum
* @optionparent plotOptions.momentum
*/
MomentumIndicator.defaultOptions = merge(SMAIndicator.defaultOptions, {
params: {
index: 3
}
});
extend(MomentumIndicator.prototype, {
nameBase: 'Momentum'
});
external_highcharts_src_js_default_SeriesRegistry_default().registerSeriesType('momentum', MomentumIndicator);
/* *
*
* Default Export
*
* */
/* harmony default export */ const Momentum_MomentumIndicator = ((/* unused pure expression or super */ null && (MomentumIndicator)));
/* *
*
* API Options
*
* */
/**
* A `Momentum` series. If the [type](#series.momentum.type) option is not
* specified, it is inherited from [chart.type](#chart.type).
*
* @extends series,plotOptions.momentum
* @since 6.0.0
* @excluding dataParser, dataURL
* @product highstock
* @requires stock/indicators/indicators
* @requires stock/indicators/momentum
* @apioption series.momentum
*/
''; // To include the above in the js output
;// ./code/es-modules/masters/indicators/momentum.src.js
/* harmony default export */ const momentum_src = ((external_highcharts_src_js_default_default()));
export { momentum_src as default };