@millistream/millistream-widgets 0.0.16 → 0.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.
@@ -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,29 +484,44 @@ 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
+ if (width < 2) width = 2;
497
+ else if (width > 20) width = 20;
498
+ m_ctx.lineWidth = width;
510
499
  for (var i = 0; i < m_datapoints.length; i++) {
511
- m_ctx.moveTo(m_datapoints[i].x + 0.5, m_chartspaces.lowerChart.bottom - 0.5);
500
+ var x = Math.round(m_datapoints[i].x);
501
+ if (x - width < m_chartspaces.lowerChart.left) {
502
+ x += width / 4;
503
+ m_ctx.lineWidth = width / 2;
504
+ } else
505
+ if (x + width > m_chartspaces.lowerChart.right) {
506
+ x -= width / 4;
507
+ m_ctx.lineWidth = width / 2;
508
+ }
509
+
510
+ m_ctx.moveTo(x + 0.5, m_chartspaces.lowerChart.bottom);
512
511
  var y = Math.round(m_chartspaces.lowerChart.bottom - (m_datapoints[i].quantity * valuePerPixel));
513
- m_ctx.lineTo(m_datapoints[i].x + 0.5, y - 0.5);
512
+ m_ctx.lineTo(x + 0.5, y);
514
513
  m_ctx.stroke();
515
514
  }
515
+ m_ctx.closePath();
516
516
  m_ctx.restore();
517
517
  }
518
518
 
519
519
  function drawYLegendLower(x, numticks, lineLength, markers) {
520
- m_ctx.save();
520
+ m_ctx.strokeStyle = m_gridHorizontalCss.color;
521
+ m_ctx.fillStyle = m_yLegendCss.color;
522
+
521
523
  m_ctx.textAlign = 'right';
522
524
  var tickSize = getTickValue(_this.scaleinfoY.lowLowerChart, _this.scaleinfoY.highLowerChart, numticks);
523
- console.log(_this.scaleinfoY.highLowerChart, tickSize, lineLength);
524
525
  var maxValue = _this.scaleinfoY.highLowerChart == 0 ? 100 : _this.scaleinfoY.highLowerChart + (tickSize * 0.2);
525
526
  var valuePerPixel = lineLength / maxValue;
526
527
  if (isNaN(valuePerPixel) || !isFinite(valuePerPixel)) {
@@ -530,7 +531,6 @@ function Milli_Chart(settings) {
530
531
  var value = 0;
531
532
  for (;;) {
532
533
  var y = Math.round(m_chartspaces.lowerChart.bottom - (value * valuePerPixel));
533
- console.log(value, y, tickSize, maxValue);
534
534
 
535
535
  if (y <= m_chartspaces.lowerChart.top) break;
536
536
  if (y <= m_chartspaces.lowerChart.bottom) {
@@ -562,17 +562,14 @@ function Milli_Chart(settings) {
562
562
  }
563
563
  value += tickSize;
564
564
  }
565
- m_ctx.restore();
566
- plotLower(valuePerPixel);
565
+ plotLower(valuePerPixel, lineLength);
567
566
  return true;
568
567
  }
569
568
 
570
569
  function drawYAxisLower() {
571
-
572
570
  //m_ctx.save();
573
571
  m_ctx.strokeStyle = m_gridHorizontalCss.color;
574
572
  m_ctx.font = m_yLegendCss['font-weight'] + ' ' + m_yLegendCss['font-size'] + ' ' + m_yLegendCss['font-family'];
575
- console.log(m_yLegendCss.color, m_gridHorizontalCss.color);
576
573
  m_ctx.fillStyle = m_yLegendCss.color;
577
574
  var lineLen = m_chartspaces.lowerChart.bottom - m_chartspaces.lowerChart.top;
578
575
  var numticks = lineLen / (getFontSize(m_yLegendCss) * 2);
@@ -590,11 +587,9 @@ function Milli_Chart(settings) {
590
587
 
591
588
  function drawYLegend(si, x, side, gridHorizontalLines, number) {
592
589
  var value;
593
- if (si.highValue == si.lowValue) console.log(si.tickSize);
594
590
  si.maxValue = si.highValue + (si.tickSize * 0.2);
595
591
  si.minValue = si.lowValue - (si.tickSize * 0.2);
596
592
  m_ctx.font = m_yLegendCss['font-weight'] + ' ' + m_yLegendCss['font-size'] + ' ' + m_yLegendCss['font-family'];
597
- // console.log('drawYLegend in 2,', si.highValue, si.lowValue, si.tickSize);
598
593
  if (si.highValue == si.lowValue) { // only have one value so set values for 1 line only
599
594
  si.maxValue = si.maxValue + si.tickSize;
600
595
  si.minValue = si.minValue - si.tickSize;
@@ -659,7 +654,6 @@ function Milli_Chart(settings) {
659
654
  }
660
655
  value += si.tickSize;
661
656
  }
662
- // console.log('drawYLegend out');
663
657
  return true;
664
658
  }
665
659
 
@@ -747,7 +741,6 @@ function Milli_Chart(settings) {
747
741
  drawYLegend(_this.scaleinfoY2, x, 'right', _this.settings.gridHorizontalLines2, 2);
748
742
  }
749
743
  m_ctx.restore();
750
- // console.log('draw Y axis out');
751
744
  }
752
745
 
753
746
  function drawXAxisGridlines(p, newday) {
@@ -1005,7 +998,6 @@ function Milli_Chart(settings) {
1005
998
  currentDate = new Date(currentDate.getTime() + 86400000);
1006
999
  continue;
1007
1000
  }
1008
- console.log(x, lastx);
1009
1001
  if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
1010
1002
  draw = false;
1011
1003
  }
@@ -1013,23 +1005,19 @@ function Milli_Chart(settings) {
1013
1005
  lastx = x;
1014
1006
  var text = formatDate(currentDate.toISOString().substring(0, 10), _this.settings.dateformat);
1015
1007
  if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left > x - getMaxDateWidth()) { // not to far right?
1016
- //m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
1017
- m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) + 10);
1008
+ m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_chartspaces.chart.bottom + 10);
1018
1009
  }
1019
- //drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
1020
- drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) });
1010
+ drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom });
1021
1011
  }
