Commit 1cc9bc01a4dfd63eb90523690008f08f9533b6b3
1 parent
626eb75b
UI: Fix minor issues in Flot widget.
Showing
3 changed files
with
115 additions
and
54 deletions
... | ... | @@ -51,7 +51,7 @@ |
51 | 51 | "clipboard": "^1.5.15", |
52 | 52 | "compass-sass-mixins": "^0.12.7", |
53 | 53 | "event-source-polyfill": "0.0.9", |
54 | - "flot": "git://github.com/flot/flot.git#0.9-work", | |
54 | + "flot": "git://github.com/thingsboard/flot.git#0.9-work", | |
55 | 55 | "flot-curvedlines": "git://github.com/MichaelZinsmaier/CurvedLines.git#master", |
56 | 56 | "font-awesome": "^4.6.3", |
57 | 57 | "javascript-detect-element-resize": "^0.5.3", |
... | ... | @@ -108,7 +108,7 @@ |
108 | 108 | "html-loader": "^0.4.3", |
109 | 109 | "html-minifier": "^3.2.2", |
110 | 110 | "html-minifier-loader": "^1.3.4", |
111 | - "html-webpack-plugin": "^2.22.0", | |
111 | + "html-webpack-plugin": "^2.30.1", | |
112 | 112 | "img-loader": "^1.3.1", |
113 | 113 | "less": "^2.7.1", |
114 | 114 | "less-loader": "^2.2.3", | ... | ... |
... | ... | @@ -241,6 +241,10 @@ function TelemetryWebsocketService($rootScope, $websocket, $timeout, $window, ty |
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
244 | + var index = reconnectSubscribers.indexOf(subscriber); | |
245 | + if (index > -1) { | |
246 | + reconnectSubscribers.splice(index, 1); | |
247 | + } | |
244 | 248 | subscribersCount--; |
245 | 249 | publishCommands(); |
246 | 250 | } | ... | ... |
... | ... | @@ -480,10 +480,9 @@ export default class TbFlot { |
480 | 480 | ? this.subscription.data[i].data[0][1] : 0; |
481 | 481 | } |
482 | 482 | this.pieDataRendered(); |
483 | - this.ctx.plot = $.plot(this.$element, this.pieData, this.options); | |
484 | - } else { | |
485 | - this.ctx.plot = $.plot(this.$element, this.subscription.data, this.options); | |
486 | 483 | } |
484 | + this.ctx.plotInited = true; | |
485 | + this.createPlot(); | |
487 | 486 | } |
488 | 487 | |
489 | 488 | createYAxis(keySettings, units) { |
... | ... | @@ -578,16 +577,13 @@ export default class TbFlot { |
578 | 577 | if (this.chartType === 'bar') { |
579 | 578 | this.ctx.plot.getOptions().series.bars.barWidth = this.subscription.timeWindow.interval * 0.6; |
580 | 579 | } |
581 | - this.ctx.plot.setData(this.subscription.data); | |
582 | - this.ctx.plot.setupGrid(); | |
583 | - this.ctx.plot.draw(); | |
580 | + this.updateData(); | |
584 | 581 | } |
585 | 582 | } else if (this.chartType === 'pie') { |
586 | 583 | if (this.ctx.animatedPie) { |
587 | 584 | this.nextPieDataAnimation(true); |
588 | 585 | } else { |
589 | - this.ctx.plot.setData(this.subscription.data); | |
590 | - this.ctx.plot.draw(); | |
586 | + this.updateData(); | |
591 | 587 | } |
592 | 588 | } |
593 | 589 | } else if (this.isMouseInteraction && this.ctx.plot){ |
... | ... | @@ -599,13 +595,105 @@ export default class TbFlot { |
599 | 595 | } |
600 | 596 | } |
601 | 597 | |
598 | + updateData() { | |
599 | + this.ctx.plot.setData(this.subscription.data); | |
600 | + if (this.chartType !== 'pie') { | |
601 | + this.ctx.plot.setupGrid(); | |
602 | + } | |
603 | + this.ctx.plot.draw(); | |
604 | + } | |
605 | + | |
602 | 606 | resize() { |
607 | + if (this.resizeTimeoutHandle) { | |
608 | + this.ctx.$scope.$timeout.cancel(this.resizeTimeoutHandle); | |
609 | + this.resizeTimeoutHandle = null; | |
610 | + } | |
611 | + if (this.ctx.plot && this.ctx.plotInited) { | |
612 | + var width = this.$element.width(); | |
613 | + var height = this.$element.height(); | |
614 | + if (width && height) { | |
615 | + this.ctx.plot.resize(); | |
616 | + if (this.chartType !== 'pie') { | |
617 | + this.ctx.plot.setupGrid(); | |
618 | + } | |
619 | + this.ctx.plot.draw(); | |
620 | + } else { | |
621 | + var tbFlot = this; | |
622 | + this.resizeTimeoutHandle = this.ctx.$scope.$timeout(function() { | |
623 | + tbFlot.resize(); | |
624 | + }, 30, false); | |
625 | + } | |
626 | + } | |
627 | + } | |
628 | + | |
629 | + | |
630 | + redrawPlot() { | |
631 | + if (this.ctx.plot && this.ctx.plotInited) { | |
632 | + this.ctx.plot.destroy(); | |
633 | + this.ctx.plot = null; | |
634 | + this.createPlot(); | |
635 | + } | |
636 | + } | |
637 | + | |
638 | + createPlot() { | |
639 | + if (this.createPlotTimeoutHandle) { | |
640 | + this.ctx.$scope.$timeout.cancel(this.createPlotTimeoutHandle); | |
641 | + this.createPlotTimeoutHandle = null; | |
642 | + } | |
643 | + if (this.ctx.plotInited && !this.ctx.plot) { | |
644 | + var width = this.$element.width(); | |
645 | + var height = this.$element.height(); | |
646 | + if (width && height) { | |
647 | + if (this.chartType === 'pie' && this.ctx.animatedPie) { | |
648 | + this.ctx.plot = $.plot(this.$element, this.pieData, this.options); | |
649 | + } else { | |
650 | + this.ctx.plot = $.plot(this.$element, this.subscription.data, this.options); | |
651 | + } | |
652 | + } else { | |
653 | + var tbFlot = this; | |
654 | + this.createPlotTimeoutHandle = this.ctx.$scope.$timeout(function() { | |
655 | + tbFlot.createPlot(); | |
656 | + }, 30, false); | |
657 | + } | |
658 | + } | |
659 | + } | |
660 | + | |
661 | + destroy() { | |
662 | + this.cleanup(); | |
603 | 663 | if (this.ctx.plot) { |
604 | - this.ctx.plot.resize(); | |
605 | - if (this.chartType !== 'pie') { | |
606 | - this.ctx.plot.setupGrid(); | |
664 | + this.ctx.plot.destroy(); | |
665 | + this.ctx.plot = null; | |
666 | + this.ctx.plotInited = false; | |
667 | + } | |
668 | + } | |
669 | + | |
670 | + cleanup() { | |
671 | + if (this.updateTimeoutHandle) { | |
672 | + this.ctx.$scope.$timeout.cancel(this.updateTimeoutHandle); | |
673 | + this.updateTimeoutHandle = null; | |
674 | + } | |
675 | + if (this.createPlotTimeoutHandle) { | |
676 | + this.ctx.$scope.$timeout.cancel(this.createPlotTimeoutHandle); | |
677 | + this.createPlotTimeoutHandle = null; | |
678 | + } | |
679 | + if (this.resizeTimeoutHandle) { | |
680 | + this.ctx.$scope.$timeout.cancel(this.resizeTimeoutHandle); | |
681 | + this.resizeTimeoutHandle = null; | |
682 | + } | |
683 | + } | |
684 | + | |
685 | + checkMouseEvents() { | |
686 | + var enabled = !this.ctx.isMobile && !this.ctx.isEdit; | |
687 | + if (angular.isUndefined(this.mouseEventsEnabled) || this.mouseEventsEnabled != enabled) { | |
688 | + this.mouseEventsEnabled = enabled; | |
689 | + if (this.$element) { | |
690 | + if (enabled) { | |
691 | + this.enableMouseEvents(); | |
692 | + } else { | |
693 | + this.disableMouseEvents(); | |
694 | + } | |
695 | + this.redrawPlot(); | |
607 | 696 | } |
608 | - this.ctx.plot.draw(); | |
609 | 697 | } |
610 | 698 | } |
611 | 699 | |
... | ... | @@ -1020,46 +1108,6 @@ export default class TbFlot { |
1020 | 1108 | } |
1021 | 1109 | } |
1022 | 1110 | |
1023 | - checkMouseEvents() { | |
1024 | - var enabled = !this.ctx.isMobile && !this.ctx.isEdit; | |
1025 | - if (angular.isUndefined(this.mouseEventsEnabled) || this.mouseEventsEnabled != enabled) { | |
1026 | - this.mouseEventsEnabled = enabled; | |
1027 | - if (this.$element) { | |
1028 | - if (enabled) { | |
1029 | - this.enableMouseEvents(); | |
1030 | - } else { | |
1031 | - this.disableMouseEvents(); | |
1032 | - } | |
1033 | - if (this.ctx.plot) { | |
1034 | - this.ctx.plot.destroy(); | |
1035 | - if (this.chartType === 'pie' && this.ctx.animatedPie) { | |
1036 | - this.ctx.plot = $.plot(this.$element, this.pieData, this.options); | |
1037 | - } else { | |
1038 | - this.ctx.plot = $.plot(this.$element, this.subscription.data, this.options); | |
1039 | - } | |
1040 | - } | |
1041 | - } | |
1042 | - } | |
1043 | - } | |
1044 | - | |
1045 | - redrawPlot() { | |
1046 | - if (this.ctx.plot) { | |
1047 | - this.ctx.plot.destroy(); | |
1048 | - if (this.chartType === 'pie' && this.ctx.animatedPie) { | |
1049 | - this.ctx.plot = $.plot(this.$element, this.pieData, this.options); | |
1050 | - } else { | |
1051 | - this.ctx.plot = $.plot(this.$element, this.subscription.data, this.options); | |
1052 | - } | |
1053 | - } | |
1054 | - } | |
1055 | - | |
1056 | - destroy() { | |
1057 | - if (this.ctx.plot) { | |
1058 | - this.ctx.plot.destroy(); | |
1059 | - this.ctx.plot = null; | |
1060 | - } | |
1061 | - } | |
1062 | - | |
1063 | 1111 | enableMouseEvents() { |
1064 | 1112 | this.$element.css('pointer-events',''); |
1065 | 1113 | this.$element.addClass('mouse-events'); |
... | ... | @@ -1069,6 +1117,9 @@ export default class TbFlot { |
1069 | 1117 | |
1070 | 1118 | if (!this.flotHoverHandler) { |
1071 | 1119 | this.flotHoverHandler = function (event, pos, item) { |
1120 | + if (!tbFlot.ctx.plot) { | |
1121 | + return; | |
1122 | + } | |
1072 | 1123 | if (!tbFlot.ctx.tooltipIndividual || item) { |
1073 | 1124 | |
1074 | 1125 | var multipleModeTooltip = !tbFlot.ctx.tooltipIndividual; |
... | ... | @@ -1128,6 +1179,9 @@ export default class TbFlot { |
1128 | 1179 | |
1129 | 1180 | if (!this.flotSelectHandler) { |
1130 | 1181 | this.flotSelectHandler = function (event, ranges) { |
1182 | + if (!tbFlot.ctx.plot) { | |
1183 | + return; | |
1184 | + } | |
1131 | 1185 | tbFlot.ctx.plot.clearSelection(); |
1132 | 1186 | tbFlot.subscription.onUpdateTimewindow(ranges.xaxis.from, ranges.xaxis.to); |
1133 | 1187 | }; |
... | ... | @@ -1153,6 +1207,9 @@ export default class TbFlot { |
1153 | 1207 | } |
1154 | 1208 | if (!this.mouseleaveHandler) { |
1155 | 1209 | this.mouseleaveHandler = function () { |
1210 | + if (!tbFlot.ctx.plot) { | |
1211 | + return; | |
1212 | + } | |
1156 | 1213 | tbFlot.ctx.tooltip.stop(true); |
1157 | 1214 | tbFlot.ctx.tooltip.hide(); |
1158 | 1215 | tbFlot.ctx.plot.unhighlight(); | ... | ... |