@millistream/millistream-widgets 1.0.40 → 1.0.46
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 +181 -100
- package/package.json +2 -2
package/millistream-widgets.js
CHANGED
|
@@ -74,7 +74,8 @@ function Milli_Chart(settings) {
|
|
|
74
74
|
},
|
|
75
75
|
xAxisSpacing: 0,
|
|
76
76
|
yAxisSpacing: 4, // undocumented
|
|
77
|
-
xAxisModulo: 1 // undocumented,
|
|
77
|
+
xAxisModulo: 1, // undocumented,
|
|
78
|
+
cursor: 'crosshair' //'crosshair'
|
|
78
79
|
};
|
|
79
80
|
var m_startdate = null;
|
|
80
81
|
var m_chartspaces = {
|
|
@@ -1087,9 +1088,11 @@ function Milli_Chart(settings) {
|
|
|
1087
1088
|
|
|
1088
1089
|
function checkXLegendSides(x, text) {
|
|
1089
1090
|
// right
|
|
1090
|
-
if
|
|
1091
|
+
if(x + (m_ctx.measureText(text).width / 2) > m_chartspaces.chart.width) return false;
|
|
1092
|
+
//if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left < x + (m_ctx.measureText(text).width / 2)) return false;
|
|
1091
1093
|
// left
|
|
1092
|
-
if (m_chartspaces.chart.left > x - (m_ctx.measureText(text).width / 2)) return false;
|
|
1094
|
+
//if (m_chartspaces.chart.left > x - (m_ctx.measureText(text).width / 2)) return false;
|
|
1095
|
+
if (0 > x - (m_ctx.measureText(text).width / 2)) return false;
|
|
1093
1096
|
return true;
|
|
1094
1097
|
|
|
1095
1098
|
}
|
|
@@ -1257,11 +1260,12 @@ function Milli_Chart(settings) {
|
|
|
1257
1260
|
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1258
1261
|
}
|
|
1259
1262
|
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
|
|
1263
|
+
//if (lastx == 0 && m_chartspaces.chart.left > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
|
|
1264
|
+
if (lastx == 0 && 0 > 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) {
|
|
@@ -1765,6 +1769,48 @@ function Milli_Chart(settings) {
|
|
|
1765
1769
|
if (m_zoom.mousedown && m_zoom.mousedown.pos != m_zoom.mouseup.pos) return;
|
|
1766
1770
|
}
|
|
1767
1771
|
|
|
1772
|
+
function findClosestValue(dataset, target) {
|
|
1773
|
+
//returns closest value and position in array
|
|
1774
|
+
let left = 0;
|
|
1775
|
+
let right = dataset.length - 1;
|
|
1776
|
+
let closest = null;
|
|
1777
|
+
let iterations = 0;
|
|
1778
|
+
let mid;
|
|
1779
|
+
while (left <= right) {
|
|
1780
|
+
iterations++;
|
|
1781
|
+
mid = Math.floor((left + right) / 2);
|
|
1782
|
+
const midValue = dataset[mid];
|
|
1783
|
+
|
|
1784
|
+
if (midValue === target) {
|
|
1785
|
+
return [midValue,mid];
|
|
1786
|
+
}
|
|
1787
|
+
|
|
1788
|
+
if (closest === null || Math.abs(midValue - target) < Math.abs(closest - target)) {
|
|
1789
|
+
closest = midValue;
|
|
1790
|
+
}
|
|
1791
|
+
|
|
1792
|
+
if (midValue < target) {
|
|
1793
|
+
left = mid + 1;
|
|
1794
|
+
} else {
|
|
1795
|
+
right = mid - 1;
|
|
1796
|
+
}
|
|
1797
|
+
}
|
|
1798
|
+
return [closest,mid];
|
|
1799
|
+
}
|
|
1800
|
+
function getDivHeight(elem) {
|
|
1801
|
+
let style = getComputedStyle(elem);
|
|
1802
|
+
let h = elem.offsetHeight + parseInt(style.marginBottom) + parseInt(style.marginTop);
|
|
1803
|
+
let divs = elem.children;
|
|
1804
|
+
if(divs) {
|
|
1805
|
+
for(let d = 0; d < divs.length; d++) {
|
|
1806
|
+
if(divs[d].nodeName == 'DIV' && divs[d].offsetWidth != 0) {
|
|
1807
|
+
style = getComputedStyle(divs[d]);
|
|
1808
|
+
h = Math.max(h,divs[d].offsetHeight + parseInt(style.marginBottom) + parseInt(style.marginTop));
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
return h;
|
|
1813
|
+
}
|
|
1768
1814
|
function onMouseMove(pos) {
|
|
1769
1815
|
if (m_dataPoints.arr.length == 0) return;
|
|
1770
1816
|
var rect = m_canvas.getBoundingClientRect();
|
|
@@ -1790,28 +1836,39 @@ function Milli_Chart(settings) {
|
|
|
1790
1836
|
onMouseOut();
|
|
1791
1837
|
return;
|
|
1792
1838
|
}
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1839
|
+
let obj = [];
|
|
1840
|
+
let i;
|
|
1841
|
+
let a = findClosestValue(m_dataPoints.arr,x); // closest and pos
|
|
1842
|
+
|
|
1843
|
+
for(let s = 0; s < _this.instruments.length; s++) {
|
|
1844
|
+
if(_this.instruments[s].insref != 0) {
|
|
1845
|
+
//for (i = 0; i < m_dataPoints.arr.length; i++) {
|
|
1846
|
+
//for (i = m_dataPoints.arr.length - 1; i >= 0; i--) {
|
|
1847
|
+
for (i = a[1]; i >= 0; i--) {
|
|
1848
|
+
if (x >= m_dataPoints.arr[i]) {
|
|
1849
|
+
let o = m_dataPoints.map.get(m_dataPoints.arr[i]);
|
|
1850
|
+
let breakout = false;
|
|
1851
|
+
for(let ss = 0; ss < o.instruments.length; ss++) {
|
|
1852
|
+
if(o.instruments[ss] && o.instruments[ss].insref == _this.instruments[s].insref) {
|
|
1853
|
+
obj[s] = {timestamp: o.timestamp,instruments: o.instruments[ss]};
|
|
1854
|
+
breakout = true;
|
|
1855
|
+
break;
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
if(breakout) break;
|
|
1859
|
+
}
|
|
1860
|
+
}
|
|
1797
1861
|
}
|
|
1798
1862
|
}
|
|
1799
|
-
if (
|
|
1800
|
-
if (i != 0) {
|
|
1801
|
-
if (Math.abs(x - m_dataPoints.arr[i]) > Math.abs(x - m_dataPoints.arr[i - 1]))
|
|
1802
|
-
i--;
|
|
1803
|
-
}
|
|
1804
|
-
var obj = m_dataPoints.map.get(m_dataPoints.arr[i]);
|
|
1805
|
-
if (obj == null) {
|
|
1863
|
+
if (obj.length == 0) {
|
|
1806
1864
|
return;
|
|
1807
1865
|
}
|
|
1808
|
-
var highy = -1;
|
|
1809
|
-
var lowy = m_chartspaces.chart.height;
|
|
1810
1866
|
var toolArray = [];
|
|
1811
1867
|
let pointerWidth = 0;
|
|
1812
1868
|
for (x = 0; x < _this.instruments.length; x++) {
|
|
1813
|
-
if (_this.instruments[x].insref != 0 && typeof obj.instruments[x] !== 'undefined') {
|
|
1814
|
-
|
|
1869
|
+
//if (_this.instruments[x].insref != 0 && typeof obj.instruments[x] !== 'undefined') {
|
|
1870
|
+
if (_this.instruments[x].insref != 0 && typeof obj[x] !== 'undefined') {
|
|
1871
|
+
var instr = {};
|
|
1815
1872
|
instr.chartType = chartType;
|
|
1816
1873
|
instr.name = _this.instruments[x].name;
|
|
1817
1874
|
instr.instrumenttype = _this.instruments[x].instrumenttype;
|
|
@@ -1820,9 +1877,23 @@ function Milli_Chart(settings) {
|
|
|
1820
1877
|
instr.symbol = _this.instruments[x].symbol;
|
|
1821
1878
|
|
|
1822
1879
|
instr.data = {};
|
|
1823
|
-
MillistreamWidgetApi_AssignObject(obj
|
|
1880
|
+
MillistreamWidgetApi_AssignObject(obj[x].instruments, instr.data);
|
|
1824
1881
|
instr.data.price = formatNiceNumber(instr.data.price, _this.settings.thousandseparator, _this.settings.decimalseparator, _this.settings.num_decimals, false);
|
|
1825
|
-
|
|
1882
|
+
if(x == 0) {
|
|
1883
|
+
for (let s = 0; s < _this.settings.indicators.length; s++) {
|
|
1884
|
+
if(_this.settings.indicators[s].method != 'news') {
|
|
1885
|
+
for(let ss = 0; ss < _this.settings.indicators[s].timeseries.length;ss++) {
|
|
1886
|
+
if(_this.settings.indicators[s].timeseries[ss].timestamp <= instr.data.timestamp) {
|
|
1887
|
+
instr.data.indicator = {
|
|
1888
|
+
method: _this.settings.indicators[s].method,
|
|
1889
|
+
datapoints: _this.settings.indicators[s].timeseries[ss].datapoints
|
|
1890
|
+
};
|
|
1891
|
+
} else break;
|
|
1892
|
+
}
|
|
1893
|
+
}
|
|
1894
|
+
}
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1826
1897
|
if (typeof _this.instruments[x].toolTip === 'undefined') {
|
|
1827
1898
|
// add textdiv
|
|
1828
1899
|
_this.instruments[x].toolTip = document.createElement('div');
|
|
@@ -1835,29 +1906,33 @@ function Milli_Chart(settings) {
|
|
|
1835
1906
|
m_canvas.parentNode.appendChild(_this.instruments[x].toolTipPointer);
|
|
1836
1907
|
_this.instruments[x].toolTipPointer.setAttribute('class', 'millistream-chart-pointer');
|
|
1837
1908
|
_this.instruments[x].toolTipPointer.style.left = (m_dataPoints.arr[i] - (_this.instruments[x].toolTipPointer.clientWidth / 2)) + 'px';
|
|
1838
|
-
_this.instruments[x].toolTipPointer.style.top = (obj
|
|
1909
|
+
_this.instruments[x].toolTipPointer.style.top = (obj[x].instruments.y - (_this.instruments[x].toolTipPointer.clientHeight / 2)) + 'px';
|
|
1839
1910
|
_this.instruments[x].toolTipPointer.style.position = 'absolute';
|
|
1840
1911
|
_this.instruments[x].toolTipPointer.style.backgroundColor = typeof m_instrumentCss[x].pointerColor === 'string' ? m_instrumentCss[x].pointerColor : m_instrumentCss[x].color;
|
|
1841
1912
|
_this.instruments[x].toolTipPointer.style.pointerEvents = 'none';
|
|
1842
1913
|
|
|
1843
1914
|
}
|
|
1915
|
+
_this.instruments[x].toolTip.innerHTML = _this.settings.tooltip.formatter.call(instr, m_chartspaces, obj[x].instruments.x);
|
|
1844
1916
|
var pointerStyle = getComputedStyle(_this.instruments[x].toolTipPointer);
|
|
1845
|
-
pointerWidth = _this.instruments[x].toolTipPointer.offsetWidth + parseInt(pointerStyle.marginLeft) + parseInt(pointerStyle.marginRight);
|
|
1917
|
+
pointerWidth = _this.instruments[x].toolTipPointer.offsetWidth + parseInt(pointerStyle.marginLeft) + (parseInt(pointerStyle.marginRight));
|
|
1846
1918
|
var pointerHeight = _this.instruments[x].toolTipPointer.offsetHeight + parseInt(pointerStyle.marginTop) + parseInt(pointerStyle.marginBottom);
|
|
1847
|
-
var posy = obj
|
|
1919
|
+
var posy = obj[x].instruments.y - (getDivHeight(_this.instruments[x].toolTip ) / 2);
|
|
1920
|
+
//var posy = obj[x].instruments.y - (_this.instruments[x].toolTip.offsetHeight / 2);
|
|
1848
1921
|
_this.instruments[x].toolTip.style.top = posy + 'px';
|
|
1849
|
-
toolArray.push({ top: (obj
|
|
1850
|
-
_this.instruments[x].toolTipPointer.style.left = (obj
|
|
1851
|
-
_this.instruments[x].toolTipPointer.style.top = (obj
|
|
1852
|
-
|
|
1853
|
-
|
|
1854
|
-
|
|
1855
|
-
|
|
1922
|
+
toolArray.push({ top: (obj[x].instruments.y - (pointerHeight / 2)), instrument: x });
|
|
1923
|
+
_this.instruments[x].toolTipPointer.style.left = (obj[x].instruments.x - (pointerWidth / 2)) + 1 + 'px'; // hmm plus 1??
|
|
1924
|
+
_this.instruments[x].toolTipPointer.style.top = (obj[x].instruments.y - (pointerHeight / 2)) + 'px';
|
|
1925
|
+
let divs = _this.instruments[x].toolTip.children;
|
|
1926
|
+
let width = _this.instruments[x].toolTip.offsetWidth;
|
|
1927
|
+
for(let d = 0; d < divs.length; d++) {
|
|
1928
|
+
if(divs[d].nodeName == 'DIV' && divs[d].offsetWidth != 0) width = Math.max(width,divs[d].offsetWidth);
|
|
1929
|
+
}
|
|
1930
|
+
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
1931
|
// draw the hover to the left
|
|
1857
|
-
_this.instruments[x].toolTip.style.left = (obj
|
|
1932
|
+
_this.instruments[x].toolTip.style.left = (obj[x].instruments.x - width - (pointerWidth / 2)) + 1 + 'px';
|
|
1858
1933
|
} else {
|
|
1859
1934
|
// draw hover to the right
|
|
1860
|
-
_this.instruments[x].toolTip.style.left = (obj
|
|
1935
|
+
_this.instruments[x].toolTip.style.left = (obj[x].instruments.x + (pointerWidth / 2)) + 'px';
|
|
1861
1936
|
}
|
|
1862
1937
|
} else {
|
|
1863
1938
|
if (_this.instruments[x].toolTip) {
|
|
@@ -1868,17 +1943,26 @@ function Milli_Chart(settings) {
|
|
|
1868
1943
|
}
|
|
1869
1944
|
}
|
|
1870
1945
|
}
|
|
1946
|
+
|
|
1871
1947
|
//indicator hover
|
|
1872
1948
|
for (x = 0; x < _this.settings.indicators.length; x++) {
|
|
1873
1949
|
var px = getScaledSetting(pos.clientX) - getScaledSetting(rect.left) - 1;
|
|
1874
1950
|
if (typeof _this.settings.indicators[x].toolTip === 'undefined') continue;
|
|
1875
1951
|
if (_this.settings.indicators[x].staticTooltip == true) continue;
|
|
1876
|
-
|
|
1877
|
-
|
|
1952
|
+
let width = 5;
|
|
1953
|
+
let height = 5;
|
|
1954
|
+
let remove = true;
|
|
1955
|
+
if(typeof _this.settings.indicators[x].image !== 'undefined') {
|
|
1956
|
+
width = _this.settings.indicators[x].image.width;
|
|
1957
|
+
height = _this.settings.indicators[x].image.height;
|
|
1958
|
+
} else {
|
|
1959
|
+
width = m_ctx.measureText(_this.settings.indicators[x].indicator).width;
|
|
1960
|
+
height = parseInt(_this.settings.indicators[x].fontSize);
|
|
1961
|
+
}
|
|
1878
1962
|
for (var xx = 0; xx < _this.settings.indicators[x].timeseries.length; xx++) {
|
|
1879
1963
|
if (typeof _this.settings.indicators[x].timeseries[xx].pos === 'undefined') continue;
|
|
1880
1964
|
if (typeof _this.settings.indicators[x].timeseries[xx].hl === 'undefined') continue;
|
|
1881
|
-
if (px >= _this.settings.indicators[x].timeseries[xx].pos.x -
|
|
1965
|
+
if (px >= _this.settings.indicators[x].timeseries[xx].pos.x -(width/2) && px < _this.settings.indicators[x].timeseries[xx].pos.x + (width/2)) {
|
|
1882
1966
|
if (typeof _this.settings.indicators[x].toolTip.div === 'undefined') {
|
|
1883
1967
|
_this.settings.indicators[x].toolTip.div = document.createElement('div');
|
|
1884
1968
|
_this.settings.indicators[x].toolTip.div.style.display = _this.settings.tooltip.display;
|
|
@@ -1887,23 +1971,25 @@ function Milli_Chart(settings) {
|
|
|
1887
1971
|
m_canvas.parentNode.appendChild(_this.settings.indicators[x].toolTip.div);
|
|
1888
1972
|
}
|
|
1889
1973
|
_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
|
-
_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
|
|
1974
|
+
//_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
|
|
1975
|
+
_this.settings.indicators[x].toolTip.div.style.top = toolArray[0].top + 2 + 'px'; // this i modified in the data for the instruments, but not for indicators
|
|
1976
|
+
|
|
1891
1977
|
_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)
|
|
1978
|
+
if (y > _this.settings.indicators[x].timeseries[xx].pos.y -(height/2) && y < _this.settings.indicators[x].timeseries[xx].pos.y + (height/2))
|
|
1894
1979
|
m_canvas.style.cursor = "pointer";
|
|
1895
|
-
else
|
|
1896
|
-
m_canvas.style.cursor =
|
|
1980
|
+
else {
|
|
1981
|
+
m_canvas.style.cursor = _this.settings.cursor;
|
|
1982
|
+
}
|
|
1897
1983
|
remove = false;
|
|
1898
1984
|
toolArray.push({ top: parseInt(_this.settings.indicators[x].toolTip.div.style.top), indicator: x });
|
|
1899
|
-
}
|
|
1985
|
+
}
|
|
1900
1986
|
|
|
1901
1987
|
}
|
|
1902
1988
|
if (remove) {
|
|
1903
1989
|
if (_this.settings.indicators[x].toolTip.div && _this.settings.indicators[x].staticTooltip != true) {
|
|
1904
1990
|
_this.settings.indicators[x].toolTip.div.parentNode.removeChild(_this.settings.indicators[x].toolTip.div);
|
|
1905
1991
|
_this.settings.indicators[x].toolTip.div = undefined;
|
|
1906
|
-
m_canvas.style.cursor =
|
|
1992
|
+
m_canvas.style.cursor = _this.settings.cursor;
|
|
1907
1993
|
}
|
|
1908
1994
|
|
|
1909
1995
|
}
|
|
@@ -1913,26 +1999,20 @@ function Milli_Chart(settings) {
|
|
|
1913
1999
|
let lastHeight = 0;
|
|
1914
2000
|
for (x = 0; x < toolArray.length; x++) {
|
|
1915
2001
|
if (typeof toolArray[x].instrument !== 'undefined') {
|
|
1916
|
-
//if (x != 0 && typeof _this.instruments[x - 1].toolTip !== 'undefined') {
|
|
1917
|
-
//if (lastTop + _this.instruments[x - 1].toolTip.offsetHeight > toolArray[x].top) {
|
|
1918
2002
|
if (lastTop + lastHeight > toolArray[x].top) {
|
|
1919
|
-
|
|
1920
|
-
toolArray[x].top = (lastTop + lastHeight);
|
|
2003
|
+
toolArray[x].top = (lastTop + lastHeight)+1;
|
|
1921
2004
|
}
|
|
1922
|
-
//}
|
|
1923
2005
|
} else {
|
|
1924
|
-
//if (lastTop + _this.settings.indicators[toolArray[x].indicator].toolTip.div.offsetHeight > toolArray[x].top) {
|
|
1925
2006
|
if (lastTop + lastHeight > toolArray[x].top) {
|
|
1926
|
-
//toolArray[x].top = (lastTop + _this.settings.indicators[toolArray[x].indicator].toolTip.div.offsetHeight);
|
|
1927
2007
|
toolArray[x].top = (lastTop + lastHeight);
|
|
1928
2008
|
}
|
|
1929
2009
|
}
|
|
1930
2010
|
if (typeof toolArray[x].instrument !== 'undefined') {
|
|
1931
2011
|
_this.instruments[toolArray[x].instrument].toolTip.style.top = toolArray[x].top + 'px';
|
|
1932
|
-
lastHeight = _this.instruments[toolArray[x].instrument].toolTip
|
|
2012
|
+
lastHeight = getDivHeight(_this.instruments[toolArray[x].instrument].toolTip);
|
|
1933
2013
|
} else {
|
|
1934
2014
|
_this.settings.indicators[toolArray[x].indicator].toolTip.div.style.top = toolArray[x].top + 'px';
|
|
1935
|
-
lastHeight = _this.settings.indicators[toolArray[x].indicator].toolTip.div
|
|
2015
|
+
lastHeight = getDivHeight(_this.settings.indicators[toolArray[x].indicator].toolTip.div);
|
|
1936
2016
|
}
|
|
1937
2017
|
lastTop = toolArray[x].top;
|
|
1938
2018
|
}
|
|
@@ -1968,7 +2048,10 @@ function Milli_Chart(settings) {
|
|
|
1968
2048
|
m_zoom.mouseup.timestamp = new Date().toISOString().split('T')[0];
|
|
1969
2049
|
m_zoom.mouseup.timestamp = new Date(m_zoom.mouseup.timestamp + 'T00:00:00Z');
|
|
1970
2050
|
}
|
|
1971
|
-
|
|
2051
|
+
if(366 > dateDiffInDays(m_zoom.mousedown.timestamp ,m_zoom.mouseup.timestamp ))
|
|
2052
|
+
_this.settings.chartlen = 'ytd';
|
|
2053
|
+
else
|
|
2054
|
+
_this.settings.chartlen = 'max';
|
|
1972
2055
|
chartType = 'history';
|
|
1973
2056
|
_this.drawChart();
|
|
1974
2057
|
};
|
|
@@ -2028,10 +2111,10 @@ function Milli_Chart(settings) {
|
|
|
2028
2111
|
m_chartspaces.chart.marginTop = getScaledSetting(m_chartCss.marginTop);
|
|
2029
2112
|
m_chartspaces.chart.top = m_chartspaces.chart.marginTop;
|
|
2030
2113
|
m_chartspaces.chart.left = getScaledSetting(m_chartCss.marginLeft);
|
|
2031
|
-
m_chartspaces.chart.right = m_canvas.getWidth()- getScaledSetting(m_chartCss.marginRight) - 50;
|
|
2114
|
+
m_chartspaces.chart.right = m_canvas.getWidth()- getScaledSetting(m_chartCss.marginRight);// - 50;
|
|
2032
2115
|
m_chartspaces.chart.marginBottom = getScaledSetting(m_chartCss.marginBottom);
|
|
2033
2116
|
m_chartspaces.chart.bottom = (m_chartspaces.chart.height - m_chartspaces.chart.marginBottom);
|
|
2034
|
-
m_chartspaces.chart.width = m_canvas.getWidth()
|
|
2117
|
+
m_chartspaces.chart.width = m_canvas.getWidth();
|
|
2035
2118
|
|
|
2036
2119
|
m_chartspaces.lowerChart.marginBottom = getScaledSetting(20) / window.devicePixelRatio;
|
|
2037
2120
|
m_chartspaces.lowerChart.marginTop = getScaledSetting(0);
|
|
@@ -2040,7 +2123,7 @@ function Milli_Chart(settings) {
|
|
|
2040
2123
|
m_chartspaces.lowerChart.left = m_chartspaces.chart.left;
|
|
2041
2124
|
m_chartspaces.lowerChart.right = m_chartspaces.chart.right;
|
|
2042
2125
|
m_chartspaces.lowerChart.bottom = m_canvas.getHeight() - m_chartspaces.lowerChart.marginBottom;
|
|
2043
|
-
m_chartspaces.lowerChart.width = m_canvas.getWidth()
|
|
2126
|
+
m_chartspaces.lowerChart.width = m_canvas.getWidth();
|
|
2044
2127
|
}
|
|
2045
2128
|
|
|
2046
2129
|
function calculateIndicators() {
|
|
@@ -2107,17 +2190,18 @@ function Milli_Chart(settings) {
|
|
|
2107
2190
|
if (m_dataPoints.map) m_dataPoints.map.clear();
|
|
2108
2191
|
m_dataPoints.map = new Map();
|
|
2109
2192
|
m_dataPoints.arr = [];
|
|
2193
|
+
|
|
2110
2194
|
if (_this.instruments.length < 0) {
|
|
2111
2195
|
console.log('no chartdata');
|
|
2112
2196
|
return;
|
|
2113
2197
|
}
|
|
2114
2198
|
calcChartSpaces();
|
|
2115
|
-
|
|
2116
2199
|
m_ctx.clearRect(0, 0, m_canvas.getWidth(), m_canvas.getHeight());
|
|
2117
2200
|
m_ctx.lineWidth = 1 / 1;
|
|
2118
2201
|
m_ctx.textBaseline = 'top'; // important!
|
|
2119
2202
|
var s;
|
|
2120
2203
|
if (period == 'd' && _this.settings.chartlen != 'ytd') {
|
|
2204
|
+
if(_this.instruments[0].trades.length == 0) return;
|
|
2121
2205
|
if (m_zoom.mousedown.timestamp) {
|
|
2122
2206
|
_this.scaleinfoX.endTimeStamp = m_zoom.mouseup.timestamp > m_zoom.mousedown.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
|
|
2123
2207
|
_this.scaleinfoX.startTimeStamp = m_zoom.mouseup.timestamp < m_zoom.mousedown.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
|
|
@@ -2144,17 +2228,14 @@ function Milli_Chart(settings) {
|
|
|
2144
2228
|
|
|
2145
2229
|
var tradetimestamp = new Date(_this.instruments[0].trades[_this.instruments[0].trades.length - 1].timestamp).getTime();
|
|
2146
2230
|
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();
|
|
2147
|
-
//console.log(tradetimestamp,closetimestamp);
|
|
2148
2231
|
if (closetimestamp < tradetimestamp)
|
|
2149
2232
|
_this.scaleinfoX.endTimeStamp = new Date(closetimestamp); // borde inte rita med closeprice1d då heller eller spelar det ingen roll?
|
|
2150
2233
|
else
|
|
2151
2234
|
_this.scaleinfoX.endTimeStamp = new Date(tradetimestamp);
|
|
2152
|
-
//console.log(new Date(_this.scaleinfoX.endTimeStamp));
|
|
2153
2235
|
}
|
|
2154
2236
|
if (_this.scaleinfoX.endTimeStamp - (_this.scaleinfoX.endTimeStamp % 86400000) > _this.instruments[0].quotedate) {
|
|
2155
2237
|
_this.scaleinfoX.endTimeStamp -= _this.scaleinfoX.endTimeStamp - _this.scaleinfoX.endTimeStamp % 86400000;
|
|
2156
2238
|
_this.scaleinfoX.endTimeStamp += _this.instruments[0].quotedate; // set enddate = last Quotedate
|
|
2157
|
-
//console.log('asdasd',new Date(_this.scaleinfoX.endTimeStamp));
|
|
2158
2239
|
}
|
|
2159
2240
|
|
|
2160
2241
|
for (var i = 0; i < _this.settings.indicators.length; i++) {
|
|
@@ -2164,7 +2245,6 @@ function Milli_Chart(settings) {
|
|
|
2164
2245
|
}
|
|
2165
2246
|
}
|
|
2166
2247
|
}
|
|
2167
|
-
//console.log(new Date(_this.scaleinfoX.startTimeStamp),new Date(_this.scaleinfoX.endTimeStamp),new Date(_this.instruments[0].quotedate));
|
|
2168
2248
|
setTimeSpanData();
|
|
2169
2249
|
if (_this.settings.absoluteScaling == true) {
|
|
2170
2250
|
for (s = 1; s < _this.instruments.length; s++) _this.instruments[s].factor = 1;
|
|
@@ -2172,7 +2252,7 @@ function Milli_Chart(settings) {
|
|
|
2172
2252
|
if (_this.instruments.length > 1) {
|
|
2173
2253
|
// calc factors
|
|
2174
2254
|
var instrumentprice;
|
|
2175
|
-
for (i = 0; i < _this.instruments[0].trades.length; i++) {
|
|
2255
|
+
for (let i = 0; i < _this.instruments[0].trades.length; i++) {
|
|
2176
2256
|
if (_this.instruments[0].trades[i].timestamp >= _this.scaleinfoX.startTimeStamp) {
|
|
2177
2257
|
instrumentprice = _this.instruments[0].trades[i].price;
|
|
2178
2258
|
break;
|
|
@@ -2180,7 +2260,7 @@ function Milli_Chart(settings) {
|
|
|
2180
2260
|
}
|
|
2181
2261
|
for (s = 1; s < _this.instruments.length; s++) {
|
|
2182
2262
|
if (_this.instruments[s].insref != 0) {
|
|
2183
|
-
for (i = 0; i < _this.instruments[s].trades.length; i++) {
|
|
2263
|
+
for (let i = 0; i < _this.instruments[s].trades.length; i++) {
|
|
2184
2264
|
if (_this.instruments[s].trades[i].timestamp >= _this.scaleinfoX.startTimeStamp) {
|
|
2185
2265
|
_this.instruments[s].factor = instrumentprice / _this.instruments[s].trades[i].price;
|
|
2186
2266
|
break;
|
|
@@ -2229,7 +2309,7 @@ function Milli_Chart(settings) {
|
|
|
2229
2309
|
|
|
2230
2310
|
} else
|
|
2231
2311
|
if (period == 'm') {
|
|
2232
|
-
|
|
2312
|
+
if(_this.instruments[0].history.length == 0) return;
|
|
2233
2313
|
if (m_zoom.mousedown.timestamp) {
|
|
2234
2314
|
_this.scaleinfoX.startTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
|
|
2235
2315
|
_this.scaleinfoX.endTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mousedown.timestamp : m_zoom.mouseup.timestamp;
|
|
@@ -2298,6 +2378,7 @@ function Milli_Chart(settings) {
|
|
|
2298
2378
|
}
|
|
2299
2379
|
} else
|
|
2300
2380
|
if ((period == 'y' || _this.settings.chartlen == 'ytd' || _this.settings.chartlen == 'max')) {
|
|
2381
|
+
if(_this.instruments[0].history.length == 0) return;
|
|
2301
2382
|
if (m_zoom.mousedown.timestamp) {
|
|
2302
2383
|
_this.scaleinfoX.startTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
|
|
2303
2384
|
_this.scaleinfoX.startTimeStamp -= (_this.scaleinfoX.startTimeStamp % 3600000);
|
|
@@ -2404,7 +2485,6 @@ function Milli_Chart(settings) {
|
|
|
2404
2485
|
case 'rsi':
|
|
2405
2486
|
if (chartType == 'history') _this.settings.indicators[i].timeseries = calculateRSI(_this.instruments[0].history, _this.settings.indicators[i].method_length);
|
|
2406
2487
|
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
2488
|
if (_this.settings.indicators[i].target == 'upper') {
|
|
2409
2489
|
lowerScale = drawYAxisIndicator(_this.settings.indicators[i].timeseries, m_chartspaces.chart, false);
|
|
2410
2490
|
plotIndicatorLine(_this.settings.indicators[i], lowerScale, m_chartspaces.chart);
|
|
@@ -2785,7 +2865,6 @@ function Milli_Chart(settings) {
|
|
|
2785
2865
|
let lastPos = null;
|
|
2786
2866
|
for (var i = start - 1; i >= 0; i--) {
|
|
2787
2867
|
if (typeof data[i].pos === 'undefined') {
|
|
2788
|
-
console.log(i);
|
|
2789
2868
|
break;
|
|
2790
2869
|
}
|
|
2791
2870
|
m_ctx.lineTo(data[i].pos.x, data[i].pos.y);
|
|
@@ -2839,9 +2918,10 @@ function Milli_Chart(settings) {
|
|
|
2839
2918
|
} else if (method.indicator) {
|
|
2840
2919
|
m_ctx.fillStyle = method.color;
|
|
2841
2920
|
width = m_ctx.measureText(method.indicator).width;
|
|
2921
|
+
let height = parseInt(method.fontSize);
|
|
2842
2922
|
if (method.type == NEWSINDICATOR) {
|
|
2843
|
-
if (fabs(lastPos.x - data[i].pos.x) > width || fabs(lastPos.y > data[i].pos.y) >
|
|
2844
|
-
m_ctx.fillText(method.indicator, data[i].pos.x - (width / 2), data[i].pos.y);
|
|
2923
|
+
if (fabs(lastPos.x - data[i].pos.x) > width || fabs(lastPos.y > data[i].pos.y) > height) {
|
|
2924
|
+
m_ctx.fillText(method.indicator, data[i].pos.x - (width / 2), data[i].pos.y - (height/2));
|
|
2845
2925
|
lastPos = { x: data[i].pos.x, y: data[i].y };
|
|
2846
2926
|
method.timeseries[i].hl = [{ timestamp: data[i].timestamp, headline: data[i].headline,newsid: data[i].newsid }];
|
|
2847
2927
|
hlPos = i;
|
|
@@ -3257,10 +3337,8 @@ function Milli_Chart(settings) {
|
|
|
3257
3337
|
let newstimestamp = data[i].timestamp;
|
|
3258
3338
|
if(data[i].timestamp < (data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].opentimestamp)) {
|
|
3259
3339
|
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
3340
|
} else if(data[i].timestamp > (data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].closetimestamp)) {
|
|
3262
3341
|
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
3342
|
}
|
|
3265
3343
|
if (newstimestamp >= _this.scaleinfoX.startTimeStamp) {
|
|
3266
3344
|
let item = null;
|
|
@@ -3284,7 +3362,6 @@ function Milli_Chart(settings) {
|
|
|
3284
3362
|
if(item) timeseries.push(item);
|
|
3285
3363
|
}
|
|
3286
3364
|
}
|
|
3287
|
-
console.log(timeseries);
|
|
3288
3365
|
return timeseries;
|
|
3289
3366
|
}
|
|
3290
3367
|
|
|
@@ -3447,20 +3524,14 @@ function Milli_Chart(settings) {
|
|
|
3447
3524
|
if (indicatorAlreadyExists(method)) return;
|
|
3448
3525
|
switch (method.method) {
|
|
3449
3526
|
case 'sma':
|
|
3450
|
-
|
|
3451
|
-
if (typeof method.method_length !== 'number') return;
|
|
3452
|
-
}
|
|
3527
|
+
if (typeof method.method_length !== 'number') return;
|
|
3453
3528
|
break;
|
|
3454
3529
|
case 'ema':
|
|
3455
|
-
|
|
3456
|
-
|
|
3457
|
-
break;
|
|
3458
|
-
}
|
|
3530
|
+
if (typeof method.method_length !== 'number') return;
|
|
3531
|
+
break;
|
|
3459
3532
|
case 'bb':
|
|
3460
|
-
|
|
3461
|
-
|
|
3462
|
-
break;
|
|
3463
|
-
}
|
|
3533
|
+
if (typeof method.method_length !== 'number' || typeof method.stddev !== 'number') return;
|
|
3534
|
+
break;
|
|
3464
3535
|
case 'rsi':
|
|
3465
3536
|
case 'quantity':
|
|
3466
3537
|
case 'momentum':
|
|
@@ -3610,8 +3681,9 @@ function Milli_Chart(settings) {
|
|
|
3610
3681
|
parseData(resp[0], 1);
|
|
3611
3682
|
var period = _this.settings.chartlen.substring(_this.settings.chartlen.length - 1);
|
|
3612
3683
|
var len = parseInt(_this.settings.chartlen.substring(0, _this.settings.chartlen.length - 1));
|
|
3613
|
-
if ((period == 'd' && _this.settings.chartlen != 'ytd') && typeof resp[0].trades === 'undefined') {
|
|
3614
|
-
|
|
3684
|
+
//if ((period == 'd' && _this.settings.chartlen != 'ytd') && typeof resp[0].trades === 'undefined') {
|
|
3685
|
+
if ((period == 'd' && _this.settings.chartlen != 'ytd') && typeof _this.instruments[0].trades === 'undefined' ) {
|
|
3686
|
+
return;
|
|
3615
3687
|
}
|
|
3616
3688
|
if ((period == 'm' || period == 'y' || _this.settings.chartlen == 'ytd' || _this.settings.chartlen == 'max') && typeof resp[0].history === 'undefined') {
|
|
3617
3689
|
return;
|
|
@@ -3625,7 +3697,7 @@ function Milli_Chart(settings) {
|
|
|
3625
3697
|
setChartSize();
|
|
3626
3698
|
m_canvas.addEventListener('mousemove', onMouseMove, false); // disable while loading and enable on drawReady
|
|
3627
3699
|
m_canvas.addEventListener('mouseout', onMouseOut, false);
|
|
3628
|
-
m_canvas.style.cursor = "crosshair";
|
|
3700
|
+
m_canvas.style.cursor = _this.settings.cursor; //"crosshair";
|
|
3629
3701
|
m_canvas.onmousedown = (function(evt) {
|
|
3630
3702
|
if (evt.which != 1) return; // ignore right and middle
|
|
3631
3703
|
var rect = m_canvas.getBoundingClientRect();
|
|
@@ -3947,7 +4019,7 @@ function Milli_Chart(settings) {
|
|
|
3947
4019
|
return 0;
|
|
3948
4020
|
};
|
|
3949
4021
|
|
|
3950
|
-
function fetchNews(indicator) {
|
|
4022
|
+
function fetchNews(indicator,alreadyadded) {
|
|
3951
4023
|
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
4024
|
url += '&instruments=' + _this.instruments[0].insref;
|
|
3953
4025
|
|
|
@@ -3967,7 +4039,8 @@ function Milli_Chart(settings) {
|
|
|
3967
4039
|
});
|
|
3968
4040
|
indicator.method = 'news';
|
|
3969
4041
|
indicator.type = NEWSINDICATOR;
|
|
3970
|
-
_this.addIndicator(indicator);
|
|
4042
|
+
if(alreadyadded == false) _this.addIndicator(indicator);
|
|
4043
|
+
else _this.drawChart();
|
|
3971
4044
|
requestStreaming();
|
|
3972
4045
|
});
|
|
3973
4046
|
}
|
|
@@ -3978,11 +4051,11 @@ function Milli_Chart(settings) {
|
|
|
3978
4051
|
var i;
|
|
3979
4052
|
for (i = 0; i < _this.settings.indicators.length; i++) {
|
|
3980
4053
|
if (_this.settings.indicators[i].method == indicator.method) {
|
|
3981
|
-
_this.removeIndicator(_this.settings.indicators[i]);
|
|
3982
|
-
return;
|
|
4054
|
+
return _this.removeIndicator(_this.settings.indicators[i]);
|
|
3983
4055
|
}
|
|
3984
4056
|
}
|
|
3985
|
-
fetchNews(indicator);
|
|
4057
|
+
fetchNews(indicator,false);
|
|
4058
|
+
return true;
|
|
3986
4059
|
};
|
|
3987
4060
|
|
|
3988
4061
|
function setHighDPIContext(context)
|
|
@@ -4178,6 +4251,12 @@ function Milli_Chart(settings) {
|
|
|
4178
4251
|
hashmap: new Map(),
|
|
4179
4252
|
intradayQuantity: []
|
|
4180
4253
|
};
|
|
4254
|
+
for(let i = 0; i < _this.settings.indicators.length; i++) {
|
|
4255
|
+
if(_this.settings.indicators[i].method == 'news' || _this.settings.indicators[i].type == NEWSINDICATOR) {
|
|
4256
|
+
fetchNews(_this.settings.indicators[i],true);
|
|
4257
|
+
break;
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4181
4260
|
|
|
4182
4261
|
if (_this.settings.intradaylen) {
|
|
4183
4262
|
var d = new Date().getTime();
|
|
@@ -4219,12 +4298,6 @@ function Milli_Chart(settings) {
|
|
|
4219
4298
|
if (insrefs[i] != 0)
|
|
4220
4299
|
this.addCompare(insrefs[i]);
|
|
4221
4300
|
}
|
|
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
4301
|
};
|
|
4229
4302
|
if (this.settings.autodraw == true) {
|
|
4230
4303
|
this.drawWidget();
|
|
@@ -6563,7 +6636,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
6563
6636
|
case 'weight':
|
|
6564
6637
|
return [3201, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
|
|
6565
6638
|
case '3202':
|
|
6566
|
-
case '
|
|
6639
|
+
case 'preferredlistname':
|
|
6567
6640
|
return [3202, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
6568
6641
|
case '3203':
|
|
6569
6642
|
case 'sectorname':
|
|
@@ -6630,6 +6703,8 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
|
|
|
6630
6703
|
case 'sectorl1name':
|
|
6631
6704
|
case 'sectorl1symbol':
|
|
6632
6705
|
return [3312, 'string', 'left', widget.get_lang_text(name) || name, 0];
|
|
6706
|
+
case 'insref':
|
|
6707
|
+
return [3312, 'string', 'right', widget.get_lang_text(name) || name, 0]; // so it will not get thousandseparator etc
|
|
6633
6708
|
default:
|
|
6634
6709
|
return [0, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
|
|
6635
6710
|
}
|
|
@@ -6925,9 +7000,15 @@ function formatDate(date, format, widget) {
|
|
|
6925
7000
|
}
|
|
6926
7001
|
if (format == 'b dd') { // Jan 01
|
|
6927
7002
|
timeStamp = new Date(date);
|
|
6928
|
-
|
|
7003
|
+
if(typeof widget.settings.locale !== 'undefined') {
|
|
7004
|
+
mon = timeStamp.toLocaleString(widget.settings.locale, { month: 'short' }).substring(0, 3);
|
|
7005
|
+
}
|
|
7006
|
+
else {
|
|
7007
|
+
mon = timeStamp.toDateString().split(' ');
|
|
7008
|
+
mon = mon[1];
|
|
7009
|
+
}
|
|
6929
7010
|
day = timeStamp.getDate();
|
|
6930
|
-
return mon
|
|
7011
|
+
return mon + ' ' + (day <= 9 ? '0' + day : day);
|
|
6931
7012
|
}
|
|
6932
7013
|
if (format == 'b dd yyyy') { // Jan 01 2017
|
|
6933
7014
|
timeStamp = new Date(date);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@millistream/millistream-widgets",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.46",
|
|
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
|
+
}
|