Skip to content

change use of patternfly setting functions from '$()' to 'patternfly' #417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/charts/c3/c3-chart-defaults.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(function () {
(function (patternfly) {
'use strict';

var patternflyDefaults = $().c3ChartDefaults();
var patternflyDefaults = patternfly.c3ChartDefaults();

angular.module('patternfly.charts').constant('c3ChartDefaults', {
getDefaultColors: patternflyDefaults.getDefaultColors,
Expand All @@ -20,4 +20,4 @@
getDefaultSparklineConfig: patternflyDefaults.getDefaultSparklineConfig,
getDefaultLineConfig: patternflyDefaults.getDefaultLineConfig
});
})();
})(patternfly);
6 changes: 3 additions & 3 deletions src/charts/c3/c3-chart.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
$scope.total = 1000;
$scope.available = $scope.total - $scope.used;

$scope.chartConfig = $().c3ChartDefaults().getDefaultDonutConfig('MHz Used');
$scope.chartConfig = patternfly.c3ChartDefaults().getDefaultDonutConfig('MHz Used');
$scope.chartConfig.data = {
type: "donut",
columns: [
Expand Down Expand Up @@ -72,7 +72,7 @@
</file>
</example>
*/
(function () {
(function (patternfly) {
'use strict';

angular.module('patternfly.charts').directive('pfC3Chart', function ($timeout) {
Expand Down Expand Up @@ -103,4 +103,4 @@
}
};
});
}());
}(patternfly));
305 changes: 153 additions & 152 deletions src/charts/donut/donut-pct-chart-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,179 +257,180 @@
</file>
</example>
*/
angular.module('patternfly.charts').directive('pfDonutPctChart', function (pfUtils, $timeout) {
(function (patternfly) {
'use strict';
angular.module('patternfly.charts').directive('pfDonutPctChart', function (pfUtils, $timeout) {
return {
restrict: 'A',
scope: {
config: '=',
data: '=',
chartHeight: '=?',
centerLabel: '=?'
},
replace: true,
templateUrl: 'charts/donut/donut-pct-chart.html',
controller: ['$scope',
function ($scope) {
var donutTooltip;

$scope.donutChartId = 'donutChart';
if ($scope.config.chartId) {
$scope.donutChartId = $scope.config.chartId + $scope.donutChartId;
}

return {
restrict: 'A',
scope: {
config: '=',
data: '=',
chartHeight: '=?',
centerLabel: '=?'
},
replace: true,
templateUrl: 'charts/donut/donut-pct-chart.html',
controller: ['$scope',
function ($scope) {
var donutTooltip;

$scope.donutChartId = 'donutChart';
if ($scope.config.chartId) {
$scope.donutChartId = $scope.config.chartId + $scope.donutChartId;
}

$scope.updateAvailable = function () {
$scope.data.available = $scope.data.total - $scope.data.used;
};
$scope.updateAvailable = function () {
$scope.data.available = $scope.data.total - $scope.data.used;
};

if ($scope.data.available === undefined) {
$scope.updateAvailable();
}
if ($scope.data.available === undefined) {
$scope.updateAvailable();
}

$scope.getStatusColor = function (used, thresholds) {
var color = pfUtils.colorPalette.blue;
$scope.getStatusColor = function (used, thresholds) {
var color = pfUtils.colorPalette.blue;

if (thresholds) {
color = pfUtils.colorPalette.green;
if (used >= thresholds.error) {
color = pfUtils.colorPalette.red;
} else if (used >= thresholds.warning) {
color = pfUtils.colorPalette.orange;
if (thresholds) {
color = pfUtils.colorPalette.green;
if (used >= thresholds.error) {
color = pfUtils.colorPalette.red;
} else if (used >= thresholds.warning) {
color = pfUtils.colorPalette.orange;
}
}
}

return color;
};
return color;
};

$scope.statusDonutColor = function (scope) {
var color, percentUsed;
$scope.statusDonutColor = function (scope) {
var color, percentUsed;

color = { pattern: [] };
percentUsed = scope.data.used / scope.data.total * 100.0;
color.pattern[0] = $scope.getStatusColor(percentUsed, scope.config.thresholds);
color.pattern[1] = pfUtils.colorPalette.black300;
return color;
};
color = { pattern: [] };
percentUsed = scope.data.used / scope.data.total * 100.0;
color.pattern[0] = $scope.getStatusColor(percentUsed, scope.config.thresholds);
color.pattern[1] = pfUtils.colorPalette.black300;
return color;
};

donutTooltip = function (scope) {
return {
contents: function (d) {
var tooltipHtml;

if (scope.config.tooltipFn) {
tooltipHtml = '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
scope.config.tooltipFn(d) +
'</span>';
} else {
tooltipHtml = '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
Math.round(d[0].ratio * 100) + '%' + ' ' + $scope.config.units + ' ' + d[0].name +
'</span>';
donutTooltip = function (scope) {
return {
contents: function (d) {
var tooltipHtml;

if (scope.config.tooltipFn) {
tooltipHtml = '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
scope.config.tooltipFn(d) +
'</span>';
} else {
tooltipHtml = '<span class="donut-tooltip-pf" style="white-space: nowrap;">' +
Math.round(d[0].ratio * 100) + '%' + ' ' + $scope.config.units + ' ' + d[0].name +
'</span>';
}

return tooltipHtml;
}

return tooltipHtml;
}
};
};
};

$scope.getDonutData = function (scope) {
return {
columns: [
['Used', scope.data.used],
['Available', scope.data.available]
],
type: 'donut',
donut: {
label: {
show: false
}
},
groups: [
['used', 'available']
],
order: null
$scope.getDonutData = function (scope) {
return {
columns: [
['Used', scope.data.used],
['Available', scope.data.available]
],
type: 'donut',
donut: {
label: {
show: false
}
},
groups: [
['used', 'available']
],
order: null
};
};
};

$scope.getCenterLabelText = function () {
var centerLabelText;

// default to 'used' info.
centerLabelText = { bigText: $scope.data.used,
smText: $scope.config.units + ' Used' };

if ($scope.config.centerLabelFn) {
centerLabelText.bigText = $scope.config.centerLabelFn();
centerLabelText.smText = '';
} else if ($scope.centerLabel === 'none') {
centerLabelText.bigText = '';
centerLabelText.smText = '';
} else if ($scope.centerLabel === 'available') {
centerLabelText.bigText = $scope.data.available;
centerLabelText.smText = $scope.config.units + ' Available';
} else if ($scope.centerLabel === 'percent') {
centerLabelText.bigText = Math.round($scope.data.used / $scope.data.total * 100.0) + '%';
centerLabelText.smText = 'of ' + $scope.data.total + ' ' + $scope.config.units;
}
$scope.getCenterLabelText = function () {
var centerLabelText;

// default to 'used' info.
centerLabelText = { bigText: $scope.data.used,
smText: $scope.config.units + ' Used' };

if ($scope.config.centerLabelFn) {
centerLabelText.bigText = $scope.config.centerLabelFn();
centerLabelText.smText = '';
} else if ($scope.centerLabel === 'none') {
centerLabelText.bigText = '';
centerLabelText.smText = '';
} else if ($scope.centerLabel === 'available') {
centerLabelText.bigText = $scope.data.available;
centerLabelText.smText = $scope.config.units + ' Available';
} else if ($scope.centerLabel === 'percent') {
centerLabelText.bigText = Math.round($scope.data.used / $scope.data.total * 100.0) + '%';
centerLabelText.smText = 'of ' + $scope.data.total + ' ' + $scope.config.units;
}

return centerLabelText;
};
return centerLabelText;
};


$scope.updateAll = function (scope) {
$scope.updateAvailable();
$scope.config.data = pfUtils.merge($scope.config.data, $scope.getDonutData($scope));
$scope.config.color = $scope.statusDonutColor($scope);
$scope.config.tooltip = donutTooltip(scope);
$scope.config.data.onclick = $scope.config.onClickFn;
};
$scope.updateAll = function (scope) {
$scope.updateAvailable();
$scope.config.data = pfUtils.merge($scope.config.data, $scope.getDonutData($scope));
$scope.config.color = $scope.statusDonutColor($scope);
$scope.config.tooltip = donutTooltip(scope);
$scope.config.data.onclick = $scope.config.onClickFn;
};

$scope.config = pfUtils.merge($().c3ChartDefaults().getDefaultDonutConfig(), $scope.config);
$scope.updateAll($scope);
$scope.config = pfUtils.merge(patternfly.c3ChartDefaults().getDefaultDonutConfig(), $scope.config);
$scope.updateAll($scope);


}
],
link: function (scope, element) {
var setupDonutChartTitle = function () {
$timeout(function () {
var donutChartTitle, centerLabelText;

donutChartTitle = d3.select(element[0]).select('text.c3-chart-arcs-title');
if (!donutChartTitle) {
return;
}
}
],
link: function (scope, element) {
var setupDonutChartTitle = function () {
$timeout(function () {
var donutChartTitle, centerLabelText;

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

centerLabelText = scope.getCenterLabelText();

centerLabelText = scope.getCenterLabelText();
// Remove any existing title.
donutChartTitle.selectAll('*').remove();
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);
}
}, 300);
};

// Remove any existing title.
donutChartTitle.selectAll('*').remove();
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);
scope.$watch('config', function () {
scope.updateAll(scope);
setupDonutChartTitle();
}, true);
scope.$watch('chartHeight', function () {
if (scope.chartHeight) {
scope.config.size.height = scope.chartHeight;
}
}, 300);
};

scope.$watch('config', function () {
scope.updateAll(scope);
setupDonutChartTitle();
}, true);
scope.$watch('chartHeight', function () {
if (scope.chartHeight) {
scope.config.size.height = scope.chartHeight;
}
});
scope.$watch('data', function () {
scope.updateAll(scope);
setupDonutChartTitle();
}, true);

scope.$watch('centerLabel', function () {
setupDonutChartTitle();
});
}
};
});
});
scope.$watch('data', function () {
scope.updateAll(scope);
setupDonutChartTitle();
}, true);

scope.$watch('centerLabel', function () {
setupDonutChartTitle();
});
}
};
});
}(patternfly));
Loading