Skip to content

Commit

Permalink
Addressed code climate warnings.
Browse files Browse the repository at this point in the history
Addressed syntax related code climate warnings that were brought over by downloading patternfly components from patternfly repo.

https://www.pivotaltracker.com/story/show/147962059
  • Loading branch information
h-kataria committed Sep 28, 2017
1 parent 9197810 commit 1459d4e
Show file tree
Hide file tree
Showing 17 changed files with 540 additions and 542 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ angular.module( 'patternfly.card' ).component('pfAggregateStatusCard', {
status: '=',
showTopBorder: '@?',
altLayout: '@?',
layout: '@?'
layout: '@?',
},
templateUrl: '/static/pf_charts/aggregate-status-card.html.haml',
controller: function () {
controller: function() {
'use strict';
var vm = this;
vm.$onInit = function () {
vm.$onInit = function() {
vm.shouldShowTopBorder = (vm.showTopBorder === 'true');
vm.isAltLayout = (vm.altLayout === 'true' || vm.layout === 'tall');
vm.isMiniLayout = (vm.layout === 'mini');
};
}
},
});
21 changes: 11 additions & 10 deletions app/assets/javascripts/components/pf_charts/c3-chart.component.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,35 @@
angular.module('patternfly.charts').component('pfC3Chart', {
bindings: {
config: '<',
getChartCallback: '<'
getChartCallback: '<',
},
template: '<div id=""></div>',
controller: c3ChartController
controller: c3ChartController,
});
c3ChartController.$inject = ['$timeout', '$attrs']
c3ChartController.$inject = ['$timeout', '$attrs'];

