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

Documenting Chart Registry for #676 #1082

Closed
wants to merge 1 commit into from
Closed
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
55 changes: 55 additions & 0 deletions src/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ var dc = {
};
/*jshint +W079*/

/**
* dc.chartRegistry maintains a mapping of all instantiated dc.js charts under a given or a default group
* to facilitate rendering and filtering charts simultaneously using the functions dc.filterAll,
* dc.refocusAll, renderAll, redrawAll.
*
* @type {{has, register, deregister, clear, list}}
*/
dc.chartRegistry = (function () {
// chartGroup:string => charts:array
var _chartMap = {};
Expand All @@ -51,6 +58,11 @@ dc.chartRegistry = (function () {
}

return {
/**
* Determine if a given chart instance resides in any group in the registry.
* @param {*} chart dc.js chart instance
* @returns {Boolean}
*/
has: function (chart) {
for (var e in _chartMap) {
if (_chartMap[e].indexOf(chart) >= 0) {
Expand All @@ -60,11 +72,23 @@ dc.chartRegistry = (function () {
return false;
},

/**
* Add given chart instance to the given group, creating the group if necessary.
* If no group is provided, a default group will be created using dc.constants.DEFAULT_CHART_GROUP.
* @param {*} chart dc.js chart instance
* @param {String} [group] Group name
*/
register: function (chart, group) {
group = initializeChartGroup(group);
_chartMap[group].push(chart);
},

/**
* Remove given chart instance from the given group, creating the group if necessary.
* If no group is provided, a default group will be created using dc.constants.DEFAULT_CHART_GROUP.
* @param {*} chart dc.js chart instance
* @param {String} [group] Group name
*/
deregister: function (chart, group) {
group = initializeChartGroup(group);
for (var i = 0; i < _chartMap[group].length; i++) {
Expand All @@ -75,6 +99,10 @@ dc.chartRegistry = (function () {
}
},

/**
* Clear given group if one is provided, otherwise clears all groups.
* @param {String} group Group name
*/
clear: function (group) {
if (group) {
delete _chartMap[group];
Expand All @@ -83,25 +111,52 @@ dc.chartRegistry = (function () {
}
},

/**
* Get an array of each chart instance in the given group.
* If no group is provided, the default group is returned.
* @param {String} [group] Group name
* @returns {*}
*/
list: function (group) {
group = initializeChartGroup(group);
return _chartMap[group];
}
};
})();

/**
* Add given chart instance to the given group, creating the group if necessary.
* If no group is provided, a default group will be created using dc.constants.DEFAULT_CHART_GROUP.
* @param {*} chart dc.js chart instance
* @param {String} [group] Group name
*/
dc.registerChart = function (chart, group) {
dc.chartRegistry.register(chart, group);
};

/**
* Remove given chart instance from the given group, creating the group if necessary.
* If no group is provided, a default group will be created using dc.constants.DEFAULT_CHART_GROUP.
* @param {*} chart dc.js chart instance
* @param {String} [group] Group name
*/
dc.deregisterChart = function (chart, group) {
dc.chartRegistry.deregister(chart, group);
};

/**
* Determine if a given chart instance resides in any group in the registry.
* @param {*} chart dc.js chart instance
* @returns {Boolean}
*/
dc.hasChart = function (chart) {
return dc.chartRegistry.has(chart);
};

/**
* Clear given group if one is provided, otherwise clears all groups.
* @param {String} group Group name
*/
dc.deregisterAllCharts = function (group) {
dc.chartRegistry.clear(group);
};
Expand Down