1022
1012
  currentDate = new Date(currentDate.getTime() + 86400000);
1023
1013
  }
1024
1014
  // vad är detta?
1025
1015
  if (typeof m_chartCss.boxShadow !== 'undefined') {
1026
1016
  var boxshadow = m_chartCss.boxShadow.split(' ');
1027
- //if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1028
- if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) }, false);
1017
+ if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false);
1029
1018
 
1030
1019
  } else {
1031
- //drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1032
- drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']) }, false);
1020
+ drawXAxisGridlines({ 'x': x, y: m_chartspaces.chart.bottom }, false);
1033
1021
  }
1034
1022
  m_ctx.restore();
1035
1023
  }
@@ -1042,7 +1030,6 @@ function Milli_Chart(settings) {
1042
1030
  _this.scaleinfoX.itemwidth = getStringWidth(m_ctx, '88:88') * 2; // kolla rätt format en 8a för varje tecken
1043
1031
  var maxLegendItems = Math.floor(_this.scaleinfoX.lineLength / (_this.scaleinfoX.itemwidth * 2));
1044
1032
 
1045
- //if (_this.scaleinfoX.days < 1) {
1046
1033
  if (_this.scaleinfoY.type != 'history') {
1047
1034
  var arr = [];
1048
1035
  var tmptime = starttime;
@@ -1094,7 +1081,6 @@ function Milli_Chart(settings) {
1094
1081
  else factor = 1;
1095
1082
  _this.scaleinfoX.ticksize = factor * 60000; // time to add to next legenditem
1096
1083
  }
1097
- //console.log('calcx out',numticks,_this.scaleinfoX.ticksize,factor,totalmilli);
1098
1084
  return;
1099
1085
  }
1100
1086
  }
@@ -1133,8 +1119,6 @@ function Milli_Chart(settings) {
1133
1119
  days++;
1134
1120
  }
1135
1121
  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
1122
  }
1139
1123
 
