@millistream/millistream-widgets 0.0.12 → 0.0.15
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 +544 -85
- package/package.json +1 -1
package/millistream-widgets.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
function Milli_Chart(settings) {
|
|
2
4
|
var _this = this;
|
|
3
5
|
_this.mdf_fields = [];
|
|
@@ -41,7 +43,7 @@ function Milli_Chart(settings) {
|
|
|
41
43
|
hcurve: false,
|
|
42
44
|
adjusted: true,
|
|
43
45
|
nochartlabel: "No data to draw on",
|
|
44
|
-
|
|
46
|
+
yearLabelsPos: 'bottom'
|
|
45
47
|
};
|
|
46
48
|
_this.unsubscriptions = {};
|
|
47
49
|
var m_dummyDiv = null; // dummy div For chartclasses
|
|
@@ -161,12 +163,10 @@ function Milli_Chart(settings) {
|
|
|
161
163
|
}
|
|
162
164
|
*/
|
|
163
165
|
MillistreamWidgetApi_AssignObject(MillistreamWidgetSettings, _this.settings);
|
|
164
|
-
|
|
165
166
|
if (settings) {
|
|
166
167
|
MillistreamWidgetApi_AssignObject(settings, _this.settings);
|
|
167
168
|
}
|
|
168
169
|
|
|
169
|
-
|
|
170
170
|
_this.get_lang_text = function(string) {
|
|
171
171
|
return string;
|
|
172
172
|
};
|
|
@@ -248,6 +248,32 @@ function Milli_Chart(settings) {
|
|
|
248
248
|
return parseInt(obj['font-size']);
|
|
249
249
|
}
|
|
250
250
|
|
|
251
|
+
function getMaxTimeWidth() {
|
|
252
|
+
switch (_this.settings.dateformat) {
|
|
253
|
+
case 'HH:mm':
|
|
254
|
+
return m_ctx.measureText('88:88').width;
|
|
255
|
+
default:
|
|
256
|
+
return m_ctx.measureText('88:88').width;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function getMaxDateWidth() {
|
|
261
|
+
switch (_this.settings.dateformat) {
|
|
262
|
+
case 'yyyy-mm-dd':
|
|
263
|
+
return m_ctx.measureText("8888-88-88").width;
|
|
264
|
+
case 'b dd':
|
|
265
|
+
return m_ctx.measureText("MMM 88").width;
|
|
266
|
+
case 'b dd yyyy':
|
|
267
|
+
return m_ctx.measureText("MMM 88 8888").width;
|
|
268
|
+
case 'dd/mm':
|
|
269
|
+
case 'd/m':
|
|
270
|
+
return m_ctx.measureText("88/88").width;
|
|
271
|
+
default:
|
|
272
|
+
return m_ctx.measureText(_this.settings.dateformat).width;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
|
|
251
277
|
function getStringWidth(ctx, format) {
|
|
252
278
|
switch (format) {
|
|
253
279
|
case 'yyyy-mm-dd':
|
|
@@ -556,7 +582,7 @@ function Milli_Chart(settings) {
|
|
|
556
582
|
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
557
583
|
m_ctx.font = m_yLegendCss['font-weight'] + ' ' + m_yLegendCss['font-size'] + ' ' + m_yLegendCss['font-family'];
|
|
558
584
|
m_ctx.fillStyle = m_yLegendCss.color;
|
|
559
|
-
if (_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') firstvalue = _this.instruments[0].closeprice1d;
|
|
585
|
+
//if (_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') firstvalue = _this.instruments[0].closeprice1d;
|
|
560
586
|
|
|
561
587
|
if (0 == calcHighLow()) {
|
|
562
588
|
// console.log('no data to draw on');
|
|
@@ -680,6 +706,7 @@ function Milli_Chart(settings) {
|
|
|
680
706
|
}
|
|
681
707
|
|
|
682
708
|
function calcXScale(starttime, endtime) {
|
|
709
|
+
// vad är detta?
|
|
683
710
|
_this.scaleinfoX.startDate = new Date(starttime);
|
|
684
711
|
_this.scaleinfoX.endDate = new Date(endtime);
|
|
685
712
|
_this.scaleinfoX.days = getNumberOfDays(starttime, endtime);
|
|
@@ -715,6 +742,18 @@ function Milli_Chart(settings) {
|
|
|
715
742
|
return;
|
|
716
743
|
}
|
|
717
744
|
|
|
745
|
+
function getDatePosition(x) {
|
|
746
|
+
var timestamp = _this.scaleinfoX.startDate.getTime();
|
|
747
|
+
for (var i = 0; i < 1000; i++) {
|
|
748
|
+
var xx = getXPosition(new Date(timestamp));
|
|
749
|
+
if (xx >= x) return timestamp;
|
|
750
|
+
timestamp += 86400000;
|
|
751
|
+
}
|
|
752
|
+
//var timestamp = (x - Math.round(parseInt(m_chartCss['margin-left'] + offset)) * _this.scaleinfoX.timePerPixel) - _this.scaleinfoX.startDate.getTime();
|
|
753
|
+
|
|
754
|
+
return 0;
|
|
755
|
+
}
|
|
756
|
+
|
|
718
757
|
function getXPosition(timestamp) {
|
|
719
758
|
var offset = (timestamp.getTime() - _this.scaleinfoX.startDate.getTime()) / (86400000 * 7); // veckor
|
|
720
759
|
offset = offset * 86400000 * 2 / _this.scaleinfoX.timePerPixel;
|
|
@@ -745,16 +784,15 @@ function Milli_Chart(settings) {
|
|
|
745
784
|
x = getXPosition(new Date(year + '-01-01T00:00:00Z'));
|
|
746
785
|
draw = true;
|
|
747
786
|
for (i = 0; i < legendItems.length; i++) {
|
|
748
|
-
if (
|
|
749
|
-
//if (x < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2)) {
|
|
787
|
+
if (legendItems[i].x + (m_ctx.measureText('8888').width / 2) > (x - (m_ctx.measureText('8888').width))) {
|
|
750
788
|
draw = false;
|
|
751
789
|
}
|
|
752
790
|
}
|
|
753
791
|
if (draw) {
|
|
754
792
|
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
|
|
755
793
|
text = year;
|
|
756
|
-
if (_this.scaleinfoX.lineLength >
|
|
757
|
-
if (_this.settings.
|
|
794
|
+
if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - m_ctx.measureText(text).width) { // not to far right?
|
|
795
|
+
if (_this.settings.yearLabelsPos == 'top') {
|
|
758
796
|
m_ctx.save(); // flip and write new years on top
|
|
759
797
|
var fontMetrix = m_ctx.measureText(text);
|
|
760
798
|
x = x + fontMetrix.actualBoundingBoxAscent + fontMetrix.actualBoundingBoxDescent + 2;
|
|
@@ -767,35 +805,38 @@ function Milli_Chart(settings) {
|
|
|
767
805
|
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
768
806
|
}
|
|
769
807
|
numItems++;
|
|
808
|
+
legendItems.push({ text: year.toString(), timestamp: new Date(year + '-01-01T00:00:00Z'), 'x': x });
|
|
770
809
|
}
|
|
771
|
-
legendItems.push({ text: year.toString(), timestamp: new Date(year + '-01-01T00:00:00Z'), 'x': x });
|
|
772
810
|
year++;
|
|
773
811
|
}
|
|
812
|
+
if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11; // keep it clean
|
|
774
813
|
// draw half year
|
|
775
|
-
if (numItems < 10) { // max 10 items här för att skriva
|
|
776
|
-
year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-07-01T00:00:00Z');
|
|
814
|
+
if (numItems < 10) { // max 10 items här för att skriva halvår
|
|
815
|
+
year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-07-01T00:00:00Z');
|
|
777
816
|
if (year.getTime() < _this.scaleinfoX.startDate.getTime())
|
|
778
|
-
year = new Date(_this.scaleinfoX.startDate.getFullYear() + 1 + '-07-01T00:00:00Z');
|
|
817
|
+
year = new Date(_this.scaleinfoX.startDate.getFullYear() + 1 + '-07-01T00:00:00Z');
|
|
779
818
|
while (year < _this.scaleinfoX.endDate) {
|
|
780
819
|
x = getXPosition(new Date(year.getFullYear() + '-07-01T00:00:00Z')); // 7
|
|
781
820
|
draw = true;
|
|
782
821
|
for (i = 0; i < legendItems.length; i++) {
|
|
783
|
-
if (Math.abs(legendItems[i].x - x) < (
|
|
784
|
-
|
|
822
|
+
//if (Math.abs(legendItems[i].x - x) < (getMaxDateWidth() / 2)) {
|
|
823
|
+
if (Math.abs(legendItems[i].x - x) < getMaxDateWidth()) {
|
|
785
824
|
draw = false;
|
|
786
825
|
}
|
|
787
826
|
}
|
|
788
827
|
if (draw) {
|
|
789
828
|
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
|
|
790
|
-
text = formatDate(year.getFullYear() + '-07-01', _this.settings.dateformat);
|
|
829
|
+
text = formatDate(year.getFullYear() + '-07-01', _this.settings.dateformat);
|
|
830
|
+
// ingen if som på year???
|
|
791
831
|
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
792
832
|
numItems++;
|
|
833
|
+
legendItems.push({ 'text': text, timestamp: new Date(year + '-07-01T00:00:00Z'), 'x': x });
|
|
793
834
|
}
|
|
794
|
-
|
|
795
|
-
year = new Date((year.getFullYear() + 1) + '-07-01T00:00:00Z'); // 7
|
|
835
|
+
year = new Date((year.getFullYear() + 1) + '-07-01T00:00:00Z');
|
|
796
836
|
}
|
|
797
837
|
}
|
|
798
838
|
// draw Quarter
|
|
839
|
+
if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11; // keep it clean
|
|
799
840
|
if (numItems < 10) { // max 10 items här för att skriva kvartal
|
|
800
841
|
year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-04-01T00:00:00Z');
|
|
801
842
|
if (year.getTime() < _this.scaleinfoX.startDate.getTime())
|
|
@@ -805,8 +846,7 @@ function Milli_Chart(settings) {
|
|
|
805
846
|
x = getXPosition(new Date(year.getFullYear() + '-04-01T00:00:00Z'));
|
|
806
847
|
draw = true;
|
|
807
848
|
for (i = 0; i < legendItems.length; i++) {
|
|
808
|
-
if (Math.abs(legendItems[i].x - x) < (
|
|
809
|
-
//if (x < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2)) {
|
|
849
|
+
if (Math.abs(legendItems[i].x - x) < getMaxDateWidth()) {
|
|
810
850
|
draw = false;
|
|
811
851
|
dontPrint = true;
|
|
812
852
|
}
|
|
@@ -829,8 +869,7 @@ function Milli_Chart(settings) {
|
|
|
829
869
|
x = getXPosition(new Date(year.getFullYear() + '-10-01T00:00:00Z'));
|
|
830
870
|
draw = true;
|
|
831
871
|
for (i = 0; i < legendItems.length; i++) {
|
|
832
|
-
if (Math.abs(legendItems[i].x - x) < (
|
|
833
|
-
//if (x < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2)) {
|
|
872
|
+
if (Math.abs(legendItems[i].x - x) < getMaxDateWidth()) {
|
|
834
873
|
draw = false;
|
|
835
874
|
}
|
|
836
875
|
}
|
|
@@ -849,6 +888,61 @@ function Milli_Chart(settings) {
|
|
|
849
888
|
}
|
|
850
889
|
|
|
851
890
|
function drawXAxisMonth(starttime, endtime) {
|
|
891
|
+
starttime -= starttime % 8640000;
|
|
892
|
+
endtime -= starttime % 8640000;
|
|
893
|
+
m_ctx.save();
|
|
894
|
+
m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
|
|
895
|
+
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
896
|
+
m_ctx.fillStyle = m_xLegendCss.color;
|
|
897
|
+
calcXScale(starttime, endtime);
|
|
898
|
+
if (_this.settings.drawxaxis != 0) { // draw line
|
|
899
|
+
m_ctx.beginPath();
|
|
900
|
+
m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
901
|
+
m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
902
|
+
m_ctx.stroke();
|
|
903
|
+
m_ctx.closePath();
|
|
904
|
+
}
|
|
905
|
+
m_ctx.textAlign = "left";
|
|
906
|
+
var currentDate = new Date(starttime);
|
|
907
|
+
var x;
|
|
908
|
+
var lastx = 0;
|
|
909
|
+
var draw = true;
|
|
910
|
+
var offset = 0;
|
|
911
|
+
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) { // oklart om det skall vara så här 2021-06-01
|
|
912
|
+
draw = true;
|
|
913
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
914
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
915
|
+
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
916
|
+
}
|
|
917
|
+
x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
918
|
+
if (lastx == 0 && parseInt(m_chartCss['margin-left']) > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
|
|
919
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
920
|
+
continue;
|
|
921
|
+
}
|
|
922
|
+
console.log(x, lastx);
|
|
923
|
+
if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
|
|
924
|
+
draw = false;
|
|
925
|
+
}
|
|
926
|
+
if (draw) {
|
|
927
|
+
lastx = x;
|
|
928
|
+
var text = formatDate(currentDate.toISOString().substring(0, 10), _this.settings.dateformat);
|
|
929
|
+
if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxDateWidth()) // not to far right?
|
|
930
|
+
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
931
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
|
|
932
|
+
}
|
|
933
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
934
|
+
}
|
|
935
|
+
// vad är detta?
|
|
936
|
+
if (typeof m_chartCss['box-shadow'] !== 'undefined') {
|
|
937
|
+
var boxshadow = m_chartCss['box-shadow'].split(' ');
|
|
938
|
+
if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
939
|
+
|
|
940
|
+
} else
|
|
941
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
942
|
+
m_ctx.restore();
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
function drawXAxisMonth2(starttime, endtime) {
|
|
852
946
|
// month axis
|
|
853
947
|
starttime -= starttime % 8640000;
|
|
854
948
|
endtime -= starttime % 8640000;
|
|
@@ -871,68 +965,31 @@ function Milli_Chart(settings) {
|
|
|
871
965
|
var endDate = new Date(endtime);
|
|
872
966
|
var p = { x: 0, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) };
|
|
873
967
|
var offset = 0; // timeoffset for closed hours,and weekends
|
|
874
|
-
var newday = true;
|
|
875
968
|
var last = 0;
|
|
876
|
-
var nextYear = currentDate.getFullYear() + 1;
|
|
877
969
|
var olddate = '';
|
|
878
|
-
//while (p.x < (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2))) {
|
|
879
970
|
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) { // oklart om det skall vara så här 2021-06-01
|
|
880
971
|
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
881
972
|
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
882
973
|
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
883
|
-
if (nextYear == currentDate.getFullYear()) {
|
|
884
|
-
lastDate = currentDate;
|
|
885
|
-
drawXAxisGridlines(p, true); //, '#FF0000');
|
|
886
|
-
datum = nextYear;
|
|
887
|
-
|
|
888
|
-
if (_this.settings.yearLablesPos == 'top') {
|
|
889
|
-
m_ctx.save();
|
|
890
|
-
var fontMetrix = m_ctx.measureText(datum);
|
|
891
|
-
var x = p.x + fontMetrix.actualBoundingBoxAscent + fontMetrix.actualBoundingBoxDescent + 2;
|
|
892
|
-
var y = parseInt(m_chartCss['margin-top']); // + m_ctx.measureText(datum).width;
|
|
893
|
-
m_ctx.translate(x, y);
|
|
894
|
-
m_ctx.rotate(90 * Math.PI / 180);
|
|
895
|
-
m_ctx.fillText(datum, 0, 0);
|
|
896
|
-
m_ctx.restore();
|
|
897
|
-
} else
|
|
898
|
-
m_ctx.fillText(datum, p.x - (m_ctx.measureText(datum).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
899
|
-
last = p.x;
|
|
900
|
-
nextYear = currentDate.getFullYear() + 1;
|
|
901
|
-
}
|
|
902
974
|
}
|
|
903
|
-
//oldx = p.x; används inte tydligen
|
|
904
975
|
p.x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
905
976
|
var datum;
|
|
906
977
|
var dash = false;
|
|
907
|
-
newday = false;
|
|
908
|
-
if (nextYear == currentDate.getFullYear()) {
|
|
909
|
-
//drawXAxisGridlines(p, true);
|
|
910
|
-
datum = nextYear;
|
|
911
|
-
//datum = formatDate(nextYear + '-01-01', _this.settings.dateformat);
|
|
912
|
-
// m_ctx.fillText(datum, p.x - (m_ctx.measureText(datum).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
913
|
-
//last = p.x;
|
|
914
|
-
nextYear = currentDate.getFullYear() + 1;
|
|
915
|
-
}
|
|
916
|
-
//datum = currentDate.getDate() + '/' + (currentDate.getMonth() + 1); // format date
|
|
917
978
|
datum = formatDate(currentDate.toISOString().substring(0, 10), _this.settings.dateformat);
|
|
918
|
-
//dash = true;
|
|
919
979
|
offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel); // * dateDiffInDays(lastdate, currentDate); // varför?
|
|
920
980
|
currentDate = new Date(currentDate.getTime() + _this.scaleinfoX.ticksize);
|
|
981
|
+
if (parseInt(m_chartCss['margin-left']) + (getMaxDateWidth() / 2) > (p.x - (getMaxDateWidth()))) {
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
|
|
921
985
|
lastDate = new Date(currentDate);
|
|
922
986
|
lastDate.setHours(endDate.getHours());
|
|
923
987
|
lastDate.setMinutes(endDate.getMinutes());
|
|
924
988
|
lastDate.setSeconds(endDate.getSeconds());
|
|
925
|
-
newday = true;
|
|
926
989
|
var printLegendItem = true;
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
if (nextYearX - p.x < (Math.floor(_this.scaleinfoX.itemwidth))) {
|
|
990
|
+
|
|
991
|
+
if (p.x != parseInt(m_chartCss['margin-left']) && p.x - last < (Math.floor(_this.scaleinfoX.itemwidth))) {
|
|
930
992
|
printLegendItem = false;
|
|
931
|
-
} else {
|
|
932
|
-
//var nextx = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
933
|
-
if (p.x != parseInt(m_chartCss['margin-left']) && p.x - last < (Math.floor(_this.scaleinfoX.itemwidth))) {
|
|
934
|
-
printLegendItem = false;
|
|
935
|
-
}
|
|
936
993
|
}
|
|
937
994
|
if (printLegendItem) {
|
|
938
995
|
if (olddate != datum) {
|
|
@@ -998,7 +1055,7 @@ function Milli_Chart(settings) {
|
|
|
998
1055
|
pixelsperday[i] = arr[i] * timePerPixel;
|
|
999
1056
|
}
|
|
1000
1057
|
var x = totalmilli / maxLegendItems / 60000;
|
|
1001
|
-
numticks = maxLegendItems;
|
|
1058
|
+
var numticks = maxLegendItems;
|
|
1002
1059
|
|
|
1003
1060
|
_this.scaleinfoX.milliPerDay = new Date('2019-01-01T' + _this.instruments[0].marketclose + 'Z') - new Date('2019-01-01T' + _this.instruments[0].marketopen + 'Z');
|
|
1004
1061
|
_this.scaleinfoX.timePerPixel = timePerPixel;
|
|
@@ -1053,7 +1110,414 @@ function Milli_Chart(settings) {
|
|
|
1053
1110
|
return datetime.toTimeString().substring(0, 8);
|
|
1054
1111
|
}
|
|
1055
1112
|
|
|
1113
|
+
function calcTimeSpanInDays(startdate, enddate) {
|
|
1114
|
+
console.log(startdate, enddate)
|
|
1115
|
+
var s = Math.ceil(startdate / 86400000) * 86400000;
|
|
1116
|
+
var e = Math.ceil(enddate / 86400000) * 86400000;
|
|
1117
|
+
console.log(e - s / 86400000);
|
|
1118
|
+
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1056
1121
|
function drawXAxisTick(starttime, endtime) {
|
|
1122
|
+
m_ctx.save();
|
|
1123
|
+
m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
|
|
1124
|
+
|
|
1125
|
+
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
1126
|
+
m_ctx.fillStyle = m_xLegendCss.color;
|
|
1127
|
+
m_ctx.textAlign = "left";
|
|
1128
|
+
calcXScaleTick(starttime, endtime);
|
|
1129
|
+
if (_this.settings.drawxaxis != 0) { // draw line for legend
|
|
1130
|
+
m_ctx.beginPath();
|
|
1131
|
+
m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
1132
|
+
m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
1133
|
+
m_ctx.stroke();
|
|
1134
|
+
m_ctx.closePath();
|
|
1135
|
+
}
|
|
1136
|
+
// if(startime.date == endtime.date && starttime > open || endtime < close ) // no date
|
|
1137
|
+
|
|
1138
|
+
var currentDate = new Date(starttime);
|
|
1139
|
+
console.log('startdate', currentDate);
|
|
1140
|
+
var x;
|
|
1141
|
+
var lastx = 0;
|
|
1142
|
+
var draw = true;
|
|
1143
|
+
var offset = 0;
|
|
1144
|
+
var legendItems = [];
|
|
1145
|
+
// add days (daychanges)
|
|
1146
|
+
//currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1147
|
+
if (currentDate.getTime() % 3600000 != 0) // if not full hour, move up to next full hour
|
|
1148
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1149
|
+
console.log(currentDate);
|
|
1150
|
+
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
|
|
1151
|
+
draw = true;
|
|
1152
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1153
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1154
|
+
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1155
|
+
}
|
|
1156
|
+
//currentDate = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
1157
|
+
x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1158
|
+
if (lastx != 0 && lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1159
|
+
draw = false;
|
|
1160
|
+
}
|
|
1161
|
+
if (draw) {
|
|
1162
|
+
lastx = x;
|
|
1163
|
+
x += 0.5;
|
|
1164
|
+
var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1165
|
+
// if day change and setting print on top as well
|
|
1166
|
+
if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
|
|
1167
|
+
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1168
|
+
legendItems.push({ x: x, type: 0, text: text });
|
|
1169
|
+
}
|
|
1170
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }); // dash?
|
|
1171
|
+
}
|
|
1172
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1173
|
+
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1174
|
+
//offset += (86400000 - _this.scaleinfoX.milliPerDay);
|
|
1175
|
+
}
|
|
1176
|
+
var currentDate = new Date(starttime);
|
|
1177
|
+
console.log(currentDate);
|
|
1178
|
+
//currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1179
|
+
if (currentDate.getTime() % 3600000 != 0) // if not full hour, move up to next full hour
|
|
1180
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1181
|
+
console.log(currentDate);
|
|
1182
|
+
|
|
1183
|
+
var maxHourLegends;
|
|
1184
|
+
console.log(legendItems);
|
|
1185
|
+
if (legendItems.length == 0)
|
|
1186
|
+
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - parseInt(m_chartCss['margin-left']) - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1187
|
+
else
|
|
1188
|
+
if (legendItems.length == 1)
|
|
1189
|
+
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1190
|
+
else
|
|
1191
|
+
maxHourLegends = Math.floor((legendItems[1].x - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1192
|
+
var tickSize;
|
|
1193
|
+
calcTimeSpanInDays(starttime, endtime);
|
|
1194
|
+
|
|
1195
|
+
//if (m_zoom.isZooming) {
|
|
1196
|
+
console.log(starttime, endtime);
|
|
1197
|
+
tickSize = new Date(endtime - starttime);
|
|
1198
|
+
console.log(tickSize.getTime());
|
|
1199
|
+
//} else
|
|
1200
|
+
// 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'));
|
|
1201
|
+
var interval;
|
|
1202
|
+
var modularvalue = 3600000;
|
|
1203
|
+
if (tickSize.getTime() < 3600000) {
|
|
1204
|
+
tickSize = tickSize.getTime() / 300000;
|
|
1205
|
+
interval = Math.floor(tickSize / (maxHourLegends + 1)) * 300000;
|
|
1206
|
+
modularvalue = 300000;
|
|
1207
|
+
} else
|
|
1208
|
+
if (tickSize.getTime() < 7200000 * 3) {
|
|
1209
|
+
tickSize = tickSize.getTime() / 600000;
|
|
1210
|
+
interval = Math.floor(tickSize / (maxHourLegends + 1)) * 600000;
|
|
1211
|
+
modularvalue = 600000;
|
|
1212
|
+
} else {
|
|
1213
|
+
tickSize = tickSize.getTime() / 3600000;
|
|
1214
|
+
interval = Math.floor(tickSize / (maxHourLegends + 1)) * 3600000;
|
|
1215
|
+
}
|
|
1216
|
+
if (interval == 0) interval = 300000;
|
|
1217
|
+
|
|
1218
|
+
console.log('MAX', maxHourLegends, tickSize, interval);
|
|
1219
|
+
// print other times
|
|
1220
|
+
offset = 0;
|
|
1221
|
+
lastx = 0;
|
|
1222
|
+
var closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
1223
|
+
var workDate = new Date(currentDate);
|
|
1224
|
+
currentDate = new Date(starttime);
|
|
1225
|
+
if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
|
|
1226
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1227
|
+
|
|
1228
|
+
console.log('workdate', workDate);
|
|
1229
|
+
var count = 0;
|
|
1230
|
+
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
|
|
1231
|
+
console.log('workdate', workDate);
|
|
1232
|
+
if (count++ > 30) break;
|
|
1233
|
+
draw = true;
|
|
1234
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1235
|
+
console.log('Helg', currentDate);
|
|
1236
|
+
closeTime = new Date(closeTime.getTime() + 86400000);
|
|
1237
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1238
|
+
//currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1239
|
+
if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
|
|
1240
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1241
|
+
var workDate = new Date(workDate.getTime() + 86400000);
|
|
1242
|
+
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1243
|
+
}
|
|
1244
|
+
console.log(currentDate, closeTime);
|
|
1245
|
+
if (currentDate.getTime() > closeTime.getTime()) {
|
|
1246
|
+
// draw DayEnd(start) dash line
|
|
1247
|
+
/*var dayStart = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z')
|
|
1248
|
+
x = Math.round(parseInt(m_chartCss['margin-left']) + ((dayStart.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1249
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, true); // dash?*/
|
|
1250
|
+
|
|
1251
|
+
|
|
1252
|
+
closeTime = new Date(closeTime.getTime() + 86400000);
|
|
1253
|
+
workDate = new Date(workDate.getTime() + 86400000);
|
|
1254
|
+
currentDate = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
1255
|
+
if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
|
|
1256
|
+
currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1257
|
+
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1258
|
+
console.log('CLOSED', currentDate, closeTime);
|
|
1259
|
+
continue;
|
|
1260
|
+
}
|
|
1261
|
+
console.log(currentDate, closeTime);
|
|
1262
|
+
x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1263
|
+
for (var i = 0; i < legendItems.length; i++) {
|
|
1264
|
+
if (x < legendItems[i].x && x + (getMaxTimeWidth() / 2) > (legendItems[i].x - getMaxTimeWidth())) {
|
|
1265
|
+
draw = false;
|
|
1266
|
+
break;
|
|
1267
|
+
}
|
|
1268
|
+
if (x > legendItems[i].x && legendItems[i].x + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1269
|
+
draw = false;
|
|
1270
|
+
break;
|
|
1271
|
+
}
|
|
1272
|
+
}
|
|
1273
|
+
console.log(x, lastx, offset);
|
|
1274
|
+
if (lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1275
|
+
//draw = false;
|
|
1276
|
+
//console.log('false');
|
|
1277
|
+
}
|
|
1278
|
+
if (draw) {
|
|
1279
|
+
lastx = x;
|
|
1280
|
+
var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1281
|
+
// if day change and setting print on top as well
|
|
1282
|
+
if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
|
|
1283
|
+
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1284
|
+
legendItems.push({ x: x, type: 0 });
|
|
1285
|
+
}
|
|
1286
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
|
|
1287
|
+
}
|
|
1288
|
+
currentDate = new Date(currentDate.getTime() + interval);
|
|
1289
|
+
//currentDate = new Date(currentDate.getTime() + 3600000);
|
|
1290
|
+
}
|
|
1291
|
+
|
|
1292
|
+
// vad är detta?
|
|
1293
|
+
if (typeof m_chartCss['box-shadow'] !== 'undefined') {
|
|
1294
|
+
var boxshadow = m_chartCss['box-shadow'].split(' ');
|
|
1295
|
+
if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1296
|
+
|
|
1297
|
+
} else
|
|
1298
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1299
|
+
m_ctx.restore();
|
|
1300
|
+
|
|
1301
|
+
}
|
|
1302
|
+
|
|
1303
|
+
function drawXAxisTickBra(starttime, endtime) {
|
|
1304
|
+
m_ctx.save();
|
|
1305
|
+
m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
|
|
1306
|
+
|
|
1307
|
+
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
1308
|
+
m_ctx.fillStyle = m_xLegendCss.color;
|
|
1309
|
+
m_ctx.textAlign = "left";
|
|
1310
|
+
calcXScaleTick(starttime, endtime);
|
|
1311
|
+
if (_this.settings.drawxaxis != 0) { // draw line for legend
|
|
1312
|
+
m_ctx.beginPath();
|
|
1313
|
+
m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
1314
|
+
m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
1315
|
+
m_ctx.stroke();
|
|
1316
|
+
m_ctx.closePath();
|
|
1317
|
+
}
|
|
1318
|
+
// if(startime.date == endtime.date && starttime > open || endtime < close ) // no date
|
|
1319
|
+
|
|
1320
|
+
var currentDate = new Date(starttime);
|
|
1321
|
+
console.log('startdate', currentDate);
|
|
1322
|
+
var x;
|
|
1323
|
+
var lastx = 0;
|
|
1324
|
+
var draw = true;
|
|
1325
|
+
var offset = 0;
|
|
1326
|
+
var legendItems = [];
|
|
1327
|
+
// add days (daychanges)
|
|
1328
|
+
currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1329
|
+
console.log(currentDate);
|
|
1330
|
+
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
|
|
1331
|
+
draw = true;
|
|
1332
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1333
|
+
// console.log('Helg', currentDate);
|
|
1334
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1335
|
+
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1336
|
+
}
|
|
1337
|
+
//currentDate = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
1338
|
+
x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1339
|
+
if (lastx != 0 && lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1340
|
+
draw = false;
|
|
1341
|
+
}
|
|
1342
|
+
if (draw) {
|
|
1343
|
+
lastx = x;
|
|
1344
|
+
x += 0.5;
|
|
1345
|
+
var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1346
|
+
// if day change and setting print on top as well
|
|
1347
|
+
if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
|
|
1348
|
+
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1349
|
+
legendItems.push({ x: x, type: 0, text: text });
|
|
1350
|
+
}
|
|
1351
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }); // dash?
|
|
1352
|
+
}
|
|
1353
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1354
|
+
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1355
|
+
}
|
|
1356
|
+
var currentDate = new Date(starttime);
|
|
1357
|
+
console.log(currentDate);
|
|
1358
|
+
currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1359
|
+
|
|
1360
|
+
var maxHourLegends;
|
|
1361
|
+
console.log(legendItems);
|
|
1362
|
+
if (legendItems.length == 0)
|
|
1363
|
+
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - parseInt(m_chartCss['margin-left']) - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1364
|
+
else
|
|
1365
|
+
if (legendItems.length == 1)
|
|
1366
|
+
maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1367
|
+
else
|
|
1368
|
+
maxHourLegends = Math.floor((legendItems[1].x - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
|
|
1369
|
+
var 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'));
|
|
1370
|
+
var tickSize = tickSize.getTime() / 3600000;
|
|
1371
|
+
var interval = Math.floor(tickSize / (maxHourLegends + 1)) * 3600000;
|
|
1372
|
+
|
|
1373
|
+
// print other times
|
|
1374
|
+
offset = 0;
|
|
1375
|
+
lastx = 0;
|
|
1376
|
+
var closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
1377
|
+
var workDate = new Date(currentDate);
|
|
1378
|
+
console.log('workdate', workDate);
|
|
1379
|
+
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
|
|
1380
|
+
console.log('workdate', workDate);
|
|
1381
|
+
draw = true;
|
|
1382
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1383
|
+
console.log('Helg', currentDate);
|
|
1384
|
+
closeTime = new Date(closeTime.getTime() + 86400000);
|
|
1385
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1386
|
+
currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1387
|
+
var workDate = new Date(workDate.getTime() + 86400000);
|
|
1388
|
+
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1389
|
+
}
|
|
1390
|
+
console.log(currentDate, closeTime);
|
|
1391
|
+
if (currentDate.getTime() > closeTime.getTime()) {
|
|
1392
|
+
closeTime = new Date(closeTime.getTime() + 86400000);
|
|
1393
|
+
workDate = new Date(workDate.getTime() + 86400000);
|
|
1394
|
+
currentDate = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
1395
|
+
currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
|
|
1396
|
+
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1397
|
+
console.log('CLOSED', currentDate, closeTime);
|
|
1398
|
+
continue;
|
|
1399
|
+
}
|
|
1400
|
+
console.log(currentDate, closeTime);
|
|
1401
|
+
x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1402
|
+
for (var i = 0; i < legendItems.length; i++) {
|
|
1403
|
+
console.log('loop', x, legendItems[i].x);
|
|
1404
|
+
if (x < legendItems[i].x && x + (getMaxTimeWidth() / 2) > (legendItems[i].x - getMaxTimeWidth())) {
|
|
1405
|
+
draw = false;
|
|
1406
|
+
console.log('False1');
|
|
1407
|
+
break;
|
|
1408
|
+
}
|
|
1409
|
+
if (x > legendItems[i].x && legendItems[i].x + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1410
|
+
draw = false;
|
|
1411
|
+
console.log('False2');
|
|
1412
|
+
break;
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
console.log(x, lastx, offset);
|
|
1416
|
+
if (lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
|
|
1417
|
+
//draw = false;
|
|
1418
|
+
console.log('false');
|
|
1419
|
+
}
|
|
1420
|
+
if (draw) {
|
|
1421
|
+
lastx = x;
|
|
1422
|
+
var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1423
|
+
// if day change and setting print on top as well
|
|
1424
|
+
if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
|
|
1425
|
+
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1426
|
+
legendItems.push({ x: x, type: 0 });
|
|
1427
|
+
}
|
|
1428
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
|
|
1429
|
+
}
|
|
1430
|
+
currentDate = new Date(currentDate.getTime() + interval);
|
|
1431
|
+
//currentDate = new Date(currentDate.getTime() + 3600000);
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
// vad är detta?
|
|
1435
|
+
if (typeof m_chartCss['box-shadow'] !== 'undefined') {
|
|
1436
|
+
var boxshadow = m_chartCss['box-shadow'].split(' ');
|
|
1437
|
+
if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1438
|
+
|
|
1439
|
+
} else
|
|
1440
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1441
|
+
m_ctx.restore();
|
|
1442
|
+
|
|
1443
|
+
}
|
|
1444
|
+
|
|
1445
|
+
function drawXAxisTickTest(starttime, endtime) {
|
|
1446
|
+
m_ctx.save();
|
|
1447
|
+
m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
|
|
1448
|
+
|
|
1449
|
+
m_ctx.strokeStyle = m_gridHorizontalCss.color;
|
|
1450
|
+
m_ctx.fillStyle = m_xLegendCss.color;
|
|
1451
|
+
m_ctx.textAlign = "left";
|
|
1452
|
+
calcXScaleTick(starttime, endtime);
|
|
1453
|
+
if (_this.settings.drawxaxis != 0) { // draw line for legend
|
|
1454
|
+
m_ctx.beginPath();
|
|
1455
|
+
m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
1456
|
+
m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
|
|
1457
|
+
m_ctx.stroke();
|
|
1458
|
+
m_ctx.closePath();
|
|
1459
|
+
}
|
|
1460
|
+
// if(startime.date == endtime.date && starttime > open || endtime < close ) // no date
|
|
1461
|
+
|
|
1462
|
+
var currentDate = new Date(starttime);
|
|
1463
|
+
console.log('startdate', currentDate);
|
|
1464
|
+
var x;
|
|
1465
|
+
var lastx = 0;
|
|
1466
|
+
var draw = true;
|
|
1467
|
+
var offset = 0;
|
|
1468
|
+
var legendItems = [];
|
|
1469
|
+
// add days (daychanges)
|
|
1470
|
+
while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
|
|
1471
|
+
draw = true;
|
|
1472
|
+
while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
|
|
1473
|
+
console.log('Helg', currentDate);
|
|
1474
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1475
|
+
offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1476
|
+
}
|
|
1477
|
+
var closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
|
|
1478
|
+
if (currentDate.getTime() > closeTime.getTime()) {
|
|
1479
|
+
currentDate = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
|
|
1480
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1481
|
+
// offset += 86400000 / _this.scaleinfoX.timePerPixel;
|
|
1482
|
+
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1483
|
+
console.log('STÄNGT', currentDate);
|
|
1484
|
+
continue;
|
|
1485
|
+
}
|
|
1486
|
+
console.log(currentDate);
|
|
1487
|
+
x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1488
|
+
/*if (lastx == 0 && parseInt(m_chartCss['margin-left']) > (x - (getMaxTimeWidth() / 2))) { // do not print left of y legend
|
|
1489
|
+
console.log('ftst', currentDate);
|
|
1490
|
+
currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1491
|
+
continue;
|
|
1492
|
+
}*/
|
|
1493
|
+
console.log(x, lastx, offset);
|
|
1494
|
+
if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
|
|
1495
|
+
draw = false;
|
|
1496
|
+
console.log('false');
|
|
1497
|
+
}
|
|
1498
|
+
if (draw) {
|
|
1499
|
+
lastx = x;
|
|
1500
|
+
var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
|
|
1501
|
+
// if day change and setting print on top as well
|
|
1502
|
+
if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxDateWidth()) // not to far right?
|
|
1503
|
+
m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1504
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
|
|
1505
|
+
}
|
|
1506
|
+
//currentDate = new Date(currentDate.getTime() + 86400000);
|
|
1507
|
+
currentDate = new Date(currentDate.getTime() + _this.scaleinfoX.ticksize);
|
|
1508
|
+
}
|
|
1509
|
+
// vad är detta?
|
|
1510
|
+
if (typeof m_chartCss['box-shadow'] !== 'undefined') {
|
|
1511
|
+
var boxshadow = m_chartCss['box-shadow'].split(' ');
|
|
1512
|
+
if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1513
|
+
|
|
1514
|
+
} else
|
|
1515
|
+
drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
|
|
1516
|
+
m_ctx.restore();
|
|
1517
|
+
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
function drawXAxisTick2(starttime, endtime) {
|
|
1057
1521
|
// day and month axis
|
|
1058
1522
|
m_ctx.save();
|
|
1059
1523
|
m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
|
|
@@ -1086,7 +1550,6 @@ function Milli_Chart(settings) {
|
|
|
1086
1550
|
while (p.x < (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2))) { // && oldx != p.x) {
|
|
1087
1551
|
var dayChange = false;
|
|
1088
1552
|
if (currentDate.getTime() > endtime) {
|
|
1089
|
-
//console.log('larget than endtime', currentDate, new Date(endtime));
|
|
1090
1553
|
break;
|
|
1091
1554
|
}
|
|
1092
1555
|
oldx = p.x;
|
|
@@ -1118,16 +1581,7 @@ function Milli_Chart(settings) {
|
|
|
1118
1581
|
}
|
|
1119
1582
|
//console.log(currentDate, _this.scaleinfoX.endDate);
|
|
1120
1583
|
if (currentDate.getTime() > _this.scaleinfoX.endDate.getTime()) {
|
|
1121
|
-
//console.log('break out', currentDate, _this.scaleinfoX.endDate);
|
|
1122
|
-
// draw the last item on the scale (ie closetime for trades)
|
|
1123
1584
|
break;
|
|
1124
|
-
/*if (p.x < m_canvas.width - m_ctx.measureText(datum).width) {
|
|
1125
|
-
//console.log('3', datum, 'Kolla om den är för nära den innan också');
|
|
1126
|
-
m_ctx.fillText(datum, p.x - (m_ctx.measureText(datum).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1127
|
-
}
|
|
1128
|
-
drawXAxisGridlines(p, dash);
|
|
1129
|
-
//console.log('breaking out', currentDate.getTime(), _this.scaleinfoX.endDate.getTime());
|
|
1130
|
-
break;*/
|
|
1131
1585
|
}
|
|
1132
1586
|
offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
|
|
1133
1587
|
lastDate = new Date(currentDate);
|
|
@@ -1136,8 +1590,9 @@ function Milli_Chart(settings) {
|
|
|
1136
1590
|
}
|
|
1137
1591
|
var fontMetrix;
|
|
1138
1592
|
var nextx = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
|
|
1139
|
-
//
|
|
1140
|
-
|
|
1593
|
+
//if ((nextx - p.x < Math.floor(_this.scaleinfoX.itemwidth)) && new Date(currentDate.getTime() + _this.scaleinfoX.ticksize).getDate() != drawDate.getDate()) { // skriv bara ut om utrymmet får plats innan nästa punkt kommer skrivas (dagbrytningar)
|
|
1594
|
+
console.log(nextx, p.x, currentDate);
|
|
1595
|
+
if ((nextx - p.x < m_ctx.measureText('88:88').width) && new Date(currentDate.getTime() + _this.scaleinfoX.ticksize).getDate() != drawDate.getDate()) { // skriv bara ut om utrymmet får plats innan nästa punkt kommer skrivas (dagbrytningar)
|
|
1141
1596
|
//console.log('1', datum, 'Skall nog skrivas ut men för nära sista....',nextx,_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 1));
|
|
1142
1597
|
if (nextx < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 1)) { // is it too close to next?
|
|
1143
1598
|
//console.log('HIDE');
|
|
@@ -1191,7 +1646,8 @@ function Milli_Chart(settings) {
|
|
|
1191
1646
|
drawXAxisGridlines(p, p.x == parseInt(m_chartCss['margin-left']) ? false : dash);
|
|
1192
1647
|
}
|
|
1193
1648
|
lastDrawX = p.x;
|
|
1194
|
-
}
|
|
1649
|
+
}
|
|
1650
|
+
//else
|
|
1195
1651
|
if (p.x < m_canvas.width - m_ctx.measureText(datum).width) { // if text will be cropped do not print
|
|
1196
1652
|
m_ctx.fillText(datum, p.x - (m_ctx.measureText(datum).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
|
|
1197
1653
|
if (drawGridline) {
|
|
@@ -1305,6 +1761,7 @@ function Milli_Chart(settings) {
|
|
|
1305
1761
|
m_toolTip.dateDiv.innerHTML += ':' + zeroPad(d.getMinutes(), 2);
|
|
1306
1762
|
m_toolTip.dateDiv.innerHTML += ':' + zeroPad(d.getSeconds(), 2);
|
|
1307
1763
|
}
|
|
1764
|
+
m_toolTip.dateDiv.innerHTML += 'X:' + x;
|
|
1308
1765
|
m_toolTip.dateDiv.setAttribute('class', 'millistream-chart-tooltip'); // set class so we can measure it might change below depending on position
|
|
1309
1766
|
m_toolTip.dateDiv.style.left = m_dataPoints.arr[i] + 'px'; // TODO: räkna ut 7 px beroende på hur hoverpilen ser ut från höjden på diven
|
|
1310
1767
|
|
|
@@ -1406,7 +1863,6 @@ function Milli_Chart(settings) {
|
|
|
1406
1863
|
m_toolTip.arrowDiv[k].style.position = 'absolute';
|
|
1407
1864
|
color = m_instrumentCss[k].color;
|
|
1408
1865
|
m_toolTip.arrowDiv[k].style.backgroundColor = color;
|
|
1409
|
-
m_toolTip.arrowDiv[k].style.boxShadow = '0px 0px 17px 7px ' + color;
|
|
1410
1866
|
m_toolTip.arrowDiv[k].style.pointerEvents = 'none';
|
|
1411
1867
|
}
|
|
1412
1868
|
if (posy > highy) highy = posy;
|
|
@@ -1424,8 +1880,8 @@ function Milli_Chart(settings) {
|
|
|
1424
1880
|
|
|
1425
1881
|
function setTimeSpanData() {
|
|
1426
1882
|
if (typeof _this.settings.timespanelement === 'undefined' || _this.settings.timespanelement == null) return;
|
|
1427
|
-
startdate = new Date(_this.scaleinfoX.startTimeStamp);
|
|
1428
|
-
enddate = new Date(_this.scaleinfoX.endTimeStamp);
|
|
1883
|
+
var startdate = new Date(_this.scaleinfoX.startTimeStamp);
|
|
1884
|
+
var enddate = new Date(_this.scaleinfoX.endTimeStamp);
|
|
1429
1885
|
if (startdate.getTime() - (startdate.getTime() % 86400000) == enddate.getTime() - (enddate.getTime() % 86400000)) {
|
|
1430
1886
|
_this.settings.timespanelement.innerHTML = startdate.toTimeString().substring(0, 8) + ' - ' + enddate.toTimeString().substring(0, 8);
|
|
1431
1887
|
} else {
|
|
@@ -1850,6 +2306,7 @@ function Milli_Chart(settings) {
|
|
|
1850
2306
|
m_resizeing = false;
|
|
1851
2307
|
m_canvas.setAttribute('height', _this.settings.target.offsetHeight + 'px');
|
|
1852
2308
|
m_canvas.setAttribute('width', _this.settings.target.offsetWidth + 'px'); // läs från css?
|
|
2309
|
+
console.log('Width:', _this.settings.target.offsetWidth);
|
|
1853
2310
|
_this.drawChart();
|
|
1854
2311
|
};
|
|
1855
2312
|
|
|
@@ -2017,8 +2474,11 @@ function Milli_Chart(settings) {
|
|
|
2017
2474
|
//console.log(startpoint.x);
|
|
2018
2475
|
|
|
2019
2476
|
// TODO: här blir det fel när det är från 00:00: 23:59 men göms av tmpx < startpoint.x
|
|
2020
|
-
if (_this.scaleinfoY.type == 'trades' && tmpx < startpoint.x)
|
|
2477
|
+
if (_this.scaleinfoY.type == 'trades' && tmpx < startpoint.x) {
|
|
2021
2478
|
m_ctx.lineTo(startpoint.x, startpoint.y);
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
//m_ctx.lineTo(startpoint.x, startpoint.y);
|
|
2022
2482
|
|
|
2023
2483
|
}
|
|
2024
2484
|
//p.x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset); // from drawXaxis
|
|
@@ -2046,6 +2506,8 @@ function Milli_Chart(settings) {
|
|
|
2046
2506
|
if (tmpx < startpoint.x) {
|
|
2047
2507
|
if (_this.settings.hcurve) m_ctx.lineTo(startpoint.x, endpoint.y);
|
|
2048
2508
|
m_ctx.lineTo(startpoint.x, startpoint.y);
|
|
2509
|
+
//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"
|
|
2510
|
+
|
|
2049
2511
|
if (instrument == 0) {
|
|
2050
2512
|
point = { price: data[i].price, open: data[i].openprice, x: startpoint.x - 0.5, y: startpoint.y - 0.5, timestamp: data[i].timestamp, date: new Date(data[i].timestamp) };
|
|
2051
2513
|
if (typeof data[i].dividend !== 'undefined') point.dividend = data[i].dividend;
|
|
@@ -2271,12 +2733,9 @@ function Milli_Chart(settings) {
|
|
|
2271
2733
|
}
|
|
2272
2734
|
//console.log('onmouseup', m_zoom.mousedown.timestamp, m_zoom.mouseup.timestamp)
|
|
2273
2735
|
}
|
|
2274
|
-
//m_zoom.mousedown.timestamp = null;
|
|
2275
|
-
//m_zoom.mouseup.timestamp = null;
|
|
2276
2736
|
if (m_zoom.div) m_canvas.parentNode.removeChild(m_zoom.div);
|
|
2277
2737
|
m_zoom.div = null;
|
|
2278
2738
|
m_zoom.isZooming = false;
|
|
2279
|
-
//console.log('CLEAR');
|
|
2280
2739
|
});
|
|
2281
2740
|
} else {
|
|
2282
2741
|
//m_ctx.clearRect(0, 0, m_canvas.width, m_canvas.height);
|