Skip to content

Commit

Permalink
kien.luu/always-create-chart-if-has-no-data
Browse files Browse the repository at this point in the history
  • Loading branch information
trungkien1208 committed Aug 4, 2021
1 parent 24be2ec commit 892b982
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
7 changes: 4 additions & 3 deletions angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
chartClick: '=?',
chartHover: '=?',
chartDatasetOverride: '=?',
chartForceUpdate: '=?'
chartForceUpdate: '=?',
chartDisplayWhenNoData: '=?'
},
link: function (scope, elem/*, attrs */) {
if (useExcanvas) window.G_vmlCanvasManager.initElement(elem[0]);
Expand All @@ -133,7 +134,7 @@
});

function watchData (newVal, oldVal) {
if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) {
if (!scope.chartDisplayWhenNoData && (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length))) {
destroyChart(scope);
return;
}
Expand Down Expand Up @@ -174,7 +175,7 @@

function createChart (type, scope, elem) {
var options = getChartOptions(type, scope);
if (! hasData(scope) || ! canDisplay(type, scope, elem, options)) return;
if (!scope.chartDisplayWhenNoData && (! hasData(scope) || ! canDisplay(type, scope, elem, options))) return;

var cvs = elem[0];
var ctx = cvs.getContext('2d');
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-chart.js",
"version": "1.1.2",
"version": "1.1.3",
"main": [
"./dist/angular-chart.js"
],
Expand Down
7 changes: 4 additions & 3 deletions dist/angular-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@
chartClick: '=?',
chartHover: '=?',
chartDatasetOverride: '=?',
chartForceUpdate: '=?'
chartForceUpdate: '=?',
chartDisplayWhenNoData: '=?'
},
link: function (scope, elem/*, attrs */) {
if (useExcanvas) window.G_vmlCanvasManager.initElement(elem[0]);
Expand All @@ -133,7 +134,7 @@
});

function watchData (newVal, oldVal) {
if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) {
if (!scope.chartDisplayWhenNoData && (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length))) {
destroyChart(scope);
return;
}
Expand Down Expand Up @@ -174,7 +175,7 @@

function createChart (type, scope, elem) {
var options = getChartOptions(type, scope);
if (! hasData(scope) || ! canDisplay(type, scope, elem, options)) return;
if (!scope.chartDisplayWhenNoData && (! hasData(scope) || ! canDisplay(type, scope, elem, options))) return;

var cvs = elem[0];
var ctx = cvs.getContext('2d');
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-chart.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 892b982

Please sign in to comment.