1140
1124
  function drawXAxisTickLowerChart() {
@@ -1336,7 +1320,6 @@ function Milli_Chart(settings) {
1336
1320
  }
1337
1321
  if (lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
1338
1322
  //draw = false;
1339
- //console.log('false');
1340
1323
  }
1341
1324
  var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
1342
1325
  if (draw) {
@@ -1428,7 +1411,6 @@ function Milli_Chart(settings) {
1428
1411
  }
1429
1412
  var obj = m_dataPoints.map.get(m_dataPoints.arr[i]);
1430
1413
  if (obj == null) {
1431
- //console.log('not found', m_dataPoints, obj);
1432
1414
  return;
1433
1415
  }
1434
1416
  // datetime
@@ -1490,7 +1472,6 @@ function Milli_Chart(settings) {
1490
1472
  //posy = parseFloat(highy) + 20;
1491
1473
  }
1492
1474
  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
1475
  if (typeof obj.instruments[k].diff !== 'undefined') m_toolTip.instrDiv[k].innerHTML += ', diff:' + formatNiceNumber(obj.instruments[k].diff, ' ', ',', m_y2settings.decimals);
1495
1476
  m_toolTip.instrDiv[k].setAttribute('class', 'millistream-chart-tooltip'); // set class so we can measure it might change below depending on position
1496
1477
  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 +1611,12 @@ function Milli_Chart(settings) {
1630
1611
  var count = 0;
1631
1612
  for (var i = 0; i < data.length; i++) {
1632
1613
  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
1614
  if (count++ > 0) {
1635
1615
  return true;
1636
1616
  }
1637
1617
  }
1638
1618
  }
1639
1619
  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
1620
  var y = m_chartspaces.chart.bottom - m_chartspaces.chart.top / 2 + m_chartspaces.chart.top;
1643
1621
  var x = m_chartspaces.chart.right - m_chartspaces.chart.left / 2 + m_chartspaces.chart.left;
1644
1622
  m_ctx.save();
@@ -1654,20 +1632,18 @@ function Milli_Chart(settings) {
1654
1632
  }
1655
1633
 
1656
1634
  function calcChartSpaces() {
1657
- m_chartspaces.chart.height = m_canvas.height * (m_chartspaces.chart.percent / 100);
1635
+ m_chartspaces.chart.height = Math.round(m_canvas.height * (m_chartspaces.chart.percent / 100));
1658
1636
  m_chartspaces.chart.top = parseInt(m_chartCss['margin-top']);
1659
1637
  m_chartspaces.chart.left = parseInt(m_chartCss['margin-left']);
1660
1638
  m_chartspaces.chart.right = m_canvas.width - parseInt(m_chartCss['margin-right']);
1661
1639
  m_chartspaces.chart.bottom = m_chartspaces.chart.height - parseInt(m_chartCss['margin-bottom']);
1662
1640
  m_chartspaces.chart.width = m_canvas.width;
1663
1641
  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;
1642
+ m_chartspaces.lowerChart.top = Math.round(m_chartspaces.chart.bottom + parseInt(m_chartCss['margin-bottom']) + m_chartspaces.chart.top);
1665
1643
  m_chartspaces.lowerChart.left = m_chartspaces.chart.left;
1666
1644
  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
1645
  m_chartspaces.lowerChart.bottom = m_canvas.height - parseInt(m_chartCss['margin-bottom']);
1669
1646
  m_chartspaces.lowerChart.width = m_canvas.width;
1670
- console.log(m_chartspaces);
1671
1647
  }
1672
1648
 
1673
1649
  _this.drawChart = function() {
@@ -1722,7 +1698,6 @@ function Milli_Chart(settings) {
1722
1698
  _this.scaleinfoX.endTimeStamp = new Date(_this.scaleinfoX.endTimeStamp.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
1723
1699
  else if (len == 1) {
1724
1700
  // 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
1701
  if (_this.scaleinfoX.startTimeStamp % 86400000 != new Date().getTime() % 86400) {
1727
1702
  _this.scaleinfoX.endTimeStamp = new Date(new Date(_this.scaleinfoX.startTimeStamp).toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z').getTime();
1728
1703
  } else
@@ -1740,8 +1715,6 @@ function Milli_Chart(settings) {
1740
1715
  _this.scaleinfoX.endTimeStamp -= _this.scaleinfoX.endTimeStamp - _this.scaleinfoX.endTimeStamp % 86400000;
1741
1716
  _this.scaleinfoX.endTimeStamp += _this.instruments[0].quotedate; // set enddate = last Quotedate
1742
1717
  }
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
1718
  }
1746
1719
  setTimeSpanData();
1747
1720
  _this.scaleinfoY.type = 'trades';
@@ -1795,7 +1768,6 @@ function Milli_Chart(settings) {
1795
1768
 
1796
1769
  drawYAxis();
1797
1770
  drawXAxisMonth(_this.scaleinfoX.startTimeStamp, _this.scaleinfoX.endTimeStamp);
1798
- //console.log(_this.scaleinfoX.startTimeStamp, _this.scaleinfoX.endTimeStamp);
1799
1771
  if (false == checkChartData(_this.instruments[0].history)) return;
1800
1772
 
1801
1773
  for (i = 0; i < _this.instruments.length; i++) {
@@ -1839,7 +1811,6 @@ function Milli_Chart(settings) {
1839
1811
  for (i = 0; i < _this.instruments.length; i++)
1840
1812
  if (_this.instruments[i].insref != 0)
1841
1813
  plotData(_this.instruments[i].history, i);
1842
- //plotChart(_this.instruments[0].history, null);
1843
1814
 
1844
1815
  }
1845
1816
  drawBoxShadow(m_chartspaces.chart);
@@ -1852,7 +1823,6 @@ function Milli_Chart(settings) {
1852
1823
  };
1853
1824
 
1854
1825
  function drawBoxShadow(space) {
1855
- console.log(space);
1856
1826
  if (typeof m_chartCss.boxShadow === 'undefined') return;
1857
1827
  var boxShadow = m_chartCss.boxShadow;
1858
1828
  if (boxShadow.indexOf(')') != -1) {
@@ -1860,25 +1830,22 @@ function Milli_Chart(settings) {
1860
1830
  }
1861
1831
  var boxshadow = boxShadow.split(' ');
1862
1832
  m_ctx.save();
1833
+ m_ctx.beginPath();
1863
1834
  if (parseInt(boxshadow[0]) > 0) {
1864
- m_ctx.beginPath();
1865
1835
  m_ctx.strokeStyle = m_chartCss['border-top-color'];
1866
1836
  m_ctx.lineWidth = parseInt(boxshadow[1]);
1867
1837
  m_ctx.moveTo(space.left, space.top);
1868
1838
  m_ctx.lineTo(space.right, space.top);
1869
1839
  m_ctx.stroke();
1870
- m_ctx.closePath();
1871
1840
  }
1872
1841
  if (parseInt(boxshadow[1]) > 0) {
1873
- m_ctx.beginPath();
1874
1842
  m_ctx.strokeStyle = m_chartCss['border-right-color'];
1875
1843
  m_ctx.lineWidth = parseInt(boxshadow[1]);
1876
1844
  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
1845
  m_ctx.lineTo(space.right, space.bottom);
1879
1846
  m_ctx.stroke();
1880
- m_ctx.closePath();
1881
1847
  }
1848
+ m_ctx.closePath();
1882
1849
  m_ctx.restore();
1883
1850
  }
1884
1851
 
@@ -2697,7 +2664,7 @@ function Milli_Chart(settings) {
2697
2664
  _this.settings.startdate = startdate.getFullYear() + '-' + zeroPad(startdate.getMonth() + 1, 2) + '-' + zeroPad(startdate.getDate(), 2);
2698
2665
  url = MillistreamWidgetApi_buildQuery(_this, 'historychart');
2699
2666
  _this.settings.fields = oldfields;
2700
- console.log(_this.settings.fields);
2667
+ //console.log(_this.settings.fields);
2701
2668
  millistream_data_api.fetch(url, function(data) {
2702
2669
  _this.buildwidget(data);
2703
2670
 
@@ -5286,5 +5253,8 @@ function MillistreamWidgetStreamingApi(settings) {
5286
5253
  }
5287
5254
  exports.Milli_Chart = Milli_Chart;
5288
5255
  exports.MillistreamWidgetSettings = MillistreamWidgetSettings;
5289
- exports.milli_data_api_url = milli_data_api_url;
5290
5256
  exports.MillistreamWidgetStreamingApi = MillistreamWidgetStreamingApi;
5257
+
5258
+ exports.setDataApiUrl = function(url) {
5259
+ milli_data_api_url = url;
5260
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@millistream/millistream-widgets",
3
- "version": "0.0.16",
3
+ "version": "0.0.19",
4
4
  "description": "Millistream widgets node package",
5
5
  "main": "millistream-widgets.js",
6
6
  "scripts": {