@millistream/millistream-widgets 1.0.17 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/millistream-widgets.js +370 -371
- package/package.json +1 -1
package/millistream-widgets.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
/**
|
|
2
|
+
* HiDPI Canvas Polyfill (1.0.10)
|
|
3
|
+
*
|
|
4
|
+
* Author: Jonathan D. Johnson (http://jondavidjohn.com)
|
|
5
|
+
* Homepage: https://github.com/jondavidjohn/hidpi-canvas-polyfill
|
|
6
|
+
* Issue Tracker: https://github.com/jondavidjohn/hidpi-canvas-polyfill/issues
|
|
7
|
+
* License: Apache-2.0
|
|
8
|
+
*/
|
|
9
9
|
(function(prototype) {
|
|
10
10
|
|
|
11
11
|
var pixelRatio = (function() {
|
|
12
12
|
var canvas = document.createElement('canvas'),
|
|
13
13
|
context = canvas.getContext('2d');
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
/*backingStore = context.backingStorePixelRatio ||
|
|
15
|
+
context.webkitBackingStorePixelRatio ||
|
|
16
|
+
context.mozBackingStorePixelRatio ||
|
|
17
|
+
context.msBackingStorePixelRatio ||
|
|
18
|
+
context.oBackingStorePixelRatio ||
|
|
19
|
+
context.backingStorePixelRatio || 1;
|
|
20
|
+
return (window.devicePixelRatio || 1) / backingStore;
|
|
21
|
+
*/
|
|
22
22
|
})(),
|
|
23
23
|
forEach = function(obj, func) {
|
|
24
24
|
for (var p in obj) {
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
|
|
31
31
|
ratioArgs = {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
//'fillRect': 'all',
|
|
33
|
+
//'clearRect': 'all',
|
|
34
34
|
'strokeRect': 'all',
|
|
35
35
|
'moveTo': 'all',
|
|
36
36
|
'lineTo': 'all',
|
|
@@ -43,18 +43,18 @@
|
|
|
43
43
|
'rect': 'all',
|
|
44
44
|
'translate': 'all',
|
|
45
45
|
'createRadialGradient': 'all',
|
|
46
|
-
|
|
46
|
+
//'createLinearGradient': 'all'
|
|
47
47
|
};
|
|
48
48
|
|
|
49
49
|
if (pixelRatio === 1) return;
|
|
50
50
|
|
|
51
51
|
function getPixelRatio(_this) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
/* var backingStore = this.backingStorePixelRatio ||
|
|
53
|
+
this.webkitBackingStorePixelRatio ||
|
|
54
|
+
this.mozBackingStorePixelRatio ||
|
|
55
|
+
this.msBackingStorePixelRatio ||
|
|
56
|
+
this.oBackingStorePixelRatio ||
|
|
57
|
+
this.backingStorePixelRatio || 1;*/
|
|
58
58
|
var backingStore = _this.backingStorePixelRatio ||
|
|
59
59
|
_this.webkitBackingStorePixelRatio ||
|
|
60
60
|
_this.mozBackingStorePixelRatio ||
|
|
@@ -62,8 +62,7 @@
|
|
|
62
62
|
_this.oBackingStorePixelRatio ||
|
|
63
63
|
_this.backingStorePixelRatio || 1;
|
|
64
64
|
return (window.devicePixelRatio || 1) / backingStore;
|
|
65
|
-
|
|
66
|
-
return 1;
|
|
65
|
+
|
|
67
66
|
};
|
|
68
67
|
|
|
69
68
|
forEach(ratioArgs, function(value, key) {
|
|
@@ -71,7 +70,7 @@
|
|
|
71
70
|
return function() {
|
|
72
71
|
var i, len,
|
|
73
72
|
args = Array.prototype.slice.call(arguments);
|
|
74
|
-
if (key == 'lineTo' || key == 'moveTo') {
|
|
73
|
+
if (key == 'lineTo' || key == 'moveTo') { // PF
|
|
75
74
|
args = args.map(function(a) {
|
|
76
75
|
return a;
|
|
77
76
|
});
|
|
@@ -91,7 +90,7 @@
|
|
|
91
90
|
})(prototype[key]);
|
|
92
91
|
});
|
|
93
92
|
|
|
94
|
-
|
|
93
|
+
// Stroke lineWidth adjustment
|
|
95
94
|
prototype.stroke = (function(_super) {
|
|
96
95
|
return function() {
|
|
97
96
|
this.lineWidth *= getPixelRatio(this);
|
|
@@ -115,12 +114,12 @@
|
|
|
115
114
|
var i = _super.apply(this, args);
|
|
116
115
|
|
|
117
116
|
this.font = tmp;
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
117
|
+
/*this.font = this.font.replace(
|
|
118
|
+
/(\d+)(px|em|rem|pt)/g,
|
|
119
|
+
function(w, m, u) {
|
|
120
|
+
return Math.floor(m / getPixelRatio()) + u;
|
|
121
|
+
}
|
|
122
|
+
);*/
|
|
124
123
|
return i;
|
|
125
124
|
};
|
|
126
125
|
})(prototype.measureText);
|
|
@@ -146,8 +145,8 @@
|
|
|
146
145
|
return function() {
|
|
147
146
|
var args = Array.prototype.slice.call(arguments);
|
|
148
147
|
|
|
149
|
-
args[1] *= getPixelRatio(this);
|
|
150
|
-
args[2] *= getPixelRatio(this);
|
|
148
|
+
args[1] *= getPixelRatio(this); // x
|
|
149
|
+
args[2] *= getPixelRatio(this); // y
|
|
151
150
|
var tmp = this.font;
|
|
152
151
|
var _this = this;
|
|
153
152
|
this.font = this.font.replace(
|
|
@@ -159,12 +158,12 @@
|
|
|
159
158
|
|
|
160
159
|
_super.apply(this, args);
|
|
161
160
|
this.font = tmp;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
161
|
+
/*this.font = this.font.replace(
|
|
162
|
+
/(\d+)(px|em|rem|pt)/g,
|
|
163
|
+
function(w, m, u) {
|
|
164
|
+
return (m / getPixelRatio()) + u;
|
|
165
|
+
}
|
|
166
|
+
);*/
|
|
168
167
|
};
|
|
169
168
|
})(prototype.strokeText);
|
|
170
169
|
|
|
@@ -186,17 +185,17 @@
|
|
|
186
185
|
}
|
|
187
186
|
prototype.getContext = (function(_super) {
|
|
188
187
|
return function(type) {
|
|
189
|
-
|
|
188
|
+
//var backingStore, ratio;
|
|
190
189
|
context = _super.call(this, type);
|
|
191
190
|
|
|
192
191
|
if (type === '2d') {
|
|
193
192
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
193
|
+
/*backingStore = context.backingStorePixelRatio ||
|
|
194
|
+
context.webkitBackingStorePixelRatio ||
|
|
195
|
+
context.mozBackingStorePixelRatio ||
|
|
196
|
+
context.msBackingStorePixelRatio ||
|
|
197
|
+
context.oBackingStorePixelRatio ||
|
|
198
|
+
context.backingStorePixelRatio || 1;*/
|
|
200
199
|
|
|
201
200
|
var ratio = getPixelRatio();
|
|
202
201
|
if (ratio > 1) {
|
|
@@ -221,7 +220,7 @@
|
|
|
221
220
|
|
|
222
221
|
})(HTMLCanvasElement.prototype);
|
|
223
222
|
|
|
224
|
-
|
|
223
|
+
// Millistream Chart
|
|
225
224
|
function Milli_Chart(settings) {
|
|
226
225
|
"use strict";
|
|
227
226
|
var _this = this;
|
|
@@ -243,13 +242,13 @@ function Milli_Chart(settings) {
|
|
|
243
242
|
compress: 1,
|
|
244
243
|
curveOnTop: true,
|
|
245
244
|
dateformat: 'd/m',
|
|
246
|
-
drawxaxis: true,
|
|
245
|
+
drawxaxis: true, // TODO: 0 no, 1 yes, 2 yeas with markers (3px lines)
|
|
247
246
|
drawyaxis: true,
|
|
248
247
|
drawy2axis: false,
|
|
249
248
|
enablezoom: true,
|
|
250
249
|
fields: ['name', 'tradecurrency', 'time', 'date', 'tradeprice', 'tradequantity', 'marketopen', 'marketclose'],
|
|
251
250
|
fillchart: false,
|
|
252
|
-
gridVerticalLines: true,
|
|
251
|
+
gridVerticalLines: true, // 0 off, 1 draw grid lines ,2 fillrect modulo
|
|
253
252
|
gridVerticalLinesStyle: 'line',
|
|
254
253
|
gridHorizontalLines: true,
|
|
255
254
|
gridHorizontalLinesStyle: 'dash',
|
|
@@ -258,7 +257,7 @@ function Milli_Chart(settings) {
|
|
|
258
257
|
instrument: null,
|
|
259
258
|
intradayDatePos: { x: 'center', y: 'bottom', orientation: 'horizontal', dateformat: 'd mmm' },
|
|
260
259
|
intradaylen: null,
|
|
261
|
-
messagetypes: 1030,
|
|
260
|
+
messagetypes: 1030, // quote,trades and performance
|
|
262
261
|
nochartlabel: 'No data to draw on',
|
|
263
262
|
onreadyCallback: null,
|
|
264
263
|
previousDayClose: true,
|
|
@@ -273,8 +272,8 @@ function Milli_Chart(settings) {
|
|
|
273
272
|
display: 'block'
|
|
274
273
|
},
|
|
275
274
|
xAxisSpacing: 0,
|
|
276
|
-
yAxisSpacing: 4,
|
|
277
|
-
xAxisModulo: 1
|
|
275
|
+
yAxisSpacing: 4, // undocumented
|
|
276
|
+
xAxisModulo: 1 // undocumented
|
|
278
277
|
};
|
|
279
278
|
var m_startdate = null;
|
|
280
279
|
var m_chartspaces = {
|
|
@@ -287,10 +286,10 @@ function Milli_Chart(settings) {
|
|
|
287
286
|
height: 0
|
|
288
287
|
}
|
|
289
288
|
};
|
|
290
|
-
var m_dummyDiv = null;
|
|
289
|
+
var m_dummyDiv = null; // dummy div For chartclasses
|
|
291
290
|
var m_canvas = null;
|
|
292
291
|
var m_ctx = null;
|
|
293
|
-
var m_datapoints = [];
|
|
292
|
+
var m_datapoints = []; // for mouseover
|
|
294
293
|
var m_dataPoints = {
|
|
295
294
|
arr: [],
|
|
296
295
|
map: new Map()
|
|
@@ -379,7 +378,7 @@ function Milli_Chart(settings) {
|
|
|
379
378
|
}
|
|
380
379
|
var m_instrumentCss = [{
|
|
381
380
|
color: '#E2507A',
|
|
382
|
-
|
|
381
|
+
//backgroundImage: 'linear-gradient(rgba(226, 80, 122, 0.6),rgba(226, 80, 122, 0))',
|
|
383
382
|
width: 1
|
|
384
383
|
}, {
|
|
385
384
|
color: '#ff0000',
|
|
@@ -428,10 +427,10 @@ function Milli_Chart(settings) {
|
|
|
428
427
|
}
|
|
429
428
|
|
|
430
429
|
function dateDiffInDays(a, b) {
|
|
431
|
-
|
|
430
|
+
// Discard the time and time-zone information.
|
|
432
431
|
const utc1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
|
|
433
432
|
const utc2 = Date.UTC(b.getFullYear(), b.getMonth(), b.getDate());
|
|
434
|
-
return Math.floor((utc2 - utc1) / 86400000);
|
|
433
|
+
return Math.floor((utc2 - utc1) / 86400000); // ms per day
|
|
435
434
|
}
|
|
436
435
|
|
|
437
436
|
function findFirstWeekDay(date) {
|
|
@@ -445,7 +444,7 @@ function Milli_Chart(settings) {
|
|
|
445
444
|
}
|
|
446
445
|
|
|
447
446
|
function getFontSize(obj) {
|
|
448
|
-
|
|
447
|
+
//return parseInt(obj.fontSize) * window.devicePixelRatio;
|
|
449
448
|
return parseInt(obj.fontSize);
|
|
450
449
|
}
|
|
451
450
|
|
|
@@ -614,7 +613,7 @@ function Milli_Chart(settings) {
|
|
|
614
613
|
var quantity = 0;
|
|
615
614
|
|
|
616
615
|
for (i = 0; i < data.length; i++) {
|
|
617
|
-
|
|
616
|
+
// only calc on visible data
|
|
618
617
|
var price = data[i].price * _this.instruments[s].factor;
|
|
619
618
|
quantity = 0;
|
|
620
619
|
if (data[i].quantity !== 'undefined') {
|
|
@@ -632,7 +631,7 @@ function Milli_Chart(settings) {
|
|
|
632
631
|
}
|
|
633
632
|
|
|
634
633
|
if (_this.scaleinfoY.type != 'history' && (data[i].timestamp % 86400000 < _this.instruments[0].opentimestamp || data[i].timestamp % 86400000 > _this.instruments[0].closetimestamp)) {
|
|
635
|
-
|
|
634
|
+
// stämmer detta kan det bli överlapp vid sommartid/vintertid?
|
|
636
635
|
continue;
|
|
637
636
|
}
|
|
638
637
|
|
|
@@ -659,7 +658,7 @@ function Milli_Chart(settings) {
|
|
|
659
658
|
if (_this.scaleinfoY.lowLowerChart == null || _this.scaleinfoY.lowLowerChart > quantity) _this.scaleinfoY.lowLowerChart = quantity;
|
|
660
659
|
if (_this.scaleinfoY.highLowerChart == null || _this.scaleinfoY.highLowerChart < quantity) _this.scaleinfoY.highLowerChart = quantity;
|
|
661
660
|
}
|
|
662
|
-
if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) {
|
|
661
|
+
if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) { // if closeprice is used calch high/low on it
|
|
663
662
|
var cp = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
|
|
664
663
|
if (_this.scaleinfoY.lowValue > cp) _this.scaleinfoY.lowValue = cp;
|
|
665
664
|
else
|
|
@@ -688,7 +687,7 @@ function Milli_Chart(settings) {
|
|
|
688
687
|
_this.scaleinfoY.lowValue -= 1;
|
|
689
688
|
_this.scaleinfoY.highValue += 1;
|
|
690
689
|
}
|
|
691
|
-
|
|
690
|
+
// do we have any analyzis we need to take into account
|
|
692
691
|
for (i = 0; i < _this.settings.indicators.length; i++) {
|
|
693
692
|
if (_this.scaleinfoY.type == 'history') data = _this.settings.indicators[i].history;
|
|
694
693
|
else data = _this.settings.indicators[i].trades;
|
|
@@ -761,7 +760,7 @@ function Milli_Chart(settings) {
|
|
|
761
760
|
var maxValue = _this.scaleinfoY.highLowerChart == 0 ? 100 : _this.scaleinfoY.highLowerChart + (tickSize * 0.2);
|
|
762
761
|
var valuePerPixel = lineLength / maxValue;
|
|
763
762
|
if (isNaN(valuePerPixel) || !isFinite(valuePerPixel)) {
|
|
764
|
-
(
|
|
763
|
+
console.log('cant draw valuePerPixel' + valuePerPixel, lineLength, maxValue);
|
|
765
764
|
return false;
|
|
766
765
|
}
|
|
767
766
|
var value = 0;
|
|
@@ -782,7 +781,7 @@ function Milli_Chart(settings) {
|
|
|
782
781
|
m_ctx.closePath();
|
|
783
782
|
m_ctx.restore();
|
|
784
783
|
} else
|
|
785
|
-
if (_this.settings.drawyaxis == true && markers == true) {
|
|
784
|
+
if (_this.settings.drawyaxis == true && markers == true) { // draw legenditem markers for price
|
|
786
785
|
m_ctx.beginPath();
|
|
787
786
|
m_ctx.moveTo(m_chartspaces.lowerChart.left, y + 0.5);
|
|
788
787
|
m_ctx.lineTo(m_chartspaces.lowerChart.left + 3, y + 0.5);
|
|
@@ -794,7 +793,7 @@ function Milli_Chart(settings) {
|
|
|
794
793
|
var label = formatLargeNumber(value, 0, _this);
|
|
795
794
|
var textpos = x - 5;
|
|
796
795
|
if (m_yLegendCss.verticalAlign == 'top') {
|
|
797
|
-
if (y - (getFontSize(m_yLegendCss)) > 0)
|
|
796
|
+
if (y - (getFontSize(m_yLegendCss)) > 0) // dont draw if cropped
|
|
798
797
|
m_ctx.fillText(label, textpos, y - ((getFontSize(m_yLegendCss) + 2)));
|
|
799
798
|
} else
|
|
800
799
|
m_ctx.fillText(label, textpos, y - (getFontSize(m_yLegendCss) / 2));
|
|
@@ -812,7 +811,7 @@ function Milli_Chart(settings) {
|
|
|
812
811
|
m_ctx.fillStyle = m_yLegendCss.color;
|
|
813
812
|
var lineLen = m_chartspaces.lowerChart.bottom - m_chartspaces.lowerChart.top;
|
|
814
813
|
var numticks = lineLen / (getFontSize(m_yLegendCss) * 2);
|
|
815
|
-
if (numticks > 8) numticks = 8;
|
|
814
|
+
if (numticks > 8) numticks = 8; // limit to 8 items on Y legend ( this is not an absolut count, since we calculate nice legend numbers
|
|
816
815
|
|
|
817
816
|
m_ctx.beginPath();
|
|
818
817
|
m_ctx.strokeStyle = m_gridVerticalCss.color;
|
|
@@ -826,13 +825,13 @@ function Milli_Chart(settings) {
|
|
|
826
825
|
}
|
|
827
826
|
|
|
828
827
|
function checkYLegendSpace(y, text) {
|
|
829
|
-
|
|
828
|
+
//if (y - (getFontSize(m_yLegendCss) / 2) - m_chartspaces.chart.top < 0) return false;
|
|
830
829
|
if (y - (getFontSize(m_yLegendCss)) - m_chartspaces.chart.top < 0) return false;
|
|
831
830
|
if (y > m_chartspaces.chart.bottom) return false;
|
|
832
831
|
return true;
|
|
833
832
|
}
|
|
834
833
|
|
|
835
|
-
function drawY2Legend(x) {
|
|
834
|
+
function drawY2Legend(x) { // percent
|
|
836
835
|
if (_this.settings.absoluteScaling == true) {
|
|
837
836
|
for (var s = 1; s < _this.instruments.length; s++) {
|
|
838
837
|
if (_this.instruments[s].insref != 0) return;
|
|
@@ -860,7 +859,7 @@ function Milli_Chart(settings) {
|
|
|
860
859
|
var count = 0;
|
|
861
860
|
for (;;) {
|
|
862
861
|
if (count++ > 10) {
|
|
863
|
-
()
|
|
862
|
+
console.log('break out');
|
|
864
863
|
break;
|
|
865
864
|
}
|
|
866
865
|
var v;
|
|
@@ -871,9 +870,9 @@ function Milli_Chart(settings) {
|
|
|
871
870
|
var y = Math.round(m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) - ((v - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel));
|
|
872
871
|
|
|
873
872
|
if (y <= m_chartspaces.chart.top) break;
|
|
874
|
-
|
|
873
|
+
//if (y > m_chartspaces.chart.bottom) break;
|
|
875
874
|
if (y <= m_chartspaces.chart.bottom) {
|
|
876
|
-
if (_this.settings.drawy2axis == true) {
|
|
875
|
+
if (_this.settings.drawy2axis == true) { // draw legenditem markers for diff
|
|
877
876
|
m_ctx.beginPath();
|
|
878
877
|
m_ctx.moveTo(x, y + 0.5);
|
|
879
878
|
if ((m_y2LegendCss.float == 'left' && m_y2LegendCss.textAlign == 'left') || (m_y2LegendCss.float == 'right' && m_y2LegendCss.textAlign == 'left')) {
|
|
@@ -906,7 +905,7 @@ function Milli_Chart(settings) {
|
|
|
906
905
|
si.maxValue = si.highValue + (si.tickSize * 0.2);
|
|
907
906
|
si.minValue = si.lowValue - (si.tickSize * 0.2);
|
|
908
907
|
m_ctx.font = m_yLegendCss.fontWeight + ' ' + m_yLegendCss.fontSize + ' ' + m_yLegendCss.fontFamily;
|
|
909
|
-
if (si.highValue == si.lowValue) {
|
|
908
|
+
if (si.highValue == si.lowValue) { // only have one value so set values for 1 line only
|
|
910
909
|
si.maxValue = si.maxValue + si.tickSize;
|
|
911
910
|
si.minValue = si.minValue - si.tickSize;
|
|
912
911
|
value = Math.abs(si.lowValue);
|
|
@@ -918,14 +917,14 @@ function Milli_Chart(settings) {
|
|
|
918
917
|
}
|
|
919
918
|
si.valuePerPixel = si.lineLength / (si.maxValue - si.minValue);
|
|
920
919
|
if (isNaN(si.valuePerPixel) || !isFinite(si.valuePerPixel)) {
|
|
921
|
-
(
|
|
920
|
+
console.log('cant draw valuePerPixel', si.valuePerPixel, si.lineLength, si.maxValue, si.minValue);
|
|
922
921
|
return false;
|
|
923
922
|
}
|
|
924
923
|
var textpos;
|
|
925
924
|
var count = 0;
|
|
926
925
|
for (;;) {
|
|
927
926
|
if (count++ > 10) {
|
|
928
|
-
()
|
|
927
|
+
console.log('failsafe break');
|
|
929
928
|
break;
|
|
930
929
|
}
|
|
931
930
|
var y = Math.round(m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) - ((value - si.minValue) * si.valuePerPixel));
|
|
@@ -949,7 +948,7 @@ function Milli_Chart(settings) {
|
|
|
949
948
|
}
|
|
950
949
|
|
|
951
950
|
} else
|
|
952
|
-
if (_this.settings.drawyaxis == true && number == 1 && draw) {
|
|
951
|
+
if (_this.settings.drawyaxis == true && number == 1 && draw) { // draw legenditem markers for price
|
|
953
952
|
if (!draw) return;
|
|
954
953
|
m_ctx.beginPath();
|
|
955
954
|
m_ctx.moveTo(m_chartspaces.chart.left, y + 0.5);
|
|
@@ -987,35 +986,35 @@ function Milli_Chart(settings) {
|
|
|
987
986
|
m_ctx.fillStyle = m_yLegendCss.color;
|
|
988
987
|
if (0 == calcHighLow()) {
|
|
989
988
|
m_ctx.restore();
|
|
990
|
-
()
|
|
989
|
+
console.log('fail highlow');
|
|
991
990
|
return;
|
|
992
991
|
}
|
|
993
992
|
_this.scaleinfoY.lineLength = m_chartspaces.chart.bottom - m_chartspaces.chart.top;
|
|
994
993
|
_this.scaleinfoY2.lineLength = _this.scaleinfoY.lineLength;
|
|
995
|
-
|
|
994
|
+
//var numticks = (_this.scaleinfoY.lineLength / window.devicePixelRatio) / (getFontSize(m_yLegendCss) * _this.settings.yAxisSpacing);
|
|
996
995
|
var numticks = _this.scaleinfoY.lineLength / (getFontSize(m_yLegendCss) * _this.settings.yAxisSpacing);
|
|
997
|
-
if (numticks > 8) numticks = 8;
|
|
996
|
+
if (numticks > 8) numticks = 8; // limit to 8 items on Y legend ( this is not an absolut count, since we calculate nice legend numbers
|
|
998
997
|
_this.scaleinfoY.tickSize = getTickValue(_this.scaleinfoY.lowValue, _this.scaleinfoY.highValue, numticks);
|
|
999
|
-
_this.scaleinfoY.decimals = _this.scaleinfoY.tickSize.countDecimals();
|
|
998
|
+
_this.scaleinfoY.decimals = _this.scaleinfoY.tickSize.countDecimals(); // räkna på diffen mellan high low kanske?
|
|
1000
999
|
_this.scaleinfoY.decimals = _this.scaleinfoY.decimals > 4 ? 4 : _this.scaleinfoY.decimals;
|
|
1001
1000
|
_this.scaleinfoY.decimals = _this.scaleinfoY.decimals < 2 ? 2 : _this.scaleinfoY.decimals;
|
|
1002
1001
|
var label = formatNiceNumber(_this.scaleinfoY.highValue, _this.settings.thousandseparator, _this.settings.decimalseparator, _this.scaleinfoY.decimals);
|
|
1003
1002
|
if (_this.settings.drawyaxis) {
|
|
1004
1003
|
if (m_yLegendCss.float != 'right') {
|
|
1005
|
-
m_chartspaces.chart.left = 10 + Math.round(m_ctx.measureText(label).width);
|
|
1004
|
+
m_chartspaces.chart.left = 10 + Math.round(m_ctx.measureText(label).width); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
|
|
1006
1005
|
m_chartspaces.lowerChart.left = m_chartspaces.chart.left;
|
|
1007
1006
|
} else {
|
|
1008
1007
|
if (m_yLegendCss.textAlign == 'right') {
|
|
1009
|
-
m_chartspaces.chart.right = m_canvas.width - (10 + Math.round(m_ctx.measureText(label).width));
|
|
1008
|
+
m_chartspaces.chart.right = m_canvas.width - (10 + Math.round(m_ctx.measureText(label).width)); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
|
|
1010
1009
|
m_chartspaces.lowerChart.right = m_chartspaces.chart.right;
|
|
1011
1010
|
}
|
|
1012
1011
|
}
|
|
1013
1012
|
}
|
|
1014
|
-
if (_this.settings.drawy2axis) {
|
|
1015
|
-
|
|
1013
|
+
if (_this.settings.drawy2axis) { // calc space for y2
|
|
1014
|
+
//var numticks = _this.scaleinfoY2.lineLength / (getFontSize(m_yLegendCss) * _this.settings.yAxisSpacing);
|
|
1016
1015
|
_this.scaleinfoY2.tickSize = getTickValue(_this.scaleinfoY2.lowValue, _this.scaleinfoY2.highValue, numticks);
|
|
1017
1016
|
|
|
1018
|
-
_this.scaleinfoY2.decimals = _this.scaleinfoY2.tickSize.countDecimals();
|
|
1017
|
+
_this.scaleinfoY2.decimals = _this.scaleinfoY2.tickSize.countDecimals(); // räkna på diffen mellan high low kanske?
|
|
1019
1018
|
_this.scaleinfoY2.decimals = _this.scaleinfoY2.decimals > 4 ? 4 : _this.scaleinfoY2.decimals;
|
|
1020
1019
|
_this.scaleinfoY2.decimals = _this.scaleinfoY2.decimals < 0 ? 0 : _this.scaleinfoY2.decimals;
|
|
1021
1020
|
|
|
@@ -1023,12 +1022,12 @@ function Milli_Chart(settings) {
|
|
|
1023
1022
|
label = formatNiceNumber(widestDiff, _this.settings.thousandseparator, _this.settings.decimalseparator, _this.scaleinfoY2.decimals) + ' %';
|
|
1024
1023
|
if (m_y2LegendCss.float != 'right') {
|
|
1025
1024
|
if (m_y2LegendCss.textAlign == 'left')
|
|
1026
|
-
m_chartspaces.chart.left = 10 + Math.round(m_ctx.measureText(label).width);
|
|
1025
|
+
m_chartspaces.chart.left = 10 + Math.round(m_ctx.measureText(label).width); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
|
|
1027
1026
|
m_chartspaces.lowerChart.left = m_chartspaces.chart.left;
|
|
1028
1027
|
} else {
|
|
1029
|
-
|
|
1028
|
+
// kolla setting om den skall vara "i diagrammet"
|
|
1030
1029
|
if (m_y2LegendCss.textAlign == 'right')
|
|
1031
|
-
m_chartspaces.chart.right = m_canvas.width - (10 + Math.round(m_ctx.measureText(label).width));
|
|
1030
|
+
m_chartspaces.chart.right = m_canvas.width - (10 + Math.round(m_ctx.measureText(label).width)); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
|
|
1032
1031
|
m_chartspaces.lowerChart.right = m_chartspaces.chart.right;
|
|
1033
1032
|
}
|
|
1034
1033
|
}
|
|
@@ -1076,7 +1075,7 @@ function Milli_Chart(settings) {
|
|
|
1076
1075
|
}
|
|
1077
1076
|
|
|
1078
1077
|
function drawXAxisGridlines(p, newday) {
|
|
1079
|
-
|
|
1078
|
+
// draws the vertical grid or dots
|
|
1080
1079
|
m_ctx.save();
|
|
1081
1080
|
m_ctx.strokeStyle = m_gridVerticalCss.color;
|
|
1082
1081
|
if (_this.settings.gridVerticalLines) {
|
|
@@ -1099,7 +1098,7 @@ function Milli_Chart(settings) {
|
|
|
1099
1098
|
m_ctx.closePath();
|
|
1100
1099
|
}
|
|
1101
1100
|
} else
|
|
1102
|
-
if (_this.settings.drawxaxis != 0) {
|
|
1101
|
+
if (_this.settings.drawxaxis != 0) { // if no grid but drawxaxis , add markers for date/time
|
|
1103
1102
|
m_ctx.beginPath();
|
|
1104
1103
|
m_ctx.moveTo(p.x + 0.5, p.y);
|
|
1105
1104
|
m_ctx.lineTo(p.x + 0.5, p.y + 3);
|
|
@@ -1110,13 +1109,13 @@ function Milli_Chart(settings) {
|
|
|
1110
1109
|
}
|
|
1111
1110
|
|
|
1112
1111
|
function calcXScale(starttime, endtime) {
|
|
1113
|
-
|
|
1112
|
+
// vad är detta?
|
|
1114
1113
|
_this.scaleinfoX.startDate = new Date(starttime);
|
|
1115
1114
|
_this.scaleinfoX.endDate = new Date(endtime);
|
|
1116
1115
|
_this.scaleinfoX.days = getNumberOfDays(starttime, endtime);
|
|
1117
1116
|
_this.scaleinfoX.lineLength = m_chartspaces.chart.right - m_chartspaces.chart.left;
|
|
1118
|
-
var datesize = new Date('2888-12-28');
|
|
1119
|
-
_this.scaleinfoX.itemwidth = getStringWidth(m_ctx, formatDate(datesize, _this.settings.dateformat, _this)) * 2;
|
|
1117
|
+
var datesize = new Date('2888-12-28'); // bredaste datum jag kan komma på
|
|
1118
|
+
_this.scaleinfoX.itemwidth = getStringWidth(m_ctx, formatDate(datesize, _this.settings.dateformat, _this)) * 2; // kolla rätt format en 8a för varje tecken
|
|
1120
1119
|
|
|
1121
1120
|
var maxLegendItems = _this.scaleinfoX.lineLength / (_this.scaleinfoX.itemwidth * 2);
|
|
1122
1121
|
|
|
@@ -1138,7 +1137,7 @@ function Milli_Chart(settings) {
|
|
|
1138
1137
|
var tmp = 60;
|
|
1139
1138
|
while (tmp < x) {
|
|
1140
1139
|
tmp += 60;
|
|
1141
|
-
if (x - tmp < 20) break;
|
|
1140
|
+
if (x - tmp < 20) break; // if less than 20 mins to next hour breakout
|
|
1142
1141
|
}
|
|
1143
1142
|
_this.scaleinfoX.ticksize = tmp * 60000;
|
|
1144
1143
|
}
|
|
@@ -1146,22 +1145,22 @@ function Milli_Chart(settings) {
|
|
|
1146
1145
|
}
|
|
1147
1146
|
|
|
1148
1147
|
function getXPosition(timestamp) {
|
|
1149
|
-
var offset = (timestamp.getTime() - _this.scaleinfoX.startDate.getTime()) / (86400000 * 7);
|
|
1148
|
+
var offset = (timestamp.getTime() - _this.scaleinfoX.startDate.getTime()) / (86400000 * 7); // veckor
|
|
1150
1149
|
offset = offset * 86400000 * 2 / _this.scaleinfoX.timePerPixel;
|
|
1151
1150
|
return Math.round(m_chartspaces.chart.left + ((timestamp.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1152
1151
|
}
|
|
1153
1152
|
|
|
1154
1153
|
function checkXLegendSides(x, text) {
|
|
1155
|
-
|
|
1154
|
+
// right
|
|
1156
1155
|
if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left < x + (m_ctx.measureText(text).width / 2)) return false;
|
|
1157
|
-
|
|
1156
|
+
// left
|
|
1158
1157
|
if (m_chartspaces.chart.left > x - (m_ctx.measureText(text).width / 2)) return false;
|
|
1159
1158
|
return true;
|
|
1160
1159
|
|
|
1161
1160
|
}
|
|
1162
1161
|
|
|
1163
1162
|
function drawXAxisYears(starttime, endtime) {
|
|
1164
|
-
if (getNumberOfDays(starttime, endtime) < 250) return drawXAxisMonth(starttime, endtime);
|
|
1163
|
+
if (getNumberOfDays(starttime, endtime) < 250) return drawXAxisMonth(starttime, endtime); // exchange days
|
|
1165
1164
|
m_ctx.save();
|
|
1166
1165
|
m_ctx.font = m_xLegendCss.fontWeight + ' ' + m_xLegendCss.fontSize + ' ' + m_xLegendCss.fontFamily;
|
|
1167
1166
|
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
@@ -1177,7 +1176,7 @@ function Milli_Chart(settings) {
|
|
|
1177
1176
|
}
|
|
1178
1177
|
m_ctx.strokeStyle = m_gridVerticalCss.color;
|
|
1179
1178
|
var legendItems = [];
|
|
1180
|
-
|
|
1179
|
+
// draw Years
|
|
1181
1180
|
var year = _this.scaleinfoX.startDate.getFullYear() + 1;
|
|
1182
1181
|
var numItems = 0,
|
|
1183
1182
|
x, draw, i, text;
|
|
@@ -1194,7 +1193,7 @@ function Milli_Chart(settings) {
|
|
|
1194
1193
|
text = year;
|
|
1195
1194
|
if (checkXLegendSides(x, text)) {
|
|
1196
1195
|
if (_this.settings.yearLabelsPos == 'top') {
|
|
1197
|
-
m_ctx.save();
|
|
1196
|
+
m_ctx.save(); // flip and write new years on top
|
|
1198
1197
|
var fontMetrix = m_ctx.measureText(text);
|
|
1199
1198
|
x = x + fontMetrix.actualBoundingBoxAscent + fontMetrix.actualBoundingBoxDescent + 2;
|
|
1200
1199
|
var y = m_chartspaces.chart.top;
|
|
@@ -1211,14 +1210,14 @@ function Milli_Chart(settings) {
|
|
|
1211
1210
|
}
|
|
1212
1211
|
year++;
|
|
1213
1212
|
}
|
|
1214
|
-
if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11;
|
|
1215
|
-
|
|
1216
|
-
if (numItems < 10) {
|
|
1213
|
+
if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11; // keep it clean
|
|
1214
|
+
// draw half year
|
|
1215
|
+
if (numItems < 10) { // max 10 items här för att skriva halvår
|
|
1217
1216
|
year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-07-01T00:00:00Z');
|
|
1218
1217
|
if (year.getTime() < _this.scaleinfoX.startDate.getTime())
|
|
1219
1218
|
year = new Date(_this.scaleinfoX.startDate.getFullYear() + 1 + '-07-01T00:00:00Z');
|
|
1220
1219
|
while (year < _this.scaleinfoX.endDate) {
|
|
1221
|
-
x = getXPosition(new Date(year.getFullYear() + '-07-01T00:00:00Z'));
|
|
1220
|
+
x = getXPosition(new Date(year.getFullYear() + '-07-01T00:00:00Z')); // 7
|
|
1222
1221
|
draw = true;
|
|
1223
1222
|
for (i = 0; i < legendItems.length; i++) {
|
|
1224
1223
|
if (Math.abs(legendItems[i].x - x) < getMaxDateWidth()) {
|
|
@@ -1237,13 +1236,13 @@ function Milli_Chart(settings) {
|
|
|
1237
1236
|
year = new Date((year.getFullYear() + 1) + '-07-01T00:00:00Z');
|
|
1238
1237
|
}
|
|
1239
1238
|
}
|
|
1240
|
-
|
|
1241
|
-
if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11;
|
|
1242
|
-
if (numItems < 10) {
|
|
1239
|
+
// draw Quarter
|
|
1240
|
+
if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11; // keep it clean
|
|
1241
|
+
if (numItems < 10) { // max 10 items här för att skriva kvartal
|
|
1243
1242
|
year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-04-01T00:00:00Z');
|
|
1244
1243
|
if (year.getTime() < _this.scaleinfoX.startDate.getTime())
|
|
1245
1244
|
year = new Date(_this.scaleinfoX.startDate.getFullYear() + 1 + '-04-01T00:00:00Z');
|
|
1246
|
-
var dontPrint = false;
|
|
1245
|
+
var dontPrint = false; // if no space for first quarter dont print second either
|
|
1247
1246
|
while (year < _this.scaleinfoX.endDate) {
|
|
1248
1247
|
x = getXPosition(new Date(year.getFullYear() + '-04-01T00:00:00Z'));
|
|
1249
1248
|
draw = true;
|
|
@@ -1264,7 +1263,7 @@ function Milli_Chart(settings) {
|
|
|
1264
1263
|
legendItems.push({ 'text': text, timestamp: new Date(year + '-04-01T00:00:00Z'), 'x': x });
|
|
1265
1264
|
year = new Date((year.getFullYear() + 1) + '-04-01T00:00:00Z');
|
|
1266
1265
|
}
|
|
1267
|
-
|
|
1266
|
+
// Draw Quarter 2
|
|
1268
1267
|
if (dontPrint == false) {
|
|
1269
1268
|
year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-10-01T00:00:00Z');
|
|
1270
1269
|
if (year.getTime() < _this.scaleinfoX.startDate.getTime())
|
|
@@ -1301,7 +1300,7 @@ function Milli_Chart(settings) {
|
|
|
1301
1300
|
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
1302
1301
|
m_ctx.fillStyle = m_xLegendCss.color;
|
|
1303
1302
|
calcXScale(starttime, endtime);
|
|
1304
|
-
if (_this.settings.drawxaxis != 0) {
|
|
1303
|
+
if (_this.settings.drawxaxis != 0) { // draw line
|
|
1305
1304
|
m_ctx.beginPath();
|
|
1306
1305
|
m_ctx.moveTo(m_chartspaces.chart.left, m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) + 0.5);
|
|
1307
1306
|
m_ctx.lineTo(m_chartspaces.chart.right, m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) + 0.5);
|
|
@@ -1316,14 +1315,14 @@ function Milli_Chart(settings) {
|
|
|
1316
1315
|
var draw = true;
|
|
1317
1316
|
var offset = 0;
|
|
1318
1317
|
var count = 0;
|
|
1319
|
-
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
|
|
1318
|
+
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) { // oklart om det skall vara så här 2021-06-01
|
|
1320
1319
|
draw = true;
|
|
1321
|
-
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) {
|
|
1320
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1322
1321
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1323
1322
|
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1324
1323
|
}
|
|
1325
1324
|
x = Math.round(m_chartspaces.chart.left + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1326
|
-
if (lastx == 0 && m_chartspaces.chart.left > (x - (getMaxDateWidth() / 2))) {
|
|
1325
|
+
if (lastx == 0 && m_chartspaces.chart.left > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
|
|
1327
1326
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1328
1327
|
continue;
|
|
1329
1328
|
}
|
|
@@ -1341,7 +1340,7 @@ function Milli_Chart(settings) {
|
|
|
1341
1340
|
}
|
|
1342
1341
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1343
1342
|
}
|
|
1344
|
-
|
|
1343
|
+
// vad är detta?
|
|
1345
1344
|
if (typeof m_chartCss.boxShadow !== 'undefined' && typeof m_chartCss.boxShadow.rightWidth !== 'undefined') {
|
|
1346
1345
|
if (m_chartCss.boxShadow.rightWidth == 0) drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false);
|
|
1347
1346
|
} else {
|
|
@@ -1353,9 +1352,9 @@ function Milli_Chart(settings) {
|
|
|
1353
1352
|
function calcXScaleTick(starttime, endtime) {
|
|
1354
1353
|
_this.scaleinfoX.startDate = new Date(starttime);
|
|
1355
1354
|
_this.scaleinfoX.endDate = new Date(endtime);
|
|
1356
|
-
_this.scaleinfoX.days = getNumberOfDays(starttime, endtime);
|
|
1357
|
-
_this.scaleinfoX.lineLength = m_chartspaces.chart.right - m_chartspaces.chart.left;
|
|
1358
|
-
_this.scaleinfoX.itemwidth = getStringWidth(m_ctx, '88:88') * 2;
|
|
1355
|
+
_this.scaleinfoX.days = getNumberOfDays(starttime, endtime); // kan vi nog skita i
|
|
1356
|
+
_this.scaleinfoX.lineLength = m_chartspaces.chart.right - m_chartspaces.chart.left; // daybreaks can have 88/88
|
|
1357
|
+
_this.scaleinfoX.itemwidth = getStringWidth(m_ctx, '88:88') * 2; // kolla rätt format en 8a för varje tecken
|
|
1359
1358
|
var maxLegendItems = Math.floor(_this.scaleinfoX.lineLength / (_this.scaleinfoX.itemwidth * 2));
|
|
1360
1359
|
|
|
1361
1360
|
if (_this.scaleinfoY.type != 'history') {
|
|
@@ -1392,28 +1391,28 @@ function Milli_Chart(settings) {
|
|
|
1392
1391
|
|
|
1393
1392
|
var factor = 60;
|
|
1394
1393
|
if (numticks < 1)
|
|
1395
|
-
_this.scaleinfoX.ticksize = 86400000;
|
|
1394
|
+
_this.scaleinfoX.ticksize = 86400000; // öhh?
|
|
1396
1395
|
else {
|
|
1397
1396
|
if (numticks < 2) numticks = 2;
|
|
1398
1397
|
x = _this.scaleinfoX.milliPerDay / numticks / 60000;
|
|
1399
|
-
if (totalmilli > 4 * 3600000) factor = 60;
|
|
1398
|
+
if (totalmilli > 4 * 3600000) factor = 60; // 4 timmar
|
|
1400
1399
|
else
|
|
1401
|
-
if (totalmilli > 2 * 3600000) factor = 30;
|
|
1400
|
+
if (totalmilli > 2 * 3600000) factor = 30; // 2 timmar
|
|
1402
1401
|
else
|
|
1403
|
-
if (totalmilli > 3600000) factor = 20;
|
|
1402
|
+
if (totalmilli > 3600000) factor = 20; // 1 timma
|
|
1404
1403
|
else
|
|
1405
|
-
if (totalmilli > 3600000 / 2) factor = 10;
|
|
1404
|
+
if (totalmilli > 3600000 / 2) factor = 10; // 30 min
|
|
1406
1405
|
else
|
|
1407
|
-
if (totalmilli > 3600000 / 4) factor = 5;
|
|
1406
|
+
if (totalmilli > 3600000 / 4) factor = 5; // 15 min
|
|
1408
1407
|
else factor = 1;
|
|
1409
|
-
_this.scaleinfoX.ticksize = factor * 60000;
|
|
1408
|
+
_this.scaleinfoX.ticksize = factor * 60000; // time to add to next legenditem
|
|
1410
1409
|
}
|
|
1411
1410
|
return;
|
|
1412
1411
|
}
|
|
1413
1412
|
}
|
|
1414
1413
|
|
|
1415
1414
|
function formatChartTime(value, format) {
|
|
1416
|
-
|
|
1415
|
+
// internal
|
|
1417
1416
|
if (typeof value !== 'string') return "";
|
|
1418
1417
|
var datetime = new Date();
|
|
1419
1418
|
datetime.setHours(parseInt(value));
|
|
@@ -1472,7 +1471,7 @@ function Milli_Chart(settings) {
|
|
|
1472
1471
|
m_ctx.fillStyle = m_xLegendCss.color;
|
|
1473
1472
|
m_ctx.textAlign = "left";
|
|
1474
1473
|
calcXScaleTick(starttime, endtime);
|
|
1475
|
-
if (_this.settings.drawxaxis != 0) {
|
|
1474
|
+
if (_this.settings.drawxaxis != 0) { // draw line for legend
|
|
1476
1475
|
m_ctx.beginPath();
|
|
1477
1476
|
m_ctx.moveTo(m_chartspaces.chart.left, m_chartspaces.chart.bottom + 0.5);
|
|
1478
1477
|
m_ctx.lineTo(m_chartspaces.chart.right, m_chartspaces.chart.bottom + 0.5);
|
|
@@ -1489,20 +1488,20 @@ function Milli_Chart(settings) {
|
|
|
1489
1488
|
var legendItems = [];
|
|
1490
1489
|
var openhour = new Date(new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z')).getTime() % 86400000;
|
|
1491
1490
|
var closehour = new Date(new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z')).getTime() % 86400000;
|
|
1492
|
-
|
|
1491
|
+
// add daysstarts
|
|
1493
1492
|
var middleOfDay = new Date(currentDate.getTime() - (currentDate.getTime() % 86400000) + ((openhour + closehour) / 2));
|
|
1494
1493
|
if (_this.settings.intradayDatePos.x == 'left' && (_this.settings.intradayDatePos.y == 'scale' || _this.settings.intradayDatePos.y == 'top')) {
|
|
1495
1494
|
middleOfDay = new Date(currentDate.getTime());
|
|
1496
1495
|
}
|
|
1497
|
-
if (currentDate.getTime() % 3600000 != 0)
|
|
1498
|
-
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000);
|
|
1496
|
+
if (currentDate.getTime() % 3600000 != 0) // if not full hour, move up to next full hour
|
|
1497
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1499
1498
|
|
|
1500
1499
|
var firstDate = new Date(currentDate);
|
|
1501
1500
|
var days = calcTimeSpanInDays(starttime, endtime);
|
|
1502
1501
|
if (m_zoom.mouseup.timestamp == null || (m_zoom.mouseup.timestamp != null && days > 1)) {
|
|
1503
1502
|
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
|
|
1504
1503
|
draw = true;
|
|
1505
|
-
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) {
|
|
1504
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1506
1505
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1507
1506
|
if (_this.settings.intradayDatePos.x == 'left' && (_this.settings.intradayDatePos.y == 'scale' || _this.settings.intradayDatePos.y == 'top')) {
|
|
1508
1507
|
middleOfDay = new Date(currentDate.getTime());
|
|
@@ -1521,14 +1520,14 @@ function Milli_Chart(settings) {
|
|
|
1521
1520
|
lastx = x + 0.5;
|
|
1522
1521
|
var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1523
1522
|
var date = formatDate(currentDate, _this.settings.intradayDatePos.dateformat, _this);
|
|
1524
|
-
if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left > x - getMaxTimeWidth()) {
|
|
1523
|
+
if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left > x - getMaxTimeWidth()) { // not to far right?
|
|
1525
1524
|
if (_this.settings.intradayDatePos.y == 'scale' && _this.settings.chartlen != '0d' && _this.settings.chartlen != '1d') {
|
|
1526
|
-
|
|
1525
|
+
// draw date on under time, todo fix setting name
|
|
1527
1526
|
m_ctx.fillText(date, middleX - (m_ctx.measureText(date).width / 2), m_chartspaces.chart.bottom + getScaledSetting(m_xLegendCss.paddingTop));
|
|
1528
1527
|
legendItems.push({ x: middleX, type: 0, text: date, width: m_ctx.measureText(date) });
|
|
1529
1528
|
} else if (_this.settings.intradayDatePos.y == 'bottom' && _this.settings.chartlen != '0d' && _this.settings.chartlen != '1d') {
|
|
1530
1529
|
m_ctx.fillText(date, middleX - (m_ctx.measureText(date).width / 2), m_chartspaces.chart.bottom + getScaledSetting(m_xLegendCss.paddingTop) + parseInt(m_xLegendCss.fontSize) * window.devicePixelRatio);
|
|
1531
|
-
|
|
1530
|
+
// VA FAN DETTA KAN INTE VA RÄTT?
|
|
1532
1531
|
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_chartspaces.chart.bottom + getScaledSetting(m_xLegendCss.paddingTop));
|
|
1533
1532
|
legendItems.push({ x: x, type: 0, text: text });
|
|
1534
1533
|
} else {
|
|
@@ -1548,7 +1547,7 @@ function Milli_Chart(settings) {
|
|
|
1548
1547
|
if (_this.settings.intradayDatePos.x == 'center') {
|
|
1549
1548
|
m_ctx.fillText(date, middleX - (m_ctx.measureText(date).width / 2), getScaledSetting(m_chartCss.marginTop));
|
|
1550
1549
|
} else {
|
|
1551
|
-
|
|
1550
|
+
//m_ctx.fillText(date, x - (m_ctx.measureText(date).width / 2), getScaledSetting(m_chartCss.marginTop));
|
|
1552
1551
|
m_ctx.fillText(date, middleX + 1, getScaledSetting(m_chartCss.marginTop));
|
|
1553
1552
|
}
|
|
1554
1553
|
}
|
|
@@ -1556,17 +1555,17 @@ function Milli_Chart(settings) {
|
|
|
1556
1555
|
}
|
|
1557
1556
|
}
|
|
1558
1557
|
}
|
|
1559
|
-
if (x != m_chartspaces.chart.left + 0.5) {
|
|
1558
|
+
if (x != m_chartspaces.chart.left + 0.5) { // do not draw the first line, it is already drawn
|
|
1560
1559
|
if (_this.settings.intradayDatePos.y != 'bottom') {
|
|
1561
1560
|
if (openhour == currentDate.getTime() % 86400000) {
|
|
1562
|
-
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, true);
|
|
1561
|
+
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, true); // dash?
|
|
1563
1562
|
} else {
|
|
1564
|
-
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false);
|
|
1563
|
+
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false); // dash?
|
|
1565
1564
|
}
|
|
1566
1565
|
}
|
|
1567
1566
|
}
|
|
1568
1567
|
}
|
|
1569
|
-
|
|
1568
|
+
// Move to next day and set starting hour correct if we have open at half hour
|
|
1570
1569
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1571
1570
|
currentDate = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
1572
1571
|
middleOfDay = new Date(currentDate.getTime() - (currentDate.getTime() % 86400000) + ((openhour + closehour) / 2));
|
|
@@ -1574,23 +1573,23 @@ function Milli_Chart(settings) {
|
|
|
1574
1573
|
middleOfDay = new Date(currentDate);
|
|
1575
1574
|
}
|
|
1576
1575
|
|
|
1577
|
-
if (currentDate.getTime() % 3600000 != 0)
|
|
1578
|
-
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000);
|
|
1579
|
-
|
|
1576
|
+
if (currentDate.getTime() % 3600000 != 0) // if not full hour, move up to next full hour
|
|
1577
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1578
|
+
//}
|
|
1580
1579
|
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1581
1580
|
}
|
|
1582
1581
|
}
|
|
1583
|
-
|
|
1582
|
+
// add timestamps
|
|
1584
1583
|
currentDate = new Date(starttime);
|
|
1585
|
-
if (currentDate.getTime() % 3600000 != 0)
|
|
1586
|
-
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000);
|
|
1584
|
+
if (currentDate.getTime() % 3600000 != 0) // if not full hour, move up to next full hour
|
|
1585
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1587
1586
|
|
|
1588
1587
|
var maxHourLegends;
|
|
1589
1588
|
if (legendItems.length == 0)
|
|
1590
|
-
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - m_chartspaces.chart.left - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1589
|
+
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - m_chartspaces.chart.left - getMaxTimeWidth()) / (getMaxTimeWidth() * 3)); // varför tar vi bort margin???
|
|
1591
1590
|
else if (legendItems.length == 1) {
|
|
1592
1591
|
if (m_zoom.mouseup.timestamp && days == 2) {
|
|
1593
|
-
|
|
1592
|
+
// ta den största delen av linjen och mät på
|
|
1594
1593
|
if (_this.scaleinfoX.lineLength / 2 < legendItems[0].x + m_chartspaces.chart.left)
|
|
1595
1594
|
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - (_this.scaleinfoX.lineLength - legendItems[0].x) - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1596
1595
|
else
|
|
@@ -1598,15 +1597,15 @@ function Milli_Chart(settings) {
|
|
|
1598
1597
|
} else
|
|
1599
1598
|
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1600
1599
|
} else {
|
|
1601
|
-
maxHourLegends = Math.floor((legendItems[legendItems.length - 1].x - legendItems[legendItems.length - 2].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1600
|
+
maxHourLegends = Math.floor((legendItems[legendItems.length - 1].x - legendItems[legendItems.length - 2].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3)); // calculate with the last days length
|
|
1602
1601
|
}
|
|
1603
1602
|
|
|
1604
|
-
var tickSize;
|
|
1603
|
+
var tickSize; // per day
|
|
1605
1604
|
if (days == 1) {
|
|
1606
|
-
|
|
1605
|
+
// use start and endtime as ticksize
|
|
1607
1606
|
tickSize = new Date(endtime - starttime);
|
|
1608
|
-
} else if (m_zoom.mouseup.timestamp && days == 2) {
|
|
1609
|
-
|
|
1607
|
+
} else if (m_zoom.mouseup.timestamp && days == 2) { // zoom with 2 days
|
|
1608
|
+
// use the day with most time as tickSize
|
|
1610
1609
|
var tmpDate = new Date(starttime);
|
|
1611
1610
|
tickSize = new Date(new Date(tmpDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z') - new Date(starttime)).getTime();
|
|
1612
1611
|
var firstDay = tickSize;
|
|
@@ -1615,13 +1614,13 @@ function Milli_Chart(settings) {
|
|
|
1615
1614
|
tickSize += new Date(endtime - new Date(tmpDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z').getTime()).getTime();
|
|
1616
1615
|
tickSize = new Date(Math.max(firstDay, secondDay));
|
|
1617
1616
|
} else {
|
|
1618
|
-
|
|
1617
|
+
// use full day as tickSize
|
|
1619
1618
|
tickSize = new Date(new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z') - new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z'));
|
|
1620
1619
|
}
|
|
1621
1620
|
var interval;
|
|
1622
1621
|
var modularvalue = 3600000;
|
|
1623
1622
|
|
|
1624
|
-
|
|
1623
|
+
// calc the ticksize to add to time(interval) when drawing and the modulu value
|
|
1625
1624
|
if (tickSize.getTime() < 1800000) {
|
|
1626
1625
|
tickSize = tickSize.getTime() / 60000;
|
|
1627
1626
|
interval = Math.floor(tickSize / (maxHourLegends + 1)) * 60000;
|
|
@@ -1640,14 +1639,14 @@ function Milli_Chart(settings) {
|
|
|
1640
1639
|
interval = Math.floor(tickSize / (maxHourLegends + 1)) * 3600000;
|
|
1641
1640
|
}
|
|
1642
1641
|
if (interval == 0) {
|
|
1643
|
-
|
|
1642
|
+
// default 1h
|
|
1644
1643
|
interval = 3600000;
|
|
1645
1644
|
modularvalue = 3600000;
|
|
1646
1645
|
}
|
|
1647
1646
|
if (interval % 60000 != 0) {
|
|
1648
|
-
interval = (interval - interval % 60000) + 60000;
|
|
1647
|
+
interval = (interval - interval % 60000) + 60000; // remove sekunder
|
|
1649
1648
|
}
|
|
1650
|
-
|
|
1649
|
+
// print other times
|
|
1651
1650
|
offset = 0;
|
|
1652
1651
|
lastx = 0;
|
|
1653
1652
|
var closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
@@ -1656,38 +1655,38 @@ function Milli_Chart(settings) {
|
|
|
1656
1655
|
|
|
1657
1656
|
var workDate = new Date(currentDate);
|
|
1658
1657
|
currentDate = new Date(starttime);
|
|
1659
|
-
if (currentDate.getTime() % modularvalue != 0)
|
|
1660
|
-
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue);
|
|
1658
|
+
if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
|
|
1659
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1661
1660
|
|
|
1662
1661
|
var count = 0;
|
|
1663
1662
|
while (currentDate.getTime() <= _this.scaleinfoX.endTimeStamp) {
|
|
1664
1663
|
dayLightChange = (closeTime.getTimezoneOffset() - new Date().getTimezoneOffset()) * 60000;
|
|
1665
1664
|
if (count++ > 100) {
|
|
1666
|
-
break;
|
|
1665
|
+
break; // just make sure we dont do an infinity loop
|
|
1667
1666
|
|
|
1668
1667
|
}
|
|
1669
1668
|
draw = true;
|
|
1670
|
-
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) {
|
|
1671
|
-
|
|
1669
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1670
|
+
//closeTime = new Date(closeTime.getTime() + 86400000);
|
|
1672
1671
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1673
1672
|
closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
1674
|
-
if (currentDate.getTime() % modularvalue != 0)
|
|
1675
|
-
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue);
|
|
1673
|
+
if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
|
|
1674
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1676
1675
|
workDate = new Date(workDate.getTime() + 86400000);
|
|
1677
1676
|
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1678
1677
|
}
|
|
1679
1678
|
if (currentDate.getTime() > closeTime.getTime()) {
|
|
1680
|
-
|
|
1679
|
+
// draw DayEnd(start) dash line
|
|
1681
1680
|
var dayStart = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
1682
1681
|
x = Math.round(m_chartspaces.chart.left + ((dayStart.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1683
|
-
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, true);
|
|
1682
|
+
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, true); // dash?
|
|
1684
1683
|
|
|
1685
1684
|
closeTime = new Date(closeTime.getTime() + 86400000);
|
|
1686
1685
|
workDate = new Date(workDate.getTime() + 86400000);
|
|
1687
1686
|
currentDate = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
1688
1687
|
|
|
1689
|
-
if (currentDate.getTime() % modularvalue != 0)
|
|
1690
|
-
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue);
|
|
1688
|
+
if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
|
|
1689
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1691
1690
|
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1692
1691
|
continue;
|
|
1693
1692
|
}
|
|
@@ -1707,12 +1706,12 @@ function Milli_Chart(settings) {
|
|
|
1707
1706
|
}
|
|
1708
1707
|
}
|
|
1709
1708
|
if (lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1710
|
-
|
|
1709
|
+
//draw = false;
|
|
1711
1710
|
}
|
|
1712
1711
|
if (draw) {
|
|
1713
1712
|
lastx = x;
|
|
1714
|
-
|
|
1715
|
-
if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left > x - getMaxTimeWidth()) {
|
|
1713
|
+
// if day change and setting print on top as well
|
|
1714
|
+
if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left > x - getMaxTimeWidth()) { // not to far right?
|
|
1716
1715
|
var label = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1717
1716
|
x = Math.round(x);
|
|
1718
1717
|
m_ctx.fillText(label, x - (m_ctx.measureText(label).width / 2), m_chartspaces.chart.bottom + getScaledSetting(m_xLegendCss.paddingTop));
|
|
@@ -1723,7 +1722,7 @@ function Milli_Chart(settings) {
|
|
|
1723
1722
|
currentDate = new Date(currentDate.getTime() + interval);
|
|
1724
1723
|
}
|
|
1725
1724
|
|
|
1726
|
-
|
|
1725
|
+
// vad är detta?
|
|
1727
1726
|
if (typeof m_chartCss.boxShadow !== 'undefined' && typeof m_chartCss.boxShadow.rightWidth !== 'undefined') {
|
|
1728
1727
|
if (m_chartCss.boxShadow.rightWidth == 0) drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false);
|
|
1729
1728
|
|
|
@@ -1772,7 +1771,7 @@ function Milli_Chart(settings) {
|
|
|
1772
1771
|
m_priceIndicator.setAttribute('class', 'millistream-chart-price-indicator');
|
|
1773
1772
|
}
|
|
1774
1773
|
m_priceIndicator.innerHTML = newValue;
|
|
1775
|
-
m_priceIndicator.style.left = (m_chartspaces.chart.right / window.devicePixelRatio) - (offsetWidth == 0 ? -1 : m_priceIndicator.offsetWidth) + 'px';
|
|
1774
|
+
m_priceIndicator.style.left = (m_chartspaces.chart.right / window.devicePixelRatio) - (offsetWidth == 0 ? -1 : m_priceIndicator.offsetWidth) + 'px'; // offsetWidth with devicePixelRatio???
|
|
1776
1775
|
m_priceIndicator.style.top = obj.instruments[0].y - (m_priceIndicator.offsetHeight / 2) + 'px';
|
|
1777
1776
|
newValue = MillistreamWidgetApi_getElementNumber(_this, m_priceIndicator);
|
|
1778
1777
|
MillistreamWidgetApi_flashElement(_this, m_priceIndicator, newValue, oldValue);
|
|
@@ -1859,13 +1858,13 @@ function Milli_Chart(settings) {
|
|
|
1859
1858
|
instr.data.price = formatNiceNumber(instr.data.price, _this.settings.thousandseparator, _this.settings.decimalseparator, _this.settings.num_decimals, false);
|
|
1860
1859
|
|
|
1861
1860
|
if (typeof _this.instruments[x].toolTip === 'undefined') {
|
|
1862
|
-
|
|
1861
|
+
// add textdiv
|
|
1863
1862
|
_this.instruments[x].toolTip = document.createElement('div');
|
|
1864
1863
|
_this.instruments[x].toolTip.style.display = _this.settings.tooltip.display;
|
|
1865
|
-
_this.instruments[x].toolTip.setAttribute('class', 'millistream-chart-tooltip');
|
|
1864
|
+
_this.instruments[x].toolTip.setAttribute('class', 'millistream-chart-tooltip'); // set class so we can measure it might change below depending on position
|
|
1866
1865
|
_this.instruments[x].toolTip.position = 'absolute';
|
|
1867
1866
|
m_canvas.parentNode.appendChild(_this.instruments[x].toolTip);
|
|
1868
|
-
|
|
1867
|
+
// add pointer div
|
|
1869
1868
|
_this.instruments[x].toolTipPointer = document.createElement('div');
|
|
1870
1869
|
m_canvas.parentNode.appendChild(_this.instruments[x].toolTipPointer);
|
|
1871
1870
|
_this.instruments[x].toolTipPointer.setAttribute('class', 'millistream-chart-pointer');
|
|
@@ -1880,16 +1879,16 @@ function Milli_Chart(settings) {
|
|
|
1880
1879
|
var pointerWidth = _this.instruments[x].toolTipPointer.offsetWidth + parseInt(pointerStyle.marginLeft) + parseInt(pointerStyle.marginRight);
|
|
1881
1880
|
var pointerHeight = _this.instruments[x].toolTipPointer.offsetHeight + parseInt(pointerStyle.marginTop) + parseInt(pointerStyle.marginBottom);
|
|
1882
1881
|
var posy = obj.instruments[x].y - (_this.instruments[x].toolTip.offsetHeight / 2);
|
|
1883
|
-
if (m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.width) {
|
|
1884
|
-
|
|
1882
|
+
if (m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.width) { // || m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.width) { // TODO +10 should be calculated better
|
|
1883
|
+
// draw the hover to the left
|
|
1885
1884
|
_this.instruments[x].toolTip.style.left = (obj.instruments[x].x - _this.instruments[x].toolTip.offsetWidth - (pointerWidth / 2)) + 1 + 'px';
|
|
1886
1885
|
} else {
|
|
1887
|
-
|
|
1886
|
+
// draw hover to the right
|
|
1888
1887
|
_this.instruments[x].toolTip.style.left = (obj.instruments[x].x + (pointerWidth / 2)) + 'px';
|
|
1889
1888
|
}
|
|
1890
1889
|
_this.instruments[x].toolTip.style.top = posy + 'px';
|
|
1891
1890
|
toolArray.push({ top: (obj.instruments[x].y - (pointerHeight / 2)), instrument: x });
|
|
1892
|
-
_this.instruments[x].toolTipPointer.style.left = (obj.instruments[x].x - (pointerWidth / 2)) + 1 + 'px';
|
|
1891
|
+
_this.instruments[x].toolTipPointer.style.left = (obj.instruments[x].x - (pointerWidth / 2)) + 1 + 'px'; // hmm plus 1??
|
|
1893
1892
|
_this.instruments[x].toolTipPointer.style.top = (obj.instruments[x].y - (pointerHeight / 2)) + 'px';
|
|
1894
1893
|
if (posy > highy) highy = posy;
|
|
1895
1894
|
if (posy < lowy) lowy = posy;
|
|
@@ -1939,7 +1938,7 @@ function Milli_Chart(settings) {
|
|
|
1939
1938
|
startdate = startdate.replaceAll('\/', '-');
|
|
1940
1939
|
enddate = enddate.replaceAll('\/', '-');
|
|
1941
1940
|
m_zoom.mousedown.timestamp = findFirstWeekDay(new Date(startdate + 'T00:00:00Z'));
|
|
1942
|
-
()
|
|
1941
|
+
console.log(new Date(startdate + 'T00:00:00Z'), findFirstWeekDay(new Date(startdate + 'T00:00:00Z')), m_zoom.mousedown.timestamp);
|
|
1943
1942
|
|
|
1944
1943
|
m_zoom.mouseup.timestamp = new Date(enddate + 'T00:00:00Z');
|
|
1945
1944
|
|
|
@@ -1983,7 +1982,7 @@ function Milli_Chart(settings) {
|
|
|
1983
1982
|
}
|
|
1984
1983
|
}
|
|
1985
1984
|
}
|
|
1986
|
-
if (_this.scaleinfoY.type == 'trades' && count > 0 && _this.instruments[0].closeprice1d) return true;
|
|
1985
|
+
if (_this.scaleinfoY.type == 'trades' && count > 0 && _this.instruments[0].closeprice1d) return true; // we can draw on closeprice 1d -> first trade
|
|
1987
1986
|
var y = (m_chartspaces.chart.bottom - m_chartspaces.chart.top) / 2 + m_chartspaces.chart.top;
|
|
1988
1987
|
var x = (m_chartspaces.chart.right - m_chartspaces.chart.left) / 2 + m_chartspaces.chart.left;
|
|
1989
1988
|
m_ctx.save();
|
|
@@ -2015,7 +2014,7 @@ function Milli_Chart(settings) {
|
|
|
2015
2014
|
|
|
2016
2015
|
_this.drawChart = function() {
|
|
2017
2016
|
if (m_zoom.isZooming) {
|
|
2018
|
-
return;
|
|
2017
|
+
return; // prevent redraw due to push updates when zooming
|
|
2019
2018
|
}
|
|
2020
2019
|
|
|
2021
2020
|
for (var i = 0; i < _this.settings.indicators.length; i++) {
|
|
@@ -2058,7 +2057,7 @@ function Milli_Chart(settings) {
|
|
|
2058
2057
|
m_dataPoints.map = new Map();
|
|
2059
2058
|
m_dataPoints.arr = [];
|
|
2060
2059
|
if (_this.instruments.length < 0) {
|
|
2061
|
-
()
|
|
2060
|
+
console.log('no chartdata');
|
|
2062
2061
|
return;
|
|
2063
2062
|
}
|
|
2064
2063
|
calcChartSpaces();
|
|
@@ -2067,42 +2066,42 @@ function Milli_Chart(settings) {
|
|
|
2067
2066
|
var len = parseInt(_this.settings.chartlen.substring(0, _this.settings.chartlen.length - 1));
|
|
2068
2067
|
m_ctx.clearRect(0, 0, m_canvas.width, m_canvas.height);
|
|
2069
2068
|
m_ctx.lineWidth = 1 / window.devicePixelRatio;
|
|
2070
|
-
m_ctx.textBaseline = 'top';
|
|
2069
|
+
m_ctx.textBaseline = 'top'; // important!
|
|
2071
2070
|
var i;
|
|
2072
2071
|
if (period == 'd' && _this.settings.chartlen != 'ytd') {
|
|
2073
2072
|
if (m_zoom.mousedown.timestamp) {
|
|
2074
2073
|
_this.scaleinfoX.endTimeStamp = m_zoom.mouseup.timestamp > m_zoom.mousedown.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
|
|
2075
2074
|
_this.scaleinfoX.startTimeStamp = m_zoom.mouseup.timestamp < m_zoom.mousedown.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
|
|
2076
2075
|
} else {
|
|
2077
|
-
_this.scaleinfoX.startTimeStamp = getTickStartDate(len);
|
|
2078
|
-
|
|
2079
|
-
|
|
2076
|
+
_this.scaleinfoX.startTimeStamp = getTickStartDate(len); // calc not to start with weekends
|
|
2077
|
+
// back up x days from quotedate if needed
|
|
2078
|
+
// TODO if startTimeStamp < quotedate -len borde det vara
|
|
2080
2079
|
var quoteDate = businessDaysSubtraction(_this.instruments[0].quotedate, len);
|
|
2081
|
-
if (_this.scaleinfoX.startTimeStamp - _this.scaleinfoX.startTimeStamp % 86400000 > quoteDate) {
|
|
2080
|
+
if (_this.scaleinfoX.startTimeStamp - _this.scaleinfoX.startTimeStamp % 86400000 > quoteDate) { // if startdate > quotedate back startdate
|
|
2082
2081
|
_this.scaleinfoX.startTimeStamp -= _this.scaleinfoX.startTimeStamp - _this.scaleinfoX.startTimeStamp % 86400000;
|
|
2083
2082
|
_this.scaleinfoX.startTimeStamp += quoteDate;
|
|
2084
2083
|
}
|
|
2085
|
-
_this.scaleinfoX.endTimeStamp = new Date();
|
|
2084
|
+
_this.scaleinfoX.endTimeStamp = new Date(); // om helg TODO
|
|
2086
2085
|
if (len > 1)
|
|
2087
2086
|
_this.scaleinfoX.endTimeStamp = new Date(_this.scaleinfoX.endTimeStamp.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
|
|
2088
2087
|
else if (len == 1) {
|
|
2089
|
-
|
|
2088
|
+
// check if startdate is not today (due to exchange is closed f ex DJ)
|
|
2090
2089
|
if (_this.scaleinfoX.startTimeStamp % 86400000 != new Date().getTime() % 86400) {
|
|
2091
2090
|
_this.scaleinfoX.endTimeStamp = new Date(new Date(_this.scaleinfoX.startTimeStamp).toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
|
|
2092
2091
|
} else
|
|
2093
2092
|
_this.scaleinfoX.endTimeStamp = new Date(_this.scaleinfoX.endTimeStamp.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
|
|
2094
2093
|
} else {
|
|
2095
|
-
|
|
2094
|
+
// check that the last trade is not later than closetime
|
|
2096
2095
|
var tradetimestamp = new Date(_this.instruments[0].trades[_this.instruments[0].trades.length - 1].timestamp).getTime();
|
|
2097
2096
|
var closetimestamp = new Date(new Date(_this.instruments[0].trades[_this.instruments[0].trades.length - 1].timestamp).toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
|
|
2098
2097
|
if (closetimestamp < tradetimestamp)
|
|
2099
|
-
_this.scaleinfoX.endTimeStamp = new Date(closetimestamp);
|
|
2098
|
+
_this.scaleinfoX.endTimeStamp = new Date(closetimestamp); // borde inte rita med closeprice1d då heller eller spelar det ingen roll?
|
|
2100
2099
|
else
|
|
2101
2100
|
_this.scaleinfoX.endTimeStamp = new Date(tradetimestamp);
|
|
2102
2101
|
}
|
|
2103
2102
|
if (_this.scaleinfoX.endTimeStamp - (_this.scaleinfoX.endTimeStamp % 86400000) > _this.instruments[0].quotedate) {
|
|
2104
2103
|
_this.scaleinfoX.endTimeStamp -= _this.scaleinfoX.endTimeStamp - _this.scaleinfoX.endTimeStamp % 86400000;
|
|
2105
|
-
_this.scaleinfoX.endTimeStamp += _this.instruments[0].quotedate;
|
|
2104
|
+
_this.scaleinfoX.endTimeStamp += _this.instruments[0].quotedate; // set enddate = last Quotedate
|
|
2106
2105
|
}
|
|
2107
2106
|
}
|
|
2108
2107
|
setTimeSpanData();
|
|
@@ -2111,7 +2110,7 @@ function Milli_Chart(settings) {
|
|
|
2111
2110
|
for (var s = 1; s < _this.instruments.length; s++) _this.instruments[s].factor = 1;
|
|
2112
2111
|
} else
|
|
2113
2112
|
if (_this.instruments.length > 1) {
|
|
2114
|
-
|
|
2113
|
+
// calc factors
|
|
2115
2114
|
var instrumentprice;
|
|
2116
2115
|
for (i = 0; i < _this.instruments[0].trades.length; i++) {
|
|
2117
2116
|
if (_this.instruments[0].trades[i].timestamp >= _this.scaleinfoX.startTimeStamp) {
|
|
@@ -2148,7 +2147,7 @@ function Milli_Chart(settings) {
|
|
|
2148
2147
|
|
|
2149
2148
|
} else
|
|
2150
2149
|
if (period == 'm') {
|
|
2151
|
-
()
|
|
2150
|
+
console.log('mon');
|
|
2152
2151
|
|
|
2153
2152
|
if (m_zoom.mousedown.timestamp) {
|
|
2154
2153
|
_this.scaleinfoX.startTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
|
|
@@ -2163,7 +2162,7 @@ function Milli_Chart(settings) {
|
|
|
2163
2162
|
if (_this.instruments[0].history.length > 1 && _this.scaleinfoX.startTimeStamp < _this.instruments[0].history[0].timestamp) _this.scaleinfoX.startTimeStamp = _this.instruments[0].history[0].timestamp;
|
|
2164
2163
|
|
|
2165
2164
|
_this.scaleinfoX.endTimeStamp = new Date().getTime();
|
|
2166
|
-
_this.scaleinfoX.endTimeStamp = _this.scaleinfoX.endTimeStamp - (_this.scaleinfoX.endTimeStamp % 86400000);
|
|
2165
|
+
_this.scaleinfoX.endTimeStamp = _this.scaleinfoX.endTimeStamp - (_this.scaleinfoX.endTimeStamp % 86400000); // TODO: detta kan vi nog ta bort eller skall det vara med closetime?
|
|
2167
2166
|
}
|
|
2168
2167
|
setTimeSpanData();
|
|
2169
2168
|
_this.scaleinfoY.type = 'history';
|
|
@@ -2198,7 +2197,7 @@ function Milli_Chart(settings) {
|
|
|
2198
2197
|
_this.scaleinfoX.startTimeStamp = _this.instruments[0].history[0].timestamp;
|
|
2199
2198
|
} else
|
|
2200
2199
|
if (_this.settings.chartlen == 'ytd') {
|
|
2201
|
-
_this.scaleinfoX.startTimeStamp = new Date(new Date().getFullYear() + '-01-01').getTime();
|
|
2200
|
+
_this.scaleinfoX.startTimeStamp = new Date(new Date().getFullYear() + '-01-01').getTime(); // TODO, hur skall vi göra här om det inte finns data runt här?
|
|
2202
2201
|
} else {
|
|
2203
2202
|
_this.scaleinfoX.startTimeStamp = new Date().getTime() - (86400000 * 365 * (isNaN(len) ? 1 : len));
|
|
2204
2203
|
}
|
|
@@ -2206,7 +2205,7 @@ function Milli_Chart(settings) {
|
|
|
2206
2205
|
_this.scaleinfoX.startTimeStamp = findFirstWeekDay(_this.scaleinfoX.startTimeStamp).getTime();
|
|
2207
2206
|
|
|
2208
2207
|
_this.scaleinfoX.endTimeStamp = new Date().getTime();
|
|
2209
|
-
_this.scaleinfoX.endTimeStamp = _this.scaleinfoX.endTimeStamp - (_this.scaleinfoX.endTimeStamp % 86400000);
|
|
2208
|
+
_this.scaleinfoX.endTimeStamp = _this.scaleinfoX.endTimeStamp - (_this.scaleinfoX.endTimeStamp % 86400000); // TODO: detta kan vi nog ta bort eller skall det vara med closetime?
|
|
2210
2209
|
}
|
|
2211
2210
|
setTimeSpanData();
|
|
2212
2211
|
_this.scaleinfoY.type = 'history';
|
|
@@ -2228,10 +2227,10 @@ function Milli_Chart(settings) {
|
|
|
2228
2227
|
|
|
2229
2228
|
}
|
|
2230
2229
|
|
|
2231
|
-
|
|
2232
|
-
|
|
2233
|
-
|
|
2234
|
-
|
|
2230
|
+
/*for (const [key, a] of m_analyzisMethod.entries()) {
|
|
2231
|
+
if (a.method == 'bb') plotBollingerBand(a, 'history');
|
|
2232
|
+
else plotMovingAverage(a, 'history');
|
|
2233
|
+
}*/
|
|
2235
2234
|
}
|
|
2236
2235
|
drawBoxShadow(m_chartspaces.chart);
|
|
2237
2236
|
|
|
@@ -2245,11 +2244,11 @@ function Milli_Chart(settings) {
|
|
|
2245
2244
|
if (_this.settings.curveOnTop == false)
|
|
2246
2245
|
m_ctx.globalCompositeOperation = 'destination-over'
|
|
2247
2246
|
m_ctx.fillStyle = m_chartCss.backgroundColor;
|
|
2248
|
-
|
|
2247
|
+
//m_ctx.fillRect(0, 0, m_canvas.width, m_canvas.height);
|
|
2249
2248
|
m_ctx.fillRect(0, 0, m_canvas.width, m_canvas.height);
|
|
2250
2249
|
m_ctx.restore();
|
|
2251
2250
|
}
|
|
2252
|
-
|
|
2251
|
+
//onMouseOut();
|
|
2253
2252
|
};
|
|
2254
2253
|
|
|
2255
2254
|
function drawBoxShadow(space) {
|
|
@@ -2287,7 +2286,7 @@ function Milli_Chart(settings) {
|
|
|
2287
2286
|
|
|
2288
2287
|
if (typeof data.tradecurrency !== 'undefined') instr.tradecurrency = data.tradecurrency;
|
|
2289
2288
|
if (data.marketopen && data.marketclose) {
|
|
2290
|
-
if (new Date('2020-01-01T' + data.marketopen + 'Z') > new Date('2020-01-01T' + data.marketclose + 'Z')) {
|
|
2289
|
+
if (new Date('2020-01-01T' + data.marketopen + 'Z') > new Date('2020-01-01T' + data.marketclose + 'Z')) { // om close är tidiagre än open så sätter vi nedan tider
|
|
2291
2290
|
data.marketopen = '00:00:00';
|
|
2292
2291
|
data.marketclose = '22:00:00';
|
|
2293
2292
|
}
|
|
@@ -2319,7 +2318,7 @@ function Milli_Chart(settings) {
|
|
|
2319
2318
|
instr.trades = [];
|
|
2320
2319
|
instr.hashmap.clear();
|
|
2321
2320
|
for (i = 0; i < data.trades.length; i++) {
|
|
2322
|
-
if (data.trades[i].tradecode & 16) {
|
|
2321
|
+
if (data.trades[i].tradecode & 16) { // canceltrade
|
|
2323
2322
|
continue;
|
|
2324
2323
|
}
|
|
2325
2324
|
item = [];
|
|
@@ -2336,7 +2335,7 @@ function Milli_Chart(settings) {
|
|
|
2336
2335
|
}
|
|
2337
2336
|
instr.trades.push(item);
|
|
2338
2337
|
instr.hashmap.set(item.timestamp, item);
|
|
2339
|
-
|
|
2338
|
+
// we might have recieved trades from push before dataapi
|
|
2340
2339
|
instr.trades.sort(function(a, b) {
|
|
2341
2340
|
return a.timestamp - b.timestamp;
|
|
2342
2341
|
});
|
|
@@ -2349,7 +2348,7 @@ function Milli_Chart(settings) {
|
|
|
2349
2348
|
instr.history = [];
|
|
2350
2349
|
for (i = 0; i < data.history.length; i++) {
|
|
2351
2350
|
item = [];
|
|
2352
|
-
if (typeof data.history[i].date !== 'undefined' && data.history[i].closeprice != null) {
|
|
2351
|
+
if (typeof data.history[i].date !== 'undefined' && data.history[i].closeprice != null) { // inget pris eller datum = onintressant, borde kanske skippas vid selecten i pitten också
|
|
2353
2352
|
var timestamp = new Date(data.history[i].date + 'T00:00:00Z').getTime();
|
|
2354
2353
|
item.timestamp = timestamp;
|
|
2355
2354
|
} else continue;
|
|
@@ -2359,7 +2358,7 @@ function Milli_Chart(settings) {
|
|
|
2359
2358
|
if (typeof data.history[i].dividend !== 'undefined') item.dividend = data.history[i].dividend;
|
|
2360
2359
|
instr.history.push(item);
|
|
2361
2360
|
}
|
|
2362
|
-
if (_this.settings.hcurve && instr.history.length > 0) {
|
|
2361
|
+
if (_this.settings.hcurve && instr.history.length > 0) { // varför på all historik, och inte bara på hcurve
|
|
2363
2362
|
if (!isToday(new Date(instr.history[instr.history.length - 1].timestamp))) {
|
|
2364
2363
|
var addItem = {};
|
|
2365
2364
|
MillistreamWidgetApi_AssignObject(instr.history[instr.history.length - 1], addItem);
|
|
@@ -2384,7 +2383,7 @@ function Milli_Chart(settings) {
|
|
|
2384
2383
|
};
|
|
2385
2384
|
|
|
2386
2385
|
function plotExternalHistoricalData(data) {
|
|
2387
|
-
|
|
2386
|
+
// används för dividend osv
|
|
2388
2387
|
m_ctx.save();
|
|
2389
2388
|
var startpoint = { x: 0, y: 0 };
|
|
2390
2389
|
var endpoint = { x: 0, y: 0 };
|
|
@@ -2408,25 +2407,25 @@ function Milli_Chart(settings) {
|
|
|
2408
2407
|
currentDate.setMinutes(lastdate.getMinutes());
|
|
2409
2408
|
currentDate.setSeconds(lastdate.getSeconds());
|
|
2410
2409
|
|
|
2411
|
-
if (lastdate.toISOString().substring(0, 10) != currentDate.toISOString().substring(0, 10)) {
|
|
2410
|
+
if (lastdate.toISOString().substring(0, 10) != currentDate.toISOString().substring(0, 10)) { // new date
|
|
2412
2411
|
var tmp = new Date(lastdate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
2413
2412
|
var nextDate = new Date(data[i].timestamp);
|
|
2414
|
-
tmp = tmp.getTime() + 86400000 - _this.scaleinfoX.milliPerDay;
|
|
2413
|
+
tmp = tmp.getTime() + 86400000 - _this.scaleinfoX.milliPerDay; // increase to next days starttime
|
|
2415
2414
|
currentDate = new Date(tmp);
|
|
2416
2415
|
while (dateDiffInDays(currentDate, nextDate) > 0) {
|
|
2417
2416
|
if (currentDate.getDay() == 0 || currentDate.getDay() == 6)
|
|
2418
2417
|
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
2419
2418
|
else
|
|
2420
|
-
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel);
|
|
2419
|
+
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel); // * dateDiffInDays(lastdate, currentDate);
|
|
2421
2420
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
2422
2421
|
}
|
|
2423
|
-
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel);
|
|
2422
|
+
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel); // * dateDiffInDays(lastdate, currentDate);
|
|
2424
2423
|
lastdate = currentDate;
|
|
2425
2424
|
startpoint.x = Math.round(m_chartspaces.chart.left + ((data[i].timestamp - startDate) / _this.scaleinfoX.timePerPixel)) + 0.5 - offset;
|
|
2426
|
-
|
|
2425
|
+
// TODO: här blir det fel när det är från 00:00: 23:59 men göms av tmpx < startpoint.x
|
|
2427
2426
|
|
|
2428
2427
|
}
|
|
2429
|
-
|
|
2428
|
+
//startpoint.y = Math.round(m_canvas.height - getScaledSetting(m_chartCss.marginBottom) - (((data[i].price * factor) - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel)) + 0.5;
|
|
2430
2429
|
startpoint.y = Math.round(m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) - (((data[i].price * factor) - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel)) + 0.5;
|
|
2431
2430
|
maxy = maxy > startpoint.y ? maxy : startpoint.y;
|
|
2432
2431
|
|
|
@@ -2468,19 +2467,19 @@ function Milli_Chart(settings) {
|
|
|
2468
2467
|
var endtimeToday = new Date(data[i].timestamp);
|
|
2469
2468
|
if (endtimeToday.getDay() == 0 || endtimeToday.getDay() == 6) continue;
|
|
2470
2469
|
if (_this.scaleinfoY.type != 'history') {
|
|
2471
|
-
endtimeToday = new Date(endtimeToday.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
2470
|
+
endtimeToday = new Date(endtimeToday.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z'); // borde räcka att göra 1 gång när det blir nytt datum
|
|
2472
2471
|
}
|
|
2473
2472
|
if (data[i].timestamp > endtimeToday.getTime()) {
|
|
2474
|
-
continue;
|
|
2473
|
+
continue; // dataticks efter stängning ritas inte
|
|
2475
2474
|
}
|
|
2476
2475
|
currentDate = new Date(data[i].timestamp);
|
|
2477
2476
|
currentDate.setHours(lastdate.getHours());
|
|
2478
2477
|
currentDate.setMinutes(lastdate.getMinutes());
|
|
2479
2478
|
currentDate.setSeconds(lastdate.getSeconds());
|
|
2480
|
-
if (lastdate.toISOString().substring(0, 10) != currentDate.toISOString().substring(0, 10)) {
|
|
2479
|
+
if (lastdate.toISOString().substring(0, 10) != currentDate.toISOString().substring(0, 10)) { // new date
|
|
2481
2480
|
tmp = new Date(lastdate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
2482
2481
|
var nextDate = new Date(data[i].timestamp);
|
|
2483
|
-
tmp = tmp.getTime() + 86400000 - _this.scaleinfoX.milliPerDay;
|
|
2482
|
+
tmp = tmp.getTime() + 86400000 - _this.scaleinfoX.milliPerDay; // increase to next days starttime
|
|
2484
2483
|
|
|
2485
2484
|
currentDate = new Date(tmp);
|
|
2486
2485
|
while (dateDiffInDays(currentDate, nextDate) > 0) {
|
|
@@ -2490,11 +2489,11 @@ function Milli_Chart(settings) {
|
|
|
2490
2489
|
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel);
|
|
2491
2490
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
2492
2491
|
}
|
|
2493
|
-
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel);
|
|
2492
|
+
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel); // * dateDiffInDays(lastdate, currentDate);
|
|
2494
2493
|
lastdate = currentDate;
|
|
2495
2494
|
startpoint.x = Math.round(m_chartspaces.chart.left + ((data[i].timestamp - startDate) / _this.scaleinfoX.timePerPixel)) + 0.5 - offset;
|
|
2496
2495
|
|
|
2497
|
-
|
|
2496
|
+
// TODO: här blir det fel när det är från 00:00: 23:59 men göms av tmpx < startpoint.x
|
|
2498
2497
|
if (_this.scaleinfoY.type == 'trades' && tmpx < startpoint.x) {
|
|
2499
2498
|
ret.push(startpoint.x, startpoint.y);
|
|
2500
2499
|
}
|
|
@@ -2530,7 +2529,7 @@ function Milli_Chart(settings) {
|
|
|
2530
2529
|
if (line.length == 0) return;
|
|
2531
2530
|
m_ctx.save();
|
|
2532
2531
|
m_ctx.beginPath();
|
|
2533
|
-
m_ctx.closePath();
|
|
2532
|
+
m_ctx.closePath(); // clear path
|
|
2534
2533
|
m_ctx.moveTo(line[0].x, line[0].y);
|
|
2535
2534
|
for (var i = 1; i < line.length; i++) {
|
|
2536
2535
|
m_ctx.lineTo(line[i].x, line[i].y);
|
|
@@ -2561,7 +2560,7 @@ function Milli_Chart(settings) {
|
|
|
2561
2560
|
}
|
|
2562
2561
|
var sma = calcAnalyzisLine(data, 2);
|
|
2563
2562
|
m_ctx.beginPath();
|
|
2564
|
-
m_ctx.closePath();
|
|
2563
|
+
m_ctx.closePath(); // clear path
|
|
2565
2564
|
m_ctx.moveTo(sma[0].x, sma[0].y);
|
|
2566
2565
|
for (i = 0; i < sma.length; i++) m_ctx.lineTo(sma[i].x, sma[i].y);
|
|
2567
2566
|
m_ctx.stroke();
|
|
@@ -2572,7 +2571,7 @@ function Milli_Chart(settings) {
|
|
|
2572
2571
|
function plotData(data, instrument) {
|
|
2573
2572
|
m_ctx.save();
|
|
2574
2573
|
if (_this.settings.curveOnTop == false)
|
|
2575
|
-
m_ctx.globalCompositeOperation = 'destination-over';
|
|
2574
|
+
m_ctx.globalCompositeOperation = 'destination-over'; // dont draw over labels inside the chart
|
|
2576
2575
|
m_ctx.strokeStyle = m_instrumentCss[instrument].color;
|
|
2577
2576
|
var factor = _this.instruments[instrument].factor;
|
|
2578
2577
|
var startpoint = { x: 0, y: 0 };
|
|
@@ -2593,7 +2592,7 @@ function Milli_Chart(settings) {
|
|
|
2593
2592
|
|
|
2594
2593
|
for (var i = 0; i < len; i++) {
|
|
2595
2594
|
var currentDate;
|
|
2596
|
-
|
|
2595
|
+
// var lastItem = data[i];
|
|
2597
2596
|
var tmpx = startpoint.x;
|
|
2598
2597
|
var tmp;
|
|
2599
2598
|
if (data[i].timestamp < _this.scaleinfoX.startTimeStamp) {
|
|
@@ -2601,42 +2600,42 @@ function Milli_Chart(settings) {
|
|
|
2601
2600
|
continue;
|
|
2602
2601
|
}
|
|
2603
2602
|
if (data[i].timestamp > _this.scaleinfoX.endTimeStamp) {
|
|
2604
|
-
break;
|
|
2603
|
+
break; // continue?
|
|
2605
2604
|
}
|
|
2606
2605
|
if (data[i].timestamp > new Date().getTime())
|
|
2607
2606
|
break;
|
|
2608
2607
|
|
|
2609
2608
|
if (_this.scaleinfoY.type != 'history' && (data[i].timestamp % 86400000 < _this.instruments[0].opentimestamp || data[i].timestamp % 86400000 > _this.instruments[0].closetimestamp)) {
|
|
2610
|
-
|
|
2609
|
+
// stämmer detta kan det bli överlapp vid sommartid/vintertid?
|
|
2611
2610
|
continue;
|
|
2612
2611
|
}
|
|
2613
2612
|
var endtimeToday = new Date(data[i].timestamp);
|
|
2614
|
-
if (endtimeToday.getDay() == 0 || endtimeToday.getDay() == 6) continue;
|
|
2613
|
+
if (endtimeToday.getDay() == 0 || endtimeToday.getDay() == 6) continue; // do not draw weekends TODO: if main instrument has weekenddata draw it, but need to fix that in all drawfunctions
|
|
2615
2614
|
if (_this.scaleinfoY.type != 'history') {
|
|
2616
|
-
endtimeToday = new Date(endtimeToday.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
2615
|
+
endtimeToday = new Date(endtimeToday.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z'); // borde räcka att göra 1 gång när det blir nytt datum
|
|
2617
2616
|
}
|
|
2618
2617
|
if (data[i].timestamp > endtimeToday.getTime()) {
|
|
2619
|
-
continue;
|
|
2618
|
+
continue; // dataticks efter stängning ritas inte
|
|
2620
2619
|
}
|
|
2621
2620
|
|
|
2622
2621
|
if (_this.scaleinfoY.type == 'history') {
|
|
2623
|
-
|
|
2624
|
-
|
|
2622
|
+
//var point = { price: data[i].price, open: null, x: endpoint.x - 0.5, y: endpoint.y - 0.5, timestamp: data[i].timestamp };
|
|
2623
|
+
//m_datapoints.push(point);
|
|
2625
2624
|
} else
|
|
2626
|
-
if (_this.settings.previousDayClose && addedcloseprice1d == false && m_zoom.mouseup.timestamp == null) {
|
|
2625
|
+
if (_this.settings.previousDayClose && addedcloseprice1d == false && m_zoom.mouseup.timestamp == null) { // only draw closeprice1d on today charts
|
|
2627
2626
|
currentDate = new Date(data[i].timestamp);
|
|
2628
2627
|
offset = ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel) * dateDiffInDays(new Date(startDate), currentDate);
|
|
2629
2628
|
tmp = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
2630
2629
|
endpoint.x = Math.round(m_chartspaces.chart.left + ((tmp.getTime() - startDate) / _this.scaleinfoX.timePerPixel)) + 0.5 - offset;
|
|
2631
2630
|
|
|
2632
|
-
|
|
2631
|
+
//endpoint.y = Math.round(m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) - (((parseFloat(_this.instruments[instrument].startValue) * factor) - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel)) + 0.5;
|
|
2633
2632
|
endpoint.y = Math.round(m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) - (((parseFloat(_this.instruments[instrument].startValue)) - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel)) + 0.5;
|
|
2634
2633
|
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2634
|
+
/*if (_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') { // plot the closeprice1d
|
|
2635
|
+
endpoint.y = Math.round(m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) - (((parseFloat(_this.instruments[instrument].closeprice1d) * factor) - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel)) + 0.5;
|
|
2636
|
+
} else {
|
|
2637
|
+
endpoint.y = Math.round(m_chartspaces.chart.height - getScaledSetting(m_chartCss.marginBottom) - (((parseFloat(lastItem.price) * factor) - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel)) + 0.5;
|
|
2638
|
+
}*/
|
|
2640
2639
|
m_ctx.moveTo(endpoint.x, endpoint.y);
|
|
2641
2640
|
lastdate = new Date(data[i].timestamp);
|
|
2642
2641
|
addedcloseprice1d = true;
|
|
@@ -2647,25 +2646,25 @@ function Milli_Chart(settings) {
|
|
|
2647
2646
|
currentDate.setHours(lastdate.getHours());
|
|
2648
2647
|
currentDate.setMinutes(lastdate.getMinutes());
|
|
2649
2648
|
currentDate.setSeconds(lastdate.getSeconds());
|
|
2650
|
-
if (lastdate.toISOString().substring(0, 10) != currentDate.toISOString().substring(0, 10)) {
|
|
2649
|
+
if (lastdate.toISOString().substring(0, 10) != currentDate.toISOString().substring(0, 10)) { // new date
|
|
2651
2650
|
tmp = new Date(lastdate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
2652
|
-
|
|
2651
|
+
// draw Day separator?
|
|
2653
2652
|
var nextDate = new Date(data[i].timestamp);
|
|
2654
|
-
tmp = tmp.getTime() + 86400000 - _this.scaleinfoX.milliPerDay;
|
|
2653
|
+
tmp = tmp.getTime() + 86400000 - _this.scaleinfoX.milliPerDay; // increase to next days starttime
|
|
2655
2654
|
|
|
2656
2655
|
currentDate = new Date(tmp);
|
|
2657
2656
|
while (dateDiffInDays(currentDate, nextDate) > 0) {
|
|
2658
2657
|
if (currentDate.getDay() == 0 || currentDate.getDay() == 6)
|
|
2659
2658
|
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
2660
2659
|
else
|
|
2661
|
-
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel);
|
|
2660
|
+
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel); // * dateDiffInDays(lastdate, currentDate);
|
|
2662
2661
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
2663
2662
|
}
|
|
2664
|
-
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel);
|
|
2663
|
+
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel); // * dateDiffInDays(lastdate, currentDate);
|
|
2665
2664
|
lastdate = currentDate;
|
|
2666
2665
|
startpoint.x = Math.round(m_chartspaces.chart.left + ((data[i].timestamp - startDate) / _this.scaleinfoX.timePerPixel)) + 0.5 - offset;
|
|
2667
2666
|
|
|
2668
|
-
|
|
2667
|
+
// TODO: här blir det fel när det är från 00:00: 23:59 men göms av tmpx < startpoint.x
|
|
2669
2668
|
if (_this.scaleinfoY.type == 'trades' && tmpx < startpoint.x) {
|
|
2670
2669
|
m_ctx.lineTo(startpoint.x, startpoint.y);
|
|
2671
2670
|
}
|
|
@@ -2694,7 +2693,7 @@ function Milli_Chart(settings) {
|
|
|
2694
2693
|
if (tmpx < startpoint.x) {
|
|
2695
2694
|
if (_this.settings.hcurve) m_ctx.lineTo(startpoint.x, endpoint.y);
|
|
2696
2695
|
m_ctx.lineTo(startpoint.x, startpoint.y);
|
|
2697
|
-
|
|
2696
|
+
//m_ctx.bezierCurveTo(startpoint.x, startpoint.y, endpoint.x - 1, endpoint.y - 1, endpoint.x, endpoint.y); // läs på om detta för "runda linjer"
|
|
2698
2697
|
|
|
2699
2698
|
if (instrument == 0) {
|
|
2700
2699
|
point = { price: data[i].price, open: data[i].openprice, x: startpoint.x / window.devicePixelRatio - 0.5, y: startpoint.y / window.devicePixelRatio - 0.5, timestamp: data[i].timestamp, date: new Date(data[i].timestamp), quantity: quantity };
|
|
@@ -2711,7 +2710,7 @@ function Milli_Chart(settings) {
|
|
|
2711
2710
|
m_datapoints.push(point);
|
|
2712
2711
|
if (_this.settings.hcurve && _this.scaleinfoY.type == 'history') {
|
|
2713
2712
|
if (isToday(currentDate)) {
|
|
2714
|
-
|
|
2713
|
+
// only 1 point in hcurve chart, draw line from start of chart to end date
|
|
2715
2714
|
m_ctx.moveTo(m_chartspaces.chart.left, startpoint.y);
|
|
2716
2715
|
point = { price: data[i].price, open: data[i].openprice, x: m_chartspaces.chart.left / window.devicePixelRatio - 0.5, y: startpoint.y / window.devicePixelRatio - 0.5, timestamp: data[i].timestamp, date: new Date(data[i].timestamp), insref: _this.instruments[instrument].insref, diff: data[i].diff, quantity: quantity };
|
|
2717
2716
|
m_datapoints.push(point);
|
|
@@ -2719,12 +2718,12 @@ function Milli_Chart(settings) {
|
|
|
2719
2718
|
m_datapoints.push(point);
|
|
2720
2719
|
startx = m_chartspaces.chart.left;
|
|
2721
2720
|
starty = startpoint.y;
|
|
2722
|
-
|
|
2721
|
+
// last point so break out and store startx and starty from fake point
|
|
2723
2722
|
break;
|
|
2724
2723
|
} else if (hCurveLastPoint) {
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2724
|
+
/* var y = Math.round(m_canvas.height - getScaledSetting(m_chartCss.marginBottom) - (((hCurveLastPoint.price * factor) - _this.scaleinfoY.minValue) * _this.scaleinfoY.valuePerPixel)) + 0.5;
|
|
2725
|
+
m_ctx.moveTo(m_chartspaces.chart.left, y);
|
|
2726
|
+
m_ctx.lineTo(startpoint.x, y);*/
|
|
2728
2727
|
}
|
|
2729
2728
|
}
|
|
2730
2729
|
quantity = 0;
|
|
@@ -2737,7 +2736,7 @@ function Milli_Chart(settings) {
|
|
|
2737
2736
|
endpoint.y = startpoint.y;
|
|
2738
2737
|
}
|
|
2739
2738
|
if (data[i].dividend) {
|
|
2740
|
-
|
|
2739
|
+
//console.log('div', data[i]);
|
|
2741
2740
|
}
|
|
2742
2741
|
}
|
|
2743
2742
|
m_dataPoints.arr.sort(function(a, b) {
|
|
@@ -2761,7 +2760,7 @@ function Milli_Chart(settings) {
|
|
|
2761
2760
|
m_ctx.fill();
|
|
2762
2761
|
} else
|
|
2763
2762
|
m_ctx.closePath();
|
|
2764
|
-
|
|
2763
|
+
// eftersom vi kör med m_datapoints här så missar vi dom som plottas på samma ställe som punkten innan, gör vi det???
|
|
2765
2764
|
if (instrument == 0) {
|
|
2766
2765
|
drawPriceIndicator();
|
|
2767
2766
|
drawClosePriceIndicator();
|
|
@@ -2770,13 +2769,13 @@ function Milli_Chart(settings) {
|
|
|
2770
2769
|
m_ctx.restore();
|
|
2771
2770
|
}
|
|
2772
2771
|
|
|
2773
|
-
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
|
|
2778
|
-
|
|
2779
|
-
|
|
2772
|
+
/* function drawCompare(resp) {
|
|
2773
|
+
parseData(resp[0], 1);
|
|
2774
|
+
_this.drawChart();
|
|
2775
|
+
requestStreaming();
|
|
2776
|
+
return;
|
|
2777
|
+
}
|
|
2778
|
+
*/
|
|
2780
2779
|
|
|
2781
2780
|
_this.setChartLength = function(len) {
|
|
2782
2781
|
_this.settings.chartlen = len;
|
|
@@ -2908,7 +2907,7 @@ function Milli_Chart(settings) {
|
|
|
2908
2907
|
};
|
|
2909
2908
|
req.open("GET", url, true);
|
|
2910
2909
|
req.onerror = function(error) {
|
|
2911
|
-
(
|
|
2910
|
+
console.log('Fetch data error', error);
|
|
2912
2911
|
};
|
|
2913
2912
|
req.send();
|
|
2914
2913
|
}
|
|
@@ -2920,9 +2919,9 @@ function Milli_Chart(settings) {
|
|
|
2920
2919
|
fetchHistory(c.insref);
|
|
2921
2920
|
}
|
|
2922
2921
|
});
|
|
2923
|
-
|
|
2922
|
+
//fetch data and redraw ( for no push charts)
|
|
2924
2923
|
};
|
|
2925
|
-
|
|
2924
|
+
// Compare functions
|
|
2926
2925
|
_this.removeAllCompares = function() {
|
|
2927
2926
|
if (_this.instruments.length == 1) return;
|
|
2928
2927
|
for (var i = 0; i < 3; i++)
|
|
@@ -2973,7 +2972,7 @@ function Milli_Chart(settings) {
|
|
|
2973
2972
|
fetchHistory(insref);
|
|
2974
2973
|
return 1;
|
|
2975
2974
|
};
|
|
2976
|
-
|
|
2975
|
+
// Size functions
|
|
2977
2976
|
|
|
2978
2977
|
function setChartSize() {
|
|
2979
2978
|
var offset = 0;
|
|
@@ -2982,8 +2981,8 @@ function Milli_Chart(settings) {
|
|
|
2982
2981
|
}
|
|
2983
2982
|
_this.settings.target.style.height = (_this.settings.target.parentNode.offsetHeight - offset) + 'px';
|
|
2984
2983
|
_this.settings.target.style.width = _this.settings.target.parentNode.offsetWidth + 'px';
|
|
2985
|
-
|
|
2986
|
-
|
|
2984
|
+
//_this.settings.target.style.height = (_this.settings.target.parentNode.offsetHeight - offset) * window.devicePixelRatio + 'px';
|
|
2985
|
+
//_this.settings.target.style.width = _this.settings.target.parentNode.offsetWidth * window.devicePixelRatio + 'px';
|
|
2987
2986
|
m_canvas.setRect(_this.settings.target.offsetHeight, _this.settings.target.offsetWidth);
|
|
2988
2987
|
}
|
|
2989
2988
|
|
|
@@ -3003,8 +3002,8 @@ function Milli_Chart(settings) {
|
|
|
3003
3002
|
diff = (m_resizing.width - m_canvas.width) / m_canvas.width * 100;
|
|
3004
3003
|
if (Math.abs(diff) > 1) {
|
|
3005
3004
|
setChartSize();
|
|
3006
|
-
|
|
3007
|
-
|
|
3005
|
+
//m_canvas.height = Math.floor(_this.settings.target.offsetHeight * window.devicePixelRatio);
|
|
3006
|
+
//m_canvas.width = Math.floor(_this.settings.target.offsetWidth * window.devicePixelRatio);
|
|
3008
3007
|
m_resizing.width = m_canvas.width;
|
|
3009
3008
|
m_resizing.height = m_canvas.height;
|
|
3010
3009
|
_this.drawChart();
|
|
@@ -3036,11 +3035,11 @@ function Milli_Chart(settings) {
|
|
|
3036
3035
|
m_canvas = MillistreamWidgetApi_addElement(_this, 'canvas', 'millistream-chart-canvas', _this.settings.target);
|
|
3037
3036
|
m_ctx = m_canvas.getContext("2d");
|
|
3038
3037
|
setChartSize();
|
|
3039
|
-
m_canvas.addEventListener('mousemove', onMouseMove, false);
|
|
3038
|
+
m_canvas.addEventListener('mousemove', onMouseMove, false); // disable while loading and enable on drawReady
|
|
3040
3039
|
m_canvas.addEventListener('mouseout', onMouseOut, false);
|
|
3041
3040
|
m_canvas.style.cursor = "crosshair";
|
|
3042
3041
|
m_canvas.onmousedown = (function(evt) {
|
|
3043
|
-
if (!evt.which == 1) return;
|
|
3042
|
+
if (!evt.which == 1) return; // ignore right and middle
|
|
3044
3043
|
if (_this.settings.enablezoom == false) return;
|
|
3045
3044
|
if (m_datapoints.length == 0) return;
|
|
3046
3045
|
var rect = m_canvas.getBoundingClientRect();
|
|
@@ -3066,7 +3065,7 @@ function Milli_Chart(settings) {
|
|
|
3066
3065
|
clearZoom();
|
|
3067
3066
|
return;
|
|
3068
3067
|
}
|
|
3069
|
-
if (Math.abs(x - m_zoom.mousedown.pos) > 5) {
|
|
3068
|
+
if (Math.abs(x - m_zoom.mousedown.pos) > 5) { // only handle zoom with 5 pixels width
|
|
3070
3069
|
var i;
|
|
3071
3070
|
for (i = m_datapoints.length - 1; i > 0; i--) {
|
|
3072
3071
|
if (x >= m_datapoints[i].x) {
|
|
@@ -3083,7 +3082,7 @@ function Milli_Chart(settings) {
|
|
|
3083
3082
|
m_zoom.mousedown.pos = 0;
|
|
3084
3083
|
m_zoom.mousedown.i = 0;
|
|
3085
3084
|
if (m_zoom.mousedown.oldtimestamp != null) {
|
|
3086
|
-
m_zoom.mousedown.timestamp = m_zoom.mousedown.oldtimestamp;
|
|
3085
|
+
m_zoom.mousedown.timestamp = m_zoom.mousedown.oldtimestamp; // so we do not unzoom if zoomed
|
|
3087
3086
|
m_zoom.mousedown.oldtimestamp = null;
|
|
3088
3087
|
} else
|
|
3089
3088
|
m_zoom.mousedown.timestamp = null;
|
|
@@ -3171,27 +3170,27 @@ function Milli_Chart(settings) {
|
|
|
3171
3170
|
var data = instr.hashmap.get(timestamp);
|
|
3172
3171
|
if (typeof data === 'undefined') {
|
|
3173
3172
|
data = {};
|
|
3174
|
-
|
|
3173
|
+
//data.tradereference = json['14'];
|
|
3175
3174
|
data.timestamp = timestamp;
|
|
3176
3175
|
calcAnalyizis = true;
|
|
3177
3176
|
if (instr.pricetype == 'price') {
|
|
3178
3177
|
update = true;
|
|
3179
|
-
data.price = parseFloat(json['12']);
|
|
3180
|
-
data.open = parseFloat(json['12']);
|
|
3181
|
-
data.high = parseFloat(json['12']);
|
|
3182
|
-
data.low = parseFloat(json['12']);
|
|
3178
|
+
data.price = parseFloat(json['12']); // eller 201 för tradeyield
|
|
3179
|
+
data.open = parseFloat(json['12']); // eller 201 för tradeyield
|
|
3180
|
+
data.high = parseFloat(json['12']); // eller 201 för tradeyield
|
|
3181
|
+
data.low = parseFloat(json['12']); // eller 201 för tradeyield
|
|
3183
3182
|
data.quantity = typeof json['13'] === 'undefined' ? 0 : parseInt(json['13']);
|
|
3184
3183
|
} else if (instr.pricetype == 'price') {
|
|
3185
|
-
data.price = parseFloat(json['201']);
|
|
3186
|
-
data.open = parseFloat(json['201']);
|
|
3187
|
-
data.high = parseFloat(json['201']);
|
|
3188
|
-
data.low = parseFloat(json['201']);
|
|
3184
|
+
data.price = parseFloat(json['201']); // eller 201 för tradeyield
|
|
3185
|
+
data.open = parseFloat(json['201']); // eller 201 för tradeyield
|
|
3186
|
+
data.high = parseFloat(json['201']); // eller 201 för tradeyield
|
|
3187
|
+
data.low = parseFloat(json['201']); // eller 201 för tradeyield
|
|
3189
3188
|
data.quantity = typeof json['13'] === 'undefined' ? 0 : parseInt(json['13']);
|
|
3190
3189
|
update = true;
|
|
3191
3190
|
}
|
|
3192
3191
|
if (update) {
|
|
3193
3192
|
if (instr.trades.length != 0 && data.timestamp < instr.trades[instr.trades.length - 1].timestamp) {
|
|
3194
|
-
|
|
3193
|
+
// TODO console.log("pushtrade is older than last trade ignoring, should file it on correct postition");
|
|
3195
3194
|
} else
|
|
3196
3195
|
instr.hashmap.set(data.timestamp, data);
|
|
3197
3196
|
instr.trades.push(data);
|
|
@@ -3200,24 +3199,24 @@ function Milli_Chart(settings) {
|
|
|
3200
3199
|
if (instr.pricetype == 'price') {
|
|
3201
3200
|
if (data.price != parseFloat(json['12']))
|
|
3202
3201
|
calcAnalyizis = true;
|
|
3203
|
-
data.price = parseFloat(json['12']);
|
|
3202
|
+
data.price = parseFloat(json['12']); // eller 201 för tradeyield
|
|
3204
3203
|
data.quantity += typeof json['13'] === 'undefined' ? 0 : parseInt(json['13']);
|
|
3205
3204
|
if (_this.scaleinfoY.type == 'trades') update = true;
|
|
3206
3205
|
} else {
|
|
3207
3206
|
if (instr.pricetype == 'price') {
|
|
3208
3207
|
if (data.price != parseFloat(json['201']))
|
|
3209
3208
|
calcAnalyizis = true;
|
|
3210
|
-
data.price = parseFloat(json['201']);
|
|
3209
|
+
data.price = parseFloat(json['201']); // eller 201 för tradeyield
|
|
3211
3210
|
data.quantity += typeof json['13'] === 'undefined' ? 0 : parseInt(json['13']);
|
|
3212
3211
|
if (_this.scaleinfoY.type == 'trades') update = true;
|
|
3213
3212
|
}
|
|
3214
|
-
|
|
3213
|
+
// TODo: updatera med quantity, open , high,low osv?
|
|
3215
3214
|
}
|
|
3216
3215
|
}
|
|
3217
3216
|
}
|
|
3218
3217
|
if (calcAnalyizis && insref == _this.instruments[0].insref) {
|
|
3219
3218
|
for (var i = 0; i < _this.settings.indicators.length; i++) {
|
|
3220
|
-
|
|
3219
|
+
//for (const [key, a] of m_analyzisMethod.entries()) {
|
|
3221
3220
|
switch (_this.settings.indicators[i].method) {
|
|
3222
3221
|
case 'sma':
|
|
3223
3222
|
_this.settings.indicators[i].trades = [];
|
|
@@ -3232,7 +3231,7 @@ function Milli_Chart(settings) {
|
|
|
3232
3231
|
_this.settings.indicators[i].trades = bollingerBands(_this.instruments[0].trades, _this.settings.indicators[i].method_length, _this.settings.indicators[i].stddev | 2);
|
|
3233
3232
|
break;
|
|
3234
3233
|
default:
|
|
3235
|
-
|
|
3234
|
+
// draw custom added?
|
|
3236
3235
|
break;
|
|
3237
3236
|
}
|
|
3238
3237
|
}
|
|
@@ -3244,14 +3243,14 @@ function Milli_Chart(settings) {
|
|
|
3244
3243
|
};
|
|
3245
3244
|
}
|
|
3246
3245
|
|
|
3247
|
-
|
|
3246
|
+
// used by trader
|
|
3248
3247
|
_this.exportData = function() {
|
|
3249
3248
|
let ret = [];
|
|
3250
3249
|
|
|
3251
3250
|
if (_this.scaleinfoY.type == 'trades') {
|
|
3252
3251
|
if (_this.instruments.length > 0) {
|
|
3253
3252
|
for (var i = 0; i < _this.instruments[0].trades.length; i++) {
|
|
3254
|
-
var date = new Date(_this.instruments[0].trades[i].timestamp - new Date().getTimezoneOffset() * 60000);
|
|
3253
|
+
var date = new Date(_this.instruments[0].trades[i].timestamp - new Date().getTimezoneOffset() * 60000); // tz_offset in minutes
|
|
3255
3254
|
var datestr = date.toISOString();
|
|
3256
3255
|
|
|
3257
3256
|
ret.push([datestr.substring(0, 10), datestr.substring(11, 23), _this.instruments[0].trades[i].price, _this.instruments[0].trades[i].quantity]);
|
|
@@ -3280,7 +3279,7 @@ function Milli_Chart(settings) {
|
|
|
3280
3279
|
}
|
|
3281
3280
|
|
|
3282
3281
|
_this.destroyWidget = function() {
|
|
3283
|
-
|
|
3282
|
+
// if we have subscriptions send in an empty array to unsubscribe all and release it
|
|
3284
3283
|
if (MillistreamWidgetApi_isObjectEmpty(_this.unsubscriptions) == false)
|
|
3285
3284
|
_this.requestid = _this.settings.streaming.MillistreamWidgetStreamingApi_subscribeInstruments(_this, _this.requestid, []);
|
|
3286
3285
|
return 0;
|
|
@@ -3320,7 +3319,7 @@ function Milli_Chart(settings) {
|
|
|
3320
3319
|
}
|
|
3321
3320
|
|
|
3322
3321
|
_this.drawWidget = function() {
|
|
3323
|
-
|
|
3322
|
+
// remove standard fields from array, they will be requested anyway
|
|
3324
3323
|
_this.settings.fields = _this.settings.fields.filter(function(obj) {
|
|
3325
3324
|
return ['name', 'tradecurrency', 'time', 'date', 'tradeprice', 'tradequantity', 'marketopen', 'marketclose', 'closeprice1d', 'closeprice', 'closequantity'].indexOf(obj) == -1;
|
|
3326
3325
|
});
|
|
@@ -3346,7 +3345,7 @@ function Milli_Chart(settings) {
|
|
|
3346
3345
|
var e = new Date();
|
|
3347
3346
|
var days = 0;
|
|
3348
3347
|
var newlen = 0;
|
|
3349
|
-
while (days < _this.settings.intradaylen - 1) {
|
|
3348
|
+
while (days < _this.settings.intradaylen - 1) { // include today
|
|
3350
3349
|
d -= 86400000;
|
|
3351
3350
|
e.setTime(d);
|
|
3352
3351
|
if (e.getDay() != 0 && e.getDay() != 6)
|
|
@@ -3387,7 +3386,7 @@ function Milli_Chart(settings) {
|
|
|
3387
3386
|
|
|
3388
3387
|
(function updatePixelRatio() {
|
|
3389
3388
|
matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`).addEventListener('change', updatePixelRatio, { once: true });
|
|
3390
|
-
(
|
|
3389
|
+
console.log("devicePixelRatio: " + window.devicePixelRatio);
|
|
3391
3390
|
_this.drawChart();
|
|
3392
3391
|
})();
|
|
3393
3392
|
|
|
@@ -3446,14 +3445,14 @@ function MillistreamWidgetApi_buildQuery(widget, type) {
|
|
|
3446
3445
|
if (typeof widget.settings.instrumenttype !== 'object') {
|
|
3447
3446
|
throw new Error(widget.constructor.name + ': instrumenttype is not valid');
|
|
3448
3447
|
}
|
|
3449
|
-
|
|
3448
|
+
//if (widget.settings.instrument == null) // removed 2021-10-12 for "mylist" functionality
|
|
3450
3449
|
url += '&instrumenttypes=' + widget.settings.instrumenttype.join();
|
|
3451
3450
|
}
|
|
3452
3451
|
if (widget.settings.instrumentsubtype != null) {
|
|
3453
3452
|
if (typeof widget.settings.instrumentsubtype !== 'object') {
|
|
3454
3453
|
throw new Error(widget.constructor.name + ': instrumentsubtype is not valid');
|
|
3455
3454
|
}
|
|
3456
|
-
|
|
3455
|
+
//if (widget.settings.instrument == null) // removed 2021-10-12 for "mylist" functionality
|
|
3457
3456
|
url += '&instrumentsubtypes=' + widget.settings.instrumentsubtype.join();
|
|
3458
3457
|
}
|
|
3459
3458
|
if (widget.settings.derivativeindicator != null) {
|
|
@@ -3802,12 +3801,12 @@ function MillistreamWidgetApi_addPagination(widget) {
|
|
|
3802
3801
|
li.onclick = function() {
|
|
3803
3802
|
MillistreamWidgetApi_getPaginationPage(widget, 'next');
|
|
3804
3803
|
};
|
|
3805
|
-
if (widget.pagination.numPages < max + 1) li.style.display = 'none';
|
|
3804
|
+
if (widget.pagination.numPages < max + 1) li.style.display = 'none'; // dont show if less than 6 pages
|
|
3806
3805
|
li = MillistreamWidgetApi_addElement(widget, 'li', 'millistream-list-pagination-li', widget.pagination.ul, null, '>>');
|
|
3807
3806
|
li.onclick = function() {
|
|
3808
3807
|
MillistreamWidgetApi_getPaginationPage(widget, 'last');
|
|
3809
3808
|
};
|
|
3810
|
-
if (widget.pagination.numPages < max + 1) li.style.display = 'none';
|
|
3809
|
+
if (widget.pagination.numPages < max + 1) li.style.display = 'none'; // dont show if less than 6 pages
|
|
3811
3810
|
}
|
|
3812
3811
|
} else
|
|
3813
3812
|
if (widget.settings.pagination > 0 && widget.pagination.numPages < 2) {
|
|
@@ -3875,11 +3874,11 @@ function MillistreamWidgetApi_getPaginationPage(widget, page) {
|
|
|
3875
3874
|
startno = 1;
|
|
3876
3875
|
} else
|
|
3877
3876
|
if (widget.pagination.selectedPage > widget.pagination.numPages - 2) {
|
|
3878
|
-
startno = widget.pagination.numPages - (max - 1);
|
|
3877
|
+
startno = widget.pagination.numPages - (max - 1); //4;
|
|
3879
3878
|
|
|
3880
3879
|
} else {
|
|
3881
3880
|
startno = widget.pagination.selectedPage - 2 < 1 ? 1 : widget.pagination.selectedPage - (max - Math.ceil(max / 2));
|
|
3882
|
-
|
|
3881
|
+
//startno = widget.pagination.selectedPage - 1;
|
|
3883
3882
|
}
|
|
3884
3883
|
for (i = 2; i < items.length - 2; i++) {
|
|
3885
3884
|
items[i].innerHTML = (startno);
|
|
@@ -3918,15 +3917,15 @@ function MillistreamWidgetApi_getElementHeight(el) {
|
|
|
3918
3917
|
return rect.height + s;
|
|
3919
3918
|
}
|
|
3920
3919
|
|
|
3921
|
-
|
|
3920
|
+
// Push blipp funktioner
|
|
3922
3921
|
function MillistreamWidgetApi_clearFlash(el) {
|
|
3923
|
-
|
|
3922
|
+
//internal and external
|
|
3924
3923
|
el.classList.remove('millistream-flash-up');
|
|
3925
3924
|
el.classList.remove('millistream-flash-down');
|
|
3926
3925
|
}
|
|
3927
3926
|
|
|
3928
3927
|
function milli_clearValuedFlash(widget, el, oldValue) {
|
|
3929
|
-
|
|
3928
|
+
// internal borde gå att bygga bort
|
|
3930
3929
|
var currentValue = MillistreamWidgetApi_getElementNumber(widget, el);
|
|
3931
3930
|
if (currentValue == oldValue || currentValue == 0) {
|
|
3932
3931
|
MillistreamWidgetApi_clearFlash(el);
|
|
@@ -3934,7 +3933,7 @@ function milli_clearValuedFlash(widget, el, oldValue) {
|
|
|
3934
3933
|
}
|
|
3935
3934
|
|
|
3936
3935
|
function MillistreamWidgetApi_flashElement(widget, el, newValue, oldValue) {
|
|
3937
|
-
|
|
3936
|
+
// internal
|
|
3938
3937
|
if (newValue == oldValue) return;
|
|
3939
3938
|
MillistreamWidgetApi_clearFlash(el);
|
|
3940
3939
|
if (newValue == '' || !newValue) return;
|
|
@@ -3953,7 +3952,7 @@ function MillistreamWidgetApi_flashElement(widget, el, newValue, oldValue) {
|
|
|
3953
3952
|
}
|
|
3954
3953
|
|
|
3955
3954
|
|
|
3956
|
-
|
|
3955
|
+
// numeriska funktioner
|
|
3957
3956
|
function MillistreamWidgetApi_isNumber(widget, testsubject) {
|
|
3958
3957
|
if (!testsubject) return;
|
|
3959
3958
|
var n = testsubject.replace(widget.settings.decimalseparator, '.').split(widget.settings.thousandseparator).join('');
|
|
@@ -3966,7 +3965,7 @@ function MillistreamWidgetApi_getNumDecimals(widget, value, current, validfields
|
|
|
3966
3965
|
if (value == null || MillistreamWidgetApi_isNumber(widget, value) == false) return current;
|
|
3967
3966
|
var parts = value.toString().split('.');
|
|
3968
3967
|
if (parts.length == 2) {
|
|
3969
|
-
while (parts[1].charAt(parts[1].length - 1) == "0") {
|
|
3968
|
+
while (parts[1].charAt(parts[1].length - 1) == "0") { // remove trailing zeros
|
|
3970
3969
|
parts[1] = parts[1].slice(0, -1);
|
|
3971
3970
|
}
|
|
3972
3971
|
return current > parts[1].length ? current : parts[1].length;
|
|
@@ -3975,7 +3974,7 @@ function MillistreamWidgetApi_getNumDecimals(widget, value, current, validfields
|
|
|
3975
3974
|
}
|
|
3976
3975
|
|
|
3977
3976
|
function MillistreamWidgetApi_getElementNumber(widget, el) {
|
|
3978
|
-
|
|
3977
|
+
// internal and Orderbook
|
|
3979
3978
|
var res = parseFloat(el.innerHTML.replace(widget.settings.decimalseparator, '.').split(widget.settings.thousandseparator).join(''));
|
|
3980
3979
|
if (!isNaN(parseFloat(res)) && isFinite(res)) return res;
|
|
3981
3980
|
return 0;
|
|
@@ -4006,7 +4005,7 @@ function MillistreamWidgetApi_colorCell(widget, element, info) {
|
|
|
4006
4005
|
MillistreamWidgetApi_setCellColor(widget, element, v);
|
|
4007
4006
|
}
|
|
4008
4007
|
} else
|
|
4009
|
-
if (widget.settings.controlcolumn || widget.settings.controlcolumn == 0) {
|
|
4008
|
+
if (widget.settings.controlcolumn || widget.settings.controlcolumn == 0) { // works for tables
|
|
4010
4009
|
if (widget.settings.stylecolumn === null) return;
|
|
4011
4010
|
var tr = element.parentNode;
|
|
4012
4011
|
while (tr.tagName.toLowerCase() != 'tr') {
|
|
@@ -4015,13 +4014,13 @@ function MillistreamWidgetApi_colorCell(widget, element, info) {
|
|
|
4015
4014
|
if (tr.cells.length > widget.settings.controlcolumn) {
|
|
4016
4015
|
v = MillistreamWidgetApi_getElementNumber(widget, tr.cells[widget.settings.controlcolumn]);
|
|
4017
4016
|
var el;
|
|
4018
|
-
if (widget.settings.stylecolumn && widget.settings.stylecolumn[0] == -1) {
|
|
4019
|
-
el = tr;
|
|
4017
|
+
if (widget.settings.stylecolumn && widget.settings.stylecolumn[0] == -1) { // color row
|
|
4018
|
+
el = tr; //element.parentNode;
|
|
4020
4019
|
MillistreamWidgetApi_setCellColor(widget, tr, v);
|
|
4021
4020
|
|
|
4022
4021
|
} else {
|
|
4023
4022
|
for (var s = 0; s < widget.settings.stylecolumn.length; s++) {
|
|
4024
|
-
el = tr.cells[widget.settings.stylecolumn[s]];
|
|
4023
|
+
el = tr.cells[widget.settings.stylecolumn[s]]; //element.parentNode.cells[widget.stylecolumn[s]];
|
|
4025
4024
|
if (el) {
|
|
4026
4025
|
MillistreamWidgetApi_setCellColor(widget, el, v);
|
|
4027
4026
|
}
|
|
@@ -4029,17 +4028,17 @@ function MillistreamWidgetApi_colorCell(widget, element, info) {
|
|
|
4029
4028
|
}
|
|
4030
4029
|
}
|
|
4031
4030
|
} else
|
|
4032
|
-
if (widget.settings.positiveclass && widget.settings.negativeclass) {
|
|
4031
|
+
if (widget.settings.positiveclass && widget.settings.negativeclass) { // non table elements
|
|
4033
4032
|
v = MillistreamWidgetApi_getElementNumber(widget, element);
|
|
4034
4033
|
MillistreamWidgetApi_setCellColor(widget, element, v);
|
|
4035
4034
|
}
|
|
4036
4035
|
}
|
|
4037
4036
|
|
|
4038
4037
|
function print_field(widget, element, field, value, overridedecimals) {
|
|
4039
|
-
|
|
4038
|
+
// internal and external
|
|
4040
4039
|
var f = parseInt(field);
|
|
4041
4040
|
var info = MillistreamWidgetApi_getColumnInfo(widget, f.toString());
|
|
4042
|
-
if (typeof value === 'undefined' || value == null || (!value && isNaN(value) == true)) {
|
|
4041
|
+
if (typeof value === 'undefined' || value == null || (!value && isNaN(value) == true)) { // kolla field?
|
|
4043
4042
|
if (info[4] & 16) {
|
|
4044
4043
|
value = '0.0';
|
|
4045
4044
|
} else {
|
|
@@ -4085,7 +4084,7 @@ function print_field(widget, element, field, value, overridedecimals) {
|
|
|
4085
4084
|
else
|
|
4086
4085
|
element.innerHTML = formatFactorNumber(value, widget.settings.factor, widget.settings.num_decimals, widget.settings.thousandseparator, widget.settings.decimalseparator);
|
|
4087
4086
|
} else if (info[4] & 4)
|
|
4088
|
-
element.innerHTML = formatNiceNumber(value, widget.settings.thousandseparator, widget.settings.decimalseparator, 0);
|
|
4087
|
+
element.innerHTML = formatNiceNumber(value, widget.settings.thousandseparator, widget.settings.decimalseparator, 0); // no decimals
|
|
4089
4088
|
else if (info[4] & 1 && overridedecimals)
|
|
4090
4089
|
element.innerHTML = formatNiceNumber(value, widget.settings.thousandseparator, widget.settings.decimalseparator, overridedecimals || widget.settings.num_decimals);
|
|
4091
4090
|
else {
|
|
@@ -4103,8 +4102,8 @@ function print_field(widget, element, field, value, overridedecimals) {
|
|
|
4103
4102
|
}
|
|
4104
4103
|
|
|
4105
4104
|
function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
4106
|
-
|
|
4107
|
-
|
|
4105
|
+
// internal and external
|
|
4106
|
+
// return array with MDF_F_FIELD,type,align, name var, overridable decimal bitwise [1 = override output,2 = can override,4 = no decimals,8 can be shortened to M, K etc], 16 = override NULL with 0 , 32 = can color diff
|
|
4108
4107
|
switch (name) {
|
|
4109
4108
|
case '222':
|
|
4110
4109
|
case 'accountsreceivable':
|
|
@@ -4195,7 +4194,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4195
4194
|
return [232, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
|
|
4196
4195
|
case '404':
|
|
4197
4196
|
case 'd1':
|
|
4198
|
-
return [404, 'date', 'right', widget.get_lang_text(name) || name, 0];
|
|
4197
|
+
return [404, 'date', 'right', widget.get_lang_text(name) || name, 0]; // Security type
|
|
4199
4198
|
case '3':
|
|
4200
4199
|
case 'date':
|
|
4201
4200
|
return [3, 'date', 'right', widget.get_lang_text(name) || name, 0];
|
|
@@ -4449,10 +4448,10 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4449
4448
|
return [229, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
|
|
4450
4449
|
case '395':
|
|
4451
4450
|
case 'n2':
|
|
4452
|
-
return [395, 'numeric', 'left', widget.get_lang_text(name) || name, 0];
|
|
4451
|
+
return [395, 'numeric', 'left', widget.get_lang_text(name) || name, 0]; // Security type
|
|
4453
4452
|
case '396':
|
|
4454
4453
|
case 'n3':
|
|
4455
|
-
return [396, 'numeric', 'left', widget.get_lang_text(name) || name, 0];
|
|
4454
|
+
return [396, 'numeric', 'left', widget.get_lang_text(name) || name, 0]; // Security type
|
|
4456
4455
|
case '22':
|
|
4457
4456
|
case 'name':
|
|
4458
4457
|
return [22, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
@@ -4464,10 +4463,10 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4464
4463
|
return [138, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
|
|
4465
4464
|
case '48':
|
|
4466
4465
|
case 'newsid':
|
|
4467
|
-
return [48, 'string', 'left', 'newsid', 0];
|
|
4466
|
+
return [48, 'string', 'left', 'newsid', 0]; // hardoded should not be used by any display
|
|
4468
4467
|
case 'newstype':
|
|
4469
4468
|
case '86':
|
|
4470
|
-
return [86, 'string', 'left', 'newstype', 0];
|
|
4469
|
+
return [86, 'string', 'left', 'newstype', 0]; // hardoded should not be used by any display
|
|
4471
4470
|
case '219':
|
|
4472
4471
|
case 'noncurrentasset':
|
|
4473
4472
|
return [219, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
|
|
@@ -4527,13 +4526,13 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4527
4526
|
return [98, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4528
4527
|
case '180':
|
|
4529
4528
|
case 's3':
|
|
4530
|
-
return [180, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4529
|
+
return [180, 'string', 'left', widget.get_lang_text(name) || name, 0]; // Position
|
|
4531
4530
|
case '181':
|
|
4532
4531
|
case 's4':
|
|
4533
|
-
return [181, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4532
|
+
return [181, 'string', 'left', widget.get_lang_text(name) || name, 0]; // Position
|
|
4534
4533
|
case '393':
|
|
4535
4534
|
case 's10':
|
|
4536
|
-
return [393, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4535
|
+
return [393, 'string', 'left', widget.get_lang_text(name) || name, 0]; // comment
|
|
4537
4536
|
case '127':
|
|
4538
4537
|
case 'sales':
|
|
4539
4538
|
return [127, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
|
|
@@ -4570,7 +4569,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4570
4569
|
case '227':
|
|
4571
4570
|
case 'totalassets':
|
|
4572
4571
|
return [227, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
|
|
4573
|
-
case '1023':
|
|
4572
|
+
case '1023': // TODO, define this with correct value
|
|
4574
4573
|
case 'totalnumberofshares':
|
|
4575
4574
|
return [1023, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
|
|
4576
4575
|
case '233':
|
|
@@ -4619,7 +4618,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4619
4618
|
case 'vega':
|
|
4620
4619
|
return [703, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
|
|
4621
4620
|
|
|
4622
|
-
|
|
4621
|
+
// brokerstats
|
|
4623
4622
|
case '3000':
|
|
4624
4623
|
case 'boughtquantity':
|
|
4625
4624
|
return [3000, 'numeric', 'right', widget.get_lang_text(name) || name, 4];
|
|
@@ -4807,7 +4806,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4807
4806
|
case '3060':
|
|
4808
4807
|
case 'soldturnoverytd':
|
|
4809
4808
|
return [3060, 'numeric', 'left', widget.get_lang_text(name) || name, 4];
|
|
4810
|
-
|
|
4809
|
+
// key ratios egen definerade
|
|
4811
4810
|
case 'per_last':
|
|
4812
4811
|
case '3100':
|
|
4813
4812
|
return [3100, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
|
|
@@ -4928,7 +4927,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4928
4927
|
case 'latestreport':
|
|
4929
4928
|
case '3140':
|
|
4930
4929
|
return [3140, 'date', 'right', widget.get_lang_text(name) || name, 0];
|
|
4931
|
-
|
|
4930
|
+
// basicdata join fields
|
|
4932
4931
|
case 'fundcompanyname':
|
|
4933
4932
|
case '3200':
|
|
4934
4933
|
return [3200, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
@@ -4947,17 +4946,17 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
4947
4946
|
case '3205':
|
|
4948
4947
|
case 'underlyingsymbol':
|
|
4949
4948
|
return [3204, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4950
|
-
case '3206':
|
|
4949
|
+
case '3206': // tmcwatch
|
|
4951
4950
|
case 'multiplier':
|
|
4952
4951
|
return [3206, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4953
|
-
case '3207':
|
|
4952
|
+
case '3207': // tmcwach
|
|
4954
4953
|
case 'type':
|
|
4955
4954
|
return [3207, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4956
|
-
case '3208':
|
|
4955
|
+
case '3208': // tmcwach
|
|
4957
4956
|
case 'direction':
|
|
4958
4957
|
return [3208, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
4959
4958
|
|
|
4960
|
-
|
|
4959
|
+
// optionwatch
|
|
4961
4960
|
case '3300':
|
|
4962
4961
|
case 'iv30d':
|
|
4963
4962
|
case 'ivXXd':
|
|
@@ -5000,8 +4999,8 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
5000
4999
|
}
|
|
5001
5000
|
}
|
|
5002
5001
|
|
|
5003
|
-
function set_hashed_element(widget, insref, info, json, num_dec) {
|
|
5004
|
-
|
|
5002
|
+
function set_hashed_element(widget, insref, info, json, num_dec) { // called from push
|
|
5003
|
+
// external : list
|
|
5005
5004
|
var key = insref + '_' + info[0];
|
|
5006
5005
|
var arr = widget.cell_map.get(key);
|
|
5007
5006
|
if (arr !== undefined) {
|
|
@@ -5011,9 +5010,9 @@ function set_hashed_element(widget, insref, info, json, num_dec) {
|
|
|
5011
5010
|
}
|
|
5012
5011
|
}
|
|
5013
5012
|
|
|
5014
|
-
|
|
5013
|
+
// Create Element functions
|
|
5015
5014
|
function MillistreamWidgetApi_addElementToMap(insref, field, element, widget) {
|
|
5016
|
-
|
|
5015
|
+
// internal
|
|
5017
5016
|
if (insref && field && widget && widget.cell_map) {
|
|
5018
5017
|
var key = insref + '_' + field;
|
|
5019
5018
|
var arr = widget.cell_map.get(key);
|
|
@@ -5029,7 +5028,7 @@ function MillistreamWidgetApi_addElementToMap(insref, field, element, widget) {
|
|
|
5029
5028
|
}
|
|
5030
5029
|
|
|
5031
5030
|
function MillistreamWidgetApi_addElement(widget, el, cl, parent, field, value, overridedecimals) {
|
|
5032
|
-
|
|
5031
|
+
// external
|
|
5033
5032
|
var element = document.createElement(el);
|
|
5034
5033
|
if (cl)
|
|
5035
5034
|
element.setAttribute('class', cl);
|
|
@@ -5112,7 +5111,7 @@ function MillistreamWidgetApi_addTableCell(widget, key, cl, parent, json, decima
|
|
|
5112
5111
|
widget.settings.link_field.forEach(function(element) {
|
|
5113
5112
|
hrefparam[element] = json[element];
|
|
5114
5113
|
});
|
|
5115
|
-
if (info[0] == 1) {
|
|
5114
|
+
if (info[0] == 1) { // headline, borde inte behövas i list
|
|
5116
5115
|
td.onclick = function(e) {
|
|
5117
5116
|
hrefparam.event = e;
|
|
5118
5117
|
hrefparam.source = widget;
|
|
@@ -5228,7 +5227,7 @@ function fabs(value) {
|
|
|
5228
5227
|
}
|
|
5229
5228
|
|
|
5230
5229
|
function zeroPad(number, width) {
|
|
5231
|
-
|
|
5230
|
+
//internal
|
|
5232
5231
|
if (number <= 9.9999999 * Math.pow(10, width)) return ("0000000" + number).slice(-width);
|
|
5233
5232
|
return number;
|
|
5234
5233
|
}
|
|
@@ -5273,7 +5272,7 @@ function formatNiceNumber(y, thousandSeparator, decimalSeparator, precision, add
|
|
|
5273
5272
|
}
|
|
5274
5273
|
|
|
5275
5274
|
function formatDate(date, format, widget) {
|
|
5276
|
-
|
|
5275
|
+
// internal
|
|
5277
5276
|
var timeStamp, mon, day;
|
|
5278
5277
|
if (format == 'yyyy-mm-dd') {
|
|
5279
5278
|
timeStamp = new Date(date);
|
|
@@ -5287,66 +5286,66 @@ function formatDate(date, format, widget) {
|
|
|
5287
5286
|
day = timeStamp.getDate();
|
|
5288
5287
|
return timeStamp.getFullYear() % 100 + '-' + (mon <= 9 ? '0' + mon : mon) + '-' + (day <= 9 ? '0' + day : day);
|
|
5289
5288
|
}
|
|
5290
|
-
if (format == 'b dd') {
|
|
5289
|
+
if (format == 'b dd') { // Jan 01
|
|
5291
5290
|
timeStamp = new Date(date);
|
|
5292
5291
|
mon = timeStamp.toDateString().split(' ');
|
|
5293
5292
|
day = timeStamp.getDate();
|
|
5294
5293
|
return mon[1] + ' ' + (day <= 9 ? '0' + day : day);
|
|
5295
5294
|
}
|
|
5296
|
-
if (format == 'b dd yyyy') {
|
|
5295
|
+
if (format == 'b dd yyyy') { // Jan 01 2017
|
|
5297
5296
|
timeStamp = new Date(date);
|
|
5298
5297
|
mon = timeStamp.toDateString().split(' ');
|
|
5299
5298
|
day = timeStamp.getDate();
|
|
5300
5299
|
return mon[1] + ' ' + (day <= 9 ? '0' + day : day) + ' ' + timeStamp.getFullYear();
|
|
5301
5300
|
}
|
|
5302
|
-
if (format == 'dd/mm') {
|
|
5301
|
+
if (format == 'dd/mm') { // Jan 01 2017
|
|
5303
5302
|
timeStamp = new Date(date);
|
|
5304
5303
|
mon = timeStamp.getMonth() + 1;
|
|
5305
5304
|
day = timeStamp.getDate();
|
|
5306
5305
|
return (day <= 9 ? '0' + day : day) + '/' + (mon <= 9 ? '0' + mon : mon);
|
|
5307
5306
|
}
|
|
5308
|
-
if (format == 'd/m') {
|
|
5307
|
+
if (format == 'd/m') { // Jan 01 2017
|
|
5309
5308
|
timeStamp = new Date(date);
|
|
5310
5309
|
return (timeStamp.getDate() + '/' + (timeStamp.getMonth() + 1));
|
|
5311
5310
|
}
|
|
5312
5311
|
if (format == 'd mmm yyyy') {
|
|
5313
5312
|
timeStamp = new Date(date);
|
|
5314
|
-
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3);
|
|
5313
|
+
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3); // lang....
|
|
5315
5314
|
day = timeStamp.getDate();
|
|
5316
5315
|
return day + ' ' + mon + ' ' + timeStamp.getFullYear();
|
|
5317
5316
|
}
|
|
5318
5317
|
if (format == 'dd mmm yyyy') {
|
|
5319
5318
|
timeStamp = new Date(date);
|
|
5320
|
-
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3);
|
|
5319
|
+
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3); // lang....
|
|
5321
5320
|
day = timeStamp.getDate();
|
|
5322
5321
|
return (day <= 9 ? '0' + day : day) + ' ' + mon + ' ' + timeStamp.getFullYear();
|
|
5323
5322
|
}
|
|
5324
5323
|
if (format == 'dd mmm') {
|
|
5325
5324
|
timeStamp = new Date(date);
|
|
5326
|
-
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3);
|
|
5325
|
+
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3); // lang....
|
|
5327
5326
|
day = timeStamp.getDate();
|
|
5328
5327
|
return (day <= 9 ? '0' + day : day) + ' ' + mon;
|
|
5329
5328
|
}
|
|
5330
5329
|
if (format == 'd mmm') {
|
|
5331
5330
|
timeStamp = new Date(date);
|
|
5332
|
-
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3);
|
|
5331
|
+
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3); // lang....
|
|
5333
5332
|
day = timeStamp.getDate();
|
|
5334
5333
|
return day + ' ' + mon;
|
|
5335
5334
|
}
|
|
5336
5335
|
if (format == 'mmm yyyy') {
|
|
5337
5336
|
timeStamp = new Date(date);
|
|
5338
|
-
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3);
|
|
5337
|
+
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3); // lang....
|
|
5339
5338
|
timeStamp = mon + ' ' + timeStamp.getFullYear();
|
|
5340
5339
|
return timeStamp;
|
|
5341
5340
|
}
|
|
5342
5341
|
if (format == 'mmm yy') {
|
|
5343
5342
|
timeStamp = new Date(date);
|
|
5344
|
-
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3);
|
|
5343
|
+
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3); // lang
|
|
5345
5344
|
timeStamp = mon + ' ' + (timeStamp.getFullYear() % 100 < 9 ? '0' + timeStamp.getFullYear() % 100 : timeStamp.getFullYear() % 100);
|
|
5346
5345
|
return timeStamp;
|
|
5347
5346
|
}
|
|
5348
5347
|
|
|
5349
|
-
|
|
5348
|
+
// default yyyy-mm-dd
|
|
5350
5349
|
timeStamp = new Date(date);
|
|
5351
5350
|
mon = timeStamp.getMonth() + 1;
|
|
5352
5351
|
day = timeStamp.getDate();
|
|
@@ -5354,7 +5353,7 @@ function formatDate(date, format, widget) {
|
|
|
5354
5353
|
}
|
|
5355
5354
|
|
|
5356
5355
|
function formatTime(value, format) {
|
|
5357
|
-
|
|
5356
|
+
// internal
|
|
5358
5357
|
if (typeof value !== 'string') return "";
|
|
5359
5358
|
var datetime = new Date();
|
|
5360
5359
|
var tz_offset = datetime.getTimezoneOffset();
|
|
@@ -5583,7 +5582,7 @@ function MillistreamWidgetApi_scrollIntoView(scrollarea, elem, xalign, yalign) {
|
|
|
5583
5582
|
scrollarea.scrollLeft = elem.offsetLeft - scrollarea.getBoundingClientRect().width / 2;
|
|
5584
5583
|
}
|
|
5585
5584
|
|
|
5586
|
-
|
|
5585
|
+
// scrollIntoView : replace this, breaks apps
|
|
5587
5586
|
}
|
|
5588
5587
|
|
|
5589
5588
|
var MillistreamWidgetSettings = {
|
|
@@ -5603,9 +5602,9 @@ function MillistreamWidgetStreamingApi(settings) {
|
|
|
5603
5602
|
server: 'wss://stage.millistream.com:8900',
|
|
5604
5603
|
alarmClient: null
|
|
5605
5604
|
};
|
|
5606
|
-
var m_requestid = 1;
|
|
5605
|
+
var m_requestid = 1; // 0 is invalid
|
|
5607
5606
|
var m_socket = null;
|
|
5608
|
-
var m_requests = [];
|
|
5607
|
+
var m_requests = []; // queued requests not sent
|
|
5609
5608
|
var m_requestcallbacks = new Map();
|
|
5610
5609
|
|
|
5611
5610
|
|
|
@@ -5638,7 +5637,7 @@ function MillistreamWidgetStreamingApi(settings) {
|
|
|
5638
5637
|
req = new Object({
|
|
5639
5638
|
"widget": widget,
|
|
5640
5639
|
});
|
|
5641
|
-
m_requestcallbacks.set(requestid.toString(), req);
|
|
5640
|
+
m_requestcallbacks.set(requestid.toString(), req); // this requestid will be forarded to this widget
|
|
5642
5641
|
}
|
|
5643
5642
|
var request = '';
|
|
5644
5643
|
if (MillistreamWidgetApi_isObjectEmpty(widget.unsubscriptions) == false) {
|
|
@@ -5700,7 +5699,7 @@ function MillistreamWidgetStreamingApi(settings) {
|
|
|
5700
5699
|
|
|
5701
5700
|
|
|
5702
5701
|
widget.unsubscriptions.type = 'insrefs';
|
|
5703
|
-
widget.unsubscriptions.insrefs = insrefs.slice(0);
|
|
5702
|
+
widget.unsubscriptions.insrefs = insrefs.slice(0); // copy array
|
|
5704
5703
|
widget.unsubscriptions.messagetypes = widget.settings.messagetypes;
|
|
5705
5704
|
widget.unsubscriptions.requestid = requestid;
|
|
5706
5705
|
|
|
@@ -5713,7 +5712,7 @@ function MillistreamWidgetStreamingApi(settings) {
|
|
|
5713
5712
|
|
|
5714
5713
|
function reconnect() {
|
|
5715
5714
|
if (!m_socket.CLOSED) {
|
|
5716
|
-
|
|
5715
|
+
//console.log('not closed');
|
|
5717
5716
|
return;
|
|
5718
5717
|
}
|
|
5719
5718
|
m_requests.forEach(function(request) {
|
|
@@ -5732,21 +5731,21 @@ function MillistreamWidgetStreamingApi(settings) {
|
|
|
5732
5731
|
try {
|
|
5733
5732
|
m_socket = new WebSocket(_this.settings.server);
|
|
5734
5733
|
m_socket.onopen = function() {
|
|
5735
|
-
(
|
|
5734
|
+
console.log('Connected to millistream push'); /*RemoveLogging:skip*/
|
|
5736
5735
|
if (m_requests.length > 0) {
|
|
5737
5736
|
m_requests.forEach(function(request) {
|
|
5738
5737
|
if (request.send == 0) {
|
|
5739
|
-
|
|
5738
|
+
//console.log('rerequest:', request.request);
|
|
5740
5739
|
m_socket.send('{ "token":"' + _this.settings.token + '",' + request.request);
|
|
5741
5740
|
}
|
|
5742
5741
|
});
|
|
5743
5742
|
}
|
|
5744
5743
|
};
|
|
5745
5744
|
m_socket.onerror = function() {
|
|
5746
|
-
()
|
|
5745
|
+
console.log('Error, disconnected'); /*RemoveLogging:skip*/
|
|
5747
5746
|
};
|
|
5748
5747
|
m_socket.onclose = function() {
|
|
5749
|
-
()
|
|
5748
|
+
console.log('Disconnected'); /*RemoveLogging:skip*/
|
|
5750
5749
|
reconnect();
|
|
5751
5750
|
};
|
|
5752
5751
|
|
|
@@ -5755,9 +5754,9 @@ function MillistreamWidgetStreamingApi(settings) {
|
|
|
5755
5754
|
try {
|
|
5756
5755
|
jsondata = JSON.parse(msg.data);
|
|
5757
5756
|
} catch (e) {
|
|
5758
|
-
(
|
|
5757
|
+
console.log('invalid data', msg.data); /*RemoveLogging:skip*/
|
|
5759
5758
|
}
|
|
5760
|
-
|
|
5759
|
+
//console.log(JSON.stringify(jsondata));
|
|
5761
5760
|
if (typeof jsondata.instruments !== 'undefined') {
|
|
5762
5761
|
for (var s = 0; s < jsondata.instruments.length; s++) {
|
|
5763
5762
|
var insref = jsondata.instruments[s].insref;
|
|
@@ -5783,16 +5782,16 @@ function MillistreamWidgetStreamingApi(settings) {
|
|
|
5783
5782
|
if (_this.settings.statusCallback !== null) _this.settings.statusCallback(jsondata);
|
|
5784
5783
|
} else
|
|
5785
5784
|
if (typeof jsondata.alarm !== 'undefined') {
|
|
5786
|
-
(
|
|
5785
|
+
console.log('Alarm: ' + JSON.stringify(jsondata));
|
|
5787
5786
|
if (null != _this.settings.alarmClient) {
|
|
5788
5787
|
_this.settings.alarmClient(jsondata);
|
|
5789
5788
|
}
|
|
5790
5789
|
|
|
5791
5790
|
} else
|
|
5792
|
-
()
|
|
5791
|
+
console.log(JSON.stringify(jsondata)); /*RemoveLogging:skip*/
|
|
5793
5792
|
};
|
|
5794
5793
|
} catch (exception) {
|
|
5795
|
-
(
|
|
5794
|
+
console.log('Exception error: ' + exception); /*RemoveLogging:skip*/
|
|
5796
5795
|
reconnect();
|
|
5797
5796
|
}
|
|
5798
5797
|
}
|