price-indicator.src.js
3.75 KB
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
/* *
* (c) 2009-2019 Sebastian Bochann
*
* Price indicator for Highcharts
*
* License: www.highcharts.com/license
*/
'use strict';
import H from '../parts/Globals.js';
import U from '../parts/Utilities.js';
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;
}
});