@millistream/millistream-widgets 1.0.39 → 1.0.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/millistream-widgets.js +238 -849
  2. package/package.json +1 -1
@@ -210,7 +210,6 @@ function Milli_Chart(settings) {
210
210
 
211
211
  function getScaledSetting(setting) {
212
212
  return parseInt(setting);
213
- // return parseInt(setting) * window.devicePixelRatio;
214
213
  }
215
214
  _this.get_lang_text = function(string) {
216
215
  return string;
@@ -250,7 +249,6 @@ function Milli_Chart(settings) {
250
249
  }
251
250
 
252
251
  function getFontSize(obj) {
253
- //return parseInt(obj.fontSize) * 1;
254
252
  return parseInt(obj.fontSize);
255
253
  }
256
254
 
@@ -348,37 +346,32 @@ function Milli_Chart(settings) {
348
346
  }
349
347
 
350
348
  function getTickNextTickValue(value) {
351
- return (value < 0.000001 ? 0.0000005 :
352
- (value < 0.0000015 ? 0.000001 :
353
- (value < 0.0000025 ? 0.000002 :
354
- (value < 0.000005 ? 0.0000025 :
355
- (value < 0.0000075 ? 0.000005 :
356
- (value < 0.00001 ? 0.000005 :
357
- (value < 0.000015 ? 0.00001 :
358
- (value < 0.000025 ? 0.00002 :
359
- (value < 0.00005 ? 0.000025 :
360
- (value < 0.000075 ? 0.00005 :
361
- (value < 0.0001 ? 0.00005 :
362
- (value < 0.00015 ? 0.0001 :
363
- (value < 0.00025 ? 0.0002 :
364
- (value < 0.0005 ? 0.00025 :
365
- (value < 0.00075 ? 0.0005 :
366
- (value < 0.001 ? 0.0005 :
367
- (value < 0.0015 ? 0.001 :
368
- (value < 0.0025 ? 0.002 :
369
- (value < 0.005 ? 0.0025 :
370
- (value < 0.0075 ? 0.005 :
371
- (value < 0.01 ? 0.005 :
372
- (value < 0.015 ? 0.01 :
373
- (value < 0.025 ? 0.02 :
374
- (value < 0.05 ? 0.025 :
375
- (value < 0.075 ? 0.05 :
376
- (value < 0.1 ? 0.05 :
377
- (value < 0.15 ? 0.1 :
378
- (value < 0.25 ? 0.20 :
379
- (value < 0.5 ? 0.25 :
380
- (value < 0.75 ? 0.5 :
381
- 1))))))))))))))))))))))))))))));
349
+ if (value < 0.000001) return 0.0000005;
350
+ if (value < 0.0000015) return 0.000001;
351
+ if (value < 0.0000025) return 0.000002;
352
+ if (value < 0.000005) return 0.0000025;
353
+ if (value < 0.00001) return 0.000005;
354
+ if (value < 0.000015) return 0.00001;
355
+ if (value < 0.000025) return 0.00002;
356
+ if (value < 0.00005) return 0.000025;
357
+ if (value < 0.0001) return 0.00005;
358
+ if (value < 0.00015) return 0.0001;
359
+ if (value < 0.00025) return 0.0002;
360
+ if (value < 0.0005) return 0.00025;
361
+ if (value < 0.001) return 0.0005;
362
+ if (value < 0.0015) return 0.001;
363
+ if (value < 0.0025) return 0.002;
364
+ if (value < 0.005) return 0.0025;
365
+ if (value < 0.01) return 0.005;
366
+ if (value < 0.015) return 0.01;
367
+ if (value < 0.025) return 0.02;
368
+ if (value < 0.05) return 0.025;
369
+ if (value < 0.1) return 0.05;
370
+ if (value < 0.15) return 0.1;
371
+ if (value < 0.25) return 0.2;
372
+ if (value < 0.5) return 0.25;
373
+ if (value < 0.75) return 0.5;
374
+ return 1;
382
375
  }
383
376
 
384
377
  function getTickValue(minValue, maxValue, num_labels) {
@@ -411,6 +404,11 @@ function Milli_Chart(settings) {
411
404
  m_ctx.stroke();
412
405
  m_ctx.closePath();
413
406
  var x = cs.left - 3;
407
+ if (m_yLegendCss.float == 'right') {
408
+ x = cs.right;
409
+ }
410
+
411
+
414
412
  var lineLength = cs.bottom - cs.top;
415
413
  var numticks = lineLength / (getFontSize(m_yLegendCss) * 2);
416
414
  if (numticks < 1) {
@@ -478,7 +476,16 @@ function Milli_Chart(settings) {
478
476
  if (m_yLegendCss.verticalAlign == 'top') {
479
477
  if (y - (getFontSize(m_yLegendCss)) > 0) // dont draw if cropped
480
478
  m_ctx.fillText(label, textpos, y - ((getFontSize(m_yLegendCss) + 2)));
481
- } else
479
+ } else if(m_yLegendCss.float == 'right') {
480
+ if (m_yLegendCss.textAlign == 'right') {
481
+ m_ctx.textAlign = 'left';
482
+ textpos = x + 5;
483
+ } else {
484
+ m_ctx.textAlign = 'right';
485
+ textpos = x - 5;
486
+ }
487
+ m_ctx.fillText(label, textpos, y - (getFontSize(m_yLegendCss) / 2));
488
+ } else
482
489
  m_ctx.fillText(label, textpos, y - (getFontSize(m_yLegendCss) / 2));
483
490
  }
484
491
  }
@@ -494,335 +501,7 @@ function Milli_Chart(settings) {
494
501
  return true;
495
502
  }
496
503
 
497
- /*function calcHighLow(scaleinfoY, scaleinfoY2) {
498
- scaleinfoY.lowValue = null;
499
- scaleinfoY.highValue = null;
500
- scaleinfoY2.lowValue = null;
501
- scaleinfoY2.highValue = null;
502
-
503
- _this.scaleinfoY.lowValue = null;
504
- _this.scaleinfoY.highValue = null;
505
- _this.scaleinfoY2.lowValue = null;
506
- _this.scaleinfoY2.highValue = null;
507
- _this.scaleinfoY.lowLowerChart = null;
508
- _this.scaleinfoY.highLowerChart = null;
509
-
510
- var data, i;
511
- var useCloseprice = false;
512
- var today = new Date().getTime();
513
- today -= today % 86400000;
514
- var lastTradeDate = new Date().getTime();
515
- var todaysOpenTime = new Date(new Date().toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z').getTime();
516
-
517
- if (typeof _this.instruments[0].trades !== 'undefined' && _this.instruments[0].trades.length > 0) {
518
- lastTradeDate = new Date(_this.instruments[0].trades[_this.instruments[0].trades.length - 1].timestamp).getTime();
519
- lastTradeDate -= lastTradeDate % 86400000;
520
- }
521
-
522
- var quote_timestamp = _this.instruments[0].quotedate + _this.instruments[0].quotetime;
523
- if ((_this.instruments[0].quotedate == today && quote_timestamp > todaysOpenTime) || _this.instruments[0].quotedate == lastTradeDate) useCloseprice = true;
524
-
525
- for (var s = 0; s < _this.instruments.length; s++) {
526
- if (_this.instruments[s].insref == 0) continue;
527
- _this.instruments[s].startValue = null;
528
- data = _this.instruments[s][chartType];
529
- if (chartType != 'history' && useCloseprice) {
530
- if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) {
531
- _this.instruments[s].startValue = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
532
- }
533
- }
534
- //var quantity = 0;
535
- let prevPrice = null;
536
- for (i = 0; i < data.length; i++) {
537
- // only calc on visible data
538
- var price = data[i].price * _this.instruments[s].factor;
539
- let highprice = data[i].highprice * _this.instruments[s].factor;
540
- let lowprice = data[i].lowprice * _this.instruments[s].factor;
541
-
542
- //quantity = 0;
543
- if (data[i].timestamp < _this.scaleinfoX.startTimeStamp) {
544
- if (chartType == 'history') {
545
- //_this.instruments[s].startValue = price; // skall inte sättas eftersom vi inte ritar den i history
546
- scaleinfoY2.lowValue = 0;
547
- scaleinfoY2.highValue = 0;
548
- }
549
- //else if (_this.settings.chartlen != '1d' && _this.settings.chartlen != '0d' && !m_zoom.mousedown.timestamp) {
550
- else if (useCloseprice == false || m_zoom.mousedown.timestamp) {
551
- _this.instruments[s].startValue = price;
552
- }
553
- continue;
554
- }
555
- if (data[i].timestamp > _this.scaleinfoX.endTimeStamp) {
556
- break;
557
- }
558
- _this.instruments[s].endValue = price;
559
-
560
- if (chartType != 'history' && (data[i].timestamp % 86400000 < _this.instruments[0].opentimestamp || data[i].timestamp % 86400000 > _this.instruments[0].closetimestamp)) {
561
- // stämmer detta kan det bli överlapp vid sommartid/vintertid?
562
- continue;
563
- }
564
-
565
- if (_this.instruments[s].startValue == null) { // no value before this date , use this date?
566
- if (chartType == 'history') {
567
- _this.instruments[s].startValue = price;
568
- } else {
569
- if (isToday(new Date(data[i].timestamp)) && !m_zoom.mousedown.timestamp) {
570
- _this.instruments[s].startValue = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
571
- } else {
572
- _this.instruments[s].startValue = price;
573
- }
574
- }
575
- }
576
- if(_this.settings.type == 'ohlc' || _this.settings.type == 'candlestick') {
577
- if (scaleinfoY.lowValue == null || scaleinfoY.lowValue > lowprice) scaleinfoY.lowValue = lowprice;
578
- if (scaleinfoY.highValue == null || scaleinfoY.highValue < highprice) scaleinfoY.highValue = highprice;
579
- }
580
- else {
581
- if (scaleinfoY.lowValue == null || scaleinfoY.lowValue > price) scaleinfoY.lowValue = price;
582
- if (scaleinfoY.highValue == null || scaleinfoY.highValue < price) scaleinfoY.highValue = price;
583
- }
584
- var diff = (price - _this.instruments[s].startValue);
585
- if (diff != 0) diff = diff / _this.instruments[s].startValue * 100;
586
- if (_this.instruments[s].startValue == null) diff = 0;
587
- data[i].diff = diff;
588
- if (scaleinfoY2.lowValue == null || scaleinfoY2.lowValue > diff) scaleinfoY2.lowValue = diff;
589
- if (scaleinfoY2.highValue == null || scaleinfoY2.highValue < diff) scaleinfoY2.highValue = diff;
590
- //if (scaleinfoY.lowLowerChart == null || scaleinfoY.lowLowerChart > quantity) scaleinfoY.lowLowerChart = quantity;
591
- //if (scaleinfoY.highLowerChart == null || scaleinfoY.highLowerChart < quantity) scaleinfoY.highLowerChart = quantity;
592
- }
593
- if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) { // if closeprice is used calch high/low on it
594
- var cp = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
595
- if (scaleinfoY.lowValue > cp) scaleinfoY.lowValue = cp;
596
- else
597
- if (scaleinfoY.highValue < cp) scaleinfoY.highValue = cp;
598
- }
599
- if (chartType != 'history') {
600
- if (scaleinfoY2.lowValue > 0) {
601
- scaleinfoY2.lowValue = 0;
602
- } else {
603
- if (scaleinfoY2.highValue < 0) scaleinfoY2.highValue = 0;
604
- }
605
- }
606
- if (_this.instruments[s].startValue) { // ta bort? fråga mats
607
- if (_this.instruments[s].startValue > scaleinfoY.highValue) scaleinfoY.highValue = _this.instruments[s].startValue;
608
- if (_this.instruments[s].startValue < scaleinfoY.lowValue) scaleinfoY.lowValue = _this.instruments[s].startValue;
609
- }
610
- }
611
- if (scaleinfoY.lowValue == null) {
612
- scaleinfoY.lowValue = 0;
613
- scaleinfoY.highValue = 100;
614
- scaleinfoY2.lowValue = 0;
615
- scaleinfoY2.highValue = 100;
616
- return;
617
- } else
618
- if (scaleinfoY.lowValue == scaleinfoY.highValue && scaleinfoY.lowValue == 0) {
619
- scaleinfoY.lowValue -= 1;
620
- scaleinfoY.highValue += 1;
621
- scaleinfoY.lowValue -= 1;
622
- scaleinfoY.highValue += 1;
623
- }
624
- // do we have any analyzis we need to take into account
625
- for (i = 0; i < _this.settings.indicators.length; i++) {
626
- if (_this.settings.indicators[i].method == 'rsi') continue;
627
- if (_this.settings.indicators[i].method == 'quantity') continue;
628
- if (_this.settings.indicators[i].method == 'news') continue;
629
- if (_this.settings.indicators[i].target == 'lower') continue;
630
- if (!_this.settings.indicators[i].timeseries || _this.settings.indicators[i].timeseries.length == 0) {
631
- continue;
632
- }
633
- data = _this.settings.indicators[i].timeseries;
634
- for (s = 0; s < data.length; s++) {
635
- if (data[s].timestamp < _this.scaleinfoX.startTimeStamp) {
636
- continue;
637
- }
638
- if (data[s].timestamp > _this.scaleinfoX.endTimeStamp) {
639
- break;
640
- }
641
- if (typeof data[s].datapoints !== 'undefined') {
642
- for (var x = 0; x < data[s].datapoints.length; x++) {
643
- if (data[s].datapoints[x] < scaleinfoY.lowValue) {
644
- scaleinfoY.lowValue = data[s].datapoints[x];
645
- scaleinfoY2.lowValue = data[s].datapoints[x] - _this.instruments[0].startValue; // lower min diff to get full legend from bottom
646
- } else {
647
- if (data[s].datapoints[x] > scaleinfoY.highValue) {
648
- scaleinfoY.highValue = data[s].datapoints[x];
649
- scaleinfoY2.highValue = data[s].datapoints[x] - _this.instruments[0].startValue; // lower min diff to get full legend from bottom
650
- }
651
- }
652
- }
653
- }
654
- }
655
- }
656
- scaleinfoY2.lowValue = (scaleinfoY.lowValue - _this.instruments[0].startValue) / _this.instruments[0].startValue * 100;
657
- scaleinfoY2.highValue = (scaleinfoY.highValue - _this.instruments[0].startValue) / _this.instruments[0].startValue * 100;
658
- return 1;
659
- }
660
- */
661
- /* function calcHighLow2(scale, cs, css, factorInfo) {
662
- scale.lowValue = null;
663
- scale.highValue = null;
664
-
665
- let data, i;
666
- let useCloseprice = false;
667
- let today = new Date().getTime();
668
- today -= today % 86400000;
669
- let lastTradeDate = new Date().getTime();
670
- let todaysOpenTime = new Date(new Date().toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z').getTime();
671
-
672
- if (typeof _this.instruments[0].trades !== 'undefined' && _this.instruments[0].trades.length > 0) {
673
- lastTradeDate = new Date(_this.instruments[0].trades[_this.instruments[0].trades.length - 1].timestamp).getTime();
674
- lastTradeDate -= lastTradeDate % 86400000;
675
- }
676
-
677
- var quote_timestamp = _this.instruments[0].quotedate + _this.instruments[0].quotetime;
678
- if ((_this.instruments[0].quotedate == today && quote_timestamp > todaysOpenTime) || _this.instruments[0].quotedate == lastTradeDate) useCloseprice = true;
679
-
680
- for (var s = 0; s < _this.instruments.length; s++) {
681
- if (_this.instruments[s].insref == 0) continue;
682
- _this.instruments[s].startValue = null;
683
- data = _this.instruments[s][chartType];
684
- if (chartType != 'history' && useCloseprice) {
685
- if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) {
686
- _this.instruments[s].startValue = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
687
- }
688
- }
689
- //var quantity = 0;
690
-
691
- for (i = 0; i < data.length; i++) {
692
- // only calc on visible data
693
- var price = data[i].price * _this.instruments[s].factor;
694
-
695
- if (data[i].timestamp < _this.scaleinfoX.startTimeStamp) {
696
- if (chartType == 'history') {
697
- _this.instruments[s].startValue = price;
698
- }
699
- //else if (_this.settings.chartlen != '1d' && _this.settings.chartlen != '0d' && !m_zoom.mousedown.timestamp) {
700
- else if (useCloseprice == false || m_zoom.mousedown.timestamp) {
701
- _this.instruments[s].startValue = price;
702
- }
703
- continue;
704
- }
705
- if (data[i].timestamp > _this.scaleinfoX.endTimeStamp) {
706
- break;
707
- }
708
-
709
- if (chartType != 'history' && (data[i].timestamp % 86400000 < _this.instruments[0].opentimestamp || data[i].timestamp % 86400000 > _this.instruments[0].closetimestamp)) { // summertime?
710
- continue;
711
- }
712
-
713
- if (_this.instruments[s].startValue == null) { // no value before this date , use this date?
714
- if (chartType == 'history') {
715
- _this.instruments[s].startValue = price;
716
- } else {
717
- if (isToday(new Date(data[i].timestamp)) && !m_zoom.mousedown.timestamp) {
718
- _this.instruments[s].startValue = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
719
- } else {
720
- _this.instruments[s].startValue = price;
721
- }
722
- }
723
- }
724
- if (typeof factorInfo === 'undefined') {
725
- if (scale.lowValue == null || scale.lowValue > price) scale.lowValue = price;
726
- if (scale.highValue == null || scale.highValue < price) scale.highValue = price;
727
- } else {
728
- let diff = (price - _this.instruments[s].startValue);
729
- if (diff != 0) diff = diff / _this.instruments[s].startValue * 100;
730
- if (_this.instruments[s].startValue == null) diff = 0;
731
- data[i][factorInfo.name] = diff;
732
- if (scale.lowValue == null || scale.lowValue > diff) scale.lowValue = diff;
733
- if (scale.highValue == null || scale.highValue < diff) scale.highValue = diff;
734
- }
735
- }
736
- // hur hantera om factorInfo
737
- if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) { // if closeprice is used calch high/low on it
738
- var cp = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
739
- if (scale.lowValue > cp) scale.lowValue = cp;
740
- else
741
- if (scale.highValue < cp) scale.highValue = cp;
742
- }
743
- if (chartType != 'history') {
744
- consolle
745
- if (scale.lowValue > 0) {
746
- scale.lowValue = 0;
747
- } else {
748
- if (scale.highValue < 0) scale.highValue = 0;
749
- }
750
- }
751
- if (typeof factorInfo === 'undefined') {
752
- if (_this.instruments[s].startValue) { // ta bort? fråga mats
753
- if (_this.instruments[s].startValue > scale.highValue) scale.highValue = _this.instruments[s].startValue;
754
- if (_this.instruments[s].startValue < scale.lowValue) scale.lowValue = _this.instruments[s].startValue;
755
- }
756
- }
757
- }
758
- if (scale.lowValue == null) {
759
- scale.lowValue = 0;
760
- scale.highValue = 100;
761
- } else
762
- if (scale.lowValue == scale.highValue && scale.lowValue == 0) {
763
- scale.lowValue -= 1;
764
- scale.highValue += 1;
765
- }
766
- // do we have any analyzis we need to take into account
767
- if (typeof factorInfo === 'undefined') {
768
- for (i = 0; i < _this.settings.indicators.length; i++) {
769
- if (_this.settings.indicators[i].method == 'rsi') continue;
770
- if (_this.settings.indicators[i].method == 'quantity') continue;
771
- if (!_this.settings.indicators[i].timeseries || _this.settings.indicators[i].timeseries.length == 0) continue;
772
- data = _this.settings.indicators[i].timeseries;
773
- for (s = 0; s < data.length; s++) {
774
- if (data[s].timestamp < _this.scaleinfoX.startTimeStamp) {
775
- continue;
776
- }
777
- if (data[s].timestamp > _this.scaleinfoX.endTimeStamp) {
778
- break;
779
- }
780
- if (typeof data[s].datapoints !== 'undefined') {
781
- for (var x = 0; x < data[i].datapoints.length; x++) {
782
- if (data[s].datapoints[x] < scale.lowValue) {
783
- scale.lowValue = data[s].datapoints[x];
784
- } else {
785
- if (data[s].datapoints[x] > scaleinfoY.highValue) {
786
- scale.highValue = data[s].datapoints[x];
787
- }
788
- }
789
- }
790
- }
791
- }
792
- }
793
- }
794
- m_ctx.font = css.fontWeight + ' ' + css.fontSize + ' ' + css.fontFamily; // set font so measure works
795
-
796
- let v = (scale.highValue - scale.lowValue) / scale.lineLength;
797
- scale.maxValue = scale.highValue + (v * parseInt(css.fontSize));
798
- scale.minValue = scale.lowValue - (v * parseInt(css.fontSize));
799
- scale.lineLength = cs.bottom - cs.top;
800
-
801
- let numticks = scale.lineLength / (getFontSize(css) * _this.settings.yAxisSpacing);
802
- if (numticks > 8) numticks = 8; // limit to 8 items on Y legend ( this is not an absolut count, since we calculate nice legend numbers
803
- scale.tickSize = getTickValue(scale.lowValue, scale.highValue, numticks);
804
- scale.decimals = scale.tickSize.countDecimals();
805
-
806
- if (typeof factorInfo === 'undefined') {
807
- if (scale.decimals > 4) scale.decimals = 4;
808
- else if (scale.decimals < 2) scale.decimals = 2;
809
- }
810
-
811
- let widestValue = (scale.lowValue < 0 ? '-' : '') + Math.max(Math.abs(scale.highValue), Math.abs(scale.lowValue));
812
- let label = formatNiceNumber(widestValue, _this.settings.thousandseparator, _this.settings.decimalseparator, scale.decimals);
813
- if (typeof factorInfo !== 'undefined' && typeof factorInfo.suffix !== 'undefined') label += factorInfo.suffix;
814
- if (css.float != 'right') {
815
- cs.left = 10 + Math.round(m_ctx.measureText(label).width); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
816
- } else {
817
- if (css.textAlign == 'right') {
818
- cs.right = m_canvas.getWidth() - (10 + Math.round(m_ctx.measureText(label).width)); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
819
- }
820
- }
821
- return true;
822
- }
823
- */
824
-
825
- function calcHighLow(scaleinfoY, scaleinfoY2) {
504
+ function calcHighLow(scaleinfoY, scaleinfoY2) {
826
505
  scaleinfoY.lowValue = null;
827
506
  scaleinfoY.highValue = null;
828
507
  scaleinfoY2.lowValue = null;
@@ -901,167 +580,22 @@ function Milli_Chart(settings) {
901
580
  }
902
581
  }
903
582
  }
904
- if(_this.settings.type == 'ohlc' || _this.settings.type == 'candlestick') {
905
- if (scaleinfoY.lowValue == null || scaleinfoY.lowValue > lowprice) scaleinfoY.lowValue = lowprice;
906
- if (scaleinfoY.highValue == null || scaleinfoY.highValue < highprice) scaleinfoY.highValue = highprice;
907
- }
908
- else {
909
- if (scaleinfoY.lowValue == null || scaleinfoY.lowValue > price) scaleinfoY.lowValue = price;
910
- if (scaleinfoY.highValue == null || scaleinfoY.highValue < price) scaleinfoY.highValue = price;
911
- }
912
- let diff = (price - _this.instruments[s].startValue);
913
- if (diff != 0) diff = diff / _this.instruments[s].startValue * 100;
914
- if (_this.instruments[s].startValue == null) diff = 0;
915
- data[i].diff = diff;
916
- if (scaleinfoY2.lowValue == null || scaleinfoY2.lowValue > diff) scaleinfoY2.lowValue = diff;
917
- if (scaleinfoY2.highValue == null || scaleinfoY2.highValue < diff) scaleinfoY2.highValue = diff;
918
- }
919
- if (useCloseprice && !m_zoom.mousedown.timestamp) { // if closeprice is used calch high/low on it
920
- var cp = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
921
- if (scaleinfoY.lowValue > cp) scaleinfoY.lowValue = cp;
922
- else
923
- if (scaleinfoY.highValue < cp) scaleinfoY.highValue = cp;
924
- }
925
- if (chartType != 'history') {
926
- if (scaleinfoY2.lowValue > 0) {
927
- scaleinfoY2.lowValue = 0;
928
- } else {
929
- if (scaleinfoY2.highValue < 0) scaleinfoY2.highValue = 0;
930
- }
931
- }
932
- if (_this.instruments[s].startValue) {
933
- if (_this.instruments[s].startValue > scaleinfoY.highValue) scaleinfoY.highValue = _this.instruments[s].startValue;
934
- if (_this.instruments[s].startValue < scaleinfoY.lowValue) scaleinfoY.lowValue = _this.instruments[s].startValue;
935
- }
936
- }
937
- if (scaleinfoY.lowValue == null) {
938
- scaleinfoY.lowValue = 0;
939
- scaleinfoY.highValue = 100;
940
- scaleinfoY2.lowValue = 0;
941
- scaleinfoY2.highValue = 100;
942
- return;
943
- } else
944
- if (scaleinfoY.lowValue == scaleinfoY.highValue && scaleinfoY.lowValue == 0) {
945
- scaleinfoY.lowValue -= 1;
946
- scaleinfoY.highValue += 1;
947
- scaleinfoY.lowValue -= 1;
948
- scaleinfoY.highValue += 1;
949
- }
950
- // do we have any analyzis we need to take into account
951
- for (i = 0; i < _this.settings.indicators.length; i++) {
952
- if (_this.settings.indicators[i].method == 'rsi') continue;
953
- if (_this.settings.indicators[i].method == 'quantity') continue;
954
- if (_this.settings.indicators[i].method == 'news') continue;
955
- if (_this.settings.indicators[i].target == 'lower') continue;
956
- if (!_this.settings.indicators[i].timeseries || _this.settings.indicators[i].timeseries.length == 0) {
957
- continue;
958
- }
959
- data = _this.settings.indicators[i].timeseries;
960
- for (s = 0; s < data.length; s++) {
961
- if (data[s].timestamp < _this.scaleinfoX.startTimeStamp) {
962
- continue;
963
- }
964
- if (data[s].timestamp > _this.scaleinfoX.endTimeStamp) {
965
- break;
966
- }
967
- if (typeof data[s].datapoints !== 'undefined') {
968
- for (var x = 0; x < data[s].datapoints.length; x++) {
969
- if (data[s].datapoints[x] < scaleinfoY.lowValue) {
970
- scaleinfoY.lowValue = data[s].datapoints[x];
971
- scaleinfoY2.lowValue = data[s].datapoints[x] - _this.instruments[0].startValue; // lower min diff to get full legend from bottom
972
- } else {
973
- if (data[s].datapoints[x] > scaleinfoY.highValue) {
974
- scaleinfoY.highValue = data[s].datapoints[x];
975
- scaleinfoY2.highValue = data[s].datapoints[x] - _this.instruments[0].startValue; // lower min diff to get full legend from bottom
976
- }
977
- }
978
- }
979
- }
980
- }
981
- }
982
- scaleinfoY2.lowValue = (scaleinfoY.lowValue - _this.instruments[0].startValue) / _this.instruments[0].startValue * 100;
983
- scaleinfoY2.highValue = (scaleinfoY.highValue - _this.instruments[0].startValue) / _this.instruments[0].startValue * 100;
984
- return 1;
985
- }
986
- /*function calcHighLow() {
987
- scaleinfoY.lowValue = null;
988
- scaleinfoY.highValue = null;
989
- scaleinfoY2.lowValue = null;
990
- scaleinfoY2.highValue = null;
991
- scaleinfoY.lowLowerChart = null;
992
- scaleinfoY.highLowerChart = null;
993
- var data, i;
994
- var useCloseprice = false;
995
- var today = new Date().getTime();
996
- today -= today % 86400000;
997
- var lastTradeDate = new Date().getTime();
998
- var todaysOpenTime = new Date(new Date().toISOString().substring(0, 10) + 'T' + _this.instruments[0].marketopen + 'Z').getTime();
999
- if (typeof _this.instruments[0].trades !== 'undefined' && _this.instruments[0].trades.length > 0) {
1000
- lastTradeDate = new Date(_this.instruments[0].trades[_this.instruments[0].trades.length - 1].timestamp).getTime();
1001
- lastTradeDate -= lastTradeDate % 86400000;
1002
- }
1003
- var quote_timestamp = _this.instruments[0].quotedate + _this.instruments[0].quotetime;
1004
-
1005
- if ((_this.instruments[0].quotedate == today && quote_timestamp > todaysOpenTime) || _this.instruments[0].quotedate == lastTradeDate) useCloseprice = true;
1006
- for (var s = 0; s < _this.instruments.length; s++) {
1007
- if (_this.instruments[s].insref == 0) continue;
1008
- _this.instruments[s].startValue = null;
1009
- data = _this.instruments[s][chartType];
1010
- if (chartType != 'history' && useCloseprice) {
1011
- if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) {
1012
- _this.instruments[s].startValue = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
1013
- }
1014
- }
1015
- var quantity = 0;
1016
-
1017
- for (i = 0; i < data.length; i++) {
1018
- // only calc on visible data
1019
- var price = data[i].price * _this.instruments[s].factor;
1020
- quantity = 0;
1021
- if (data[i].quantity !== 'undefined') {
1022
- quantity = data[i].quantity;
1023
- }
1024
- if (data[i].timestamp < _this.scaleinfoX.startTimeStamp) {
1025
- if (chartType == 'history') _this.instruments[s].startValue = price;
1026
- //else if (_this.settings.chartlen != '1d' && _this.settings.chartlen != '0d' && !m_zoom.mousedown.timestamp) {
1027
- else if (useCloseprice == false || m_zoom.mousedown.timestamp) {
1028
- _this.instruments[s].startValue = price;
1029
- }
1030
- continue;
1031
- }
1032
- if (data[i].timestamp > _this.scaleinfoX.endTimeStamp) {
1033
- break;
1034
- }
1035
-
1036
- if (chartType != 'history' && (data[i].timestamp % 86400000 < _this.instruments[0].opentimestamp || data[i].timestamp % 86400000 > _this.instruments[0].closetimestamp)) {
1037
- // stämmer detta kan det bli överlapp vid sommartid/vintertid?
1038
- continue;
1039
- }
1040
-
1041
- if (_this.instruments[s].startValue == null) {
1042
- if (chartType == 'history') {
1043
- _this.instruments[s].startValue = price;
1044
- } else {
1045
- if (isToday(new Date(data[i].timestamp)) && !m_zoom.mousedown.timestamp) {
1046
- _this.instruments[s].startValue = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
1047
- } else {
1048
- _this.instruments[s].startValue = price;
1049
- }
1050
- }
1051
- }
1052
- if (scaleinfoY.lowValue == null || scaleinfoY.lowValue > price) scaleinfoY.lowValue = price;
1053
- if (scaleinfoY.highValue == null || scaleinfoY.highValue < price) scaleinfoY.highValue = price;
1054
- var diff = (price - _this.instruments[s].startValue);
583
+ if(_this.settings.type == 'ohlc' || _this.settings.type == 'candlestick') {
584
+ if (scaleinfoY.lowValue == null || scaleinfoY.lowValue > lowprice) scaleinfoY.lowValue = lowprice;
585
+ if (scaleinfoY.highValue == null || scaleinfoY.highValue < highprice) scaleinfoY.highValue = highprice;
586
+ }
587
+ else {
588
+ if (scaleinfoY.lowValue == null || scaleinfoY.lowValue > price) scaleinfoY.lowValue = price;
589
+ if (scaleinfoY.highValue == null || scaleinfoY.highValue < price) scaleinfoY.highValue = price;
590
+ }
591
+ let diff = (price - _this.instruments[s].startValue);
1055
592
  if (diff != 0) diff = diff / _this.instruments[s].startValue * 100;
1056
593
  if (_this.instruments[s].startValue == null) diff = 0;
1057
594
  data[i].diff = diff;
1058
-
1059
595
  if (scaleinfoY2.lowValue == null || scaleinfoY2.lowValue > diff) scaleinfoY2.lowValue = diff;
1060
596
  if (scaleinfoY2.highValue == null || scaleinfoY2.highValue < diff) scaleinfoY2.highValue = diff;
1061
- if (scaleinfoY.lowLowerChart == null || scaleinfoY.lowLowerChart > quantity) scaleinfoY.lowLowerChart = quantity;
1062
- if (scaleinfoY.highLowerChart == null || scaleinfoY.highLowerChart < quantity) scaleinfoY.highLowerChart = quantity;
1063
597
  }
1064
- if ((_this.settings.chartlen == '1d' || _this.settings.chartlen == '0d') && !m_zoom.mousedown.timestamp) { // if closeprice is used calch high/low on it
598
+ if (useCloseprice && !m_zoom.mousedown.timestamp) { // if closeprice is used calch high/low on it
1065
599
  var cp = parseFloat(_this.instruments[s].closeprice1d) * _this.instruments[s].factor;
1066
600
  if (scaleinfoY.lowValue > cp) scaleinfoY.lowValue = cp;
1067
601
  else
@@ -1079,22 +613,29 @@ function Milli_Chart(settings) {
1079
613
  if (_this.instruments[s].startValue < scaleinfoY.lowValue) scaleinfoY.lowValue = _this.instruments[s].startValue;
1080
614
  }
1081
615
  }
1082
-
1083
616
  if (scaleinfoY.lowValue == null) {
1084
617
  scaleinfoY.lowValue = 0;
1085
618
  scaleinfoY.highValue = 100;
1086
619
  scaleinfoY2.lowValue = 0;
1087
620
  scaleinfoY2.highValue = 100;
621
+ return;
1088
622
  } else
1089
623
  if (scaleinfoY.lowValue == scaleinfoY.highValue && scaleinfoY.lowValue == 0) {
1090
624
  scaleinfoY.lowValue -= 1;
1091
625
  scaleinfoY.highValue += 1;
626
+ scaleinfoY.lowValue -= 1;
627
+ scaleinfoY.highValue += 1;
1092
628
  }
1093
- console.log(_this.settings.indicators);
1094
629
  // do we have any analyzis we need to take into account
1095
630
  for (i = 0; i < _this.settings.indicators.length; i++) {
1096
- if (chartType == 'history') data = _this.settings.indicators[i].history;
1097
- else data = _this.settings.indicators[i].trades;
631
+ if (_this.settings.indicators[i].method == 'rsi') continue;
632
+ if (_this.settings.indicators[i].method == 'quantity') continue;
633
+ if (_this.settings.indicators[i].method == 'news') continue;
634
+ if (_this.settings.indicators[i].target == 'lower') continue;
635
+ if (!_this.settings.indicators[i].timeseries || _this.settings.indicators[i].timeseries.length == 0) {
636
+ continue;
637
+ }
638
+ data = _this.settings.indicators[i].timeseries;
1098
639
  for (s = 0; s < data.length; s++) {
1099
640
  if (data[s].timestamp < _this.scaleinfoX.startTimeStamp) {
1100
641
  continue;
@@ -1103,10 +644,16 @@ function Milli_Chart(settings) {
1103
644
  break;
1104
645
  }
1105
646
  if (typeof data[s].datapoints !== 'undefined') {
1106
- for (var x = 0; x < data[i].datapoints.length; x++) {
1107
- if (data[s].datapoints[x] < scaleinfoY.lowValue) scaleinfoY.lowValue = data[s].datapoints[x];
1108
- else
1109
- if (data[s].datapoints[x] > scaleinfoY.highValue) scaleinfoY.highValue = data[s].datapoints[x];
647
+ for (var x = 0; x < data[s].datapoints.length; x++) {
648
+ if (data[s].datapoints[x] < scaleinfoY.lowValue) {
649
+ scaleinfoY.lowValue = data[s].datapoints[x];
650
+ scaleinfoY2.lowValue = data[s].datapoints[x] - _this.instruments[0].startValue; // lower min diff to get full legend from bottom
651
+ } else {
652
+ if (data[s].datapoints[x] > scaleinfoY.highValue) {
653
+ scaleinfoY.highValue = data[s].datapoints[x];
654
+ scaleinfoY2.highValue = data[s].datapoints[x] - _this.instruments[0].startValue; // lower min diff to get full legend from bottom
655
+ }
656
+ }
1110
657
  }
1111
658
  }
1112
659
  }
@@ -1114,7 +661,7 @@ function Milli_Chart(settings) {
1114
661
  scaleinfoY2.lowValue = (scaleinfoY.lowValue - _this.instruments[0].startValue) / _this.instruments[0].startValue * 100;
1115
662
  scaleinfoY2.highValue = (scaleinfoY.highValue - _this.instruments[0].startValue) / _this.instruments[0].startValue * 100;
1116
663
  return 1;
1117
- }*/
664
+ }
1118
665
 
