@millistream/millistream-widgets 1.0.40 → 1.0.45

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.
@@ -1087,9 +1087,11 @@ function Milli_Chart(settings) {
1087
1087
 
1088
1088
  function checkXLegendSides(x, text) {
1089
1089
  // right
1090
- if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left < x + (m_ctx.measureText(text).width / 2)) return false;
1090
+ if(x + (m_ctx.measureText(text).width / 2) > m_chartspaces.chart.width) return false;
1091
+ //if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left < x + (m_ctx.measureText(text).width / 2)) return false;
1091
1092
  // left
1092
- if (m_chartspaces.chart.left > x - (m_ctx.measureText(text).width / 2)) return false;
1093
+ //if (m_chartspaces.chart.left > x - (m_ctx.measureText(text).width / 2)) return false;
1094
+ if (0 > x - (m_ctx.measureText(text).width / 2)) return false;
1093
1095
  return true;
1094
1096
 
1095
1097
  }
@@ -1257,11 +1259,13 @@ function Milli_Chart(settings) {
1257
1259
  offset += 86400000 / _this.scaleinfoX.timePerPixel;
1258
1260
  }
1259
1261
  x = Math.round(m_chartspaces.chart.left + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1260
- if (lastx == 0 && m_chartspaces.chart.left > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
1262
+ //if (lastx == 0 && m_chartspaces.chart.left > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
1263
+ if (lastx == 0 && 0 > x - (getMaxDateWidth() / 2)) {
1264
+ console.log(currentDate,x - (getMaxDateWidth() / 2));
1261
1265
  currentDate = new Date(currentDate.getTime() + 86400000);
1262
1266
  continue;
1263
1267
  }
1264
- if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
1268
+ if (lastx != 0 && lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
1265
1269
  draw = false;
1266
1270
  }
1267
1271
  if (draw) {
@@ -1822,7 +1826,21 @@ function Milli_Chart(settings) {
1822
1826
  instr.data = {};
1823
1827
  MillistreamWidgetApi_AssignObject(obj.instruments[x], instr.data);
1824
1828
  instr.data.price = formatNiceNumber(instr.data.price, _this.settings.thousandseparator, _this.settings.decimalseparator, _this.settings.num_decimals, false);
1825
-
1829
+ if(x == 0) {
1830
+ for (let s = 0; s < _this.settings.indicators.length; s++) {
1831
+ if(_this.settings.indicators[s].method != 'news') {
1832
+ for(let ss = 0; ss < _this.settings.indicators[s].timeseries.length;ss++) {
1833
+ if(_this.settings.indicators[s].timeseries[ss].timestamp <= instr.data.timestamp) {
1834
+ instr.data.indicator = {
1835
+ method: _this.settings.indicators[s].method,
1836
+ datapoints: _this.settings.indicators[s].timeseries[ss].datapoints
1837
+ }
1838
+ } else break;
1839
+ }
1840
+ }
1841
+ }
1842
+ }
1843
+
1826
1844
  if (typeof _this.instruments[x].toolTip === 'undefined') {
1827
1845
  // add textdiv
1828
1846
  _this.instruments[x].toolTip = document.createElement('div');
@@ -1841,8 +1859,9 @@ function Milli_Chart(settings) {
1841
1859
  _this.instruments[x].toolTipPointer.style.pointerEvents = 'none';
1842
1860
 
1843
1861
  }
1862
+ _this.instruments[x].toolTip.innerHTML = _this.settings.tooltip.formatter.call(instr, m_chartspaces, obj.instruments[x].x);
1844
1863
  var pointerStyle = getComputedStyle(_this.instruments[x].toolTipPointer);
1845
- pointerWidth = _this.instruments[x].toolTipPointer.offsetWidth + parseInt(pointerStyle.marginLeft) + parseInt(pointerStyle.marginRight);
1864
+ pointerWidth = _this.instruments[x].toolTipPointer.offsetWidth + parseInt(pointerStyle.marginLeft) + (parseInt(pointerStyle.marginRight));
1846
1865
  var pointerHeight = _this.instruments[x].toolTipPointer.offsetHeight + parseInt(pointerStyle.marginTop) + parseInt(pointerStyle.marginBottom);
1847
1866
  var posy = obj.instruments[x].y - (_this.instruments[x].toolTip.offsetHeight / 2);
1848
1867
  _this.instruments[x].toolTip.style.top = posy + 'px';
@@ -1851,10 +1870,15 @@ function Milli_Chart(settings) {
1851
1870
  _this.instruments[x].toolTipPointer.style.top = (obj.instruments[x].y - (pointerHeight / 2)) + 'px';
1852
1871
  if (posy > highy) highy = posy;
1853
1872
  if (posy < lowy) lowy = posy;
1854
- _this.instruments[x].toolTip.innerHTML = _this.settings.tooltip.formatter.call(instr, m_chartspaces, obj.instruments[x].x);
1855
- if (m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.getWidth()) { // || m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.getWidth()) { // TODO +10 should be calculated better
1873
+ // _this.instruments[x].toolTip.innerHTML = _this.settings.tooltip.formatter.call(instr, m_chartspaces, obj.instruments[x].x);
1874
+ let divs = _this.instruments[x].toolTip.children;
1875
+ let width = _this.instruments[x].toolTip.offsetWidth;
1876
+ for(let d = 0; d < divs.length; d++) {
1877
+ if(divs[d].nodeName == 'DIV' && divs[d].offsetWidth != 0) width = Math.max(width,divs[d].offsetWidth);
1878
+ }
1879
+ if (m_dataPoints.arr[i] + width > m_canvas.getWidth()) { // || m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.getWidth()) { // TODO +10 should be calculated better
1856
1880
  // draw the hover to the left
1857
- _this.instruments[x].toolTip.style.left = (obj.instruments[x].x - _this.instruments[x].toolTip.offsetWidth - (pointerWidth / 2)) + 1 + 'px';
1881
+ _this.instruments[x].toolTip.style.left = (obj.instruments[x].x - width - (pointerWidth / 2)) + 1 + 'px';
1858
1882
  } else {
1859
1883
  // draw hover to the right
1860
1884
  _this.instruments[x].toolTip.style.left = (obj.instruments[x].x + (pointerWidth / 2)) + 'px';
@@ -1868,17 +1892,26 @@ function Milli_Chart(settings) {
1868
1892
  }
1869
1893
  }
1870
1894
  }
1895
+
1871
1896
  //indicator hover
1872
1897
  for (x = 0; x < _this.settings.indicators.length; x++) {
1873
1898
  var px = getScaledSetting(pos.clientX) - getScaledSetting(rect.left) - 1;
1874
1899
  if (typeof _this.settings.indicators[x].toolTip === 'undefined') continue;
1875
1900
  if (_this.settings.indicators[x].staticTooltip == true) continue;
1876
- var width = m_ctx.measureText(_this.settings.indicators[x].indicator).width;
1877
- var remove = true;
1901
+ let width = 5;
1902
+ let height = 5;
1903
+ let remove = true;
1904
+ if(typeof _this.settings.indicators[x].image !== 'undefined') {
1905
+ width = _this.settings.indicators[x].image.width;
1906
+ height = _this.settings.indicators[x].image.height;
1907
+ } else {
1908
+ width = m_ctx.measureText(_this.settings.indicators[x].indicator).width;
1909
+ height = parseInt(_this.settings.indicators[x].fontSize);
1910
+ }
1878
1911
  for (var xx = 0; xx < _this.settings.indicators[x].timeseries.length; xx++) {
1879
1912
  if (typeof _this.settings.indicators[x].timeseries[xx].pos === 'undefined') continue;
1880
1913
  if (typeof _this.settings.indicators[x].timeseries[xx].hl === 'undefined') continue;
1881
- if (px >= _this.settings.indicators[x].timeseries[xx].pos.x - (width / 2) && px <= _this.settings.indicators[x].timeseries[xx].pos.x + (width / 2)) {
1914
+ if (px >= _this.settings.indicators[x].timeseries[xx].pos.x -(width/2) && px < _this.settings.indicators[x].timeseries[xx].pos.x + (width/2)) {
1882
1915
  if (typeof _this.settings.indicators[x].toolTip.div === 'undefined') {
1883
1916
  _this.settings.indicators[x].toolTip.div = document.createElement('div');
1884
1917
  _this.settings.indicators[x].toolTip.div.style.display = _this.settings.tooltip.display;
@@ -1889,14 +1922,14 @@ function Milli_Chart(settings) {
1889
1922
  _this.settings.indicators[x].toolTip.div.style.left = _this.settings.indicators[x].timeseries[xx].pos.x / 1 + (pointerWidth / 2) + 'px'; // this i modified in the data for the instruments, but not for indicators
1890
1923
  _this.settings.indicators[x].toolTip.div.style.top = _this.settings.indicators[x].timeseries[xx].pos.y / 1 + 'px'; // this i modified in the data for the instruments, but not for indicators
1891
1924
  _this.settings.indicators[x].toolTip.div.innerHTML = _this.settings.indicators[x].toolTip.formatter.call(_this.settings.indicators[x].timeseries[xx]);
1892
-
1893
- if (y >= _this.settings.indicators[x].timeseries[xx].pos.y && y <= _this.settings.indicators[x].timeseries[xx].pos.y + width)
1925
+ if (y > _this.settings.indicators[x].timeseries[xx].pos.y -(height/2) && y < _this.settings.indicators[x].timeseries[xx].pos.y + (height/2))
1894
1926
  m_canvas.style.cursor = "pointer";
1895
- else
1927
+ else {
1896
1928
  m_canvas.style.cursor = "crosshair";
1929
+ }
1897
1930
  remove = false;
1898
1931
  toolArray.push({ top: parseInt(_this.settings.indicators[x].toolTip.div.style.top), indicator: x });
1899
- }
1932
+ }
1900
1933
 
1901
1934
  }
1902
1935
  if (remove) {
@@ -1968,7 +2001,10 @@ function Milli_Chart(settings) {
1968
2001
  m_zoom.mouseup.timestamp = new Date().toISOString().split('T')[0];
1969
2002
  m_zoom.mouseup.timestamp = new Date(m_zoom.mouseup.timestamp + 'T00:00:00Z');
1970
2003
  }
1971
- _this.settings.chartlen = 'max';
2004
+ if(366 > dateDiffInDays(m_zoom.mousedown.timestamp ,m_zoom.mouseup.timestamp ))
2005
+ _this.settings.chartlen = 'ytd';
2006
+ else
2007
+ _this.settings.chartlen = 'max';
1972
2008
  chartType = 'history';
1973
2009
  _this.drawChart();
1974
2010
  };
@@ -2028,7 +2064,7 @@ function Milli_Chart(settings) {
2028
2064
  m_chartspaces.chart.marginTop = getScaledSetting(m_chartCss.marginTop);
2029
2065
  m_chartspaces.chart.top = m_chartspaces.chart.marginTop;
2030
2066
  m_chartspaces.chart.left = getScaledSetting(m_chartCss.marginLeft);
2031
- m_chartspaces.chart.right = m_canvas.getWidth()- getScaledSetting(m_chartCss.marginRight) - 50;
2067
+ m_chartspaces.chart.right = m_canvas.getWidth()- getScaledSetting(m_chartCss.marginRight);// - 50;
2032
2068
  m_chartspaces.chart.marginBottom = getScaledSetting(m_chartCss.marginBottom);
2033
2069
  m_chartspaces.chart.bottom = (m_chartspaces.chart.height - m_chartspaces.chart.marginBottom);
2034
2070
  m_chartspaces.chart.width = m_canvas.getWidth()
@@ -2107,6 +2143,7 @@ function Milli_Chart(settings) {
2107
2143
  if (m_dataPoints.map) m_dataPoints.map.clear();
2108
2144
  m_dataPoints.map = new Map();
2109
2145
  m_dataPoints.arr = [];
2146
+
2110
2147
  if (_this.instruments.length < 0) {
2111
2148
  console.log('no chartdata');
2112
2149
  return;
@@ -2229,7 +2266,6 @@ function Milli_Chart(settings) {
2229
2266
 
2230
2267
  } else
2231
2268
  if (period == 'm') {
2232
-
2233
2269
  if (m_zoom.mousedown.timestamp) {
2234
2270
  _this.scaleinfoX.startTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
2235
2271
  _this.scaleinfoX.endTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mousedown.timestamp : m_zoom.mouseup.timestamp;
@@ -2404,7 +2440,6 @@ function Milli_Chart(settings) {
2404
2440
  case 'rsi':
2405
2441
  if (chartType == 'history') _this.settings.indicators[i].timeseries = calculateRSI(_this.instruments[0].history, _this.settings.indicators[i].method_length);
2406
2442
  else _this.settings.indicators[i].timeseries = calculateRSI(_this.instruments[0].trades, _this.settings.indicators[i].method_length);
2407
- console.log(_this.settings.indicators[i].timeseries);
2408
2443
  if (_this.settings.indicators[i].target == 'upper') {
2409
2444
  lowerScale = drawYAxisIndicator(_this.settings.indicators[i].timeseries, m_chartspaces.chart, false);
2410
2445
  plotIndicatorLine(_this.settings.indicators[i], lowerScale, m_chartspaces.chart);
@@ -2785,7 +2820,6 @@ function Milli_Chart(settings) {
2785
2820
  let lastPos = null;
2786
2821
  for (var i = start - 1; i >= 0; i--) {
2787
2822
  if (typeof data[i].pos === 'undefined') {
2788
- console.log(i);
2789
2823
  break;
2790
2824
  }
2791
2825
  m_ctx.lineTo(data[i].pos.x, data[i].pos.y);
@@ -2839,9 +2873,10 @@ function Milli_Chart(settings) {
2839
2873
  } else if (method.indicator) {
2840
2874
  m_ctx.fillStyle = method.color;
2841
2875
  width = m_ctx.measureText(method.indicator).width;
2876
+ let height = parseInt(method.fontSize);
2842
2877
  if (method.type == NEWSINDICATOR) {
2843
- if (fabs(lastPos.x - data[i].pos.x) > width || fabs(lastPos.y > data[i].pos.y) > width) {
2844
- m_ctx.fillText(method.indicator, data[i].pos.x - (width / 2), data[i].pos.y);
2878
+ if (fabs(lastPos.x - data[i].pos.x) > width || fabs(lastPos.y > data[i].pos.y) > height) {
2879
+ m_ctx.fillText(method.indicator, data[i].pos.x - (width / 2), data[i].pos.y - (height/2));
2845
2880
  lastPos = { x: data[i].pos.x, y: data[i].y };
2846
2881
  method.timeseries[i].hl = [{ timestamp: data[i].timestamp, headline: data[i].headline,newsid: data[i].newsid }];
2847
2882
  hlPos = i;
@@ -3257,10 +3292,8 @@ function Milli_Chart(settings) {
3257
3292
  let newstimestamp = data[i].timestamp;
3258
3293
  if(data[i].timestamp < (data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].opentimestamp)) {
3259
3294
  newstimestamp = data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].opentimestamp;
3260
- console.log('1', new Date(data[i].timestamp),new Date(newstimestamp));
3261
3295
  } else if(data[i].timestamp > (data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].closetimestamp)) {
3262
3296
  newstimestamp = data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].closetimestamp;
3263
- console.log('2', new Date(data[i].timestamp),new Date(newstimestamp));
3264
3297
  }
3265
3298
  if (newstimestamp >= _this.scaleinfoX.startTimeStamp) {
3266
3299
  let item = null;
@@ -3284,7 +3317,6 @@ function Milli_Chart(settings) {
3284
3317
  if(item) timeseries.push(item);
3285
3318
  }
3286
3319
  }
3287
- console.log(timeseries);
3288
3320
  return timeseries;
3289
3321
  }
3290
3322
 
@@ -3447,20 +3479,14 @@ function Milli_Chart(settings) {
3447
3479
  if (indicatorAlreadyExists(method)) return;
3448
3480
  switch (method.method) {
3449
3481
  case 'sma':
3450
- {
3451
- if (typeof method.method_length !== 'number') return;
3452
- }
3482
+ if (typeof method.method_length !== 'number') return;
3453
3483
  break;
3454
3484
  case 'ema':
3455
- {
3456
- if (typeof method.method_length !== 'number') return;
3457
- break;
3458
- }
3485
+ if (typeof method.method_length !== 'number') return;
3486
+ break;
3459
3487
  case 'bb':
3460
- {
3461
- if (typeof method.method_length !== 'number' || typeof method.stddev !== 'number') return;
3462
- break;
3463
- }
3488
+ if (typeof method.method_length !== 'number' || typeof method.stddev !== 'number') return;
3489
+ break;
3464
3490
  case 'rsi':
3465
3491
  case 'quantity':
3466
3492
  case 'momentum':
@@ -3947,7 +3973,7 @@ function Milli_Chart(settings) {
3947
3973
  return 0;
3948
3974
  };
3949
3975
 
3950
- function fetchNews(indicator) {
3976
+ function fetchNews(indicator,alreadyadded) {
3951
3977
  var url = milli_data_api_url + "widget=chartnews&token=" + _this.settings.token + "&target=buildwidget&fields=headline,date,time&language=" + "sv" + "&insref=" + indicator.insrefs.toString() + '&xhr=' + (_this.settings.xhr == true ? '1' : '0');
3952
3978
  url += '&instruments=' + _this.instruments[0].insref;
3953
3979
 
@@ -3967,7 +3993,8 @@ function Milli_Chart(settings) {
3967
3993
  });
3968
3994
  indicator.method = 'news';
3969
3995
  indicator.type = NEWSINDICATOR;
3970
- _this.addIndicator(indicator);
3996
+ if(alreadyadded == false) _this.addIndicator(indicator);
3997
+ else _this.drawChart();
3971
3998
  requestStreaming();
3972
3999
  });
3973
4000
  }
@@ -3978,11 +4005,11 @@ function Milli_Chart(settings) {
3978
4005
  var i;
3979
4006
  for (i = 0; i < _this.settings.indicators.length; i++) {
3980
4007
  if (_this.settings.indicators[i].method == indicator.method) {
3981
- _this.removeIndicator(_this.settings.indicators[i]);
3982
- return;
4008
+ return _this.removeIndicator(_this.settings.indicators[i]);
3983
4009
  }
3984
4010
  }
3985
- fetchNews(indicator);
4011
+ fetchNews(indicator,false);
4012
+ return true;
3986
4013
  };
3987
4014
 
3988
4015
  function setHighDPIContext(context)
@@ -4178,6 +4205,12 @@ function Milli_Chart(settings) {
4178
4205
  hashmap: new Map(),
4179
4206
  intradayQuantity: []
4180
4207
  };
4208
+ for(let i = 0; i < _this.settings.indicators.length; i++) {
4209
+ if(_this.settings.indicators[i].method == 'news' || _this.settings.indicators[i].type == NEWSINDICATOR) {
4210
+ fetchNews(_this.settings.indicators[i],true);
4211
+ break;
4212
+ }
4213
+ }
4181
4214
 
4182
4215
  if (_this.settings.intradaylen) {
4183
4216
  var d = new Date().getTime();
@@ -4219,12 +4252,6 @@ function Milli_Chart(settings) {
4219
4252
  if (insrefs[i] != 0)
4220
4253
  this.addCompare(insrefs[i]);
4221
4254
  }
4222
- for (let i = 0; i < _this.settings.indicators.length; i++) {
4223
- if (_this.settings.indicators[i].type == NEWSINDICATOR) {
4224
- fetchNews(_this.settings.indicators[i]);
4225
- break;
4226
- }
4227
- }
4228
4255
  };
4229
4256
  if (this.settings.autodraw == true) {
4230
4257
  this.drawWidget();
@@ -6563,7 +6590,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
6563
6590
  case 'weight':
6564
6591
  return [3201, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
6565
6592
  case '3202':
6566
- case 'listname':
6593
+ case 'preferredlistname':
6567
6594
  return [3202, 'string', 'left', widget.get_lang_text(name) || name, 0];
6568
6595
  case '3203':
6569
6596
  case 'sectorname':
@@ -6630,6 +6657,8 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
6630
6657
  case 'sectorl1name':
6631
6658
  case 'sectorl1symbol':
6632
6659
  return [3312, 'string', 'left', widget.get_lang_text(name) || name, 0];
6660
+ case 'insref':
6661
+ return [3312, 'string', 'right', widget.get_lang_text(name) || name, 0]; // so it will not get thousandseparator etc
6633
6662
  default:
6634
6663
  return [0, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
6635
6664
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@millistream/millistream-widgets",
3
- "version": "1.0.40",
3
+ "version": "1.0.45",
4
4
  "description": "Millistream widgets node package",
5
5
  "main": "millistream-widgets.js",
6
6
  "scripts": {
@@ -11,4 +11,4 @@
11
11
  "repository": {
12
12
  "private": true
13
13
  }
14
- }
14
+ }