forked from dc-js/dc.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata-count.js
62 lines (44 loc) · 1.86 KB
/
data-count.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
## Data Count Widget
Includes: [Base Mixin](#base-mixin)
Data count is a simple widget designed to display total number records in the data set vs. the number records selected
by the current filters. Once created data count widget will automatically update the text content of the following elements
under the parent element.
* ".total-count" - total number of records
* ".filter-count" - number of records matched by the current filters
Examples:
* [Nasdaq 100 Index](http://dc-js.github.com/dc.js/)
#### dc.dataCount(parent[, chartGroup])
Create a data count widget instance and attach it to the given parent element.
Parameters:
* parent : string - any valid d3 single selector representing typically a dom block element such as a div.
* chartGroup : string (optional) - name of the chart group this chart instance should be placed in. Once a chart is placed
in a certain chart group then any interaction with such instance will only trigger events and redraw within the same
chart group.
Return:
A newly created data count widget instance
#### .dimension(allData) - **mandatory**
For data count widget the only valid dimension is the entire data set.
#### .group(groupAll) - **mandatory**
For data count widget the only valid group is the all group.
```js
var ndx = crossfilter(data);
var all = ndx.groupAll();
dc.dataCount(".dc-data-count")
.dimension(ndx)
.group(all);
```
**/
dc.dataCount = function(parent, chartGroup) {
var _formatNumber = d3.format(",d");
var _chart = dc.baseMixin({});
_chart._doRender = function() {
_chart.selectAll(".total-count").text(_formatNumber(_chart.dimension().size()));
_chart.selectAll(".filter-count").text(_formatNumber(_chart.group().value()));
return _chart;
};
_chart._doRedraw = function(){
return _chart._doRender();
};
return _chart.anchor(parent, chartGroup);
};