1119
666
  function drawY2Legend(scaleinfoY, scaleinfoY2, x) { // percent
1120
667
  if (_this.instruments[0].pricetype == 'yield') return;
@@ -1366,75 +913,6 @@ function Milli_Chart(settings) {
1366
913
  return true;
1367
914
  }
1368
915
 
1369
- function drawYAxisNew(scale, cs, css, drawAxis, gridLines, factor) {
1370
- /*let scale = {};
1371
- if (false == calcHighLow2(scale, factor)) {
1372
- console.log('fail highlow');
1373
- return;
1374
- }*/
1375
- m_ctx.save();
1376
- m_ctx.strokeStyle = m_gridHorizontalCss.color;
1377
- m_ctx.font = css.fontWeight + ' ' + css.fontSize + ' ' + css.fontFamily;
1378
- m_ctx.fillStyle = css.color;
1379
- scale.lineLength = cs.bottom - cs.top;
1380
- /* let numticks = scale.lineLength / (getFontSize(css) * _this.settings.yAxisSpacing);
1381
- if (numticks > 8) numticks = 8; // limit to 8 items on Y legend ( this is not an absolut count, since we calculate nice legend numbers
1382
- scale.tickSize = getTickValue(scale.lowValue, scale.highValue, numticks);
1383
- scale.decimals = scale.tickSize.countDecimals();*/
1384
- //scale.decimals > 4 ? 4 : (scale.decimals < 2 ? 2 : scale.decimals);
1385
-
1386
-
1387
-
1388
-
1389
- /* let widestValue = (scale.lowValue < 0 ? '-' : '') + Math.max(Math.abs(scale.highValue), Math.abs(scale.lowValue));
1390
- let label = formatNiceNumber(widestValue, _this.settings.thousandseparator, _this.settings.decimalseparator, scale.decimals);
1391
- console.log('testw', label, )
1392
- if (drawAxis) {
1393
- if (css.float != 'right') {
1394
- cs.left = 10 + Math.round(m_ctx.measureText(label).width); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
1395
- } else {
1396
- if (css.textAlign == 'right') {
1397
- cs.right = m_canvas.getWidth() - (10 + Math.round(m_ctx.measureText(label).width)); // + 'px'; // räkna fram hur hur mycket plats Y värdena tar och sätt margin till det, skall vi göra så?
1398
- }
1399
- }
1400
- }
1401
- */
1402
-
1403
-
1404
-
1405
-
1406
- if (css.float != 'right' && drawAxis) { // do we need to add space for half a date? ie prices are to tiny so date will be trunkated
1407
- m_ctx.save();
1408
- m_ctx.font = m_xLegendCss.fontWeight + ' ' + m_xLegendCss.fontSize + ' ' + m_xLegendCss.fontFamily;
1409
- if (getStringWidth(m_ctx, _this.settings.dateformat) / 2 + 5 > cs.left) {
1410
- cs.left = getStringWidth(m_ctx, _this.settings.dateformat) / 2 + 5;
1411
- }
1412
- m_ctx.restore();
1413
- }
1414
- // draw line
1415
- m_ctx.strokeStyle = m_gridVerticalCss.color;
1416
- m_ctx.beginPath();
1417
- m_ctx.moveTo(cs.left + 0.5, cs.top);
1418
- m_ctx.lineTo(cs.left + 0.5, cs.height - cs.marginBottom);
1419
- m_ctx.stroke();
1420
- m_ctx.closePath();
1421
- m_ctx.strokeStyle = m_gridHorizontalCss.color;
1422
- var x;
1423
- if (css.float == 'right')
1424
- x = cs.right;
1425
- else
1426
- x = cs.left;
1427
- if (css.textAlign == 'right') {
1428
- m_ctx.textAlign = 'left';
1429
- drawYLegendNew(scale, cs, x, css, drawAxis, gridLines, factor);
1430
- } else {
1431
- m_ctx.textAlign = 'right';
1432
- drawYLegendNew(scale, cs, x, css, drawAxis, gridLines), factor;
1433
- }
1434
- m_ctx.restore();
1435
- return scale;
1436
- }
1437
-
1438
916
  function drawYAxis(scaleinfoY, scaleinfoY2) {
1439
917
  m_ctx.save();
1440
918
  m_ctx.strokeStyle = m_gridHorizontalCss.color;
@@ -1609,9 +1087,11 @@ function Milli_Chart(settings) {
1609
1087
 
1610
1088
  function checkXLegendSides(x, text) {
1611
1089
  // right
1612
- if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left < x + (m_ctx.measureText(text).width / 2)) return false;
1090
+ if(x + (m_ctx.measureText(text).width / 2) > m_chartspaces.chart.width) return false;
1091
+ //if (_this.scaleinfoX.lineLength + m_chartspaces.chart.left < x + (m_ctx.measureText(text).width / 2)) return false;
1613
1092
  // left
1614
- if (m_chartspaces.chart.left > x - (m_ctx.measureText(text).width / 2)) return false;
1093
+ //if (m_chartspaces.chart.left > x - (m_ctx.measureText(text).width / 2)) return false;
1094
+ if (0 > x - (m_ctx.measureText(text).width / 2)) return false;
1615
1095
  return true;
1616
1096
 
1617
1097
  }
@@ -1779,11 +1259,13 @@ function Milli_Chart(settings) {
1779
1259
  offset += 86400000 / _this.scaleinfoX.timePerPixel;
1780
1260
  }
1781
1261
  x = Math.round(m_chartspaces.chart.left + ((currentDate.getTime() - _this.scaleinfoX.startDate.getTime()) / _this.scaleinfoX.timePerPixel) - offset);
1782
- if (lastx == 0 && m_chartspaces.chart.left > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
1262
+ //if (lastx == 0 && m_chartspaces.chart.left > (x - (getMaxDateWidth() / 2))) { // do not print left of y legend
1263
+ if (lastx == 0 && 0 > x - (getMaxDateWidth() / 2)) {
1264
+ console.log(currentDate,x - (getMaxDateWidth() / 2));
1783
1265
  currentDate = new Date(currentDate.getTime() + 86400000);
1784
1266
  continue;
1785
1267
  }
1786
- if (lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
1268
+ if (lastx != 0 && lastx + (getMaxDateWidth() / 2) > (x - getMaxDateWidth())) {
1787
1269
  draw = false;
1788
1270
  }
1789
1271
  if (draw) {
@@ -2344,7 +1826,21 @@ function Milli_Chart(settings) {
2344
1826
  instr.data = {};
2345
1827
  MillistreamWidgetApi_AssignObject(obj.instruments[x], instr.data);
2346
1828
  instr.data.price = formatNiceNumber(instr.data.price, _this.settings.thousandseparator, _this.settings.decimalseparator, _this.settings.num_decimals, false);
2347
-
1829
+ if(x == 0) {
1830
+ for (let s = 0; s < _this.settings.indicators.length; s++) {
1831
+ if(_this.settings.indicators[s].method != 'news') {
1832
+ for(let ss = 0; ss < _this.settings.indicators[s].timeseries.length;ss++) {
1833
+ if(_this.settings.indicators[s].timeseries[ss].timestamp <= instr.data.timestamp) {
1834
+ instr.data.indicator = {
1835
+ method: _this.settings.indicators[s].method,
1836
+ datapoints: _this.settings.indicators[s].timeseries[ss].datapoints
1837
+ }
1838
+ } else break;
1839
+ }
1840
+ }
1841
+ }
1842
+ }
1843
+
2348
1844
  if (typeof _this.instruments[x].toolTip === 'undefined') {
2349
1845
  // add textdiv
2350
1846
  _this.instruments[x].toolTip = document.createElement('div');
@@ -2363,8 +1859,9 @@ function Milli_Chart(settings) {
2363
1859
  _this.instruments[x].toolTipPointer.style.pointerEvents = 'none';
2364
1860
 
2365
1861
  }
1862
+ _this.instruments[x].toolTip.innerHTML = _this.settings.tooltip.formatter.call(instr, m_chartspaces, obj.instruments[x].x);
2366
1863
  var pointerStyle = getComputedStyle(_this.instruments[x].toolTipPointer);
2367
- pointerWidth = _this.instruments[x].toolTipPointer.offsetWidth + parseInt(pointerStyle.marginLeft) + parseInt(pointerStyle.marginRight);
1864
+ pointerWidth = _this.instruments[x].toolTipPointer.offsetWidth + parseInt(pointerStyle.marginLeft) + (parseInt(pointerStyle.marginRight));
2368
1865
  var pointerHeight = _this.instruments[x].toolTipPointer.offsetHeight + parseInt(pointerStyle.marginTop) + parseInt(pointerStyle.marginBottom);
2369
1866
  var posy = obj.instruments[x].y - (_this.instruments[x].toolTip.offsetHeight / 2);
2370
1867
  _this.instruments[x].toolTip.style.top = posy + 'px';
@@ -2373,10 +1870,15 @@ function Milli_Chart(settings) {
2373
1870
  _this.instruments[x].toolTipPointer.style.top = (obj.instruments[x].y - (pointerHeight / 2)) + 'px';
2374
1871
  if (posy > highy) highy = posy;
2375
1872
  if (posy < lowy) lowy = posy;
2376
- _this.instruments[x].toolTip.innerHTML = _this.settings.tooltip.formatter.call(instr, m_chartspaces, obj.instruments[x].x);
2377
- if (m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.getWidth()) { // || m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.getWidth()) { // TODO +10 should be calculated better
1873
+ // _this.instruments[x].toolTip.innerHTML = _this.settings.tooltip.formatter.call(instr, m_chartspaces, obj.instruments[x].x);
1874
+ let divs = _this.instruments[x].toolTip.children;
1875
+ let width = _this.instruments[x].toolTip.offsetWidth;
1876
+ for(let d = 0; d < divs.length; d++) {
1877
+ if(divs[d].nodeName == 'DIV' && divs[d].offsetWidth != 0) width = Math.max(width,divs[d].offsetWidth);
1878
+ }
1879
+ if (m_dataPoints.arr[i] + width > m_canvas.getWidth()) { // || m_dataPoints.arr[i] + (_this.instruments[x].toolTip.offsetWidth * 1.5) > m_canvas.getWidth()) { // TODO +10 should be calculated better
2378
1880
  // draw the hover to the left
2379
- _this.instruments[x].toolTip.style.left = (obj.instruments[x].x - _this.instruments[x].toolTip.offsetWidth - (pointerWidth / 2)) + 1 + 'px';
1881
+ _this.instruments[x].toolTip.style.left = (obj.instruments[x].x - width - (pointerWidth / 2)) + 1 + 'px';
2380
1882
  } else {
2381
1883
  // draw hover to the right
2382
1884
  _this.instruments[x].toolTip.style.left = (obj.instruments[x].x + (pointerWidth / 2)) + 'px';
@@ -2390,17 +1892,26 @@ function Milli_Chart(settings) {
2390
1892
  }
2391
1893
  }
2392
1894
  }
1895
+
2393
1896
  //indicator hover
2394
1897
  for (x = 0; x < _this.settings.indicators.length; x++) {
2395
1898
  var px = getScaledSetting(pos.clientX) - getScaledSetting(rect.left) - 1;
2396
1899
  if (typeof _this.settings.indicators[x].toolTip === 'undefined') continue;
2397
1900
  if (_this.settings.indicators[x].staticTooltip == true) continue;
2398
- var width = m_ctx.measureText(_this.settings.indicators[x].indicator).width;
2399
- var remove = true;
1901
+ let width = 5;
1902
+ let height = 5;
1903
+ let remove = true;
1904
+ if(typeof _this.settings.indicators[x].image !== 'undefined') {
1905
+ width = _this.settings.indicators[x].image.width;
1906
+ height = _this.settings.indicators[x].image.height;
1907
+ } else {
1908
+ width = m_ctx.measureText(_this.settings.indicators[x].indicator).width;
1909
+ height = parseInt(_this.settings.indicators[x].fontSize);
1910
+ }
2400
1911
  for (var xx = 0; xx < _this.settings.indicators[x].timeseries.length; xx++) {
2401
1912
  if (typeof _this.settings.indicators[x].timeseries[xx].pos === 'undefined') continue;
2402
1913
  if (typeof _this.settings.indicators[x].timeseries[xx].hl === 'undefined') continue;
2403
- if (px >= _this.settings.indicators[x].timeseries[xx].pos.x - (width / 2) && px <= _this.settings.indicators[x].timeseries[xx].pos.x + (width / 2)) {
1914
+ if (px >= _this.settings.indicators[x].timeseries[xx].pos.x -(width/2) && px < _this.settings.indicators[x].timeseries[xx].pos.x + (width/2)) {
2404
1915
  if (typeof _this.settings.indicators[x].toolTip.div === 'undefined') {
2405
1916
  _this.settings.indicators[x].toolTip.div = document.createElement('div');
2406
1917
  _this.settings.indicators[x].toolTip.div.style.display = _this.settings.tooltip.display;
@@ -2411,15 +1922,21 @@ function Milli_Chart(settings) {
2411
1922
  _this.settings.indicators[x].toolTip.div.style.left = _this.settings.indicators[x].timeseries[xx].pos.x / 1 + (pointerWidth / 2) + 'px'; // this i modified in the data for the instruments, but not for indicators
2412
1923
  _this.settings.indicators[x].toolTip.div.style.top = _this.settings.indicators[x].timeseries[xx].pos.y / 1 + 'px'; // this i modified in the data for the instruments, but not for indicators
2413
1924
  _this.settings.indicators[x].toolTip.div.innerHTML = _this.settings.indicators[x].toolTip.formatter.call(_this.settings.indicators[x].timeseries[xx]);
1925
+ if (y > _this.settings.indicators[x].timeseries[xx].pos.y -(height/2) && y < _this.settings.indicators[x].timeseries[xx].pos.y + (height/2))
1926
+ m_canvas.style.cursor = "pointer";
1927
+ else {
1928
+ m_canvas.style.cursor = "crosshair";
1929
+ }
2414
1930
  remove = false;
2415
1931
  toolArray.push({ top: parseInt(_this.settings.indicators[x].toolTip.div.style.top), indicator: x });
2416
- }
1932
+ }
2417
1933
 
2418
1934
  }
2419
1935
  if (remove) {
2420
1936
  if (_this.settings.indicators[x].toolTip.div && _this.settings.indicators[x].staticTooltip != true) {
2421
1937
  _this.settings.indicators[x].toolTip.div.parentNode.removeChild(_this.settings.indicators[x].toolTip.div);
2422
1938
  _this.settings.indicators[x].toolTip.div = undefined;
1939
+ m_canvas.style.cursor = "crosshair";
2423
1940
  }
2424
1941
 
2425
1942
  }
@@ -2484,7 +2001,10 @@ function Milli_Chart(settings) {
2484
2001
  m_zoom.mouseup.timestamp = new Date().toISOString().split('T')[0];
2485
2002
  m_zoom.mouseup.timestamp = new Date(m_zoom.mouseup.timestamp + 'T00:00:00Z');
2486
2003
  }
2487
- _this.settings.chartlen = 'max';
2004
+ if(366 > dateDiffInDays(m_zoom.mousedown.timestamp ,m_zoom.mouseup.timestamp ))
2005
+ _this.settings.chartlen = 'ytd';
2006
+ else
2007
+ _this.settings.chartlen = 'max';
2488
2008
  chartType = 'history';
2489
2009
  _this.drawChart();
2490
2010
  };
@@ -2544,7 +2064,7 @@ function Milli_Chart(settings) {
2544
2064
  m_chartspaces.chart.marginTop = getScaledSetting(m_chartCss.marginTop);
2545
2065
  m_chartspaces.chart.top = m_chartspaces.chart.marginTop;
2546
2066
  m_chartspaces.chart.left = getScaledSetting(m_chartCss.marginLeft);
2547
- m_chartspaces.chart.right = m_canvas.getWidth()- getScaledSetting(m_chartCss.marginRight) - 50;
2067
+ m_chartspaces.chart.right = m_canvas.getWidth()- getScaledSetting(m_chartCss.marginRight);// - 50;
2548
2068
  m_chartspaces.chart.marginBottom = getScaledSetting(m_chartCss.marginBottom);
2549
2069
  m_chartspaces.chart.bottom = (m_chartspaces.chart.height - m_chartspaces.chart.marginBottom);
2550
2070
  m_chartspaces.chart.width = m_canvas.getWidth()
@@ -2581,7 +2101,7 @@ function Milli_Chart(settings) {
2581
2101
  _this.settings.indicators[i].timeseries = calculateBollingerBands(_this.instruments[0].trades, _this.settings.indicators[i].method_length, _this.settings.indicators[i].stddev | 2);
2582
2102
  break;
2583
2103
  case 'news':
2584
- _this.settings.indicators[i].timeseries = calculateNews(_this.settings.indicators[i].news, _this.settings.indicators[i].method_length, _this.settings.indicators[i].stddev | 2);
2104
+ _this.settings.indicators[i].timeseries = calculateNews(_this.settings.indicators[i].news);
2585
2105
  break;
2586
2106
  // future events osv?
2587
2107
  default:
@@ -2623,6 +2143,7 @@ function Milli_Chart(settings) {
2623
2143
  if (m_dataPoints.map) m_dataPoints.map.clear();
2624
2144
  m_dataPoints.map = new Map();
2625
2145
  m_dataPoints.arr = [];
2146
+
2626
2147
  if (_this.instruments.length < 0) {
2627
2148
  console.log('no chartdata');
2628
2149
  return;
@@ -2745,7 +2266,6 @@ function Milli_Chart(settings) {
2745
2266
 
2746
2267
  } else
2747
2268
  if (period == 'm') {
2748
-
2749
2269
  if (m_zoom.mousedown.timestamp) {
2750
2270
  _this.scaleinfoX.startTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mouseup.timestamp : m_zoom.mousedown.timestamp;
2751
2271
  _this.scaleinfoX.endTimeStamp = m_zoom.mousedown.timestamp > m_zoom.mouseup.timestamp ? m_zoom.mousedown.timestamp : m_zoom.mouseup.timestamp;
@@ -2779,29 +2299,6 @@ function Milli_Chart(settings) {
2779
2299
  if (false == checkChartData(_this.instruments[0].history)) return;
2780
2300
  calculateIndicators();
2781
2301
 
2782
- /*let scaleY = {};
2783
- if (_this.settings.drawyaxis) {
2784
- if (false == calcHighLow2(scaleY, m_chartspaces.chart, m_yLegendCss)) {
2785
- console.log('fail highlow');
2786
- return;
2787
- }
2788
- }
2789
- let scaleY2 = {};
2790
- let factorInfo = {
2791
- name: 'diff',
2792
- actor: _this.instruments[0].startValue,
2793
- suffix: '%'
2794
- };
2795
- if (_this.settings.drawy2axis) {
2796
- if (false == calcHighLow2(scaleY2, m_chartspaces.chart, m_y2LegendCss, factorInfo)) {
2797
- console.log('fail highlow');
2798
- return;
2799
- }
2800
- }
2801
-
2802
- drawYAxisNew(scaleY, m_chartspaces.chart, m_yLegendCss, _this.settings.drawyaxis, _this.settings.gridHorizontalLines);
2803
- drawYAxisNew(scaleY2, m_chartspaces.chart, m_y2LegendCss, _this.settings.drawy2axis, false, factorInfo); *
2804
- */
2805
2302
  drawYAxis(scaleinfoY, scaleinfoY2);
2806
2303
  drawXAxisMonth(_this.scaleinfoX.startTimeStamp, _this.scaleinfoX.endTimeStamp);
2807
2304
 
@@ -3176,26 +2673,31 @@ function Milli_Chart(settings) {
3176
2673
  var startpoint = { x: 0, y: 0 };
3177
2674
  var endpoint = { x: 0, y: 0 };
3178
2675
  var startDate = _this.scaleinfoX.startTimeStamp;
3179
- var len = data.length;
3180
2676
  var lastdate = new Date(_this.scaleinfoX.startTimeStamp);
3181
2677
  var offset = 0;
3182
2678
  var maxy = 0;
3183
2679
  var ret = [];
3184
2680
  let num = 0;
3185
- for (var i = 0; i < len; i++) {
2681
+ for (var i = 0; i < data.length; i++) {
3186
2682
  var currentDate;
3187
2683
  var tmpx = startpoint.x;
3188
2684
  var tmp;
3189
- var timestamp = data[i].timestamp;
2685
+ var timestamp = typeof data[i].newstimestamp !== 'undefined' ? data[i].newstimestamp : data[i].timestamp;
3190
2686
  if (chartType == 'history') timestamp -= (timestamp % 86400000)
3191
2687
  if (timestamp < _this.scaleinfoX.startTimeStamp) {
3192
2688
  continue;
3193
2689
  }
3194
2690
  if (timestamp > _this.scaleinfoX.endTimeStamp) {
3195
- break;
2691
+ data.splice(i,1);
2692
+ i--;
2693
+ continue;
3196
2694
  }
3197
2695
 
3198
- if (chartType != 'history' && (data[i].timestamp % 86400000 < _this.instruments[0].opentimestamp || data[i].timestamp % 86400000 > _this.instruments[0].closetimestamp)) {
2696
+ //if (chartType != 'history' && (data[i].timestamp % 86400000 < _this.instruments[0].opentimestamp || data[i].timestamp % 86400000 > _this.instruments[0].closetimestamp)) {
2697
+ if (chartType != 'history' && (timestamp % 86400000 < _this.instruments[0].opentimestamp || timestamp % 86400000 > _this.instruments[0].closetimestamp)) {
2698
+ // data outside tradinghours, removed from data so we do not get data entries without pos
2699
+ data.splice(i,1);
2700
+ i--;
3199
2701
  continue;
3200
2702
  }
3201
2703
  var endtimeToday = new Date(timestamp);
@@ -3303,6 +2805,10 @@ function Milli_Chart(settings) {
3303
2805
  let data = method.timeseries;
3304
2806
  let num = calcAnalyzisLine(data, 0, undefined, cs, scale);
3305
2807
  if (num == 0) return;
2808
+ let start = data.length-1;
2809
+ while(start > 0 && typeof data[start].pos === 'undefined') start--;
2810
+ if(start < 0) return;
2811
+
3306
2812
  m_ctx.save();
3307
2813
  m_ctx.beginPath();
3308
2814
  m_ctx.closePath();
@@ -3310,10 +2816,12 @@ function Milli_Chart(settings) {
3310
2816
  m_ctx.strokeStyle = method.color;
3311
2817
  if (typeof method.lineStyle === 'string' && method.lineStyle == 'dash') m_ctx.setLineDash([3, 3]);
3312
2818
 
3313
- m_ctx.moveTo(data[data.length - 1].pos.x, data[data.length - 1].pos.y);
2819
+ m_ctx.moveTo(data[start].pos.x, data[start].pos.y);
3314
2820
  let lastPos = null;
3315
- for (var i = data.length - 2; i >= 0; i--) {
3316
- if (typeof data[i].pos === 'undefined') break;
2821
+ for (var i = start - 1; i >= 0; i--) {
2822
+ if (typeof data[i].pos === 'undefined') {
2823
+ break;
2824
+ }
3317
2825
  m_ctx.lineTo(data[i].pos.x, data[i].pos.y);
3318
2826
  lastPos = data[i].pos;
3319
2827
  }
@@ -3323,7 +2831,7 @@ function Milli_Chart(settings) {
3323
2831
  }
3324
2832
  if (typeof method.callback === 'function') method.callback.call({ x: data[data.length - 1].pos.x, y: data[data.length - 1].pos.y });
3325
2833
  m_ctx.stroke();
3326
- m_ctx.lineTo(data[data.length - 1].pos.x, cs.bottom);
2834
+ m_ctx.lineTo(data[start].pos.x, cs.bottom);
3327
2835
  m_ctx.restore();
3328
2836
  }
3329
2837
 
@@ -3365,15 +2873,16 @@ function Milli_Chart(settings) {
3365
2873
  } else if (method.indicator) {
3366
2874
  m_ctx.fillStyle = method.color;
3367
2875
  width = m_ctx.measureText(method.indicator).width;
2876
+ let height = parseInt(method.fontSize);
3368
2877
  if (method.type == NEWSINDICATOR) {
3369
- if (fabs(lastPos.x - data[i].pos.x) > width || fabs(lastPos.y > data[i].pos.y) > width) {
3370
- m_ctx.fillText(method.indicator, data[i].pos.x - (width / 2), data[i].pos.y);
2878
+ if (fabs(lastPos.x - data[i].pos.x) > width || fabs(lastPos.y > data[i].pos.y) > height) {
2879
+ m_ctx.fillText(method.indicator, data[i].pos.x - (width / 2), data[i].pos.y - (height/2));
3371
2880
  lastPos = { x: data[i].pos.x, y: data[i].y };
3372
- method.timeseries[i].hl = [{ timestamp: data[i].timestamp, headline: data[i].headline }];
2881
+ method.timeseries[i].hl = [{ timestamp: data[i].timestamp, headline: data[i].headline,newsid: data[i].newsid }];
3373
2882
  hlPos = i;
3374
2883
 
3375
2884
  } else {
3376
- method.timeseries[hlPos].hl.push({ timestamp: data[i].timestamp, headline: data[i].headline });
2885
+ method.timeseries[hlPos].hl.push({ timestamp: data[i].timestamp, headline: data[i].headline,newsid: data[i].newsid });
3377
2886
  }
3378
2887
  } else m_ctx.fillText(method.indicator, data[i].pos.x - (width / 2), data[i].pos.y);
3379
2888
 
@@ -3507,8 +3016,6 @@ function Milli_Chart(settings) {
3507
3016
  var hCurveLastPoint = null;
3508
3017
  var quantity = 0;
3509
3018
  var nextDate;
3510
- var firstDataPoint = null;
3511
- var lastDataPoint = null;
3512
3019
 
3513
3020
  var today = new Date().getTime();
3514
3021
  today -= today % 86400000;
@@ -3782,30 +3289,37 @@ function Milli_Chart(settings) {
3782
3289
  let timeseries = [];
3783
3290
  for (let i = 0; i < data.length; i++) {
3784
3291
  let s = 0;
3785
- if (data[i].timestamp >= _this.scaleinfoX.startTimeStamp) {
3292
+ let newstimestamp = data[i].timestamp;
3293
+ if(data[i].timestamp < (data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].opentimestamp)) {
3294
+ newstimestamp = data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].opentimestamp;
3295
+ } else if(data[i].timestamp > (data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].closetimestamp)) {
3296
+ newstimestamp = data[i].timestamp - (data[i].timestamp % 86400000) + _this.instruments[0].closetimestamp;
3297
+ }
3298
+ if (newstimestamp >= _this.scaleinfoX.startTimeStamp) {
3786
3299
  let item = null;
3787
3300
  for (s; s < _this.instruments[0][chartType].length; s++) {
3788
3301
  if (chartType == 'history') {
3789
3302
  if ((data[i].timestamp - (data[i].timestamp % 86400000)) < _this.instruments[0].history[s].timestamp) break;
3790
3303
  if ((data[i].timestamp - (data[i].timestamp % 86400000)) >= _this.instruments[0].history[s].timestamp) {
3791
3304
  item = data[i];
3305
+ item.newstimestamp = newstimestamp;
3792
3306
  item.datapoints = [_this.instruments[0].history[s].price];
3793
3307
  }
3794
3308
  } else {
3795
- if ((data[i].timestamp) < _this.instruments[0].trades[s].timestamp) break;
3796
- if ((data[i].timestamp) >= _this.instruments[0].trades[s].timestamp) {
3309
+ if (newstimestamp < _this.instruments[0].trades[s].timestamp) break;
3310
+ if (newstimestamp >= _this.instruments[0].trades[s].timestamp) {
3797
3311
  item = data[i];
3312
+ item.newstimestamp = newstimestamp;
3798
3313
  item.datapoints = [_this.instruments[0].trades[s].price];
3799
3314
  }
3800
3315
  }
3801
3316
  }
3802
- timeseries.push(item);
3317
+ if(item) timeseries.push(item);
3803
3318
  }
3804
3319
  }
3805
3320
  return timeseries;
3806
3321
  }
3807
3322
 
3808
-
3809
3323
  function calculateBollingerBands(prices, window, stddev) {
3810
3324
  // borde returnera ett object med high/low också
3811
3325
 
@@ -3851,29 +3365,6 @@ function Milli_Chart(settings) {
3851
3365
  return simpleMovingAverages;
3852
3366
  }
3853
3367
 
3854
-
3855
- /*function simpleMovingAverage(prices, window, n = Infinity) {
3856
- // borde returnera ett object med high/low också
3857
- if (!prices || prices.length < window) {
3858
- return [];
3859
- }
3860
- let index = window - 1;
3861
- const length = prices.length + 1;
3862
- const simpleMovingAverages = [];
3863
- let numberOfSMAsCalculated = 0;
3864
- const today = new Date().getTime();
3865
- const startDate = _this.scaleinfoX.startTimeStamp - (window * 86400000);
3866
- while (++index < length && numberOfSMAsCalculated < n) {
3867
- const windowSlice = prices.slice(index - window, index);
3868
- if (windowSlice[window - 1].timestamp > startDate) {
3869
- const sum = windowSlice.reduce((prev, curr) => prev + curr.price, 0);
3870
- simpleMovingAverages.push({ timestamp: prices[index - 1].timestamp, datapoints: [sum / window] });
3871
- numberOfSMAsCalculated++;
3872
- }
3873
- if (typeof prices[index] == 'undefined' || prices[index].timestamp > today) break;
3874
- }
3875
- return simpleMovingAverages;
3876
- }*/
3877
3368
  function exponentialMovingAverage(prices, window) {
3878
3369
  if (!prices || prices.length < window) {
3879
3370
  return [];
@@ -3896,49 +3387,6 @@ function Milli_Chart(settings) {
3896
3387
  return exponentialMovingAverages;
3897
3388
  }
3898
3389
 
3899
- /*function exponentialMovingAverage(prices, window) {
3900
- if (!prices || prices.length < window) {
3901
- return [];
3902
- }
3903
- let index = window - 1;
3904
- let previousEmaIndex = 0;
3905
- const length = prices.length;
3906
- const smoothingFactor = 2 / (window + 1);
3907
- const exponentialMovingAverages = [];
3908
-
3909
- const [sma] = simpleMovingAverage(prices, window, 1);
3910
- exponentialMovingAverages.push(sma);
3911
-
3912
- while (++index < length) {
3913
- const value = prices[index].price;
3914
- const previousEma = [exponentialMovingAverages[previousEmaIndex++].datapoints[0]];
3915
- const currentEma = (value * smoothingFactor) + (previousEma * (1 - smoothingFactor));
3916
- exponentialMovingAverages.push({ timestamp: prices[index].timestamp, datapoints: [currentEma] });
3917
- }
3918
- return exponentialMovingAverages;
3919
- }*/
3920
-
3921
- function bollingerBands(prices, window, stddev) {
3922
- if (!prices || prices.length < window) {
3923
- return [];
3924
- }
3925
-
3926
- let index = window - 1;
3927
- const length = prices.length + 1;
3928
- const standardDeviations = [];
3929
- while (++index < length) {
3930
- const windowSlice = prices.slice(index - window, index);
3931
- const mean = windowSlice.reduce((prev, curr) => prev + curr.price, 0) / window;
3932
- const variance = Math.sqrt(windowSlice.reduce((a, b) => a + (b.price - mean) ** 2, 0) / window) * stddev;
3933
- const uppervariance = mean + variance;
3934
- const lowervariance = mean - variance;
3935
- standardDeviations.push({ timestamp: prices[index - 1].timestamp, datapoints: [uppervariance, lowervariance, mean] });
3936
- if (typeof prices[index] == 'undefined' || prices[index].timestamp > new Date().getTime()) break;
3937
- }
3938
- return standardDeviations;
3939
- }
3940
-
3941
-
3942
3390
  function calculateRSI(p, window) {
3943
3391
  // borde returnera ett object med high/low också
3944
3392
  let rsi = [];
@@ -3985,6 +3433,7 @@ function Milli_Chart(settings) {
3985
3433
  }
3986
3434
  return rsi;
3987
3435
  }
3436
+
3988
3437
  _this.removeAllIndicators = function(j) {
3989
3438
  _this.settings.indicators = [];
3990
3439
  _this.drawChart();
@@ -4030,109 +3479,14 @@ function Milli_Chart(settings) {
4030
3479
  if (indicatorAlreadyExists(method)) return;
4031
3480
  switch (method.method) {
4032
3481
  case 'sma':
4033
- {
4034
- if (typeof method.method_length !== 'number') return;
4035
- }
3482
+ if (typeof method.method_length !== 'number') return;
4036
3483
  break;
4037
3484
  case 'ema':
4038
- {
4039
- if (typeof method.method_length !== 'number') return;
4040
- break;
4041
- }
4042
- case 'bb':
4043
- {
4044
- if (typeof method.method_length !== 'number' || typeof method.stddev !== 'number') return;
4045
- break;
4046
- }
4047
- case 'rsi':
4048
- case 'quantity':
4049
- case 'momentum':
4050
- if (method.target == 'lower') {
4051
- m_chartspaces.chart.percent = 70;
4052
- m_chartspaces.lowerChart.percent = 30;
4053
- }
4054
- break;
4055
- case 'news':
4056
- break;
4057
- default:
4058
- method.timeseries.sort(function(a, b) {
4059
- return a.timestamp - b.timestamp;
4060
- });
4061
- break;
4062
- }
4063
- if (typeof method.type === 'undefined') method.type = INDICATOR;
4064
- _this.settings.indicators.unshift(method);
4065
- _this.drawChart();
4066
- };
4067
-
4068
- /*_this.addIndicator = function(method) {
4069
- if (typeof method !== 'object' || method == null || typeof method.type == undefined) return;
4070
- if (indicatorAlreadyExists(method)) return;
4071
-
4072
- switch (method.method) {
4073
- case 'sma':
4074
- {
4075
- if (typeof method.method_length !== 'number') return;
4076
- method.history = simpleMovingAverage(_this.instruments[0].history, method.method_length);
4077
- method.trades = simpleMovingAverage(_this.instruments[0].trades, method.method_length);
4078
- }
3485
+ if (typeof method.method_length !== 'number') return;
4079
3486
  break;
4080
- case 'ema':
4081
- {
4082
- if (typeof method.method_length !== 'number') return;
4083
- method.history = exponentialMovingAverage(_this.instruments[0].history, method.method_length);
4084
- method.trades = exponentialMovingAverage(_this.instruments[0].trades, method.method_length);
4085
- break;
4086
- }
4087
3487
  case 'bb':
4088
- {
4089
- if (typeof method.method_length !== 'number' || typeof method.stddev !== 'number') return;
4090
- method.history = bollingerBands(_this.instruments[0].history, method.method_length, method.stddev);
4091
- method.trades = bollingerBands(_this.instruments[0].trades, method.method_length, method.stddev);
4092
- break;
4093
- }
4094
- case 'rsi':
4095
- case 'quantity':
4096
- case 'momentum':
4097
- if (method.target == 'lower') {
4098
- m_chartspaces.chart.percent = 70;
4099
- m_chartspaces.lowerChart.percent = 30;
4100
- }
4101
- break;
4102
- case 'news':
4103
- break;
4104
- default:
4105
- if (typeof method.history !== 'undefined' && typeof method.trades !== 'undefined') {
4106
- if (!Array.isArray(method.history) || !Array.isArray(method.trades)) {
4107
- return -1;
4108
- }
4109
- }
4110
- break;
4111
- }
4112
- _this.settings.indicators.push(method);
4113
- _this.drawChart();
4114
- };*/
4115
-
4116
-
4117
- /* _this.addIndicator = function(method) {
4118
- if (typeof method !== 'object' || method == null || typeof method.method == undefined) return;
4119
- if (indicatorAlreadyExists(method)) return;
4120
- switch (method.method) {
4121
- case 'sma':
4122
- {
4123
- if (typeof method.method_length !== 'number') return;
4124
- }
3488
+ if (typeof method.method_length !== 'number' || typeof method.stddev !== 'number') return;
4125
3489
  break;
4126
- case 'ema':
4127
- {
4128
- if (typeof method.method_length !== 'number') return;
4129
- break;
4130
- }
4131
- case 'bb':
4132
- {
4133
- if (typeof method.method_length !== 'number' || typeof method.stddev !== 'number') return;
4134
- break;
4135
- }
4136
3490
  case 'rsi':
4137
3491
  case 'quantity':
4138
3492
  case 'momentum':
@@ -4153,7 +3507,7 @@ function Milli_Chart(settings) {
4153
3507
  _this.settings.indicators.unshift(method);
4154
3508
  _this.drawChart();
4155
3509
  };
4156
- */
3510
+
4157
3511
  function getXhrJson(url) {
4158
3512
  var req = new XMLHttpRequest();
4159
3513
  req.onload = function() {
@@ -4303,17 +3657,24 @@ function Milli_Chart(settings) {
4303
3657
  var rect = m_canvas.getBoundingClientRect();
4304
3658
  var x = getScaledSetting(evt.clientX) - getScaledSetting(rect.left) - 1;
4305
3659
  var y = getScaledSetting(evt.clientY) - getScaledSetting(rect.top);
4306
-
4307
3660
  for (let i = 0; i < _this.settings.indicators.length; i++) {
3661
+ let newsarr = [];
4308
3662
  var width = m_ctx.measureText(_this.settings.indicators[i].indicator).width;
4309
3663
  for (let s = 0; s < _this.settings.indicators[i].timeseries.length; s++) {
4310
- if (x >= parseInt(_this.settings.indicators[i].timeseries[s].pos.x) - (width / 2) && x <= parseInt(_this.settings.indicators[i].timeseries[s].pos.x) + (width / 2)) {
4311
- if (y >= _this.settings.indicators[i].timeseries[s].pos.y && y <= _this.settings.indicators[i].timeseries[s].pos.y + width) {
4312
- if (typeof _this.settings.indicators[i].onclick === 'function') _this.settings.indicators[i].onclick.call(_this.settings.indicators[i]);
4313
- }
4314
- break;
3664
+ if(typeof _this.settings.indicators[i].timeseries[s].pos !== 'undefined') {
3665
+ if (x >= parseInt(_this.settings.indicators[i].timeseries[s].pos.x) - (width / 2) && x <= parseInt(_this.settings.indicators[i].timeseries[s].pos.x) + (width / 2)) {
3666
+ if (y >= _this.settings.indicators[i].timeseries[s].pos.y && y <= _this.settings.indicators[i].timeseries[s].pos.y + width) {
3667
+ if (typeof _this.settings.indicators[i].onclick === 'function') {
3668
+ newsarr.push({ date : new Date(_this.settings.indicators[i].timeseries[s].timestamp),newsid: _this.settings.indicators[i].timeseries[s].newsid});
3669
+ }
3670
+ }
3671
+ }// else if( x > parseInt(_this.settings.indicators[i].timeseries[s].pos.x) + (width / 2)) break;
4315
3672
  }
4316
3673
  }
3674
+ if(newsarr.length > 0) {
3675
+ _this.settings.indicators[i].onclick(_this.instruments[0].insref,newsarr);
3676
+ return;
3677
+ }
4317
3678
  }
4318
3679
 
4319
3680
 
@@ -4502,16 +3863,16 @@ function Milli_Chart(settings) {
4502
3863
  calcAnalyizis = true;
4503
3864
  if (instr.pricetype == 'price') {
4504
3865
  update = true;
4505
- data.price = parseFloat(json['12']); // eller 201 för tradeyield
4506
- data.open = parseFloat(json['12']); // eller 201 för tradeyield
4507
- data.high = parseFloat(json['12']); // eller 201 för tradeyield
4508
- data.low = parseFloat(json['12']); // eller 201 för tradeyield
3866
+ data.price = parseFloat(json['12']);
3867
+ data.open = parseFloat(json['12']);
3868
+ data.high = parseFloat(json['12']);
3869
+ data.low = parseFloat(json['12']);
4509
3870
  data.quantity = typeof json['13'] === 'undefined' ? 0 : parseInt(json['13']);
4510
3871
  } else if (instr.pricetype == 'yield') {
4511
- data.price = parseFloat(json['201']); // eller 201 för tradeyield
4512
- data.open = parseFloat(json['201']); // eller 201 för tradeyield
4513
- data.high = parseFloat(json['201']); // eller 201 för tradeyield
4514
- data.low = parseFloat(json['201']); // eller 201 för tradeyield
3872
+ data.price = parseFloat(json['201']);
3873
+ data.open = parseFloat(json['201']);
3874
+ data.high = parseFloat(json['201']);
3875
+ data.low = parseFloat(json['201']);
4515
3876
  data.quantity = typeof json['13'] === 'undefined' ? 0 : parseInt(json['13']);
4516
3877
  update = true;
4517
3878
  }
@@ -4612,7 +3973,7 @@ function Milli_Chart(settings) {
4612
3973
  return 0;
4613
3974
  };
4614
3975
 
4615
- function fetchNews(indicator) {
3976
+ function fetchNews(indicator,alreadyadded) {
4616
3977
  var url = milli_data_api_url + "widget=chartnews&token=" + _this.settings.token + "&target=buildwidget&fields=headline,date,time&language=" + "sv" + "&insref=" + indicator.insrefs.toString() + '&xhr=' + (_this.settings.xhr == true ? '1' : '0');
4617
3978
  url += '&instruments=' + _this.instruments[0].insref;
4618
3979
 
@@ -4632,7 +3993,8 @@ function Milli_Chart(settings) {
4632
3993
  });
4633
3994
  indicator.method = 'news';
4634
3995
  indicator.type = NEWSINDICATOR;
4635
- _this.addIndicator(indicator);
3996
+ if(alreadyadded == false) _this.addIndicator(indicator);
3997
+ else _this.drawChart();
4636
3998
  requestStreaming();
4637
3999
  });
4638
4000
  }
@@ -4643,11 +4005,11 @@ function Milli_Chart(settings) {
4643
4005
  var i;
4644
4006
  for (i = 0; i < _this.settings.indicators.length; i++) {
4645
4007
  if (_this.settings.indicators[i].method == indicator.method) {
4646
- _this.removeIndicator(_this.settings.indicators[i]);
4647
- return;
4008
+ return _this.removeIndicator(_this.settings.indicators[i]);
4648
4009
  }
4649
4010
  }
4650
- fetchNews(indicator);
4011
+ fetchNews(indicator,false);
4012
+ return true;
4651
4013
  };
4652
4014
 
4653
4015
  function setHighDPIContext(context)
@@ -4685,7 +4047,8 @@ function Milli_Chart(settings) {
4685
4047
  'rect': 'all',
4686
4048
  'translate': 'all',
4687
4049
  'createRadialGradient': 'all',
4688
- 'createLinearGradient': 'all'
4050
+ 'createLinearGradient': 'all',
4051
+ 'drawImage': [1,2,3,4]
4689
4052
  };
4690
4053
 
4691
4054
  if (context.pixelRatio === 1) return;
@@ -4842,6 +4205,12 @@ function Milli_Chart(settings) {
4842
4205
  hashmap: new Map(),
4843
4206
  intradayQuantity: []
4844
4207
  };
4208
+ for(let i = 0; i < _this.settings.indicators.length; i++) {
4209
+ if(_this.settings.indicators[i].method == 'news' || _this.settings.indicators[i].type == NEWSINDICATOR) {
4210
+ fetchNews(_this.settings.indicators[i],true);
4211
+ break;
4212
+ }
4213
+ }
4845
4214
 
4846
4215
  if (_this.settings.intradaylen) {
4847
4216
  var d = new Date().getTime();
@@ -4883,12 +4252,6 @@ function Milli_Chart(settings) {
4883
4252
  if (insrefs[i] != 0)
4884
4253
  this.addCompare(insrefs[i]);
4885
4254
  }
4886
- for (let i = 0; i < _this.settings.indicators.length; i++) {
4887
- if (_this.settings.indicators[i].type == NEWSINDICATOR) {
4888
- fetchNews(_this.settings.indicators[i]);
4889
- break;
4890
- }
4891
- }
4892
4255
  };
4893
4256
  if (this.settings.autodraw == true) {
4894
4257
  this.drawWidget();
@@ -4902,7 +4265,7 @@ function Milli_Chart(settings) {
4902
4265
  window.addEventListener('resize', function(a) {
4903
4266
  if (m_canvas != null) {
4904
4267
  setChartSize();
4905
- //console.log("windowresize",m_chartspaces);
4268
+ //console.log("windowresize",m_chartspaces);
4906
4269
  _this.drawChart();
4907
4270
  }
4908
4271
  });
@@ -6370,6 +5733,21 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
6370
5733
  // internal and external
6371
5734
  // return array with MDF_F_FIELD,type,align, name var, overridable decimal bitwise [1 = override output,2 = can override,4 = no decimals,8 can be shortened to M, K etc], 16 = override NULL with 0 , 32 = can color diff
6372
5735
  switch (name) {
5736
+ case '1104':
5737
+ case 'adtv1mprc':
5738
+ return [1104, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
5739
+ case '1105':
5740
+ case 'adtv1wprc':
5741
+ return [1105, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
5742
+ case '1106':
5743
+ case 'adtv1yprc':
5744
+ return [1106, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
5745
+ case '1107':
5746
+ case 'adtv3mprc':
5747
+ return [1107, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
5748
+ case '1108':
5749
+ case 'adtvytdprc':
5750
+ return [1108, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
6373
5751
  case '222':
6374
5752
  case 'accountsreceivable':
6375
5753
  return [222, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
@@ -6795,9 +6173,18 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
6795
6173
  case '181':
6796
6174
  case 's4':
6797
6175
  return [181, 'string', 'left', widget.get_lang_text(name) || name, 0]; // Position
6176
+ case '389':
6177
+ case 's6':
6178
+ return [389, 'string', 'left', widget.get_lang_text(name) || name, 0]; //
6179
+ case '390':
6180
+ case 's7':
6181
+ return [390, 'string', 'left', widget.get_lang_text(name) || name, 0]; //
6798
6182
  case '393':
6799
6183
  case 's10':
6800
6184
  return [393, 'string', 'left', widget.get_lang_text(name) || name, 0]; // comment
6185
+ case '713':
6186
+ case 's12':
6187
+ return [713, 'string', 'left', widget.get_lang_text(name) || name, 0]; // comment
6801
6188
  case '127':
6802
6189
  case 'sales':
6803
6190
  return [127, 'numeric', 'right', widget.get_lang_text(name) || name, 8];
@@ -7203,7 +6590,7 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
7203
6590
  case 'weight':
7204
6591
  return [3201, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
7205
6592
  case '3202':
7206
- case 'listname':
6593
+ case 'preferredlistname':
7207
6594
  return [3202, 'string', 'left', widget.get_lang_text(name) || name, 0];
7208
6595
  case '3203':
7209
6596
  case 'sectorname':
@@ -7270,6 +6657,8 @@ function MillistreamWidgetApi_getColumnInfo(widget, name) {
7270
6657
  case 'sectorl1name':
7271
6658
  case 'sectorl1symbol':
7272
6659
  return [3312, 'string', 'left', widget.get_lang_text(name) || name, 0];
6660
+ case 'insref':
6661
+ return [3312, 'string', 'right', widget.get_lang_text(name) || name, 0]; // so it will not get thousandseparator etc
7273
6662
  default:
7274
6663
  return [0, 'numeric', 'right', widget.get_lang_text(name) || name, 0];
7275
6664
  }