Skip to content

Commit a5248d3

Browse files
Fixes to handle no chart data for data unavailable charts.
1 parent d6f8559 commit a5248d3

File tree

34 files changed

+130
-70
lines changed

34 files changed

+130
-70
lines changed

dist/angular-patternfly.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
13001300
var determineBlockSize = function () {
13011301
var x = containerWidth;
13021302
var y = containerHeight;
1303-
var n = scope.data.length;
1303+
var n = scope.data ? scope.data.length : 0;
13041304
var px = Math.ceil(Math.sqrt(n * x / y));
13051305
var py = Math.ceil(Math.sqrt(n * y / x));
13061306
var sx, sy;
@@ -1371,11 +1371,16 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
13711371
if (typeof(newVal) !== 'undefined') {
13721372
scope.loadingDone = true;
13731373
setStyles();
1374-
setSizes();
1375-
redraw();
1374+
if (scope.chartDataAvailable !== false) {
1375+
setSizes();
1376+
redraw();
1377+
}
13761378
}
13771379
});
13781380
scope.$watch('chartDataAvailable', function () {
1381+
if (scope.chartDataAvailable === false) {
1382+
scope.loadingDone = true;
1383+
}
13791384
setStyles();
13801385
});
13811386
}
@@ -1539,14 +1544,18 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["pfUtils", fu
15391544
* Convert the config data to C3 Data
15401545
*/
15411546
$scope.getSparklineData = function (chartData) {
1542-
return {
1543-
x: chartData.xData[0],
1544-
columns: [
1545-
chartData.xData,
1546-
chartData.yData
1547-
],
1547+
var sparklineData = {
15481548
type: 'area'
15491549
};
1550+
1551+
if (chartData.dataAvailable !== false) {
1552+
sparklineData.x = chartData.xData[0];
1553+
sparklineData.columns = [
1554+
chartData.xData,
1555+
chartData.yData
1556+
];
1557+
}
1558+
return sparklineData;
15501559
};
15511560

15521561
$scope.getTooltipTableHTML = function (tipRows) {
@@ -1563,14 +1572,16 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["pfUtils", fu
15631572
return {
15641573
contents: function (d) {
15651574
var tipRows;
1566-
var percentUsed;
1575+
var percentUsed = 0;
15671576

15681577
if ($scope.config.tooltipFn) {
15691578
tipRows = $scope.config.tooltipFn(d);
15701579
} else {
15711580
switch ($scope.config.tooltipType) {
15721581
case 'usagePerDay':
1573-
percentUsed = Math.round(d[0].value / $scope.chartData.total * 100.0);
1582+
if ($scope.chartData.dataAvailable !== false && $scope.chartData.total > 0) {
1583+
percentUsed = Math.round(d[0].value / $scope.chartData.total * 100.0);
1584+
}
15741585
tipRows =
15751586
'<tr>' +
15761587
' <th colspan="2">' + d[0].x.toLocaleDateString() + '</th>' +
@@ -1879,10 +1890,19 @@ angular.module('patternfly.charts').directive('pfTrendsChart', function () {
18791890
var SMALL = 30, LARGE = 60;
18801891

18811892
$scope.getPercentageValue = function () {
1882-
return Math.round($scope.getLatestValue() / $scope.chartData.total * 100.0);
1893+
var pctValue = 0;
1894+
1895+
if ($scope.chartData.dataAvailable !== false && $scope.chartData.total > 0) {
1896+
pctValue = Math.round($scope.getLatestValue() / $scope.chartData.total * 100.0);
1897+
}
1898+
return pctValue;
18831899
};
18841900
$scope.getLatestValue = function () {
1885-
return $scope.chartData.yData[$scope.chartData.yData.length - 1];
1901+
var latestValue = 0;
1902+
if ($scope.chartData.yData && $scope.chartData.yData.length > 0) {
1903+
latestValue = $scope.chartData.yData[$scope.chartData.yData.length - 1];
1904+
}
1905+
return latestValue;
18861906
};
18871907
$scope.getChartHeight = function () {
18881908
var retValue = LARGE;

dist/angular-patternfly.min.js

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/docs/grunt-scripts/angular-patternfly.js

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,7 +1300,7 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
13001300
var determineBlockSize = function () {
13011301
var x = containerWidth;
13021302
var y = containerHeight;
1303-
var n = scope.data.length;
1303+
var n = scope.data ? scope.data.length : 0;
13041304
var px = Math.ceil(Math.sqrt(n * x / y));
13051305
var py = Math.ceil(Math.sqrt(n * y / x));
13061306
var sx, sy;
@@ -1371,11 +1371,16 @@ angular.module('patternfly.charts').directive('pfHeatmap', ["$compile", function
13711371
if (typeof(newVal) !== 'undefined') {
13721372
scope.loadingDone = true;
13731373
setStyles();
1374-
setSizes();
1375-
redraw();
1374+
if (scope.chartDataAvailable !== false) {
1375+
setSizes();
1376+
redraw();
1377+
}
13761378
}
13771379
});
13781380
scope.$watch('chartDataAvailable', function () {
1381+
if (scope.chartDataAvailable === false) {
1382+
scope.loadingDone = true;
1383+
}
13791384
setStyles();
13801385
});
13811386
}
@@ -1539,14 +1544,18 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["pfUtils", fu
15391544
* Convert the config data to C3 Data
15401545
*/
15411546
$scope.getSparklineData = function (chartData) {
1542-
return {
1543-
x: chartData.xData[0],
1544-
columns: [
1545-
chartData.xData,
1546-
chartData.yData
1547-
],
1547+
var sparklineData = {
15481548
type: 'area'
15491549
};
1550+
1551+
if (chartData.dataAvailable !== false) {
1552+
sparklineData.x = chartData.xData[0];
1553+
sparklineData.columns = [
1554+
chartData.xData,
1555+
chartData.yData
1556+
];
1557+
}
1558+
return sparklineData;
15501559
};
15511560

15521561
$scope.getTooltipTableHTML = function (tipRows) {
@@ -1563,14 +1572,16 @@ angular.module('patternfly.charts').directive('pfSparklineChart', ["pfUtils", fu
15631572
return {
15641573
contents: function (d) {
15651574
var tipRows;
1566-
var percentUsed;
1575+
var percentUsed = 0;
15671576

15681577
if ($scope.config.tooltipFn) {
15691578
tipRows = $scope.config.tooltipFn(d);
15701579
} else {
15711580
switch ($scope.config.tooltipType) {
15721581
case 'usagePerDay':
1573-
percentUsed = Math.round(d[0].value / $scope.chartData.total * 100.0);
1582+
if ($scope.chartData.dataAvailable !== false && $scope.chartData.total > 0) {
1583+
percentUsed = Math.round(d[0].value / $scope.chartData.total * 100.0);
1584+
}
15741585
tipRows =
15751586
'<tr>' +
15761587
' <th colspan="2">' + d[0].x.toLocaleDateString() + '</th>' +
@@ -1879,10 +1890,19 @@ angular.module('patternfly.charts').directive('pfTrendsChart', function () {
18791890
var SMALL = 30, LARGE = 60;
18801891

18811892
$scope.getPercentageValue = function () {
1882-
return Math.round($scope.getLatestValue() / $scope.chartData.total * 100.0);
1893+
var pctValue = 0;
1894+
1895+
if ($scope.chartData.dataAvailable !== false && $scope.chartData.total > 0) {
1896+
pctValue = Math.round($scope.getLatestValue() / $scope.chartData.total * 100.0);
1897+
}
1898+
return pctValue;
18831899
};
18841900
$scope.getLatestValue = function () {
1885-
return $scope.chartData.yData[$scope.chartData.yData.length - 1];
1901+
var latestValue = 0;
1902+
if ($scope.chartData.yData && $scope.chartData.yData.length > 0) {
1903+
latestValue = $scope.chartData.yData[$scope.chartData.yData.length - 1];
1904+
}
1905+
return latestValue;
18861906
};
18871907
$scope.getChartHeight = function () {
18881908
var retValue = LARGE;

dist/docs/js/docs-setup.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/docs/partials/api/patternfly.autofocus.pfFocused.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/autofocus/autofocus.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/32619fa/src/autofocus/autofocus.js#L39" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfFocused</code>
1+
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/autofocus/autofocus.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/fdc5142/src/autofocus/autofocus.js#L39" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfFocused</code>
22
<div><span class="hint">directive in module <code ng:non-bindable="">patternfly</code>
33
</span>
44
</div>

dist/docs/partials/api/patternfly.card.directive.pfAggregateStatusCard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/card/aggregate-status/aggregate-status-card.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/32619fa/src/card/aggregate-status/aggregate-status-card.directive.js#L129" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfAggregateStatusCard</code>
1+
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/card/aggregate-status/aggregate-status-card.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/fdc5142/src/card/aggregate-status/aggregate-status-card.directive.js#L129" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfAggregateStatusCard</code>
22
<div><span class="hint">directive in module <code ng:non-bindable="">patternfly.card</code>
33
</span>
44
</div>

dist/docs/partials/api/patternfly.card.directive.pfCard.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/card/basic/card.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/32619fa/src/card/basic/card.directive.js#L210" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfCard</code>
1+
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/card/basic/card.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/fdc5142/src/card/basic/card.directive.js#L210" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfCard</code>
22
<div><span class="hint">directive in module <code ng:non-bindable="">patternfly.card</code>
33
</span>
44
</div>

dist/docs/partials/api/patternfly.charts.directive.pfC3Chart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/charts/c3/c3-chart.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/32619fa/src/charts/c3/c3-chart.directive.js#L65" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfC3Chart</code>
1+
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/charts/c3/c3-chart.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/fdc5142/src/charts/c3/c3-chart.directive.js#L65" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfC3Chart</code>
22
<div><span class="hint">directive in module <code ng:non-bindable="">patternfly.charts</code>
33
</span>
44
</div>

dist/docs/partials/api/patternfly.charts.directive.pfDonutPctChart.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/charts/donut/donut-pct-chart-directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/32619fa/src/charts/donut/donut-pct-chart-directive.js#L233" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfDonutPctChart</code>
1+
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/charts/donut/donut-pct-chart-directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/fdc5142/src/charts/donut/donut-pct-chart-directive.js#L233" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfDonutPctChart</code>
22
<div><span class="hint">directive in module <code ng:non-bindable="">patternfly.charts</code>
33
</span>
44
</div>

dist/docs/partials/api/patternfly.charts.directive.pfHeatMap.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/charts/heatmap/heatmap.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/32619fa/src/charts/heatmap/heatmap.directive.js#L129" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfHeatMap</code>
1+
<a href="https://github.com/patternfly/angular-patternfly/edit/master/src/charts/heatmap/heatmap.directive.js" class="improve-docs"><i class="icon-edit"> </i>Improve this doc</a><a href="https://github.com/patternfly/angular-patternfly/blob/fdc5142/src/charts/heatmap/heatmap.directive.js#L129" class="view-source"><i class="icon-eye-open"> </i>View source</a><h1><code ng:non-bindable="">pfHeatMap</code>
22
<div><span class="hint">directive in module <code ng:non-bindable="">patternfly.charts</code>
33
</span>
44
</div>

0 commit comments

Comments
 (0)