Skip to content
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

[fix] do not overwrite chart's function names, append instead #34

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 1 addition & 4 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@
"dependencies": {
"angular": ">=1.2.0",
"lodash": "~2",
"dcjs": "2.0.0-beta.3",
"dcjs": "2.0.0-beta.18",
"crossfilter": "~1.3.0"
},
"devDependencies": {
"angular-mocks": "latest"
},
"resolutions": {
"crossfilter": "~1.3.0"
}
}
125 changes: 61 additions & 64 deletions dist/angular-dc.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
(function(root, factory) {
if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['angular', 'dc', 'lodash', 'd3'], function(angular, dc, _, d3) {
return (root.returnExportsGlobal = factory(angular, dc, _, d3));
// AMD. Register as an anonymous module unless amdModuleId is set
define(['angular', 'dc', 'lodash', 'd3'], function(a0, b1, c2, d3) {
return (root['angularDc'] = factory(a0, b1, c2, d3));
});
} else if (typeof exports === 'object') {
// Node. Does not work with strict CommonJS, but
// only CommonJS-like enviroments that support module.exports,
// only CommonJS-like environments that support module.exports,
// like Node.
module.exports = factory();
module.exports = factory(require("angular"), require("dc"), require("lodash"), require("d3"));
} else {
root['angularDc'] = factory(root.angular, root.dc, root._, root.d3);
root['angularDc'] = factory(angular, dc, _, d3);
}
}(this, function(angular, dc, _, d3) {
}(this, function(angular, dc, lodash, d3) {

'use strict';
var angularDc = angular.module('angularDc', []);
/* The main directive in angularDc, responsible creating Dc.js charts.

The goal of this directive is to provide a AngularJs interface to
the existing features of Dc.js. */
The goal of this directive is to provide a AngularJs interface to
the existing features of Dc.js. */
angularDc.directive('dcChart', [
'$timeout',
function($timeout) {
Expand All @@ -36,9 +36,9 @@
'postSetupChart'
];
/* Called during the directive's linking phase, this function creates
a Dc.js chart. The chart is configured based on settings read from
the $scope and the html element.
*/
a Dc.js chart. The chart is configured based on settings read from
the $scope and the html element.
*/
function setupChart(scope, iElement, iAttrs, options) {
// Get the element this directive blongs to, the root of chart
var chartElement = iElement[0],
Expand Down Expand Up @@ -88,7 +88,8 @@
// Register the eventHandlers with the chart (Dc.js)
eventHandlers.each(function(handler, evt) {
chart.on(evt, handler);
});
}).value();
// run the chain to enforce side effects (registration of handlers), ignore the result
// Run the postSetupChart callback, if provided
if (_.isFunction(options.postSetupChart)) {
options.postSetupChart(chart, options);
Expand All @@ -98,7 +99,7 @@

function getValidOptionsForChart(chart) {
// all chart options are exposed via a function
return _(chart).functions().extend(directiveOptions).map(function(s) {
return _(chart).functions().concat(directiveOptions).map(function(s) {
return 'dc' + s.charAt(0).toUpperCase() + s.substring(1);
}).value();
}
Expand Down Expand Up @@ -140,7 +141,7 @@
// by the controller
var r = scope.$eval(iAttrs[key]);
if (_.isUndefined(r)) {
throw Error(iAttrs[key] + ' is undefined');
throw new Error(iAttrs[key] + ' is undefined');
}
return r;
} catch (e) {
Expand Down Expand Up @@ -185,58 +186,54 @@
]);
/* Another directive, responsible of integration angular's select directive with dc.

<dc-select dc-dimension="fooDimension", all-label="All foos"/>
<dc-select dc-dimension="fooDimension", all-label="All foos"/>

This directive helps to filter by arbitrary dimensions without need for another graph.
This directive helps to filter by arbitrary dimensions without need for another graph.

Note that if there is a graph on the same dimension as the select, changing the select value
will not update the graph's own selection. This is also the case if you make 2 graphs
with same dimension. This is a limitation of the underlying lib dc.js
*/
angularDc.directive('dcSelect', [
function() {
return {
restrict: 'E',
scope: {
dcDimension: '=',
allLabel: '@'
},
template: '<select class="form-control" ng-model="selectModel" ' + 'ng-options="d.key for d in selectOptions">',
link: function(scope, iElement, iAttrs) {
scope.$watch('dcDimension', function(dimension) {
var allkeys, chart;
if (dimension !== null) {
// we make a fake chart so that the dimension is known by dc.filterAll()
chart = dc.baseMixin({});
chart.dimension(dimension);
chart.group(dimension);
chart._doRender = function() {};
chart._doRedraw = function() {};
scope.selectModel = {
key: scope.allLabel
};
allkeys = dimension.group().orderNatural().all();
scope.selectOptions = [scope.selectModel].concat(allkeys);
}
});
return scope.$watch('selectModel', function(sel) {
if (scope.dcDimension !== null) {
if (sel !== null && sel.key !== scope.allLabel) {
scope.dcDimension.filter(function(d) {
return d === sel.key;
});
} else {
scope.dcDimension.filter(null);
}
dc.redrawAll();
Note that if there is a graph on the same dimension as the select, changing the select value
will not update the graph's own selection. This is also the case if you make 2 graphs
with same dimension. This is a limitation of the underlying lib dc.js
*/
angularDc.directive('dcSelect', [function() {
return {
restrict: 'E',
scope: {
dcDimension: '=',
allLabel: '@'
},
template: '<select class="form-control" ng-model="selectModel" ' + 'ng-options="d.key for d in selectOptions">',
link: function(scope, iElement, iAttrs) {
scope.$watch('dcDimension', function(dimension) {
var allkeys, chart;
if (dimension !== null) {
// we make a fake chart so that the dimension is known by dc.filterAll()
chart = dc.baseMixin({});
chart.dimension(dimension);
chart.group(dimension);
chart._doRender = function() {};
chart._doRedraw = function() {};
scope.selectModel = {
key: scope.allLabel
};
allkeys = dimension.group().orderNatural().all();
scope.selectOptions = [scope.selectModel].concat(allkeys);
}
});
return scope.$watch('selectModel', function(sel) {
if (scope.dcDimension !== null) {
if (sel !== null && sel.key !== scope.allLabel) {
scope.dcDimension.filter(function(d) {
return d === sel.key;
});
} else {
scope.dcDimension.filter(null);
}
});
}
};
}
]);

dc.redrawAll();
}
});
}
};
}]);
return angularDc;


}));
16 changes: 8 additions & 8 deletions dist/angular-dc.min.js
100644 → 100755

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

6 changes: 3 additions & 3 deletions src/angular-dc.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ angularDc.directive('dcChart', ['$timeout',
// Register the eventHandlers with the chart (Dc.js)
eventHandlers.each(function(handler, evt) {
chart.on(evt, handler);
});

}).value(); // run the chain to enforce side effects (registration of handlers), ignore the result
// Run the postSetupChart callback, if provided
if (_.isFunction(options.postSetupChart)) {
options.postSetupChart(chart, options);
Expand All @@ -100,7 +100,7 @@ angularDc.directive('dcChart', ['$timeout',

// all chart options are exposed via a function
return _(chart).functions()
.extend(directiveOptions)
.concat(directiveOptions)
.map(function(s) {
return 'dc' + s.charAt(0).toUpperCase() + s.substring(1);
})
Expand Down