Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And Line chart component and related controllers, template, views to display Recent Hosts & Recent VMs line charts.
- Loading branch information
Showing
12 changed files
with
213 additions
and
97 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
app/assets/javascripts/components/pf_charts/line-chart.component.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
angular.module('patternfly.charts').component('pfLineChart', { | ||
bindings: { | ||
config: '<', | ||
chartData: '<', | ||
showXAxis: '<?', | ||
showYAxis: '<?', | ||
setAreaChart: '<?' | ||
}, | ||
templateUrl: '/static/pf_charts/line-chart.html', | ||
controller: lineChartController | ||
}); | ||
lineChartController.$inject = ['pfUtils'] | ||
|
||
function lineChartController(pfUtils) { | ||
'use strict'; | ||
var vm = this, prevChartData; | ||
|
||
vm.updateAll = function () { | ||
// Need to deep watch changes in chart data | ||
prevChartData = angular.copy(vm.chartData); | ||
|
||
// Create an ID for the chart based on the chartId in the config if given | ||
if (vm.lineChartId === undefined) { | ||
vm.lineChartId = 'lineChart'; | ||
if (vm.config.chartId) { | ||
vm.lineChartId = vm.config.chartId + vm.lineChartId; | ||
} | ||
} | ||
|
||
/* | ||
* Setup Axis options. Default is to not show either axis. This can be overridden in two ways: | ||
* 1) in the config, setting showAxis to true will show both axes | ||
* 2) in the attributes showXAxis and showYAxis will override the config if set | ||
* | ||
* By default only line and the tick marks are shown, no labels. This is a line and should be used | ||
* only to show a brief idea of trending. This can be overridden by setting the config.axis options per C3 | ||
*/ | ||
|
||
if (vm.showXAxis === undefined) { | ||
vm.showXAxis = (vm.config.showAxis !== undefined) && vm.config.showAxis; | ||
} | ||
|
||
if (vm.showYAxis === undefined) { | ||
vm.showYAxis = (vm.config.showAxis !== undefined) && vm.config.showAxis; | ||
} | ||
|
||
vm.defaultConfig = patternfly.c3ChartDefaults().getDefaultLineConfig(); | ||
vm.defaultConfig.axis = { | ||
x: { | ||
show: vm.showXAxis === true, | ||
type: 'timeseries', | ||
tick: { | ||
format: function () { | ||
return ''; | ||
} | ||
} | ||
}, | ||
y: { | ||
show: vm.showYAxis === true, | ||
tick: { | ||
format: function () { | ||
return ''; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
/* | ||
* Setup Chart type option. Default is Line Chart. | ||
*/ | ||
if (vm.setAreaChart === undefined) { | ||
vm.setAreaChart = (vm.config.setAreaChart !== undefined) && vm.config.setAreaChart; | ||
} | ||
|
||
// Convert the given data to C3 chart format | ||
vm.config.data = vm.getLineData(vm.chartData); | ||
|
||
// Override defaults with callers specifications | ||
vm.defaultConfig = pfUtils.merge(vm.defaultConfig, vm.config); | ||
|
||
// Will trigger c3 chart generation | ||
vm.chartConfig = pfUtils.merge(vm.defaultConfig, vm.config); | ||
}; | ||
|
||
/* | ||
* Convert the config data to C3 Data | ||
*/ | ||
vm.getLineData = function (chartData) { | ||
var lineData = { | ||
type: vm.setAreaChart ? "area" : "line" | ||
}; | ||
|
||
if (chartData && chartData.dataAvailable !== false && chartData.xData) { | ||
lineData.x = chartData.xData[0]; | ||
// Convert the chartData dictionary into a C3 columns data arrays | ||
lineData.columns = Object.keys(chartData).map(function (key) { | ||
return chartData[key]; | ||
}); | ||
} | ||
|
||
return lineData; | ||
}; | ||
|
||
vm.$onChanges = function (changesObj) { | ||
vm.updateAll(); | ||
}; | ||
|
||
vm.$doCheck = function () { | ||
// do a deep compare on chartData | ||
if (!angular.equals(vm.chartData, prevChartData)) { | ||
vm.updateAll(); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/assets/javascripts/controllers/pf_charts/recent_hosts_line_chart_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* global miqHttpInject */ | ||
angular.module( 'patternfly.charts' ).controller( 'recentHostsLineChartController', ['$scope', 'pfUtils', '$q', 'providerId', '$http', 'chartsMixin', function( $scope, pfUtils, $q, providerId, $http, chartsMixin ) { | ||
var vm = this; | ||
|
||
var init = function() { | ||
ManageIQ.angular.scope = vm; | ||
vm.config = chartsMixin.chartConfig['recentHostsConfig']; | ||
var url = '/ems_infra_dashboard/recent_hosts_data/' + providerId; | ||
var hostsDataPromise = $http.get(url).then(function(response) { | ||
vm.data = response.data.data; | ||
}); | ||
|
||
$q.all([hostsDataPromise]).then(function() { | ||
vm.data = chartsMixin.processData(vm.data.recentHosts, 'dates', vm.data.recentHosts.config.label) | ||
}); | ||
|
||
vm.custShowXAxis = false; | ||
vm.custShowYAxis = false; | ||
vm.custAreaChart = true; | ||
} | ||
|
||
init(); | ||
}]); |
23 changes: 23 additions & 0 deletions
23
app/assets/javascripts/controllers/pf_charts/recent_vms_line_chart_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* global miqHttpInject */ | ||
angular.module( 'patternfly.charts' ).controller( 'recentVmsLineChartController', ['$scope', 'pfUtils', '$q', 'providerId', '$http', 'chartsMixin', function( $scope, pfUtils, $q, providerId, $http, chartsMixin ) { | ||
var vm = this; | ||
|
||
var init = function() { | ||
ManageIQ.angular.scope = vm; | ||
vm.config = chartsMixin.chartConfig['recentVmsConfig']; | ||
var url = '/ems_infra_dashboard/recent_vms_data/' + providerId; | ||
var vmsDataPromise = $http.get(url).then(function(response) { | ||
vm.data = response.data.data; | ||
}); | ||
|
||
$q.all([vmsDataPromise]).then(function() { | ||
vm.data = chartsMixin.processData(vm.data.recentVms, 'dates', vm.data.recentVms.config.label) | ||
}); | ||
|
||
vm.custShowXAxis = false; | ||
vm.custShowYAxis = false; | ||
vm.custAreaChart = true; | ||
} | ||
|
||
init(); | ||
}]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
%div{'ng-controller' => "recentHostsLineChartController as vm", :class => "row", :style => "display:inline-block; width: 100%;"} | ||
%div{:class => "col-md-6"} | ||
%h3 | ||
{{vm.data.config.title}} | ||
.row.row-tile-pf | ||
.col-xs-6.col-sm-6.col-md-6.example-trend-container-hosts | ||
%pf-line-chart{'config' => "vm.config", 'chart-data' => "vm.data", 'set-area-chart' => "vm.custAreaChart", 'show-x-axis' => "vm.custShowXAxis", 'show-y-axis' => "vm.custShowYAxis"} | ||
%span.trend-footer-pf{"ng-class" => "{ 'chart-transparent-text': vm.data.dataAvailable === false }"} | ||
= _("Last 30 Days") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
%div{'ng-controller' => "recentVmsLineChartController as vm", :class => "row", :style => "display:inline-block; width: 100%;"} | ||
%div{:class => "col-md-6"} | ||
%h3 | ||
{{vm.data.config.title}} | ||
.row.row-tile-pf | ||
.col-xs-6.col-sm-6.col-md-6.example-trend-container-vms | ||
%pf-line-chart{'config' => "vm.config", 'chart-data' => "vm.data", 'set-area-chart' => "vm.custAreaChart", 'show-x-axis' => "vm.custShowXAxis", 'show-y-axis' => "vm.custShowYAxis"} | ||
%span.trend-footer-pf{"ng-class" => "{ 'chart-transparent-text': vm.data.dataAvailable === false }"} | ||
= _("Last 30 Days") |
Oops, something went wrong.