Skip to content

Commit c6854aa

Browse files
committed
The canvas used by smoothie chart will now resize correctly on browser zoom in and out fixing tariqbuilds#375.
1 parent a816611 commit c6854aa

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

js/linuxDash.js

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@
440440
/**
441441
* Fetches and displays data as line chart at a certain refresh rate
442442
*/
443-
angular.module('linuxDash').directive('lineChartPlugin', ['$interval', '$compile', 'server', function($interval, $compile, server) {
443+
angular.module('linuxDash').directive('lineChartPlugin', ['$interval', '$compile', 'server', '$window', function($interval, $compile, server, $window) {
444444
return {
445445
restrict: 'E',
446446
scope: {
@@ -458,7 +458,12 @@
458458

459459
if (!scope.color) scope.color = '0, 255, 0';
460460

461-
var series;
461+
var series, w, h, canvas;
462+
463+
angular.element($window).bind('resize', function() {
464+
canvas.width = w;
465+
canvas.height = h;
466+
});
462467

463468
// smoothieJS - Create new chart
464469
var chart = new SmoothieChart({
@@ -486,8 +491,10 @@
486491
});
487492

488493
// smoothieJS - set up canvas element for chart
489-
canvas = element.find('canvas')[0];
490-
series = new TimeSeries();
494+
canvas = element.find('canvas')[0];
495+
series = new TimeSeries();
496+
w = canvas.width;
497+
h = canvas.height;
491498

492499
chart.addTimeSeries(series, {
493500
strokeStyle: 'rgba(' + scope.color + ', 1)',
@@ -550,7 +557,7 @@
550557
* Fetches and displays data as line chart at a certain refresh rate
551558
*
552559
*/
553-
angular.module('linuxDash').directive('multiLineChartPlugin', ['$interval', '$compile', 'server', function($interval, $compile, server) {
560+
angular.module('linuxDash').directive('multiLineChartPlugin', ['$interval', '$compile', 'server', '$window', function($interval, $compile, server, $window) {
554561
return {
555562
restrict: 'E',
556563
scope: {
@@ -564,6 +571,13 @@
564571
templateUrl: 'templates/app/multi-line-chart-plugin.html',
565572
link: function(scope, element) {
566573

574+
var w, h, canvas;
575+
576+
angular.element($window).bind('resize', function() {
577+
canvas.width = w;
578+
canvas.height = h;
579+
});
580+
567581
// smoothieJS - Create new chart
568582
var chart = new SmoothieChart({
569583
borderVisible: false,
@@ -603,9 +617,11 @@
603617
}];
604618

605619
// smoothieJS - set up canvas element for chart
606-
var canvas = element.find('canvas')[0];
607-
scope.seriesArray = [];
608-
scope.metricsArray = [];
620+
var canvas = element.find('canvas')[0];
621+
w = canvas.width;
622+
h = canvas.height;
623+
scope.seriesArray = [];
624+
scope.metricsArray = [];
609625

610626
// get the data once to set up # of lines on chart
611627
server.get(scope.moduleName, function(serverResponseData) {

templates/modules/cpu-utilization-chart.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
<line-chart-plugin
32

43
heading="CPU Utilization"

0 commit comments

Comments
 (0)