Blame view

src/main/webapp/libs/Highstock-7.2.0/code/modules/price-indicator.src.js 5.84 KB
caiyongsong committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190
/**
 * @license Highstock JS v7.2.0 (2019-09-03)
 *
 * Advanced Highstock tools
 *
 * (c) 2010-2019 Highsoft AS
 * Author: Torstein Honsi
 *
 * License: www.highcharts.com/license
 */
'use strict';
(function (factory) {
    if (typeof module === 'object' && module.exports) {
        factory['default'] = factory;
        module.exports = factory;
    } else if (typeof define === 'function' && define.amd) {
        define('highcharts/modules/price-indicator', ['highcharts', 'highcharts/modules/stock'], function (Highcharts) {
            factory(Highcharts);
            factory.Highcharts = Highcharts;
            return factory;
        });
    } else {
        factory(typeof Highcharts !== 'undefined' ? Highcharts : undefined);
    }
}(function (Highcharts) {
    var _modules = Highcharts ? Highcharts._modules : {};
    function _registerModule(obj, path, args, fn) {
        if (!obj.hasOwnProperty(path)) {
            obj[path] = fn.apply(null, args);
        }
    }
    _registerModule(_modules, 'modules/price-indicator.src.js', [_modules['parts/Globals.js'], _modules['parts/Utilities.js']], function (H, U) {
        /* *
         * (c) 2009-2019 Sebastian Bochann
         *
         * Price indicator for Highcharts
         *
         * License: www.highcharts.com/license
         */


        var isArray = U.isArray;

        var addEvent = H.addEvent,
            merge = H.merge;

        /**
         * The line marks the last price from visible range of points.
         *
         * @product   highstock
         * @sample {highstock} stock/indicators/last-visible-price
         *         Last visible price
         * @apioption   plotOptions.series.lastVisiblePrice
         */

        /**
         * Enable or disable the indicator.
         *
         * @type      {boolean}
         * @product   highstock
         * @default true
         * @apioption   plotOptions.series.lastVisiblePrice.enabled
         */

        /**
         * Enable or disable the label.
         *
         * @type      {boolean}
         * @product   highstock
         * @default true
         * @apioption   plotOptions.series.lastVisiblePrice.label.enabled
         *
         */

        /**
         * The line marks the last price from all points.
         *
         * @product   highstock
         * @sample {highstock} stock/indicators/last-price
         *         Last price
         * @apioption   plotOptions.series.lastPrice
         */

        /**
         * Enable or disable the indicator.
         *
         * @type      {boolean}
         * @product   highstock
         * @default true
         * @apioption   plotOptions.series.lastPrice.enabled
         */

        /**
         * The color of the line of last price.
         *
         * @type      {string}
         * @product   highstock
         * @default red
         * @apioption   plotOptions.series.lastPrice.color
         *
         */

        addEvent(H.Series, 'afterRender', function () {
            var serie = this,
                seriesOptions = serie.options,
                pointRange = seriesOptions.pointRange,
                lastVisiblePrice = seriesOptions.lastVisiblePrice,
                lastPrice = seriesOptions.lastPrice;

            if ((lastVisiblePrice || lastPrice) &&
                    seriesOptions.id !== 'highcharts-navigator-series') {

                var xAxis = serie.xAxis,
                    yAxis = serie.yAxis,
                    origOptions = yAxis.crosshair,
                    origGraphic = yAxis.cross,
                    origLabel = yAxis.crossLabel,
                    points = serie.points,
                    yLength = serie.yData.length,
                    pLength = points.length,
                    x = serie.xData[serie.xData.length - 1],
                    y = serie.yData[yLength - 1],
                    lastPoint,
                    yValue,
                    crop;

                if (lastPrice && lastPrice.enabled) {

                    yAxis.crosshair = yAxis.options.crosshair = seriesOptions.lastPrice;

                    yAxis.cross = serie.lastPrice;
                    yValue = isArray(y) ? y[3] : y;

                    yAxis.drawCrosshair(null, {
                        x: x,
                        y: yValue,
                        plotX: xAxis.toPixels(x, true),
                        plotY: yAxis.toPixels(yValue, true)
                    });

                    // Save price
                    if (serie.yAxis.cross) {
                        serie.lastPrice = serie.yAxis.cross;
                        serie.lastPrice.y = yValue;
                    }
                }

                if (lastVisiblePrice &&
                    lastVisiblePrice.enabled &&
                    pLength > 0
                ) {

                    crop = (points[pLength - 1].x === x) || pointRange === null ? 1 : 2;

                    yAxis.crosshair = yAxis.options.crosshair = merge({
                        color: 'transparent'
                    }, seriesOptions.lastVisiblePrice);

                    yAxis.cross = serie.lastVisiblePrice;
                    lastPoint = points[pLength - crop];
                    // Save price
                    yAxis.drawCrosshair(null, lastPoint);

                    if (yAxis.cross) {
                        serie.lastVisiblePrice = yAxis.cross;
                        serie.lastVisiblePrice.y = lastPoint.y;
                    }

                    if (serie.crossLabel) {
                        serie.crossLabel.destroy();
                    }

                    serie.crossLabel = yAxis.crossLabel;

                }

                // Restore crosshair:
                yAxis.crosshair = origOptions;
                yAxis.cross = origGraphic;
                yAxis.crossLabel = origLabel;

            }
        });

    });
    _registerModule(_modules, 'masters/modules/price-indicator.src.js', [], function () {


    });
}));