whychdw
2019-09-09 c0b9ce437d409b89ca0e5388344ca9c5a56d70a4
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
/* *
 *
 *  (c) 2010-2019 Torstein Honsi
 *
 *  License: www.highcharts.com/license
 *
 *  !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
 *
 * */
'use strict';
 
Object.defineProperty(exports, "__esModule", {
    value: true
});
 
var _Globals = require('../parts/Globals.js');
 
var _Globals2 = _interopRequireDefault(_Globals);
 
var _Utilities = require('../parts/Utilities.js');
 
var _Utilities2 = _interopRequireDefault(_Utilities);
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
var defined = _Utilities2.default.defined;
var seriesTypes = _Globals2.default.seriesTypes,
    stableSort = _Globals2.default.stableSort;
/**
 * @private
 * @mixin onSeriesMixin
 */
var onSeriesMixin = {
    /* eslint-disable valid-jsdoc */
    /**
     * Override getPlotBox. If the onSeries option is valid, return the plot box
     * of the onSeries, otherwise proceed as usual.
     *
     * @private
     * @function onSeriesMixin.getPlotBox
     * @return {Highcharts.SeriesPlotBoxObject}
     */
    getPlotBox: function getPlotBox() {
        return _Globals2.default.Series.prototype.getPlotBox.call(this.options.onSeries && this.chart.get(this.options.onSeries) || this);
    },
    /**
     * Extend the translate method by placing the point on the related series
     *
     * @private
     * @function onSeriesMixin.translate
     * @return {void}
     */
    translate: function translate() {
        seriesTypes.column.prototype.translate.apply(this);
        var series = this,
            options = series.options,
            chart = series.chart,
            points = series.points,
            cursor = points.length - 1,
            point,
            lastPoint,
            optionsOnSeries = options.onSeries,
            onSeries = optionsOnSeries && chart.get(optionsOnSeries),
            onKey = options.onKey || 'y',
            step = onSeries && onSeries.options.step,
            onData = onSeries && onSeries.points,
            i = onData && onData.length,
            inverted = chart.inverted,
            xAxis = series.xAxis,
            yAxis = series.yAxis,
            xOffset = 0,
            leftPoint,
            lastX,
            rightPoint,
            currentDataGrouping,
            distanceRatio;
        // relate to a master series
        if (onSeries && onSeries.visible && i) {
            xOffset = (onSeries.pointXOffset || 0) + (onSeries.barW || 0) / 2;
            currentDataGrouping = onSeries.currentDataGrouping;
            lastX = onData[i - 1].x + (currentDataGrouping ? currentDataGrouping.totalRange : 0); // #2374
            // sort the data points
            stableSort(points, function (a, b) {
                return a.x - b.x;
            });
            onKey = 'plot' + onKey[0].toUpperCase() + onKey.substr(1);
            while (i-- && points[cursor]) {
                leftPoint = onData[i];
                point = points[cursor];
                point.y = leftPoint.y;
                if (leftPoint.x <= point.x && leftPoint[onKey] !== undefined) {
                    if (point.x <= lastX) {
                        // #803
                        point.plotY = leftPoint[onKey];
                        // interpolate between points, #666
                        if (leftPoint.x < point.x && !step) {
                            rightPoint = onData[i + 1];
                            if (rightPoint && rightPoint[onKey] !== undefined) {
                                // the distance ratio, between 0 and 1
                                distanceRatio = (point.x - leftPoint.x) / (rightPoint.x - leftPoint.x);
                                point.plotY += distanceRatio * (
                                // the plotY distance
                                rightPoint[onKey] - leftPoint[onKey]);
                                point.y += distanceRatio * (rightPoint.y - leftPoint.y);
                            }
                        }
                    }
                    cursor--;
                    i++; // check again for points in the same x position
                    if (cursor < 0) {
                        break;
                    }
                }
            }
        }
        // Add plotY position and handle stacking
        points.forEach(function (point, i) {
            var stackIndex;
            point.plotX += xOffset; // #2049
            // Undefined plotY means the point is either on axis, outside series
            // range or hidden series. If the series is outside the range of the
            // x axis it should fall through with an undefined plotY, but then
            // we must remove the shapeArgs (#847). For inverted charts, we need
            // to calculate position anyway, because series.invertGroups is not
            // defined
            if (point.plotY === undefined || inverted) {
                if (point.plotX >= 0 && point.plotX <= xAxis.len) {
                    // We're inside xAxis range
                    if (inverted) {
                        point.plotY = xAxis.translate(point.x, 0, 1, 0, 1);
                        point.plotX = defined(point.y) ? yAxis.translate(point.y, 0, 0, 0, 1) : 0;
                    } else {
                        point.plotY = (xAxis.opposite ? 0 : series.yAxis.len) + xAxis.offset; // For the windbarb demo
                    }
                } else {
                    point.shapeArgs = {}; // 847
                }
            }
            // if multiple flags appear at the same x, order them into a stack
            lastPoint = points[i - 1];
            if (lastPoint && lastPoint.plotX === point.plotX) {
                if (lastPoint.stackIndex === undefined) {
                    lastPoint.stackIndex = 0;
                }
                stackIndex = lastPoint.stackIndex + 1;
            }
            point.stackIndex = stackIndex; // #3639
        });
        this.onSeries = onSeries;
    }
    /* eslint-enable valid-jsdoc */
};
exports.default = onSeriesMixin;