Skip to content

Commit da8a833

Browse files
committed
0.9.0
1 parent 617cbe9 commit da8a833

File tree

8 files changed

+24
-16
lines changed

8 files changed

+24
-16
lines changed

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-chart.js",
3-
"version": "0.8.9",
3+
"version": "0.9.0",
44
"main": [
55
"./dist/angular-chart.js",
66
"./dist/angular-chart.css"

dist/angular-chart.js

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,15 @@
137137
// Order of setting "watch" matter
138138

139139
scope.$watch('data', function (newVal, oldVal) {
140-
if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) return;
140+
if (! newVal || ! newVal.length || (Array.isArray(newVal[0]) && ! newVal[0].length)) {
141+
destroyChart(chart, scope);
142+
return;
143+
}
141144
var chartType = type || scope.chartType;
142145
if (! chartType) return;
143146

144-
if (chart) {
145-
if (canUpdateChart(newVal, oldVal)) return updateChart(chart, newVal, scope, elem);
146-
chart.destroy();
147-
}
147+
if (chart && canUpdateChart(newVal, oldVal))
148+
return updateChart(chart, newVal, scope, elem);
148149

149150
createChart(chartType);
150151
}, true);
@@ -157,12 +158,11 @@
157158
scope.$watch('chartType', function (newVal, oldVal) {
158159
if (isEmpty(newVal)) return;
159160
if (angular.equals(newVal, oldVal)) return;
160-
if (chart) chart.destroy();
161161
createChart(newVal);
162162
});
163163

164164
scope.$on('$destroy', function () {
165-
if (chart) chart.destroy();
165+
destroyChart(chart, scope);
166166
});
167167

168168
function resetChart (newVal, oldVal) {
@@ -173,8 +173,6 @@
173173

174174
// chart.update() doesn't work for series and labels
175175
// so we have to re-create the chart entirely
176-
if (chart) chart.destroy();
177-
178176
createChart(chartType);
179177
}
180178

@@ -192,6 +190,10 @@
192190
getDataSets(scope.labels, scope.data, scope.series || [], colours) :
193191
getData(scope.labels, scope.data, colours);
194192
var options = angular.extend({}, ChartJs.getOptions(type), scope.options);
193+
194+
// Destroy old chart if it exists to avoid ghost charts issue
195+
// https://github.com/jtblin/angular-chart.js/issues/187
196+
destroyChart(chart, scope);
195197
chart = new ChartJs.Chart(ctx)[type](data, options);
196198
scope.$emit('create', chart);
197199

@@ -363,5 +365,11 @@
363365
var options = angular.extend({}, Chart.defaults.global, ChartJs.getOptions(type), scope.options);
364366
return options.responsive;
365367
}
368+
369+
function destroyChart(chart, scope) {
370+
if(! chart) return;
371+
chart.destroy();
372+
scope.$emit('destroy', chart);
373+
}
366374
}
367375
}));

dist/angular-chart.js.tar.gz

232 Bytes
Binary file not shown.

dist/angular-chart.min.js

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

dist/angular-chart.min.js.map

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

examples/charts.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h1>
6262
<p>
6363
<a class="btn btn-default btn-lg" href="https://github.com/jtblin/angular-chart"><i class="icon-github"></i>Code on Github</a>
6464
<a class="btn btn-success btn-lg" href="../dist/angular-chart.js.tar.gz" download="angular-chart.js.tar.gz">
65-
<i class="fa fa-download"></i> Download <small>(0.8.9)</small>
65+
<i class="fa fa-download"></i> Download <small>(0.9.0)</small>
6666
</a>
6767
</p>
6868
</div>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "angular-chart.js",
3-
"version": "0.8.9",
3+
"version": "0.9.0",
44
"description": "An angular.js wrapper for Chart.js",
55
"main": "dist/angular-chart.js",
66
"directories": {

test/fixtures/coverage.js

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

0 commit comments

Comments
 (0)