Skip to content

Commit d09e720

Browse files
committed
Documenting Chart Registry for dc-js#676
1 parent 96f6171 commit d09e720

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

src/core.js

+55
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ var dc = {
3434
};
3535
/*jshint +W079*/
3636

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

5360
return {
61+
/**
62+
* Determine if a given chart instance resides in any group in the registry.
63+
* @param {*} chart dc.js chart instance
64+
* @returns {Boolean}
65+
*/
5466
has: function (chart) {
5567
for (var e in _chartMap) {
5668
if (_chartMap[e].indexOf(chart) >= 0) {
@@ -60,11 +72,23 @@ dc.chartRegistry = (function () {
6072
return false;
6173
},
6274

75+
/**
76+
* Add given chart instance to the given group, creating the group if necessary.
77+
* If no group is provided, a default group will be created using dc.constants.DEFAULT_CHART_GROUP.
78+
* @param {*} chart dc.js chart instance
79+
* @param {String} [group] Group name
80+
*/
6381
register: function (chart, group) {
6482
group = initializeChartGroup(group);
6583
_chartMap[group].push(chart);
6684
},
6785

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

102+
/**
103+
* Clear given group if one is provided, otherwise clears all groups.
104+
* @param {String} group Group name
105+
*/
78106
clear: function (group) {
79107
if (group) {
80108
delete _chartMap[group];
@@ -83,25 +111,52 @@ dc.chartRegistry = (function () {
83111
}
84112
},
85113

114+
/**
115+
* Get an array of each chart instance in the given group.
116+
* If no group is provided, the default group is returned.
117+
* @param {String} [group] Group name
118+
* @returns {*}
119+
*/
86120
list: function (group) {
87121
group = initializeChartGroup(group);
88122
return _chartMap[group];
89123
}
90124
};
91125
})();
92126

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

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

147+
/**
148+
* Determine if a given chart instance resides in any group in the registry.
149+
* @param {*} chart dc.js chart instance
150+
* @returns {Boolean}
151+
*/
101152
dc.hasChart = function (chart) {
102153
return dc.chartRegistry.has(chart);
103154
};
104155

156+
/**
157+
* Clear given group if one is provided, otherwise clears all groups.
158+
* @param {String} group Group name
159+
*/
105160
dc.deregisterAllCharts = function (group) {
106161
dc.chartRegistry.clear(group);
107162
};

0 commit comments

Comments
 (0)