@millistream/millistream-widgets 0.0.16 → 0.0.17
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 +34 -59
- package/package.json +1 -1
package/millistream-widgets.js
CHANGED
|
@@ -213,7 +213,6 @@ function Milli_Chart(settings) {
|
|
|
213
213
|
}
|
|
214
214
|
|
|
215
215
|
function findFirstWeekDay(date) {
|
|
216
|
-
// console.log('DATE', date);
|
|
217
216
|
var tmp = new Date(date);
|
|
218
217
|
var count = 0;
|
|
219
218
|
while (tmp.getDay() == 0 || tmp.getDay() == 6) {
|
|
@@ -403,9 +402,7 @@ function Milli_Chart(settings) {
|
|
|
403
402
|
minValue *= 0.9;
|
|
404
403
|
}
|
|
405
404
|
var value = (maxValue - minValue) / num_labels;
|
|
406
|
-
// console.log(value);
|
|
407
405
|
var x = numDigits(value);
|
|
408
|
-
// console.log(x);
|
|
409
406
|
value = value / Math.pow(10, x);
|
|
410
407
|
for (var i = 0; i < 3; i++) {
|
|
411
408
|
value = getTickNextTickValue(value);
|
|
@@ -413,17 +410,6 @@ function Milli_Chart(settings) {
|
|
|
413
410
|
if (nt <= num_labels) break;
|
|
414
411
|
value *= 2;
|
|
415
412
|
}
|
|
416
|
-
/* var prec = (value < 0.000009 ? 7 :
|
|
417
|
-
(value < 0.000009 ? 6 :
|
|
418
|
-
(value < 0.00009 ? 5 :
|
|
419
|
-
(value < 0.0009 ? 4 :
|
|
420
|
-
(value < 0.009 ? 3 :
|
|
421
|
-
(value < 0.09 ? 2 :
|
|
422
|
-
(value < 0.9 ? 1 : 0)))))));
|
|
423
|
-
m_yAxisPrecision = m_yAxisPrecision < prec ? prec : m_yAxisPrecision;
|
|
424
|
-
*/
|
|
425
|
-
// console.log('ticksize', value, Math.pow(10, x), x);
|
|
426
|
-
|
|
427
413
|
return value * Math.pow(10, x);
|
|
428
414
|
}
|
|
429
415
|
|
|
@@ -498,26 +484,45 @@ function Milli_Chart(settings) {
|
|
|
498
484
|
_this.scaleinfoY.lowValue -= 1;
|
|
499
485
|
_this.scaleinfoY.highValue += 1;
|
|
500
486
|
}
|
|
501
|
-
console.log(_this.scaleinfoY);
|
|
502
|
-
// console.log('CALCHHIGHLOW', _this.scaleinfoY);
|
|
503
487
|
return 1;
|
|
504
488
|
}
|
|
505
489
|
|
|
506
|
-
function plotLower(valuePerPixel) {
|
|
490
|
+
function plotLower(valuePerPixel, lineLength) {
|
|
507
491
|
m_ctx.save();
|
|
508
492
|
m_ctx.strokeStyle = m_instrumentCss[0].color;
|
|
509
493
|
m_ctx.lineWidth = parseInt(m_instrumentCss[0].width);
|
|
494
|
+
m_ctx.beginPath();
|
|
495
|
+
var width = Math.round(m_chartspaces.lowerChart.width / (m_datapoints.length + 1) / 2);
|
|
496
|
+
console.log(m_chartspaces.lowerChart.width, m_datapoints.length);
|
|
497
|
+
if (width < 2) width = 2;
|
|
498
|
+
else if (width > 20) width = 20;
|
|
499
|
+
if (width * (m_datapoints.length + 1) >= m_chartspaces.lowerChart.width) console.log('test');
|
|
500
|
+
m_ctx.lineWidth = width;
|
|
501
|
+
console.log(width);
|
|
510
502
|
for (var i = 0; i < m_datapoints.length; i++) {
|
|
511
|
-
|
|
503
|
+
var x = Math.round(m_datapoints[i].x);
|
|
504
|
+
if (x - width < m_chartspaces.lowerChart.left) {
|
|
505
|
+
x += width / 4;
|
|
506
|
+
m_ctx.lineWidth = width / 2;
|
|
507
|
+
} else
|
|
508
|
+
if (x + width > m_chartspaces.lowerChart.right) {
|
|
509
|
+
x -= width / 4;
|
|
510
|
+
m_ctx.lineWidth = width / 2;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
m_ctx.moveTo(x + 0.5, m_chartspaces.lowerChart.bottom);
|
|
512
514
|
var y = Math.round(m_chartspaces.lowerChart.bottom - (m_datapoints[i].quantity * valuePerPixel));
|
|
513
|
-
m_ctx.lineTo(
|
|
515
|
+
m_ctx.lineTo(x + 0.5, y);
|
|
514
516
|
m_ctx.stroke();
|
|
515
517
|
}
|
|
518
|
+
m_ctx.closePath();
|
|
516
519
|
m_ctx.restore();
|
|
517
520
|
}
|
|
518
521
|
|
|
519
522
|
function drawYLegendLower(x, numticks, lineLength, markers) {
|
|
520
|
-
m_ctx.
|
|
523
|
+
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
524
|
+
m_ctx.fillStyle = m_yLegendCss.color;
|
|
525
|
+
|
|
521
526
|
m_ctx.textAlign = 'right';
|
|
522
527
|
var tickSize = getTickValue(_this.scaleinfoY.lowLowerChart, _this.scaleinfoY.highLowerChart, numticks);
|
|
523
528
|
console.log(_this.scaleinfoY.highLowerChart, tickSize, lineLength);
|
|
@@ -562,13 +567,11 @@ function Milli_Chart(settings) {
|
|
|
562
567
|
}
|
|
563
568
|
value += tickSize;
|
|
564
569
|
}
|
|
565
|
-
|
|
566
|
-
plotLower(valuePerPixel);
|
|
570
|
+
plotLower(valuePerPixel, lineLength);
|
|
567
571
|
return true;
|
|
568
572
|
}
|
|
569
573
|
|
|
570
574
|
function drawYAxisLower() {
|
|
571
|
-
|
|
572
575
|
//m_ctx.save();
|
|
573
576
|
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
574
577
|
m_ctx.font = m_yLegendCss['font-weight'] + ' ' + m_yLegendCss['font-size'] + ' ' + m_yLegendCss['font-family'];
|
|
@@ -659,7 +662,6 @@ function Milli_Chart(settings) {
|
|
|
659
662
|
}
|
|
660
663
|
value += si.tickSize;
|
|
661
664
|
}
|
|
662
|
-
// console.log('drawYLegend out');
|
|
663
665
|
return true;
|
|
664
666
|
}
|
|
665
667
|
|
|
@@ -747,7 +749,6 @@ function Milli_Chart(settings) {
|
|
|
747
749
|
drawYLegend(_this.scaleinfoY2, x, 'right', _this.settings.gridHorizontalLines2, 2);
|
|
748
750
|
}
|
|
749
751
|
m_ctx.restore();
|
|
750
|
-
// console.log('draw Y axis out');
|
|
751
752
|
}
|
|
752
753
|
|
|
753
754
|
function drawXAxisGridlines(p, newday) {
|
|
@@ -1005,7 +1006,6 @@ function Milli_Chart(settings) {
|
|
|
1005
1006
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1006
1007
|
continue;
|
|
1007
1008
|
}
|
|
1008
|
-
console.log(x, lastx);
|
|
1009
1009
|
if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
|
|
1010
1010
|
draw = false;
|
|
1011
1011
|
}
|
|
@@ -1013,23 +1013,19 @@ function Milli_Chart(settings) {
|
|
|
1013
1013
|
lastx = x;
|
|
1014
1014
|
var text = formatDate(currentDate.toISOString().substring(0, 10), _this.settings.dateformat);
|
|
1015
1015
|
if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left > x - getMaxDateWidth()) { // not to far right?
|
|
1016
|
-
|
|
1017
|
-
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1016
|
+
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_chartspaces.chart.bottom + 10);
|
|
1018
1017
|
}
|
|
1019
|
-
|
|
1020
|
-
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) });
|
|
1018
|
+
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom });
|
|
1021
1019
|
}
|
|
1022
1020
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1023
1021
|
}
|
|
1024
1022
|
// vad är detta?
|
|
1025
1023
|
if (typeof m_chartCss.boxShadow !== 'undefined') {
|
|
1026
1024
|
var boxshadow = m_chartCss.boxShadow.split(' ');
|
|
1027
|
-
|
|
1028
|
-
if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1025
|
+
if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false);
|
|
1029
1026
|
|
|
1030
1027
|
} else {
|
|
1031
|
-
|
|
1032
|
-
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1028
|
+
drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false);
|
|
1033
1029
|
}
|
|
1034
1030
|
m_ctx.restore();
|
|
1035
1031
|
}
|
|
@@ -1042,7 +1038,6 @@ function Milli_Chart(settings) {
|
|
|
1042
1038
|
_this.scaleinfoX.itemwidth = getStringWidth(m_ctx, '88:88') * 2; // kolla rätt format en 8a för varje tecken
|
|
1043
1039
|
var maxLegendItems = Math.floor(_this.scaleinfoX.lineLength / (_this.scaleinfoX.itemwidth * 2));
|
|
1044
1040
|
|
|
1045
|
-
//if (_this.scaleinfoX.days < 1) {
|
|
1046
1041
|
if (_this.scaleinfoY.type != 'history') {
|
|
1047
1042
|
var arr = [];
|
|
1048
1043
|
var tmptime = starttime;
|
|
@@ -1094,7 +1089,6 @@ function Milli_Chart(settings) {
|
|
|
1094
1089
|
else factor = 1;
|
|
1095
1090
|
_this.scaleinfoX.ticksize = factor * 60000; // time to add to next legenditem
|
|
1096
1091
|
}
|
|
1097
|
-
//console.log('calcx out',numticks,_this.scaleinfoX.ticksize,factor,totalmilli);
|
|
1098
1092
|
return;
|
|
1099
1093
|
}
|
|
1100
1094
|
}
|
|
@@ -1133,8 +1127,6 @@ function Milli_Chart(settings) {
|
|
|
1133
1127
|
days++;
|
|
1134
1128
|
}
|
|
1135
1129
|
return Math.min(days, 5);
|
|
1136
|
-
// Dra av helgen om det är någon där
|
|
1137
|
-
return Math.min(((e - s) / 86400000 + 1), 5);
|
|
1138
1130
|
}
|
|
1139
1131
|
|
|
1140
1132
|
function drawXAxisTickLowerChart() {
|
|
@@ -1336,7 +1328,6 @@ function Milli_Chart(settings) {
|
|
|
1336
1328
|
}
|
|
1337
1329
|
if (lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1338
1330
|
//draw = false;
|
|
1339
|
-
//console.log('false');
|
|
1340
1331
|
}
|
|
1341
1332
|
var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1342
1333
|
if (draw) {
|
|
@@ -1428,7 +1419,6 @@ function Milli_Chart(settings) {
|
|
|
1428
1419
|
}
|
|
1429
1420
|
var obj = m_dataPoints.map.get(m_dataPoints.arr[i]);
|
|
1430
1421
|
if (obj == null) {
|
|
1431
|
-
//console.log('not found', m_dataPoints, obj);
|
|
1432
1422
|
return;
|
|
1433
1423
|
}
|
|
1434
1424
|
// datetime
|
|
@@ -1490,7 +1480,6 @@ function Milli_Chart(settings) {
|
|
|
1490
1480
|
//posy = parseFloat(highy) + 20;
|
|
1491
1481
|
}
|
|
1492
1482
|
m_toolTip.instrDiv[k].innerHTML = formatNiceNumber(obj.instruments[k].price, _this.settings.thousandseparator, _this.settings.decimalseparator, obj.instruments[k].price.countDecimals());
|
|
1493
|
-
//console.log()
|
|
1494
1483
|
if (typeof obj.instruments[k].diff !== 'undefined') m_toolTip.instrDiv[k].innerHTML += ', diff:' + formatNiceNumber(obj.instruments[k].diff, ' ', ',', m_y2settings.decimals);
|
|
1495
1484
|
m_toolTip.instrDiv[k].setAttribute('class', 'millistream-chart-tooltip'); // set class so we can measure it might change below depending on position
|
|
1496
1485
|
m_toolTip.instrDiv[k].style.top = posy + 'px'; // TODO: räkna ut 7 px beroende på hur hoverpilen ser ut från höjden på diven depending on position
|
|
@@ -1630,15 +1619,12 @@ function Milli_Chart(settings) {
|
|
|
1630
1619
|
var count = 0;
|
|
1631
1620
|
for (var i = 0; i < data.length; i++) {
|
|
1632
1621
|
if (data[i].timestamp >= _this.scaleinfoX.startTimeStamp && data[i].timestamp <= _this.scaleinfoX.endTimeStamp) {
|
|
1633
|
-
//console.log(new Date(data[i].timestamp), new Date(_this.scaleinfoX.startTimeStamp), new Date(_this.scaleinfoX.endTimeStamp), data[i]);
|
|
1634
1622
|
if (count++ > 0) {
|
|
1635
1623
|
return true;
|
|
1636
1624
|
}
|
|
1637
1625
|
}
|
|
1638
1626
|
}
|
|
1639
1627
|
console.log('NO data to draw on');
|
|
1640
|
-
// var y = (m_canvas.height - parseInt(m_chartCss['margin-bottom'])) / 2 + m_chartspaces.chart.top;
|
|
1641
|
-
// var x = (m_canvas.width - parseInt(m_chartCss['margin-bottom'])) / 2 + m_chartspaces.chart.left;
|
|
1642
1628
|
var y = m_chartspaces.chart.bottom - m_chartspaces.chart.top / 2 + m_chartspaces.chart.top;
|
|
1643
1629
|
var x = m_chartspaces.chart.right - m_chartspaces.chart.left / 2 + m_chartspaces.chart.left;
|
|
1644
1630
|
m_ctx.save();
|
|
@@ -1654,20 +1640,18 @@ function Milli_Chart(settings) {
|
|
|
1654
1640
|
}
|
|
1655
1641
|
|
|
1656
1642
|
function calcChartSpaces() {
|
|
1657
|
-
m_chartspaces.chart.height = m_canvas.height * (m_chartspaces.chart.percent / 100);
|
|
1643
|
+
m_chartspaces.chart.height = Math.round(m_canvas.height * (m_chartspaces.chart.percent / 100));
|
|
1658
1644
|
m_chartspaces.chart.top = parseInt(m_chartCss['margin-top']);
|
|
1659
1645
|
m_chartspaces.chart.left = parseInt(m_chartCss['margin-left']);
|
|
1660
1646
|
m_chartspaces.chart.right = m_canvas.width - parseInt(m_chartCss['margin-right']);
|
|
1661
1647
|
m_chartspaces.chart.bottom = m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']);
|
|
1662
1648
|
m_chartspaces.chart.width = m_canvas.width;
|
|
1663
1649
|
m_chartspaces.lowerChart.height = m_canvas.height * (m_chartspaces.lowerChart.percent / 100);
|
|
1664
|
-
m_chartspaces.lowerChart.top = m_chartspaces.chart.bottom + parseInt(m_chartCss['margin-bottom']) + m_chartspaces.chart.top;
|
|
1650
|
+
m_chartspaces.lowerChart.top = Math.round(m_chartspaces.chart.bottom + parseInt(m_chartCss['margin-bottom']) + m_chartspaces.chart.top);
|
|
1665
1651
|
m_chartspaces.lowerChart.left = m_chartspaces.chart.left;
|
|
1666
1652
|
m_chartspaces.lowerChart.right = m_chartspaces.chart.right;
|
|
1667
|
-
//m_chartspaces.lowerChart.bottom =m_chartspaces.lowerChart.top +m_chartspaces.lowerChart.height - parseInt(m_chartCss['margin-bottom']);
|
|
1668
1653
|
m_chartspaces.lowerChart.bottom = m_canvas.height - parseInt(m_chartCss['margin-bottom']);
|
|
1669
1654
|
m_chartspaces.lowerChart.width = m_canvas.width;
|
|
1670
|
-
console.log(m_chartspaces);
|
|
1671
1655
|
}
|
|
1672
1656
|
|
|
1673
1657
|
_this.drawChart = function() {
|
|
@@ -1722,7 +1706,6 @@ function Milli_Chart(settings) {
|
|
|
1722
1706
|
_this.scaleinfoX.endTimeStamp = new Date(_this.scaleinfoX.endTimeStamp.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
|
|
1723
1707
|
else if (len == 1) {
|
|
1724
1708
|
// check if startdate is not today (due to exchange is closed f ex DJ)
|
|
1725
|
-
//console.log(new Date(_this.scaleinfoX.endTimeStamp), new Date(_this.scaleinfoX.startTimeStamp));
|
|
1726
1709
|
if (_this.scaleinfoX.startTimeStamp % 86400000 != new Date().getTime() % 86400) {
|
|
1727
1710
|
_this.scaleinfoX.endTimeStamp = new Date(new Date(_this.scaleinfoX.startTimeStamp).toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
|
|
1728
1711
|
} else
|
|
@@ -1740,8 +1723,6 @@ function Milli_Chart(settings) {
|
|
|
1740
1723
|
_this.scaleinfoX.endTimeStamp -= _this.scaleinfoX.endTimeStamp - _this.scaleinfoX.endTimeStamp % 86400000;
|
|
1741
1724
|
_this.scaleinfoX.endTimeStamp += _this.instruments[0].quotedate; // set enddate = last Quotedate
|
|
1742
1725
|
}
|
|
1743
|
-
//console.log('Starttimestamp',new Date(_this.scaleinfoX.startTimeStamp));
|
|
1744
|
-
//console.log('endtimestammp',new Date(_this.scaleinfoX.endTimeStamp), 'quotedate',new Date(_this.instruments[0].quotedate));
|
|
1745
1726
|
}
|
|
1746
1727
|
setTimeSpanData();
|
|
1747
1728
|
_this.scaleinfoY.type = 'trades';
|
|
@@ -1795,7 +1776,6 @@ function Milli_Chart(settings) {
|
|
|
1795
1776
|
|
|
1796
1777
|
drawYAxis();
|
|
1797
1778
|
drawXAxisMonth(_this.scaleinfoX.startTimeStamp, _this.scaleinfoX.endTimeStamp);
|
|
1798
|
-
//console.log(_this.scaleinfoX.startTimeStamp, _this.scaleinfoX.endTimeStamp);
|
|
1799
1779
|
if (false == checkChartData(_this.instruments[0].history)) return;
|
|
1800
1780
|
|
|
1801
1781
|
for (i = 0; i < _this.instruments.length; i++) {
|
|
@@ -1839,7 +1819,6 @@ function Milli_Chart(settings) {
|
|
|
1839
1819
|
for (i = 0; i < _this.instruments.length; i++)
|
|
1840
1820
|
if (_this.instruments[i].insref != 0)
|
|
1841
1821
|
plotData(_this.instruments[i].history, i);
|
|
1842
|
-
//plotChart(_this.instruments[0].history, null);
|
|
1843
1822
|
|
|
1844
1823
|
}
|
|
1845
1824
|
drawBoxShadow(m_chartspaces.chart);
|
|
@@ -1852,7 +1831,6 @@ function Milli_Chart(settings) {
|
|
|
1852
1831
|
};
|
|
1853
1832
|
|
|
1854
1833
|
function drawBoxShadow(space) {
|
|
1855
|
-
console.log(space);
|
|
1856
1834
|
if (typeof m_chartCss.boxShadow === 'undefined') return;
|
|
1857
1835
|
var boxShadow = m_chartCss.boxShadow;
|
|
1858
1836
|
if (boxShadow.indexOf(')') != -1) {
|
|
@@ -1860,25 +1838,22 @@ function Milli_Chart(settings) {
|
|
|
1860
1838
|
}
|
|
1861
1839
|
var boxshadow = boxShadow.split(' ');
|
|
1862
1840
|
m_ctx.save();
|
|
1841
|
+
m_ctx.beginPath();
|
|
1863
1842
|
if (parseInt(boxshadow[0]) > 0) {
|
|
1864
|
-
m_ctx.beginPath();
|
|
1865
1843
|
m_ctx.strokeStyle = m_chartCss['border-top-color'];
|
|
1866
1844
|
m_ctx.lineWidth = parseInt(boxshadow[1]);
|
|
1867
1845
|
m_ctx.moveTo(space.left, space.top);
|
|
1868
1846
|
m_ctx.lineTo(space.right, space.top);
|
|
1869
1847
|
m_ctx.stroke();
|
|
1870
|
-
m_ctx.closePath();
|
|
1871
1848
|
}
|
|
1872
1849
|
if (parseInt(boxshadow[1]) > 0) {
|
|
1873
|
-
m_ctx.beginPath();
|
|
1874
1850
|
m_ctx.strokeStyle = m_chartCss['border-right-color'];
|
|
1875
1851
|
m_ctx.lineWidth = parseInt(boxshadow[1]);
|
|
1876
1852
|
m_ctx.moveTo(space.right, space.top + 0.5);
|
|
1877
|
-
//m_ctx.lineTo(spaces.chart.right, spaces.chart.height - parseInt(m_chartCss['margin-bottom']));
|
|
1878
1853
|
m_ctx.lineTo(space.right, space.bottom);
|
|
1879
1854
|
m_ctx.stroke();
|
|
1880
|
-
m_ctx.closePath();
|
|
1881
1855
|
}
|
|
1856
|
+
m_ctx.closePath();
|
|
1882
1857
|
m_ctx.restore();
|
|
1883
1858
|
}
|
|
1884
1859
|
|