function c3ChartController($timeout, $attrs) {
var vm = this, prevConfig;
var vm = this;
var prevConfig;

// store the chart object
var chart;
vm.generateChart = function () {
vm.generateChart = function() {
var chartData;

// Need to deep watch changes in chart config
prevConfig = angular.copy(vm.config);

$timeout(function () {
$timeout(function() {
chartData = vm.config;
if (chartData) {
chartData.bindto = '#' + $attrs.id;
// only re-generate donut pct chart if it has a threshold object
// because it's colors will change based on data and thresholds
if (!chart || ($attrs.id.indexOf('donutPctChart') !== -1 && chartData.thresholds)) {
if (! chart || ($attrs.id.indexOf('donutPctChart') !== -1 && chartData.thresholds)) {
chart = c3.generate(chartData);
} else {
//if chart is already created, then we only need to re-load data
// if chart is already created, then we only need to re-load data
chart.load(vm.config.data);
}
if (vm.getChartCallback) {
Expand All @@ -39,9 +40,9 @@ function c3ChartController($timeout, $attrs) {
});
};

vm.$doCheck = function () {
vm.$doCheck = function() {
// do a deep compare on config
if (!angular.equals(vm.config, prevConfig)) {
if (! angular.equals(vm.config, prevConfig)) {
vm.generateChart();
}
};
Expand Down
161 changes: 81 additions & 80 deletions app/assets/javascripts/components/pf_charts/donut-chart.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,115 +2,116 @@ angular.module('patternfly.charts').component('pfDonutChart', {
bindings: {
config: '<',
data: '<',
chartHeight: '<?'
chartHeight: '<?',
},
templateUrl: '/static/pf_charts/donut-chart.html.haml',
controller: donutChartController
controller: donutChartController,
});
donutChartController.$inject = ['pfUtils', '$element', '$timeout', '$log']
donutChartController.$inject = ['pfUtils', '$element', '$timeout', '$log'];

function donutChartController(pfUtils, $element, $timeout, $log) {
'use strict';
var vm = this, prevData;
var vm = this;
var prevData;

vm.$onInit = function () {
vm.$onInit = function() {
vm.donutChartId = 'donutChart';
if (vm.config.chartId) {
vm.donutChartId = vm.config.chartId + vm.donutChartId;
}
if (vm.config.chartId) {
vm.donutChartId = vm.config.chartId + vm.donutChartId;
}

vm.updateAll();
};

vm.getDonutData = function () {
return {
type: 'donut',
columns: vm.data,
order: null,
colors: vm.config.colors
};
vm.getDonutData = function() {
return {
type: 'donut',
columns: vm.data,
order: null,
colors: vm.config.colors,
};
};

vm.updateAll = function () {
// Need to deep watch changes in chart data
prevData = angular.copy(vm.data);
vm.updateAll = function() {
// Need to deep watch changes in chart data
prevData = angular.copy(vm.data);

vm.config = pfUtils.merge(patternfly.c3ChartDefaults().getDefaultDonutConfig(), vm.config);
vm.config.tooltip = { contents: patternfly.pfDonutTooltipContents };
vm.config.data = vm.getDonutData();
vm.config.data.onclick = vm.config.onClickFn;
};

};

vm.getTotal = function () {
var total = 0;
angular.forEach(vm.data, function (value) {
angular.forEach(value, function (value) {
if (!isNaN(value)) {
total += Number(value);
}
});
vm.getTotal = function() {
var total = 0;
angular.forEach(vm.data, function(value) {
angular.forEach(value, function(value) {
if (! isNaN(value)) {
total += Number(value);
}
});
return total;
};

vm.getCenterLabelText = function () {
var centerLabelText;

// default
centerLabelText = { bigText: vm.getTotal(),
smText: vm.config.donut.title};

if (vm.config.centerLabelFn) {
centerLabelText.bigText = vm.config.centerLabelFn();
centerLabelText.smText = '';
}

return centerLabelText;
};
});
return total;
};

vm.setupDonutChartTitle = function () {
var donutChartTitle, centerLabelText;
vm.getCenterLabelText = function() {
var centerLabelText;

if (angular.isUndefined(vm.chart)) {
return;
}
// default
centerLabelText = { bigText: vm.getTotal(),
smText: vm.config.donut.title};

donutChartTitle = d3.select(vm.chart.element).select('text.c3-chart-arcs-title');
if (!donutChartTitle) {
return;
}
if (vm.config.centerLabelFn) {
centerLabelText.bigText = vm.config.centerLabelFn();
centerLabelText.smText = '';
}

centerLabelText = vm.getCenterLabelText();
return centerLabelText;
};

// Remove any existing title.
donutChartTitle.text('');
if (centerLabelText.bigText && !centerLabelText.smText) {
donutChartTitle.text(centerLabelText.bigText);
} else {
donutChartTitle.insert('tspan').text(centerLabelText.bigText).classed('donut-title-big-pf', true).attr('dy', 0).attr('x', 0);
donutChartTitle.insert('tspan').text(centerLabelText.smText).classed('donut-title-small-pf', true).attr('dy', 20).attr('x', 0);
}
};
vm.setupDonutChartTitle = function() {
var donutChartTitle;
var centerLabelText;

if (angular.isUndefined(vm.chart)) {
return;
}

donutChartTitle = d3.select(vm.chart.element).select('text.c3-chart-arcs-title');
if (! donutChartTitle) {
return;
}

centerLabelText = vm.getCenterLabelText();

// Remove any existing title.
donutChartTitle.text('');
if (centerLabelText.bigText && ! centerLabelText.smText) {
donutChartTitle.text(centerLabelText.bigText);
} else {
donutChartTitle.insert('tspan').text(centerLabelText.bigText).classed('donut-title-big-pf', true).attr('dy', 0).attr('x', 0);
donutChartTitle.insert('tspan').text(centerLabelText.smText).classed('donut-title-small-pf', true).attr('dy', 20).attr('x', 0);
}
};

vm.setChart = function (chart) {
vm.setChart = function(chart) {
vm.chart = chart;
vm.setupDonutChartTitle();
};
};

vm.$onChanges = function (changesObj) {
if (changesObj.config || changesObj.data) {
vm.updateAll();
}
if (changesObj.chartHeight) {
vm.config.size.height = changesObj.chartHeight.currentValue;
}
};
vm.$onChanges = function(changesObj) {
if (changesObj.config || changesObj.data) {
vm.updateAll();
}
if (changesObj.chartHeight) {
vm.config.size.height = changesObj.chartHeight.currentValue;
}
};

vm.$doCheck = function () {
// do a deep compare on data
if (!angular.equals(vm.data, prevData)) {
vm.updateAll();
}
};
vm.$doCheck = function() {
// do a deep compare on data
if (! angular.equals(vm.data, prevData)) {
vm.updateAll();
}
};
}
Loading

0 comments on commit 1459d4e

Please sign in to comment.