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
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
/* *
 *
 *  (c) 2010-2019 Torstein Honsi
 *
 *  License: www.highcharts.com/license
 *
 *  !!!!!!! SOURCE GETS TRANSPILED BY TYPESCRIPT. EDIT TS FILE ONLY. !!!!!!!
 *
 * */
'use strict';
 
var _Globals = require('./Globals.js');
 
var _Globals2 = _interopRequireDefault(_Globals);
 
require('./Utilities.js');
 
require('./Options.js');
 
require('./Series.js');
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
var pick = _Globals2.default.pick,
    seriesType = _Globals2.default.seriesType;
/**
 * Spline series type.
 *
 * @private
 * @class
 * @name Highcharts.seriesTypes.spline
 *
 * @augments Highcarts.Series
 */
seriesType('spline', 'line',
/**
 * A spline series is a special type of line series, where the segments
 * between the data points are smoothed.
 *
 * @sample {highcharts} highcharts/demo/spline-irregular-time/
 *         Spline chart
 * @sample {highstock} stock/demo/spline/
 *         Spline chart
 *
 * @extends      plotOptions.series
 * @excluding    step
 * @product      highcharts highstock
 * @optionparent plotOptions.spline
 */
{},
/**
 * @lends seriesTypes.spline.prototype
 */
{
    /* eslint-disable valid-jsdoc */
    /**
     * Get the spline segment from a given point's previous neighbour to the
     * given point.
     *
     * @private
     * @function Highcharts.seriesTypes.spline#getPointSpline
     *
     * @param {Array<Highcharts.Point>}
     *
     * @param {Highcharts.Point} point
     *
     * @param {number} i
     *
     * @return {Highcharts.SVGPathArray}
     */
    getPointSpline: function getPointSpline(points, point, i) {
        var
        // 1 means control points midway between points, 2 means 1/3
        // from the point, 3 is 1/4 etc
        smoothing = 1.5,
            denom = smoothing + 1,
            plotX = point.plotX,
            plotY = point.plotY,
            lastPoint = points[i - 1],
            nextPoint = points[i + 1],
            leftContX,
            leftContY,
            rightContX,
            rightContY,
            ret;
        /**
         * @private
         */
        function doCurve(otherPoint) {
            return otherPoint && !otherPoint.isNull && otherPoint.doCurve !== false &&
            // #6387, area splines next to null:
            !point.isCliff;
        }
        // Find control points
        if (doCurve(lastPoint) && doCurve(nextPoint)) {
            var lastX = lastPoint.plotX,
                lastY = lastPoint.plotY,
                nextX = nextPoint.plotX,
                nextY = nextPoint.plotY,
                correction = 0;
            leftContX = (smoothing * plotX + lastX) / denom;
            leftContY = (smoothing * plotY + lastY) / denom;
            rightContX = (smoothing * plotX + nextX) / denom;
            rightContY = (smoothing * plotY + nextY) / denom;
            // Have the two control points make a straight line through main
            // point
            if (rightContX !== leftContX) {
                // #5016, division by zero
                correction = (rightContY - leftContY) * (rightContX - plotX) / (rightContX - leftContX) + plotY - rightContY;
            }
            leftContY += correction;
            rightContY += correction;
            // to prevent false extremes, check that control points are
            // between neighbouring points' y values
            if (leftContY > lastY && leftContY > plotY) {
                leftContY = Math.max(lastY, plotY);
                // mirror of left control point
                rightContY = 2 * plotY - leftContY;
            } else if (leftContY < lastY && leftContY < plotY) {
                leftContY = Math.min(lastY, plotY);
                rightContY = 2 * plotY - leftContY;
            }
            if (rightContY > nextY && rightContY > plotY) {
                rightContY = Math.max(nextY, plotY);
                leftContY = 2 * plotY - rightContY;
            } else if (rightContY < nextY && rightContY < plotY) {
                rightContY = Math.min(nextY, plotY);
                leftContY = 2 * plotY - rightContY;
            }
            // record for drawing in next point
            point.rightContX = rightContX;
            point.rightContY = rightContY;
        }
        // Visualize control points for debugging
        /*
        if (leftContX) {
        this.chart.renderer.circle(
                leftContX + this.chart.plotLeft,
                leftContY + this.chart.plotTop,
                2
            )
            .attr({
                stroke: 'red',
                'stroke-width': 2,
                fill: 'none',
                zIndex: 9
            })
            .add();
        this.chart.renderer.path(['M', leftContX + this.chart.plotLeft,
            leftContY + this.chart.plotTop,
            'L', plotX + this.chart.plotLeft, plotY + this.chart.plotTop])
            .attr({
                stroke: 'red',
                'stroke-width': 2,
                zIndex: 9
            })
            .add();
        }
        if (rightContX) {
        this.chart.renderer.circle(
                rightContX + this.chart.plotLeft,
                rightContY + this.chart.plotTop,
                2
            )
            .attr({
                stroke: 'green',
                'stroke-width': 2,
                fill: 'none',
                zIndex: 9
            })
            .add();
        this.chart.renderer.path(['M', rightContX + this.chart.plotLeft,
            rightContY + this.chart.plotTop,
            'L', plotX + this.chart.plotLeft, plotY + this.chart.plotTop])
            .attr({
                stroke: 'green',
                'stroke-width': 2,
                zIndex: 9
            })
            .add();
        }
        // */
        ret = ['C', pick(lastPoint.rightContX, lastPoint.plotX), pick(lastPoint.rightContY, lastPoint.plotY), pick(leftContX, plotX), pick(leftContY, plotY), plotX, plotY];
        // reset for updating series later
        lastPoint.rightContX = lastPoint.rightContY = null;
        return ret;
    }
    /* eslint-enable valid-jsdoc */
});
/**
 * A `spline` series. If the [type](#series.spline.type) option is
 * not specified, it is inherited from [chart.type](#chart.type).
 *
 * @extends   series,plotOptions.spline
 * @excluding dataParser, dataURL, step
 * @product   highcharts highstock
 * @apioption series.spline
 */
