@millistream/millistream-widgets 0.0.11 → 0.0.14

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/README.md CHANGED
@@ -16,12 +16,25 @@ $ npm install @millistream/millistream-widgets
16
16
  ...
17
17
  loadChart) {
18
18
  (async function () {
19
- const { Milli_List } = await import('@millistream/millistream-widgets');
19
+ const {
20
+ MillistreamWidgetStreamingApi,
21
+ Milli_Chart,
22
+ MillistreamWidgetSettings,
23
+ } = await import(
24
+ // @ts-ignore
25
+ '@millistream/millistream-widgets'
26
+ );
27
+
28
+ MillistreamWidgetSettings.token = 'xxx';
29
+
30
+ let pushapi = new MillistreamWidgetStreamingApi({
31
+ token: MillistreamWidgetSettings.token,
32
+ server: 'wss://push.millistream.com',
33
+ });
20
34
 
21
35
  let ml = new Milli_Chart({
22
36
  instrument: [6485],
23
37
  target: document.getElementById('chart'),
24
- token: '5b09a1bb-3f27-4026-8c08-0acc9ef7a872',
25
38
  autodraw: true,
26
39
  intradaylen: '5',
27
40
  historylen: '5y',
@@ -33,8 +46,9 @@ loadChart) {
33
46
  drawyaxis: true,
34
47
  fillchart: true,
35
48
  timeformat: 'HH:mm',
36
- /*streaming: pushapi*/
49
+ streaming: pushapi,
37
50
  });
51
+
38
52
  })();
39
53
  ```
40
54
 
@@ -104,9 +118,7 @@ loadChart) {
104
118
  background: rgb(255, 153, 0, 0.1);
105
119
  pointer-events: none;
106
120
  }
107
-
108
- ...
109
-
121
+ ```
110
122
 
111
123
  ## Widget documentation
112
124
  Please refer to non npm-version documentation on widget customization.
@@ -41,7 +41,7 @@ function Milli_Chart(settings) {
41
41
  hcurve: false,
42
42
  adjusted: true,
43
43
  nochartlabel: "No data to draw on",
44
- yearLablesPos: 'top'
44
+ yearLabelsPos: 'bottom'
45
45
  };
46
46
  _this.unsubscriptions = {};
47
47
  var m_dummyDiv = null; // dummy div For chartclasses
@@ -161,12 +161,10 @@ function Milli_Chart(settings) {
161
161
  }
162
162
  */
163
163
  MillistreamWidgetApi_AssignObject(MillistreamWidgetSettings, _this.settings);
164
-
165
164
  if (settings) {
166
165
  MillistreamWidgetApi_AssignObject(settings, _this.settings);
167
166
  }
168
167
 
169
-
170
168
  _this.get_lang_text = function(string) {
171
169
  return string;
172
170
  };
@@ -248,6 +246,32 @@ function Milli_Chart(settings) {
248
246
  return parseInt(obj['font-size']);
249
247
  }
250
248
 
249
+ function getMaxTimeWidth() {
250
+ switch (_this.settings.dateformat) {
251
+ case 'HH:mm':
252
+ return m_ctx.measureText('88:88').width;
253
+ default:
254
+ return m_ctx.measureText('88:88').width;
255
+ }
256
+ }
257
+
258
+ function getMaxDateWidth() {
259
+ switch (_this.settings.dateformat) {
260
+ case 'yyyy-mm-dd':
261
+ return m_ctx.measureText("8888-88-88").width;
262
+ case 'b dd':
263
+ return m_ctx.measureText("MMM 88").width;
264
+ case 'b dd yyyy':
265
+ return m_ctx.measureText("MMM 88 8888").width;
266
+ case 'dd/mm':
267
+ case 'd/m':
268
+ return m_ctx.measureText("88/88").width;
269
+ default:
270
+ return m_ctx.measureText(_this.settings.dateformat).width;
271
+ }
272
+ }
273
+
274
+
251
275
  function getStringWidth(ctx, format) {
252
276
  switch (format) {
253
277
  case 'yyyy-mm-dd':
@@ -680,6 +704,7 @@ function Milli_Chart(settings) {
680
704
  }
681
705
 
682
706
  function calcXScale(starttime, endtime) {
707
+ // vad är detta?
683
708
  _this.scaleinfoX.startDate = new Date(starttime);
684
709
  _this.scaleinfoX.endDate = new Date(endtime);
685
710
  _this.scaleinfoX.days = getNumberOfDays(starttime, endtime);
@@ -715,6 +740,18 @@ function Milli_Chart(settings) {
715
740
  return;
716
741
  }
717
742
 
743
+ function getDatePosition(x) {
744
+ var timestamp = _this.scaleinfoX.startDate.getTime();
745
+ for (var i = 0; i < 1000; i++) {
746
+ var xx = getXPosition(new Date(timestamp));
747
+ if (xx >= x) return timestamp;
748
+ timestamp += 86400000;
749
+ }
750
+ //var timestamp = (x - Math.round(parseInt(m_chartCss['margin-left'] + offset)) * _this.scaleinfoX.timePerPixel) - _this.scaleinfoX.startDate.getTime();
751
+
752
+ return 0;
753
+ }
754
+
718
755
  function getXPosition(timestamp) {
719
756
  var offset = (timestamp.getTime() - _this.scaleinfoX.startDate.getTime()) / (86400000 * 7); // veckor
720
757
  offset = offset * 86400000 * 2 / _this.scaleinfoX.timePerPixel;
@@ -745,16 +782,15 @@ function Milli_Chart(settings) {
745
782
  x = getXPosition(new Date(year + '-01-01T00:00:00Z'));
746
783
  draw = true;
747
784
  for (i = 0; i < legendItems.length; i++) {
748
- if (Math.abs(legendItems[i].x - x) < (_this.scaleinfoX.itemwidth / 2)) {
749
- //if (x < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2)) {
785
+ if (legendItems[i].x + (m_ctx.measureText('8888').width / 2) > (x - (m_ctx.measureText('8888').width))) {
750
786
  draw = false;
751
787
  }
752
788
  }
753
789
  if (draw) {
754
790
  drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
755
791
  text = year;
756
- if (_this.scaleinfoX.lineLength > (x - (m_ctx.measureText(text).width / 2) + m_ctx.measureText(text).width / 2)) {
757
- if (_this.settings.yearLablesPos == 'top') {
792
+ if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - m_ctx.measureText(text).width) { // not to far right?
793
+ if (_this.settings.yearLabelsPos == 'top') {
758
794
  m_ctx.save(); // flip and write new years on top
759
795
  var fontMetrix = m_ctx.measureText(text);
760
796
  x = x + fontMetrix.actualBoundingBoxAscent + fontMetrix.actualBoundingBoxDescent + 2;
@@ -767,35 +803,38 @@ function Milli_Chart(settings) {
767
803
  m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
768
804
  }
769
805
  numItems++;
806
+ legendItems.push({ text: year.toString(), timestamp: new Date(year + '-01-01T00:00:00Z'), 'x': x });
770
807
  }
771
- legendItems.push({ text: year.toString(), timestamp: new Date(year + '-01-01T00:00:00Z'), 'x': x });
772
808
  year++;
773
809
  }
810
+ if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11; // keep it clean
774
811
  // draw half year
775
- if (numItems < 10) { // max 10 items här för att skriva kvartal
776
- year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-07-01T00:00:00Z'); // 7
812
+ if (numItems < 10) { // max 10 items här för att skriva halvår
813
+ year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-07-01T00:00:00Z');
777
814
  if (year.getTime() < _this.scaleinfoX.startDate.getTime())
778
- year = new Date(_this.scaleinfoX.startDate.getFullYear() + 1 + '-07-01T00:00:00Z'); // 7
815
+ year = new Date(_this.scaleinfoX.startDate.getFullYear() + 1 + '-07-01T00:00:00Z');
779
816
  while (year < _this.scaleinfoX.endDate) {
780
817
  x = getXPosition(new Date(year.getFullYear() + '-07-01T00:00:00Z')); // 7
781
818
  draw = true;
782
819
  for (i = 0; i < legendItems.length; i++) {
783
- if (Math.abs(legendItems[i].x - x) < (_this.scaleinfoX.itemwidth / 2)) {
784
- //if (x < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2)) {
820
+ //if (Math.abs(legendItems[i].x - x) < (getMaxDateWidth() / 2)) {
821
+ if (Math.abs(legendItems[i].x - x) < getMaxDateWidth()) {
785
822
  draw = false;
786
823
  }
787
824
  }
788
825
  if (draw) {
789
826
  drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
790
- text = formatDate(year.getFullYear() + '-07-01', _this.settings.dateformat); // 6
827
+ text = formatDate(year.getFullYear() + '-07-01', _this.settings.dateformat);
828
+ // ingen if som på year???
791
829
  m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
792
830
  numItems++;
831
+ legendItems.push({ 'text': text, timestamp: new Date(year + '-07-01T00:00:00Z'), 'x': x });
793
832
  }
794
- legendItems.push({ 'text': text, timestamp: new Date(year + '-07-01T00:00:00Z'), 'x': x }); // 7
795
- year = new Date((year.getFullYear() + 1) + '-07-01T00:00:00Z'); // 7
833
+ year = new Date((year.getFullYear() + 1) + '-07-01T00:00:00Z');
796
834
  }
797
835
  }
798
836
  // draw Quarter
837
+ if (numItems * m_ctx.measureText('8888').width / _this.scaleinfoX.lineLength > 0.3) numItems = 11; // keep it clean
799
838
  if (numItems < 10) { // max 10 items här för att skriva kvartal
800
839
  year = new Date(_this.scaleinfoX.startDate.getFullYear() + '-04-01T00:00:00Z');
801
840
  if (year.getTime() < _this.scaleinfoX.startDate.getTime())
@@ -805,8 +844,7 @@ function Milli_Chart(settings) {
805
844
  x = getXPosition(new Date(year.getFullYear() + '-04-01T00:00:00Z'));
806
845
  draw = true;
807
846
  for (i = 0; i < legendItems.length; i++) {
808
- if (Math.abs(legendItems[i].x - x) < (_this.scaleinfoX.itemwidth / 2)) {
809
- //if (x < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2)) {
847
+ if (Math.abs(legendItems[i].x - x) < getMaxDateWidth()) {
810
848
  draw = false;
811
849
  dontPrint = true;
812
850
  }
@@ -829,8 +867,7 @@ function Milli_Chart(settings) {
829
867
  x = getXPosition(new Date(year.getFullYear() + '-10-01T00:00:00Z'));
830
868
  draw = true;
831
869
  for (i = 0; i < legendItems.length; i++) {
832
- if (Math.abs(legendItems[i].x - x) < (_this.scaleinfoX.itemwidth / 2)) {
833
- //if (x < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2)) {
870
+ if (Math.abs(legendItems[i].x - x) < getMaxDateWidth()) {
834
871
  draw = false;
835
872
  }
836
873
  }
@@ -849,6 +886,61 @@ function Milli_Chart(settings) {
849
886
  }
850
887
 
851
888
  function drawXAxisMonth(starttime, endtime) {
889
+ starttime -= starttime % 8640000;
890
+ endtime -= starttime % 8640000;
891
+ m_ctx.save();
892
+ m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
893
+ m_ctx.strokeStyle = m_gridHorizontalCss.color;
894
+ m_ctx.fillStyle = m_xLegendCss.color;
895
+ calcXScale(starttime, endtime);
896
+ if (_this.settings.drawxaxis != 0) { // draw line
897
+ m_ctx.beginPath();
898
+ m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
899
+ m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
900
+ m_ctx.stroke();
901
+ m_ctx.closePath();
902
+ }
903
+ m_ctx.textAlign = "left";
904
+ var currentDate = new Date(starttime);
905
+ var x;
906
+ var lastx = 0;
907
+ var draw = true;
908
+ var offset = 0;
909
+ while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) { // oklart om det skall vara så här 2021-06-01
910
+ draw = true;
911
+ while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
912
+ currentDate = new Date(currentDate.getTime() + 86400000);
913
+ offset += 86400000 / _this.scaleinfoX.timePerPixel;
914
+ }
915
+ x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
916
+ if (lastx == 0 && parseInt(m_chartCss['margin-left']) > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
917
+ currentDate = new Date(currentDate.getTime() + 86400000);
918
+ continue;
919
+ }
920
+ console.log(x, lastx);
921
+ if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
922
+ draw = false;
923
+ }
924
+ if (draw) {
925
+ lastx = x;
926
+ var text = formatDate(currentDate.toISOString().substring(0, 10), _this.settings.dateformat);
927
+ if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxDateWidth()) // not to far right?
928
+ m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
929
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
930
+ }
931
+ currentDate = new Date(currentDate.getTime() + 86400000);
932
+ }
933
+ // vad är detta?
934
+ if (typeof m_chartCss['box-shadow'] !== 'undefined') {
935
+ var boxshadow = m_chartCss['box-shadow'].split(' ');
936
+ if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
937
+
938
+ } else
939
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
940
+ m_ctx.restore();
941
+ }
942
+
943
+ function drawXAxisMonth2(starttime, endtime) {
852
944
  // month axis
853
945
  starttime -= starttime % 8640000;
854
946
  endtime -= starttime % 8640000;
@@ -871,68 +963,31 @@ function Milli_Chart(settings) {
871
963
  var endDate = new Date(endtime);
872
964
  var p = { x: 0, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) };
873
965
  var offset = 0; // timeoffset for closed hours,and weekends
874
- var newday = true;
875
966
  var last = 0;
876
- var nextYear = currentDate.getFullYear() + 1;
877
967
  var olddate = '';
878
- //while (p.x < (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2))) {
879
968
  while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) { // oklart om det skall vara så här 2021-06-01
880
969
  while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
881
970
  currentDate = new Date(currentDate.getTime() + 86400000);
882
971
  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
972
  }
903
- //oldx = p.x; används inte tydligen
904
973
  p.x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
905
974
  var datum;
906
975
  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
976
  datum = formatDate(currentDate.toISOString().substring(0, 10), _this.settings.dateformat);
918
- //dash = true;
919
977
  offset += ((86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel); // * dateDiffInDays(lastdate, currentDate); // varför?
920
978
  currentDate = new Date(currentDate.getTime() + _this.scaleinfoX.ticksize);
979
+ if (parseInt(m_chartCss['margin-left']) + (getMaxDateWidth() / 2) > (p.x - (getMaxDateWidth()))) {
980
+ continue;
981
+ }
982
+
921
983
  lastDate = new Date(currentDate);
922
984
  lastDate.setHours(endDate.getHours());
923
985
  lastDate.setMinutes(endDate.getMinutes());
924
986
  lastDate.setSeconds(endDate.getSeconds());
925
- newday = true;
926
987
  var printLegendItem = true;
927
- var nextYearDate = new Date(nextYear + '-01-01');
928
- var nextYearX = Math.round(parseInt(m_chartCss['margin-left']) + ((nextYearDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
929
- if (nextYearX - p.x < (Math.floor(_this.scaleinfoX.itemwidth))) {
988
+
989
+ if (p.x != parseInt(m_chartCss['margin-left']) && p.x - last < (Math.floor(_this.scaleinfoX.itemwidth))) {
930
990
  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
991
  }
937
992
  if (printLegendItem) {
938
993
  if (olddate != datum) {
@@ -998,7 +1053,7 @@ function Milli_Chart(settings) {
998
1053
  pixelsperday[i] = arr[i] * timePerPixel;
999
1054
  }
1000
1055
  var x = totalmilli / maxLegendItems / 60000;
1001
- numticks = maxLegendItems;
1056
+ var numticks = maxLegendItems;
1002
1057
 
1003
1058
  _this.scaleinfoX.milliPerDay = new Date('2019-01-01T' + _this.instruments[0].marketclose + 'Z') - new Date('2019-01-01T' + _this.instruments[0].marketopen + 'Z');
1004
1059
  _this.scaleinfoX.timePerPixel = timePerPixel;
@@ -1054,6 +1109,403 @@ function Milli_Chart(settings) {
1054
1109
  }
1055
1110
 
1056
1111
  function drawXAxisTick(starttime, endtime) {
1112
+ m_ctx.save();
1113
+ m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
1114
+
1115
+ m_ctx.strokeStyle = m_gridHorizontalCss.color;
1116
+ m_ctx.fillStyle = m_xLegendCss.color;
1117
+ m_ctx.textAlign = "left";
1118
+ calcXScaleTick(starttime, endtime);
1119
+ if (_this.settings.drawxaxis != 0) { // draw line for legend
1120
+ m_ctx.beginPath();
1121
+ m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
1122
+ m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
1123
+ m_ctx.stroke();
1124
+ m_ctx.closePath();
1125
+ }
1126
+ // if(startime.date == endtime.date && starttime > open || endtime < close ) // no date
1127
+
1128
+ var currentDate = new Date(starttime);
1129
+ console.log('startdate', currentDate);
1130
+ var x;
1131
+ var lastx = 0;
1132
+ var draw = true;
1133
+ var offset = 0;
1134
+ var legendItems = [];
1135
+ // add days (daychanges)
1136
+ //currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1137
+ if (currentDate.getTime() % 3600000 != 0) // if not full hour, move up to next full hour
1138
+ currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1139
+ console.log(currentDate);
1140
+ while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
1141
+ draw = true;
1142
+ while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
1143
+ currentDate = new Date(currentDate.getTime() + 86400000);
1144
+ offset += 86400000 / _this.scaleinfoX.timePerPixel;
1145
+ }
1146
+ //currentDate = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
1147
+ x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1148
+ if (lastx != 0 && lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
1149
+ draw = false;
1150
+ }
1151
+ if (draw) {
1152
+ lastx = x;
1153
+ x += 0.5;
1154
+ var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
1155
+ // if day change and setting print on top as well
1156
+ if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
1157
+ m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
1158
+ legendItems.push({ x: x, type: 0, text: text });
1159
+ }
1160
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }); // dash?
1161
+ }
1162
+ currentDate = new Date(currentDate.getTime() + 86400000);
1163
+ offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
1164
+ //offset += (86400000 - _this.scaleinfoX.milliPerDay);
1165
+ }
1166
+ var currentDate = new Date(starttime);
1167
+ console.log(currentDate);
1168
+ //currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1169
+ if (currentDate.getTime() % 3600000 != 0) // if not full hour, move up to next full hour
1170
+ currentDate = new Date(currentDate.getTime() - currentDate.getTime() % 3600000 + 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1171
+ console.log(currentDate);
1172
+
1173
+ var maxHourLegends;
1174
+ console.log(legendItems);
1175
+ if (legendItems.length == 0)
1176
+ maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - parseInt(m_chartCss['margin-left']) - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
1177
+ else
1178
+ if (legendItems.length == 1)
1179
+ maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
1180
+ else
1181
+ maxHourLegends = Math.floor((legendItems[1].x - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
1182
+ var tickSize;
1183
+ if (m_zoom.isZooming) {
1184
+ console.log(starttime, endtime);
1185
+ tickSize = new Date(endtime - starttime);
1186
+ console.log(tickSize.getTime());
1187
+ } else
1188
+ 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'));
1189
+ var interval;
1190
+ var modularvalue = 3600000;
1191
+ if (tickSize.getTime() < 3600000) {
1192
+ tickSize = tickSize.getTime() / 300000;
1193
+ interval = Math.floor(tickSize / (maxHourLegends + 1)) * 300000;
1194
+ modularvalue = 300000;
1195
+ } else
1196
+ if (tickSize.getTime() < 7200000 * 3) {
1197
+ tickSize = tickSize.getTime() / 600000;
1198
+ interval = Math.floor(tickSize / (maxHourLegends + 1)) * 600000;
1199
+ modularvalue = 600000;
1200
+ } else {
1201
+ tickSize = tickSize.getTime() / 3600000;
1202
+ interval = Math.floor(tickSize / (maxHourLegends + 1)) * 3600000;
1203
+ }
1204
+ if (interval == 0) interval = 300000;
1205
+
1206
+ console.log('MAX', maxHourLegends, tickSize, interval);
1207
+ // print other times
1208
+ offset = 0;
1209
+ lastx = 0;
1210
+ var closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
1211
+ var workDate = new Date(currentDate);
1212
+ var currentDate = new Date(startdate);
1213
+ if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
1214
+ currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
1215
+
1216
+ console.log('workdate', workDate);
1217
+ var count = 0;
1218
+ while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
1219
+ console.log('workdate', workDate);
1220
+ if (count++ > 30) break;
1221
+ draw = true;
1222
+ while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
1223
+ console.log('Helg', currentDate);
1224
+ closeTime = new Date(closeTime.getTime() + 86400000);
1225
+ currentDate = new Date(currentDate.getTime() + 86400000);
1226
+ //currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1227
+ if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
1228
+ currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
1229
+ var workDate = new Date(workDate.getTime() + 86400000);
1230
+ offset += 86400000 / _this.scaleinfoX.timePerPixel;
1231
+ }
1232
+ console.log(currentDate, closeTime);
1233
+ if (currentDate.getTime() > closeTime.getTime()) {
1234
+ // draw DayEnd(start) dash line
1235
+ /*var dayStart = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z')
1236
+ x = Math.round(parseInt(m_chartCss['margin-left']) + ((dayStart.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1237
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, true); // dash?*/
1238
+
1239
+
1240
+ closeTime = new Date(closeTime.getTime() + 86400000);
1241
+ workDate = new Date(workDate.getTime() + 86400000);
1242
+ currentDate = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
1243
+ if (currentDate.getTime() % modularvalue != 0) // if not full hour, move up to next full hour
1244
+ currentDate = new Date(currentDate.getTime() - currentDate.getTime() % modularvalue + modularvalue); // START om full hour (if modulo == 0 then + 3600000 kanske)
1245
+ offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
1246
+ console.log('CLOSED', currentDate, closeTime);
1247
+ continue;
1248
+ }
1249
+ console.log(currentDate, closeTime);
1250
+ x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1251
+ for (var i = 0; i < legendItems.length; i++) {
1252
+ if (x < legendItems[i].x && x + (getMaxTimeWidth() / 2) > (legendItems[i].x - getMaxTimeWidth())) {
1253
+ draw = false;
1254
+ break;
1255
+ }
1256
+ if (x > legendItems[i].x && legendItems[i].x + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
1257
+ draw = false;
1258
+ break;
1259
+ }
1260
+ }
1261
+ console.log(x, lastx, offset);
1262
+ if (lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
1263
+ //draw = false;
1264
+ //console.log('false');
1265
+ }
1266
+ if (draw) {
1267
+ lastx = x;
1268
+ var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
1269
+ // if day change and setting print on top as well
1270
+ if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
1271
+ m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
1272
+ legendItems.push({ x: x, type: 0 });
1273
+ }
1274
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
1275
+ }
1276
+ currentDate = new Date(currentDate.getTime() + interval);
1277
+ //currentDate = new Date(currentDate.getTime() + 3600000);
1278
+ }
1279
+
1280
+ // vad är detta?
1281
+ if (typeof m_chartCss['box-shadow'] !== 'undefined') {
1282
+ var boxshadow = m_chartCss['box-shadow'].split(' ');
1283
+ if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1284
+
1285
+ } else
1286
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1287
+ m_ctx.restore();
1288
+
1289
+ }
1290
+
1291
+ function drawXAxisTickBra(starttime, endtime) {
1292
+ m_ctx.save();
1293
+ m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
1294
+
1295
+ m_ctx.strokeStyle = m_gridHorizontalCss.color;
1296
+ m_ctx.fillStyle = m_xLegendCss.color;
1297
+ m_ctx.textAlign = "left";
1298
+ calcXScaleTick(starttime, endtime);
1299
+ if (_this.settings.drawxaxis != 0) { // draw line for legend
1300
+ m_ctx.beginPath();
1301
+ m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
1302
+ m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
1303
+ m_ctx.stroke();
1304
+ m_ctx.closePath();
1305
+ }
1306
+ // if(startime.date == endtime.date && starttime > open || endtime < close ) // no date
1307
+
1308
+ var currentDate = new Date(starttime);
1309
+ console.log('startdate', currentDate);
1310
+ var x;
1311
+ var lastx = 0;
1312
+ var draw = true;
1313
+ var offset = 0;
1314
+ var legendItems = [];
1315
+ // add days (daychanges)
1316
+ currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1317
+ console.log(currentDate);
1318
+ while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
1319
+ draw = true;
1320
+ while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
1321
+ // console.log('Helg', currentDate);
1322
+ currentDate = new Date(currentDate.getTime() + 86400000);
1323
+ offset += 86400000 / _this.scaleinfoX.timePerPixel;
1324
+ }
1325
+ //currentDate = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
1326
+ x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1327
+ if (lastx != 0 && lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
1328
+ draw = false;
1329
+ }
1330
+ if (draw) {
1331
+ lastx = x;
1332
+ x += 0.5;
1333
+ var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
1334
+ // if day change and setting print on top as well
1335
+ if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
1336
+ m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
1337
+ legendItems.push({ x: x, type: 0, text: text });
1338
+ }
1339
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }); // dash?
1340
+ }
1341
+ currentDate = new Date(currentDate.getTime() + 86400000);
1342
+ offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
1343
+ }
1344
+ var currentDate = new Date(starttime);
1345
+ console.log(currentDate);
1346
+ currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1347
+
1348
+ var maxHourLegends;
1349
+ console.log(legendItems);
1350
+ if (legendItems.length == 0)
1351
+ maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - parseInt(m_chartCss['margin-left']) - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
1352
+ else
1353
+ if (legendItems.length == 1)
1354
+ maxHourLegends = Math.floor((_this.scaleinfoX.lineLength - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
1355
+ else
1356
+ maxHourLegends = Math.floor((legendItems[1].x - legendItems[0].x - getMaxTimeWidth()) / (getMaxTimeWidth() * 3));
1357
+ 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'));
1358
+ var tickSize = tickSize.getTime() / 3600000;
1359
+ var interval = Math.floor(tickSize / (maxHourLegends + 1)) * 3600000;
1360
+
1361
+ // print other times
1362
+ offset = 0;
1363
+ lastx = 0;
1364
+ var closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
1365
+ var workDate = new Date(currentDate);
1366
+ console.log('workdate', workDate);
1367
+ while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
1368
+ console.log('workdate', workDate);
1369
+ draw = true;
1370
+ while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
1371
+ console.log('Helg', currentDate);
1372
+ closeTime = new Date(closeTime.getTime() + 86400000);
1373
+ currentDate = new Date(currentDate.getTime() + 86400000);
1374
+ currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1375
+ var workDate = new Date(workDate.getTime() + 86400000);
1376
+ offset += 86400000 / _this.scaleinfoX.timePerPixel;
1377
+ }
1378
+ console.log(currentDate, closeTime);
1379
+ if (currentDate.getTime() > closeTime.getTime()) {
1380
+ closeTime = new Date(closeTime.getTime() + 86400000);
1381
+ workDate = new Date(workDate.getTime() + 86400000);
1382
+ currentDate = new Date(workDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
1383
+ currentDate = new Date(currentDate.getTime() + currentDate.getTime() % 3600000); // START om full hour (if modulo == 0 then + 3600000 kanske)
1384
+ offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
1385
+ console.log('CLOSED', currentDate, closeTime);
1386
+ continue;
1387
+ }
1388
+ console.log(currentDate, closeTime);
1389
+ x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1390
+ for (var i = 0; i < legendItems.length; i++) {
1391
+ console.log('loop', x, legendItems[i].x);
1392
+ if (x < legendItems[i].x && x + (getMaxTimeWidth() / 2) > (legendItems[i].x - getMaxTimeWidth())) {
1393
+ draw = false;
1394
+ console.log('False1');
1395
+ break;
1396
+ }
1397
+ if (x > legendItems[i].x && legendItems[i].x + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
1398
+ draw = false;
1399
+ console.log('False2');
1400
+ break;
1401
+ }
1402
+ }
1403
+ console.log(x, lastx, offset);
1404
+ if (lastx + (getMaxTimeWidth() / 2) > (x - getMaxTimeWidth())) {
1405
+ //draw = false;
1406
+ console.log('false');
1407
+ }
1408
+ if (draw) {
1409
+ lastx = x;
1410
+ var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
1411
+ // if day change and setting print on top as well
1412
+ if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxTimeWidth()) { // not to far right?
1413
+ m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
1414
+ legendItems.push({ x: x, type: 0 });
1415
+ }
1416
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
1417
+ }
1418
+ currentDate = new Date(currentDate.getTime() + interval);
1419
+ //currentDate = new Date(currentDate.getTime() + 3600000);
1420
+ }
1421
+
1422
+ // vad är detta?
1423
+ if (typeof m_chartCss['box-shadow'] !== 'undefined') {
1424
+ var boxshadow = m_chartCss['box-shadow'].split(' ');
1425
+ if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1426
+
1427
+ } else
1428
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1429
+ m_ctx.restore();
1430
+
1431
+ }
1432
+
1433
+ function drawXAxisTickTest(starttime, endtime) {
1434
+ m_ctx.save();
1435
+ m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
1436
+
1437
+ m_ctx.strokeStyle = m_gridHorizontalCss.color;
1438
+ m_ctx.fillStyle = m_xLegendCss.color;
1439
+ m_ctx.textAlign = "left";
1440
+ calcXScaleTick(starttime, endtime);
1441
+ if (_this.settings.drawxaxis != 0) { // draw line for legend
1442
+ m_ctx.beginPath();
1443
+ m_ctx.moveTo(parseInt(m_chartCss['margin-left']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
1444
+ m_ctx.lineTo(m_canvas.width - parseInt(m_chartCss['margin-right']), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 0.5);
1445
+ m_ctx.stroke();
1446
+ m_ctx.closePath();
1447
+ }
1448
+ // if(startime.date == endtime.date && starttime > open || endtime < close ) // no date
1449
+
1450
+ var currentDate = new Date(starttime);
1451
+ console.log('startdate', currentDate);
1452
+ var x;
1453
+ var lastx = 0;
1454
+ var draw = true;
1455
+ var offset = 0;
1456
+ var legendItems = [];
1457
+ // add days (daychanges)
1458
+ while (currentDate.getTime() < _this.scaleinfoX.endTimeStamp) {
1459
+ draw = true;
1460
+ while (currentDate.getDay() == 0 || currentDate.getDay() == 6) { // move past weekends , maybe skip this if date is available in data
1461
+ console.log('Helg', currentDate);
1462
+ currentDate = new Date(currentDate.getTime() + 86400000);
1463
+ offset += 86400000 / _this.scaleinfoX.timePerPixel;
1464
+ }
1465
+ var closeTime = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketclose + 'Z');
1466
+ if (currentDate.getTime() > closeTime.getTime()) {
1467
+ currentDate = new Date(currentDate.toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z');
1468
+ currentDate = new Date(currentDate.getTime() + 86400000);
1469
+ // offset += 86400000 / _this.scaleinfoX.timePerPixel;
1470
+ offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
1471
+ console.log('STÄNGT', currentDate);
1472
+ continue;
1473
+ }
1474
+ console.log(currentDate);
1475
+ x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1476
+ /*if (lastx == 0 && parseInt(m_chartCss['margin-left']) > (x - (getMaxTimeWidth() / 2))) { // do not print left of y legend
1477
+ console.log('ftst', currentDate);
1478
+ currentDate = new Date(currentDate.getTime() + 86400000);
1479
+ continue;
1480
+ }*/
1481
+ console.log(x, lastx, offset);
1482
+ if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
1483
+ draw = false;
1484
+ console.log('false');
1485
+ }
1486
+ if (draw) {
1487
+ lastx = x;
1488
+ var text = formatChartTime(currentDate.toTimeString().substring(0, 8), _this.settings.timeformat);
1489
+ // if day change and setting print on top as well
1490
+ if (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) > x - getMaxDateWidth()) // not to far right?
1491
+ m_ctx.fillText(text, x - (m_ctx.measureText(text).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
1492
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) });
1493
+ }
1494
+ //currentDate = new Date(currentDate.getTime() + 86400000);
1495
+ currentDate = new Date(currentDate.getTime() + _this.scaleinfoX.ticksize);
1496
+ }
1497
+ // vad är detta?
1498
+ if (typeof m_chartCss['box-shadow'] !== 'undefined') {
1499
+ var boxshadow = m_chartCss['box-shadow'].split(' ');
1500
+ if (parseInt(boxshadow[1]) == 0) drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1501
+
1502
+ } else
1503
+ drawXAxisGridlines({ 'x': x, y: m_canvas.height - parseInt(m_chartCss['margin-bottom']) }, false);
1504
+ m_ctx.restore();
1505
+
1506
+ }
1507
+
1508
+ function drawXAxisTick2(starttime, endtime) {
1057
1509
  // day and month axis
1058
1510
  m_ctx.save();
1059
1511
  m_ctx.font = m_xLegendCss['font-weight'] + ' ' + m_xLegendCss['font-size'] + ' ' + m_xLegendCss['font-family'];
@@ -1086,7 +1538,6 @@ function Milli_Chart(settings) {
1086
1538
  while (p.x < (_this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 2))) { // && oldx != p.x) {
1087
1539
  var dayChange = false;
1088
1540
  if (currentDate.getTime() > endtime) {
1089
- //console.log('larget than endtime', currentDate, new Date(endtime));
1090
1541
  break;
1091
1542
  }
1092
1543
  oldx = p.x;
@@ -1118,16 +1569,7 @@ function Milli_Chart(settings) {
1118
1569
  }
1119
1570
  //console.log(currentDate, _this.scaleinfoX.endDate);
1120
1571
  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
1572
  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
1573
  }
1132
1574
  offset += (86400000 - _this.scaleinfoX.milliPerDay) / _this.scaleinfoX.timePerPixel;
1133
1575
  lastDate = new Date(currentDate);
@@ -1136,8 +1578,9 @@ function Milli_Chart(settings) {
1136
1578
  }
1137
1579
  var fontMetrix;
1138
1580
  var nextx = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1139
- //console.log(datum,nextx,p.x,_this.scaleinfoX.itemwidth,lastDrawX);
1140
- 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)
1581
+ //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)
1582
+ console.log(nextx, p.x, currentDate);
1583
+ 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
1584
  //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
1585
  if (nextx < _this.scaleinfoX.lineLength + parseInt(m_chartCss['margin-left']) - (_this.scaleinfoX.itemwidth / 1)) { // is it too close to next?
1143
1586
  //console.log('HIDE');
@@ -1191,7 +1634,8 @@ function Milli_Chart(settings) {
1191
1634
  drawXAxisGridlines(p, p.x == parseInt(m_chartCss['margin-left']) ? false : dash);
1192
1635
  }
1193
1636
  lastDrawX = p.x;
1194
- } else
1637
+ }
1638
+ //else
1195
1639
  if (p.x < m_canvas.width - m_ctx.measureText(datum).width) { // if text will be cropped do not print
1196
1640
  m_ctx.fillText(datum, p.x - (m_ctx.measureText(datum).width / 2), m_canvas.height - parseInt(m_chartCss['margin-bottom']) + 10);
1197
1641
  if (drawGridline) {
@@ -1305,6 +1749,7 @@ function Milli_Chart(settings) {
1305
1749
  m_toolTip.dateDiv.innerHTML += ':' + zeroPad(d.getMinutes(), 2);
1306
1750
  m_toolTip.dateDiv.innerHTML += ':' + zeroPad(d.getSeconds(), 2);
1307
1751
  }
1752
+ m_toolTip.dateDiv.innerHTML += 'X:' + x;
1308
1753
  m_toolTip.dateDiv.setAttribute('class', 'millistream-chart-tooltip'); // set class so we can measure it might change below depending on position
1309
1754
  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
1755
 
@@ -1406,7 +1851,6 @@ function Milli_Chart(settings) {
1406
1851
  m_toolTip.arrowDiv[k].style.position = 'absolute';
1407
1852
  color = m_instrumentCss[k].color;
1408
1853
  m_toolTip.arrowDiv[k].style.backgroundColor = color;
1409
- m_toolTip.arrowDiv[k].style.boxShadow = '0px 0px 17px 7px ' + color;
1410
1854
  m_toolTip.arrowDiv[k].style.pointerEvents = 'none';
1411
1855
  }
1412
1856
  if (posy > highy) highy = posy;
@@ -1850,6 +2294,7 @@ function Milli_Chart(settings) {
1850
2294
  m_resizeing = false;
1851
2295
  m_canvas.setAttribute('height', _this.settings.target.offsetHeight + 'px');
1852
2296
  m_canvas.setAttribute('width', _this.settings.target.offsetWidth + 'px'); // läs från css?
2297
+ console.log('Width:', _this.settings.target.offsetWidth);
1853
2298
  _this.drawChart();
1854
2299
  };
1855
2300
 
@@ -2017,8 +2462,11 @@ function Milli_Chart(settings) {
2017
2462
  //console.log(startpoint.x);
2018
2463
 
2019
2464
  // 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)
2465
+ if (_this.scaleinfoY.type == 'trades' && tmpx < startpoint.x) {
2021
2466
  m_ctx.lineTo(startpoint.x, startpoint.y);
2467
+ }
2468
+
2469
+ //m_ctx.lineTo(startpoint.x, startpoint.y);
2022
2470
 
2023
2471
  }
2024
2472
  //p.x = Math.round(parseInt(m_chartCss['margin-left']) + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset); // from drawXaxis
@@ -2046,6 +2494,8 @@ function Milli_Chart(settings) {
2046
2494
  if (tmpx < startpoint.x) {
2047
2495
  if (_this.settings.hcurve) m_ctx.lineTo(startpoint.x, endpoint.y);
2048
2496
  m_ctx.lineTo(startpoint.x, startpoint.y);
2497
+ //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"
2498
+
2049
2499
  if (instrument == 0) {
2050
2500
  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
2501
  if (typeof data[i].dividend !== 'undefined') point.dividend = data[i].dividend;
@@ -2271,12 +2721,9 @@ function Milli_Chart(settings) {
2271
2721
  }
2272
2722
  //console.log('onmouseup', m_zoom.mousedown.timestamp, m_zoom.mouseup.timestamp)
2273
2723
  }
2274
- //m_zoom.mousedown.timestamp = null;
2275
- //m_zoom.mouseup.timestamp = null;
2276
2724
  if (m_zoom.div) m_canvas.parentNode.removeChild(m_zoom.div);
2277
2725
  m_zoom.div = null;
2278
2726
  m_zoom.isZooming = false;
2279
- //console.log('CLEAR');
2280
2727
  });
2281
2728
  } else {
2282
2729
  //m_ctx.clearRect(0, 0, m_canvas.width, m_canvas.height);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@millistream/millistream-widgets",
3
- "version": "0.0.11",
3
+ "version": "0.0.14",
4
4
  "description": "Millistream widgets node package",
5
5
  "main": "millistream-widgets.js",
6
6
  "scripts": {