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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
'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 isNumber = _Utilities2.default.isNumber;
 
var Annotation = _Globals2.default.Annotation,
    ControlPoint = Annotation.ControlPoint,
    merge = _Globals2.default.merge;
 
/**
 * @class
 * @extends Annotation
 * @memberOf Annotation
 */
function Measure() {
    Annotation.apply(this, arguments);
}
 
Annotation.types.measure = Measure;
 
_Globals2.default.extendAnnotation(Measure, null,
/** @lends Annotation.Measure# */
{
    /**
     * Init annotation object.
     */
    init: function init() {
        Annotation.prototype.init.apply(this, arguments);
 
        this.offsetX = 0;
        this.offsetY = 0;
        this.resizeX = 0;
        this.resizeY = 0;
 
        this.calculations.init.call(this);
        this.addValues();
        this.addShapes();
    },
 
    /**
     * Overrides default setter to get axes from typeOptions.
     */
    setClipAxes: function setClipAxes() {
        this.clipXAxis = this.chart.xAxis[this.options.typeOptions.xAxis];
        this.clipYAxis = this.chart.yAxis[this.options.typeOptions.yAxis];
    },
 
    /**
     * Get measure points configuration objects.
     *
     * @return {Array<Highcharts.MockPointOptions>}
     */
    pointsOptions: function pointsOptions() {
        return this.options.options.points;
    },
 
    /**
     * Get points configuration objects for shapes.
     *
     * @return {Array<Highcharts.MockPointOptions>}
     */
    shapePointsOptions: function shapePointsOptions() {
 
        var options = this.options.typeOptions,
            xAxis = options.xAxis,
            yAxis = options.yAxis;
 
        return [{
            x: this.xAxisMin,
            y: this.yAxisMin,
            xAxis: xAxis,
            yAxis: yAxis
        }, {
            x: this.xAxisMax,
            y: this.yAxisMin,
            xAxis: xAxis,
            yAxis: yAxis
        }, {
            x: this.xAxisMax,
            y: this.yAxisMax,
            xAxis: xAxis,
            yAxis: yAxis
        }, {
            x: this.xAxisMin,
            y: this.yAxisMax,
            xAxis: xAxis,
            yAxis: yAxis
        }];
    },
 
    addControlPoints: function addControlPoints() {
        var selectType = this.options.typeOptions.selectType,
            controlPoint;
 
        controlPoint = new ControlPoint(this.chart, this, this.options.controlPointOptions, 0);
 
        this.controlPoints.push(controlPoint);
 
        // add extra controlPoint for horizontal and vertical range
        if (selectType !== 'xy') {
            controlPoint = new ControlPoint(this.chart, this, this.options.controlPointOptions, 1);
 
            this.controlPoints.push(controlPoint);
        }
    },
    /**
     * Add label with calculated values (min, max, average, bins).
     *
     * @param {boolean} resize - the flag for resize shape
     */
    addValues: function addValues(resize) {
        var typeOptions = this.options.typeOptions,
            formatter = typeOptions.label.formatter;
 
        // set xAxisMin, xAxisMax, yAxisMin, yAxisMax
        this.calculations.recalculate.call(this, resize);
 
        if (!typeOptions.label.enabled) {
            return;
        }
 
        if (this.labels.length > 0) {
            this.labels[0].text = formatter && formatter.call(this) || this.calculations.defaultFormatter.call(this);
        } else {
            this.initLabel(_Globals2.default.extend({
                shape: 'rect',
                backgroundColor: 'none',
                color: 'black',
                borderWidth: 0,
                dashStyle: 'dash',
                overflow: 'none',
                align: 'left',
                vertical: 'top',
                crop: true,
                point: function point(target) {
                    var annotation = target.annotation,
                        chart = annotation.chart,
                        inverted = chart.inverted,
                        xAxis = chart.xAxis[typeOptions.xAxis],
                        yAxis = chart.yAxis[typeOptions.yAxis],
                        top = chart.plotTop,
                        left = chart.plotLeft;
 
                    return {
                        x: (inverted ? top : 10) + xAxis.toPixels(annotation.xAxisMin, !inverted),
                        y: (inverted ? -left + 10 : top) + yAxis.toPixels(annotation.yAxisMin)
                    };
                },
                text: formatter && formatter.call(this) || this.calculations.defaultFormatter.call(this)
            }, typeOptions.label));
        }
    },
    /**
     * Crosshair, background (rect)
     */
    addShapes: function addShapes() {
        this.addCrosshairs();
        this.addBackground();
    },
 
    /**
     * Add background shape.
     */
    addBackground: function addBackground() {
        var shapePoints = this.shapePointsOptions();
 
        if (shapePoints[0].x === undefined) {
            return;
        }
 
        this.initShape(_Globals2.default.extend({
            type: 'path',
            points: this.shapePointsOptions()
        }, this.options.typeOptions.background), false);
    },
 
    /**
     * Add internal crosshair shapes (on top and bottom)
     */
    addCrosshairs: function addCrosshairs() {
        var chart = this.chart,
            options = this.options.typeOptions,
            point = this.options.typeOptions.point,
            xAxis = chart.xAxis[options.xAxis],
            yAxis = chart.yAxis[options.yAxis],
            inverted = chart.inverted,
            xAxisMin = xAxis.toPixels(this.xAxisMin),
            xAxisMax = xAxis.toPixels(this.xAxisMax),
            yAxisMin = yAxis.toPixels(this.yAxisMin),
            yAxisMax = yAxis.toPixels(this.yAxisMax),
            defaultOptions = {
            point: point,
            type: 'path'
        },
            pathH = [],
            pathV = [],
            crosshairOptionsX,
            crosshairOptionsY,
            temp;
 
        if (inverted) {
            temp = xAxisMin;
            xAxisMin = yAxisMin;
            yAxisMin = temp;
 
            temp = xAxisMax;
            xAxisMax = yAxisMax;
            yAxisMax = temp;
        }
        // horizontal line
        if (options.crosshairX.enabled) {
            pathH = ['M', xAxisMin, yAxisMin + (yAxisMax - yAxisMin) / 2, 'L', xAxisMax, yAxisMin + (yAxisMax - yAxisMin) / 2];
        }
 
        // vertical line
        if (options.crosshairY.enabled) {
            pathV = ['M', xAxisMin + (xAxisMax - xAxisMin) / 2, yAxisMin, 'L', xAxisMin + (xAxisMax - xAxisMin) / 2, yAxisMax];
        }
 
        // Update existed crosshair
        if (this.shapes.length > 0) {
 
            this.shapes[0].options.d = pathH;
            this.shapes[1].options.d = pathV;
        } else {
 
            // Add new crosshairs
            crosshairOptionsX = merge(defaultOptions, options.crosshairX);
            crosshairOptionsY = merge(defaultOptions, options.crosshairY);
 
            this.initShape(_Globals2.default.extend({
                d: pathH
            }, crosshairOptionsX), false);
 
            this.initShape(_Globals2.default.extend({
                d: pathV
            }, crosshairOptionsY), false);
        }
    },
 
    onDrag: function onDrag(e) {
        var translation = this.mouseMoveToTranslation(e),
            selectType = this.options.typeOptions.selectType,
            x = selectType === 'y' ? 0 : translation.x,
            y = selectType === 'x' ? 0 : translation.y;
 
        this.translate(x, y);
 
        this.offsetX += x;
        this.offsetY += y;
 
        // animation, resize, setStartPoints
        this.redraw(false, false, true);
    },
 
    /**
     * Translate start or end ("left" or "right") side of the measure.
     * Update start points (startXMin, startXMax, startYMin, startYMax)
     *
     * @param {number} dx - the amount of x translation
     * @param {number} dy - the amount of y translation
     * @param {number} cpIndex - index of control point
     * @param {number} selectType - x / y / xy
     */
    resize: function resize(dx, dy, cpIndex, selectType) {
 
        // background shape
        var bckShape = this.shapes[2];
 
        if (selectType === 'x') {
            if (cpIndex === 0) {
                bckShape.translatePoint(dx, 0, 0);
                bckShape.translatePoint(dx, dy, 3);
            } else {
                bckShape.translatePoint(dx, 0, 1);
                bckShape.translatePoint(dx, dy, 2);
            }
        } else if (selectType === 'y') {
            if (cpIndex === 0) {
                bckShape.translatePoint(0, dy, 0);
                bckShape.translatePoint(0, dy, 1);
            } else {
                bckShape.translatePoint(0, dy, 2);
                bckShape.translatePoint(0, dy, 3);
            }
        } else {
            bckShape.translatePoint(dx, 0, 1);
            bckShape.translatePoint(dx, dy, 2);
            bckShape.translatePoint(0, dy, 3);
        }
 
        this.calculations.updateStartPoints.call(this, false, true, cpIndex, dx, dy);
 
        this.options.typeOptions.background.height = Math.abs(this.startYMax - this.startYMin);
 
        this.options.typeOptions.background.width = Math.abs(this.startXMax - this.startXMin);
    },
    /**
     * Redraw event which render elements and update start points
     * if needed
     *
     * @param {Boolean} animation
     * @param {Boolean} resize - flag if resized
     * @param {Boolean} setStartPoints - update position of start points
     */
    redraw: function redraw(animation, resize, setStartPoints) {
 
        this.linkPoints();
 
        if (!this.graphic) {
            this.render();
        }
 
        if (setStartPoints) {
            this.calculations.updateStartPoints.call(this, true, false);
        }
 
        // #11174 - clipBox was not recalculate during resize / redraw
        if (this.clipRect) {
            this.clipRect.animate(this.getClipBox());
        }
 
        this.addValues(resize);
        this.addCrosshairs();
        this.redrawItems(this.shapes, animation);
        this.redrawItems(this.labels, animation);
 
        // redraw control point to run positioner
        this.controlPoints.forEach(function (controlPoint) {
            controlPoint.redraw();
        });
    },
    translate: function translate(dx, dy) {
        this.shapes.forEach(function (item) {
            item.translate(dx, dy);
        });
 
        this.options.typeOptions.point.x = this.startXMin;
        this.options.typeOptions.point.y = this.startYMin;
    },
    calculations: {
        /**
         * Set starting points
         * @private
         */
        init: function init() {
            var options = this.options.typeOptions,
                chart = this.chart,
                getPointPos = this.calculations.getPointPos,
                inverted = chart.inverted,
                xAxis = chart.xAxis[options.xAxis],
                yAxis = chart.yAxis[options.yAxis],
                bck = options.background,
                width = inverted ? bck.height : bck.width,
                height = inverted ? bck.width : bck.height,
                selectType = options.selectType,
                top = inverted ? chart.plotLeft : chart.plotTop,
                left = inverted ? chart.plotTop : chart.plotLeft;
 
            this.startXMin = options.point.x;
            this.startYMin = options.point.y;
 
            if (isNumber(width)) {
                this.startXMax = this.startXMin + width;
            } else {
                this.startXMax = getPointPos(xAxis, this.startXMin, parseFloat(width));
            }
 
            if (isNumber(height)) {
                this.startYMax = this.startYMin - height;
            } else {
                this.startYMax = getPointPos(yAxis, this.startYMin, parseFloat(height));
            }
 
            // x / y selection type
            if (selectType === 'x') {
                this.startYMin = yAxis.toValue(top);
                this.startYMax = yAxis.toValue(top + yAxis.len);
            } else if (selectType === 'y') {
                this.startXMin = xAxis.toValue(left);
                this.startXMax = xAxis.toValue(left + xAxis.len);
            }
        },
        /**
         * Set current xAxisMin, xAxisMax, yAxisMin, yAxisMax.
         * Calculations of measure values (min, max, average, bins).
         * @private
         * @param {Boolean} resize - flag if shape is resized
         */
        recalculate: function recalculate(resize) {
            var calc = this.calculations,
                options = this.options.typeOptions,
                xAxis = this.chart.xAxis[options.xAxis],
                yAxis = this.chart.yAxis[options.yAxis],
                getPointPos = this.calculations.getPointPos,
                offsetX = this.offsetX,
                offsetY = this.offsetY;
 
            this.xAxisMin = getPointPos(xAxis, this.startXMin, offsetX);
            this.xAxisMax = getPointPos(xAxis, this.startXMax, offsetX);
            this.yAxisMin = getPointPos(yAxis, this.startYMin, offsetY);
            this.yAxisMax = getPointPos(yAxis, this.startYMax, offsetY);
 
            this.min = calc.min.call(this);
            this.max = calc.max.call(this);
            this.average = calc.average.call(this);
            this.bins = calc.bins.call(this);
 
            if (resize) {
                this.resize(0, 0);
            }
        },
        /**
         * Set current xAxisMin, xAxisMax, yAxisMin, yAxisMax.
         * Calculations of measure values (min, max, average, bins).
         * @private
         * @param {Object} axis - x or y axis reference
         * @param {Number} value - point's value (x or y)
         * @param {Number} offset - amount of pixels
         */
        getPointPos: function getPointPos(axis, value, offset) {
            return axis.toValue(axis.toPixels(value) + offset);
        },
        /**
         * Update position of start points
         * (startXMin, startXMax, startYMin, startYMax)
         * @private
         * @param {Boolean} redraw - flag if shape is redraw
         * @param {Boolean} resize - flag if shape is resized
         * @param {Boolean} cpIndex - index of controlPoint
         */
        updateStartPoints: function updateStartPoints(redraw, resize, cpIndex, dx, dy) {
            var options = this.options.typeOptions,
                selectType = options.selectType,
                xAxis = this.chart.xAxis[options.xAxis],
                yAxis = this.chart.yAxis[options.yAxis],
                getPointPos = this.calculations.getPointPos,
                startXMin = this.startXMin,
                startXMax = this.startXMax,
                startYMin = this.startYMin,
                startYMax = this.startYMax,
                offsetX = this.offsetX,
                offsetY = this.offsetY;
 
            if (resize) {
                if (selectType === 'x') {
                    if (cpIndex === 0) {
                        this.startXMin = getPointPos(xAxis, startXMin, dx);
                    } else {
                        this.startXMax = getPointPos(xAxis, startXMax, dx);
                    }
                } else if (selectType === 'y') {
                    if (cpIndex === 0) {
                        this.startYMin = getPointPos(yAxis, startYMin, dy);
                    } else {
                        this.startYMax = getPointPos(yAxis, startYMax, dy);
                    }
                } else {
                    this.startXMax = getPointPos(xAxis, startXMax, dx);
                    this.startYMax = getPointPos(yAxis, startYMax, dy);
                }
            }
 
            if (redraw) {
                this.startXMin = getPointPos(xAxis, startXMin, offsetX);
                this.startXMax = getPointPos(xAxis, startXMax, offsetX);
                this.startYMin = getPointPos(yAxis, startYMin, offsetY);
                this.startYMax = getPointPos(yAxis, startYMax, offsetY);
 
                this.offsetX = 0;
                this.offsetY = 0;
            }
        },
        /**
         * Default formatter of label's content
         * @private
         */
        defaultFormatter: function defaultFormatter() {
            return 'Min: ' + this.min + '<br>Max: ' + this.max + '<br>Average: ' + this.average + '<br>Bins: ' + this.bins;
        },
        /**
         * Set values for xAxisMin, xAxisMax, yAxisMin, yAxisMax, also
         * when chart is inverted
         * @private
         */
        getExtremes: function getExtremes(xAxisMin, xAxisMax, yAxisMin, yAxisMax) {
            return {
                xAxisMin: Math.min(xAxisMax, xAxisMin),
                xAxisMax: Math.max(xAxisMax, xAxisMin),
                yAxisMin: Math.min(yAxisMax, yAxisMin),
                yAxisMax: Math.max(yAxisMax, yAxisMin)
            };
        },
        /**
         * Definitions of calculations (min, max, average, bins)
         * @private
         */
        min: function min() {
            var min = Infinity,
                series = this.chart.series,
                ext = this.calculations.getExtremes(this.xAxisMin, this.xAxisMax, this.yAxisMin, this.yAxisMax),
                isCalculated = false; // to avoid Infinity in formatter
 
            series.forEach(function (serie) {
                if (serie.visible && serie.options.id !== 'highcharts-navigator-series') {
                    serie.points.forEach(function (point) {
                        if (!point.isNull && point.y < min && point.x > ext.xAxisMin && point.x <= ext.xAxisMax && point.y > ext.yAxisMin && point.y <= ext.yAxisMax) {
                            min = point.y;
                            isCalculated = true;
                        }
                    });
                }
            });
 
            if (!isCalculated) {
                min = '';
            }
 
            return min;
        },
        max: function max() {
            var max = -Infinity,
                series = this.chart.series,
                ext = this.calculations.getExtremes(this.xAxisMin, this.xAxisMax, this.yAxisMin, this.yAxisMax),
                isCalculated = false; // to avoid Infinity in formatter
 
            series.forEach(function (serie) {
                if (serie.visible && serie.options.id !== 'highcharts-navigator-series') {
                    serie.points.forEach(function (point) {
                        if (!point.isNull && point.y > max && point.x > ext.xAxisMin && point.x <= ext.xAxisMax && point.y > ext.yAxisMin && point.y <= ext.yAxisMax) {
                            max = point.y;
                            isCalculated = true;
                        }
                    });
                }
            });
 
            if (!isCalculated) {
                max = '';
            }
 
            return max;
        },
        average: function average() {
            var average = '';
 
            if (this.max !== '' && this.min !== '') {
                average = (this.max + this.min) / 2;
            }
 
            return average;
        },
        bins: function bins() {
            var bins = 0,
                series = this.chart.series,
                ext = this.calculations.getExtremes(this.xAxisMin, this.xAxisMax, this.yAxisMin, this.yAxisMax),
                isCalculated = false; // to avoid Infinity in formatter
 
            series.forEach(function (serie) {
                if (serie.visible && serie.options.id !== 'highcharts-navigator-series') {
                    serie.points.forEach(function (point) {
                        if (!point.isNull && point.x > ext.xAxisMin && point.x <= ext.xAxisMax && point.y > ext.yAxisMin && point.y <= ext.yAxisMax) {
                            bins++;
                            isCalculated = true;
                        }
                    });
                }
            });
 
            if (!isCalculated) {
                bins = '';
            }
 
            return bins;
        }
    }
},
/**
 * A measure annotation.
 *
 * @extends annotations.crookedLine
 * @excluding labels, labelOptions, shapes, shapeOptions
 * @sample highcharts/annotations-advanced/measure/
 *         Measure
 * @product highstock
 * @optionparent annotations.measure
 */
{
    typeOptions: {
        /**
         * Decides in what dimensions the user can resize by dragging the
         * mouse. Can be one of x, y or xy.
         */
        selectType: 'xy',
        /**
         * This number defines which xAxis the point is connected to.
         * It refers to either the axis id or the index of the axis
         * in the xAxis array.
         */
        xAxis: 0,
        /**
         * This number defines which yAxis the point is connected to.
         * It refers to either the axis id or the index of the axis
         * in the yAxis array.
         */
        yAxis: 0,
        background: {
            /**
             * The color of the rectangle.
             */
            fill: 'rgba(130, 170, 255, 0.4)',
            /**
             * The width of border.
             */
            strokeWidth: 0,
            /**
             * The color of border.
             */
            stroke: undefined
        },
        /**
         * Configure a crosshair that is horizontally placed in middle of
         * rectangle.
         *
         */
        crosshairX: {
            /**
             * Enable or disable the horizontal crosshair.
             *
             */
            enabled: true,
            /**
             * The Z index of the crosshair in annotation.
             */
            zIndex: 6,
            /**
             * The dash or dot style of the crosshair's line. For possible
             * values, see
             * [this demonstration](https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-dashstyle-all/).
             *
             * @type    {Highcharts.DashStyleValue}
             * @default Dash
             */
            dashStyle: 'Dash',
            /**
             * The marker-end defines the arrowhead that will be drawn
             * at the final vertex of the given crosshair's path.
             *
             * @type       {string}
             * @default    arrow
             */
            markerEnd: 'arrow'
        },
        /**
         * Configure a crosshair that is vertically placed in middle of
         * rectangle.
         */
        crosshairY: {
            /**
             * Enable or disable the vertical crosshair.
             *
             */
            enabled: true,
            /**
             * The Z index of the crosshair in annotation.
             */
            zIndex: 6,
            /**
             * The dash or dot style of the crosshair's line. For possible
             * values, see [this demonstration](https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/highcharts/plotoptions/series-dashstyle-all/).
             *
             * @type      {Highcharts.DashStyleValue}
             * @default   Dash
             * @apioption annotations.measure.typeOptions.crosshairY.dashStyle
             *
             */
            dashStyle: 'Dash',
            /**
             * The marker-end defines the arrowhead that will be drawn
             * at the final vertex of the given crosshair's path.
             *
             * @type       {string}
             * @default    arrow
             * @validvalue ["none", "arrow"]
             *
             */
            markerEnd: 'arrow'
        },
        label: {
            /**
             * Enable or disable the label text (min, max, average,
             * bins values).
             *
             * Defaults to true.
             */
            enabled: true,
            /**
             * CSS styles for the measure label.
             *
             * @type    {Highcharts.CSSObject}
             * @default {"color": "#666666", "fontSize": "11px"}
             */
            style: {
                fontSize: '11px',
                color: '#666666'
            },
            /**
             * Formatter function for the label text.
             *
             * Available data are:
             *
             * <table>
             *
             * <tbody>
             *
             * <tr>
             *
             * <td>`this.min`</td>
             *
             * <td>The mininimum value of the points in the selected
             * range.</td>
             *
             * </tr>
             *
             * <tr>
             *
             * <td>`this.max`</td>
             *
             * <td>The maximum value of the points in the selected
             * range.</td>
             *
             * </tr>
             *
             * <tr>
             *
             * <td>`this.average`</td>
             *
             * <td>The average value of the points in the selected
             * range.</td>
             *
             * </tr>
             *
             * <tr>
             *
             * <td>`this.bins`</td>
             *
             * <td>The amount of the points in the selected range.</td>
             *
             * </tr>
             *
             * </table>
             *
             * @type      {function}
             *
             */
            formatter: undefined
        }
    },
    controlPointOptions: {
        positioner: function positioner(target) {
            var cpIndex = this.index,
                chart = target.chart,
                options = target.options,
                typeOptions = options.typeOptions,
                selectType = typeOptions.selectType,
                controlPointOptions = options.controlPointOptions,
                inverted = chart.inverted,
                xAxis = chart.xAxis[typeOptions.xAxis],
                yAxis = chart.yAxis[typeOptions.yAxis],
                targetX = target.xAxisMax,
                targetY = target.yAxisMax,
                ext = target.calculations.getExtremes(target.xAxisMin, target.xAxisMax, target.yAxisMin, target.yAxisMax),
                x,
                y;
 
            if (selectType === 'x') {
                targetY = (ext.yAxisMax - ext.yAxisMin) / 2;
 
                // first control point
                if (cpIndex === 0) {
                    targetX = target.xAxisMin;
                }
            }
 
            if (selectType === 'y') {
                targetX = ext.xAxisMin + (ext.xAxisMax - ext.xAxisMin) / 2;
 
                // first control point
                if (cpIndex === 0) {
                    targetY = target.yAxisMin;
                }
            }
 
            if (inverted) {
                x = yAxis.toPixels(targetY);
                y = xAxis.toPixels(targetX);
            } else {
                x = xAxis.toPixels(targetX);
                y = yAxis.toPixels(targetY);
            }
 
            return {
                x: x - controlPointOptions.width / 2,
                y: y - controlPointOptions.height / 2
            };
        },
        events: {
            drag: function drag(e, target) {
                var translation = this.mouseMoveToTranslation(e),
                    selectType = target.options.typeOptions.selectType,
                    index = this.index,
                    x = selectType === 'y' ? 0 : translation.x,
                    y = selectType === 'x' ? 0 : translation.y;
 
                target.resize(x, y, index, selectType);
 
                target.resizeX += x;
                target.resizeY += y;
                target.redraw(false, true);
            }
        }
    }
});
 
Annotation.types.measure = Measure;
 
exports.default = Measure;