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
'use strict';
 
Object.defineProperty(exports, "__esModule", {
    value: true
});
 
var _Globals = require('../../parts/Globals.js');
 
var _Globals2 = _interopRequireDefault(_Globals);
 
require('../../parts/Utilities.js');
 
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
 
var Annotation = _Globals2.default.Annotation,
    MockPoint = Annotation.MockPoint;
 
/**
 * @class
 * @extends Annotation
 * @memberOf Highcharts
 */
function VerticalLine() {
    _Globals2.default.Annotation.apply(this, arguments);
}
 
VerticalLine.connectorFirstPoint = function (target) {
    var annotation = target.annotation,
        point = annotation.points[0],
        xy = MockPoint.pointToPixels(point, true),
        y = xy.y,
        offset = annotation.options.typeOptions.label.offset;
 
    if (annotation.chart.inverted) {
        y = xy.x;
    }
 
    return {
        x: point.x,
        xAxis: point.series.xAxis,
        y: y + offset
    };
};
 
VerticalLine.connectorSecondPoint = function (target) {
    var annotation = target.annotation,
        typeOptions = annotation.options.typeOptions,
        point = annotation.points[0],
        yOffset = typeOptions.yOffset,
        xy = MockPoint.pointToPixels(point, true),
        y = xy[annotation.chart.inverted ? 'x' : 'y'];
 
    if (typeOptions.label.offset < 0) {
        yOffset *= -1;
    }
 
    return {
        x: point.x,
        xAxis: point.series.xAxis,
        y: y + yOffset
    };
};
 
_Globals2.default.extendAnnotation(VerticalLine, null,
 
/** @lends Annotation.VerticalLine# */
{
    getPointsOptions: function getPointsOptions() {
        return [this.options.typeOptions.point];
    },
 
    addShapes: function addShapes() {
        var typeOptions = this.options.typeOptions,
            connector = this.initShape(_Globals2.default.merge(typeOptions.connector, {
            type: 'path',
            points: [VerticalLine.connectorFirstPoint, VerticalLine.connectorSecondPoint]
        }), false);
 
        typeOptions.connector = connector.options;
    },
 
    addLabels: function addLabels() {
        var typeOptions = this.options.typeOptions,
            labelOptions = typeOptions.label,
            x = 0,
            y = labelOptions.offset,
            verticalAlign = labelOptions.offset < 0 ? 'bottom' : 'top',
            align = 'center';
 
        if (this.chart.inverted) {
            x = labelOptions.offset;
            y = 0;
            verticalAlign = 'middle';
            align = labelOptions.offset < 0 ? 'right' : 'left';
        }
 
        var label = this.initLabel(_Globals2.default.merge(labelOptions, {
            verticalAlign: verticalAlign,
            align: align,
            x: x,
            y: y
        }));
 
        typeOptions.label = label.options;
    }
},
 
/**
 * A vertical line annotation.
 *
 * @sample highcharts/annotations-advanced/vertical-line/
 *         Vertical line
 *
 * @extends      annotations.crookedLine
 * @excluding    labels, shapes, controlPointOptions
 * @product      highstock
 * @optionparent annotations.verticalLine
 */
{
    typeOptions: {
        /**
         * @ignore
         */
        yOffset: 10,
 
        /**
         * Label options.
         *
         * @extends annotations.crookedLine.labelOptions
         */
        label: {
            offset: -40,
            point: function point(target) {
                return target.annotation.points[0];
            },
            allowOverlap: true,
            backgroundColor: 'none',
            borderWidth: 0,
            crop: true,
            overflow: 'none',
            shape: 'rect',
            text: '{y:.2f}'
        },
 
        /**
         * Connector options.
         *
         * @extends   annotations.crookedLine.shapeOptions
         * @excluding height, r, type, width
         */
        connector: {
            strokeWidth: 1,
            markerEnd: 'arrow'
        }
    }
});
 
Annotation.types.verticalLine = VerticalLine;
 
exports.default = VerticalLine;