/**
 * An array of data points for the series. For the `spline` series type,
 * points can be given in the following ways:
 *
 * 1. An array of numerical values. In this case, the numerical values will be
 *    interpreted as `y` options. The `x` values will be automatically
 *    calculated, either starting at 0 and incremented by 1, or from
 *    `pointStart` and `pointInterval` given in the series options. If the axis
 *    has categories, these will be used. Example:
 *    ```js
 *    data: [0, 5, 3, 5]
 *    ```
 *
 * 2. An array of arrays with 2 values. In this case, the values correspond to
 *    `x,y`. If the first value is a string, it is applied as the name of the
 *    point, and the `x` value is inferred.
 *    ```js
 *    data: [
 *        [0, 9],
 *        [1, 2],
 *        [2, 8]
 *    ]
 *    ```
 *
 * 3. 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.spline.turboThreshold),
 *    this option is not available.
 *    ```js
 *    data: [{
 *        x: 1,
 *        y: 9,
 *        name: "Point2",
 *        color: "#00FF00"
 *    }, {
 *        x: 1,
 *        y: 0,
 *        name: "Point1",
 *        color: "#FF00FF"
 *    }]
 *    ```
 *
 * @sample {highcharts} highcharts/chart/reflow-true/
 *         Numerical values
 * @sample {highcharts} highcharts/series/data-array-of-arrays/
 *         Arrays of numeric x and y
 * @sample {highcharts} highcharts/series/data-array-of-arrays-datetime/
 *         Arrays of datetime x and y
 * @sample {highcharts} highcharts/series/data-array-of-name-value/
 *         Arrays of point.name and y
 * @sample {highcharts} highcharts/series/data-array-of-objects/
 *         Config objects
 *
 * @type      {Array<number|Array<(number|string),(number|null)>|null|*>}
 * @extends   series.line.data
 * @product   highcharts highstock
 * @apioption series.spline.data
 */
''; // adds doclets above intro transpilat