diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js index de1deb8bea..319eea9cf0 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/routers/router.js @@ -1,5 +1,5 @@ /* jshint unused: false */ -/* global window, $, Backbone, document */ +/* global window, $, Backbone, document, d3 */ /* global $, arangoHelper, btoa, _, frontendConfig */ (function () { @@ -52,6 +52,11 @@ this.queryView.cleanupGraphs(); } + if (this.lastRoute === '#dasboard' || window.location.hash.substr(0, 5) === '#node') { + // dom graph cleanup + d3.selectAll('svg > *').remove(); + } + this.lastRoute = window.location.hash; // this function executes before every route call $('#subNavigationBar .breadcrumb').html(''); diff --git a/js/apps/system/_admin/aardvark/APP/frontend/js/views/dashboardView.js b/js/apps/system/_admin/aardvark/APP/frontend/js/views/dashboardView.js index 816ee3064b..f45b0d17ca 100644 --- a/js/apps/system/_admin/aardvark/APP/frontend/js/views/dashboardView.js +++ b/js/apps/system/_admin/aardvark/APP/frontend/js/views/dashboardView.js @@ -19,6 +19,14 @@ interval: 10000, // in milliseconds defaultTimeFrame: 20 * 60 * 1000, // 20 minutes in milliseconds defaultDetailFrame: 2 * 24 * 60 * 60 * 1000, + reRender: true, + reRenderDistribution: true, + isVisible: true, + distributionCharts: { + totalTimeDistribution: null, + dataTransferDistribution: null + }, + residentChart: null, history: {}, graphs: {}, @@ -578,8 +586,27 @@ }); }, + checkState: function () { + var self = this; + + // if view is currently not active (#dashboard = standalone, #node = cluster) + if (window.location.hash === '#dashboard' || window.location.hash.substr(0, 5) === '#node') { + self.isVisible = true; + } else { + // chart data state + self.residentChart = null; + + // render state + self.isVisible = false; + self.reRender = true; + self.reRenderDistribution = false; + } + }, + getStatistics: function (callback, modalView) { var self = this; + self.checkState(); + var url = arangoHelper.databaseUrl('/_admin/aardvark/statistics/short', '_system'); var urlParams = '?start='; @@ -697,8 +724,9 @@ this.removeEmptyDataLabels(); } - nv.addGraph(function () { - var chart = nv.models.multiBarHorizontalChart() + if (self.reRender && self.isVisible) { + nv.addGraph(function () { + self.residentChart = nv.models.multiBarHorizontalChart() .x(function (d) { return d.label; }) @@ -722,44 +750,71 @@ .showControls(false) .stacked(true); - chart.yAxis + self.residentChart.yAxis .tickFormat(function (d) { return d + '%'; }) .showMaxMin(false); - chart.xAxis.showMaxMin(false); + self.residentChart.xAxis.showMaxMin(false); - d3.select('#residentSizeChart svg') + d3.select('#residentSizeChart svg') .datum(self.history[self.server].residentSizeChart) - .call(chart); + .call(self.residentChart); - d3.select('#residentSizeChart svg').select('.nv-zeroLine').remove(); + d3.select('#residentSizeChart svg').select('.nv-zeroLine').remove(); - if (update) { - d3.select('#residentSizeChart svg').select('#total').remove(); - d3.select('#residentSizeChart svg').select('#percentage').remove(); - } + if (update) { + d3.select('#residentSizeChart svg').select('#total').remove(); + d3.select('#residentSizeChart svg').select('#percentage').remove(); + } - d3.select('.dashboard-bar-chart-title .percentage') + d3.select('.dashboard-bar-chart-title .percentage') .html(currentA + ' (' + currentP + ' %)'); - d3.select('.dashboard-bar-chart-title .absolut') + d3.select('.dashboard-bar-chart-title .absolut') .html(data[0]); - nv.utils.windowResize(chart.update); + nv.utils.windowResize(self.residentChart.update); - return chart; - }, function () { - d3.selectAll('#residentSizeChart .nv-bar').on('click', - function () { - // no idea why this has to be empty, well anyways... + return self.residentChart; + }, function () { + d3.selectAll('#residentSizeChart .nv-bar').on('click', + function () { + // no idea why this has to be empty, well anyways... + } + ); + }); + self.reRender = false; + } else { + if (self.residentChart) { + // TODO FIX ME: THE MAIN FUNCTION MUCH TO OFTEN CALLED + + if (self.isVisible) { + // update widths + self.residentChart.width(dimensions.width); + self.residentChart.height(dimensions.height); + + // update labels + d3.select('.dashboard-bar-chart-title .percentage') + .html(currentA + ' (' + currentP + ' %)'); + d3.select('.dashboard-bar-chart-title .absolut') + .html(data[0]); + + // update data + d3.select('#residentSizeChart svg') + .datum(self.history[self.server].residentSizeChart) + .call(self.residentChart); + + // trigger resize + nv.utils.windowResize(self.residentChart.update); } - ); - }); + } + } }, prepareD3Charts: function (update) { var self = this; + var barCharts = { totalTimeDistribution: [ 'queueTimeDistributionPercent', 'requestTimeDistributionPercent'], @@ -785,31 +840,40 @@ self.removeEmptyDataLabels(); } - nv.addGraph(function () { - var tickMarks = [0, 0.25, 0.5, 0.75, 1]; - var marginLeft = 75; - var marginBottom = 23; - var bottomSpacer = 6; + if (self.reRenderDistribution && self.isVisible) { + // append custom legend + $('#' + k + 'Container').append( + '