Skip to content

Commit

Permalink
release v0.1.1; fixed memory leaks, resizing, clearing, refreshing ...
Browse files Browse the repository at this point in the history
  • Loading branch information
krispo committed Feb 24, 2015
1 parent 385f589 commit 97ff366
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 56 deletions.
2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = function(grunt){
'* <%= pkg.title || pkg.name %>, ' +
'v<%= pkg.version %>; ' +
'<%= pkg.license %>; ' +
'<%= grunt.template.today("mm/dd/yyyy HH:MM") %>\n' +
'<%= grunt.template.today("dd/mm/yyyy HH:MM") %>\n' +
'<%= pkg.homepage ? "* " + pkg.homepage + "\\n" : "" %>' +
'**************************************************************************/\n',
stripBanners: true
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# Angular-nvD3

[![Build Status](https://travis-ci.org/krispo/angular-nvd3.svg?branch=master)](https://travis-ci.org/krispo/angular-nvd3)

This thing is designed to make it easier to work with [nvd3.js](https://github.com/novus/nvd3) re-usable charting library. This directive allows you to easily customize your charts via JSON API.

The key feature is that the original hierarchical structure of nvd3 models is completely preserved in directive JSON structure. This means that while you creating a complex chart that containing multiple elementary chart models (such as `line`, `bar`, `axis`, ...), you can in turn customize the properties of each internal elementary models as well as the global charting properties the way you want. This can be done as usual, but it becomes quite easily to customize while applying JSON approach to.
Expand Down
4 changes: 2 additions & 2 deletions bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "angular-nvd3",
"version": "0.1.0",
"version": "0.1.1",
"description": "An AngularJS directive for NVD3.js reusable charting library (based on D3.js)",
"main": ["dist/angular-nvd3.min.js"],
"license": "MIT",
Expand All @@ -27,7 +27,7 @@
"url": "https://github.com/krispo/angular-nvd3.git"
},
"dependencies": {
"angular": "~1.2",
"angular": "~1.x",
"d3": "~3.3.13",
"nvd3": "~v1.1.15-beta"
},
Expand Down
58 changes: 32 additions & 26 deletions dist/angular-nvd3.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************
* AngularJS-nvD3, v0.1.0; MIT License; 02/21/2015 17:55
* AngularJS-nvD3, v0.1.1; MIT License; 24/02/2015 19:26
* http://krispo.github.io/angular-nvd3
**************************************************************************/
(function(){
Expand Down Expand Up @@ -58,8 +58,11 @@
// Initialize chart with specific type
scope.chart = nv.models[options.chart.type]();

// Generate random chart ID
scope.chart.id = Math.random().toString(36).substr(2, 15);

angular.forEach(scope.chart, function(value, key){
if (key === 'options');
if (key === 'options' || key === 'id' || key === 'resizeHandler');

else if (key === 'dispatch') {
if (options.chart[key] === undefined || options.chart[key] === null) {
Expand Down Expand Up @@ -175,13 +178,17 @@
element.find('.subtitle').remove();
element.find('.caption').remove();
element.empty();
if (scope.chart && scope.chart.resizeHandler) {
scope.chart.resizeHandler.clear();
if (scope.chart) {
// clear window resize event handler
if (scope.chart.resizeHandler) scope.chart.resizeHandler.clear();

// remove chart from nv.graph list
for (var i = 0; i < nv.graphs.length; i++)
if (nv.graphs[i].id === scope.chart.id) {
nv.graphs.splice(i, 1);
}
}

scope.chart = null;
nv.render.queue = [];
nv.graphs = [];
nv.tooltip.cleanup();
},

Expand Down Expand Up @@ -236,7 +243,7 @@
// Configure 'title', 'subtitle', 'caption'.
// nvd3 has no sufficient models for it yet.
function configureWrapper(name){
var _ = extendDeep(defaultWrapper(name), scope.options[name] || {});
var _ = utils.deepExtend(defaultWrapper(name), scope.options[name] || {});

if (scope._config.extended) scope.options[name] = _;

Expand All @@ -256,7 +263,7 @@

// Add some styles to the whole directive element
function configureStyles(){
var _ = extendDeep(defaultStyles(), scope.options['styles'] || {});
var _ = utils.deepExtend(defaultStyles(), scope.options['styles'] || {});

if (scope._config.extended) scope.options['styles'] = _;

Expand Down Expand Up @@ -310,22 +317,6 @@
};
}

// Deep Extend json object
function extendDeep(dst) {
angular.forEach(arguments, function(obj) {
if (obj !== dst) {
angular.forEach(obj, function(value, key) {
if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
extendDeep(dst[key], value);
} else {
dst[key] = value;
}
});
}
});
return dst;
}

/* Event Handling */
// Watching on options changing
scope.$watch('options', utils.debounce(function(newOptions){
Expand All @@ -343,7 +334,7 @@

// Watching on config changing
scope.$watch('config', function(newConfig, oldConfig){
if (newConfig !== oldConfig && scope.chart){
if (newConfig !== oldConfig){
scope._config = angular.extend(defaultConfig, newConfig);
scope.api.refresh();
}
Expand Down Expand Up @@ -391,6 +382,21 @@
window.removeEventListener('resize', handler);
}
};
},
deepExtend: function(dst){
var me = this;
angular.forEach(arguments, function(obj) {
if (obj !== dst) {
angular.forEach(obj, function(value, key) {
if (dst[key] && dst[key].constructor && dst[key].constructor === Object) {
me.deepExtend(dst[key], value);
} else {
dst[key] = value;
}
});
}
});
return dst;
}
};
});
Expand Down
Loading

0 comments on commit 97ff366

Please sign in to comment.