Skip to content
This repository was archived by the owner on Oct 4, 2023. It is now read-only.

Commit 136111a

Browse files
committed
Trial to use a reduce function to get status value from ownersDim dimension. Not working yet.
1 parent 08e5b9e commit 136111a

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

metadata/static/catalog/js/panorama-generator.js

+48-4
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,20 @@ d3.json(url, function(error, data) {
9393
.size(5);
9494

9595
// Owners chart:
96-
//var ownersChart = dc.bubbleChart("#ownersAndVulnerabilitiesChart");
97-
//var ownersDim = ndx.dimension(function(d) { return d["owner"]; });
98-
// http://bl.ocks.org/jun9/5631952
96+
// var ownersChart = dc.bubbleChart("#ownersAndVulnerabilitiesChart");
97+
// var ownersDim = ndx.dimension(function(d) { return d["owner"]; });
98+
//
99+
// var ownersGroup = ownersDim.group();
100+
//
101+
// ownersChart
102+
// .dimension(ownersDim)
103+
// .group(ownersGroup)
104+
// .colorAcessor(function (p) { return ''; } )
105+
// .keyAcessor(function (p) { return d.value; } )
106+
// .valueAcessor(function (p) { return d.value; } )
107+
// .x(d3.scale.linear().domain[0, 100]);
108+
// // http://bl.ocks.org/jun9/5631952
109+
99110

100111

101112
// Time Overall chart:
@@ -114,10 +125,43 @@ d3.json(url, function(error, data) {
114125
max = tmp;
115126
}
116127
}
128+
129+
// https://github.com/dc-js/dc.js/wiki/FAQ#what-if-the-rows-contain-multiple-values
117130

131+
function reduceFieldsAdd(fields) {
132+
return function(p, v) {
133+
fields.forEach(function(f) {
134+
p[f] += v[f];
135+
});
136+
return p;
137+
};
138+
}
139+
function reduceFieldsRemove(fields) {
140+
return function(p, v) {
141+
fields.forEach(function(f) {
142+
p[f] -= v[f];
143+
});
144+
return p;
145+
};
146+
}
147+
function reduceFieldsInitial(fields) {
148+
return function() {
149+
var ret = {};
150+
fields.forEach(function(f) {
151+
ret[f] = 0;
152+
});
153+
return ret;
154+
};
155+
}
156+
157+
var fields = ['status'];
118158
var overallDim = ndx.dimension(function(d) { return timeParser.parse(d["identification_date"]); });
119-
var overallGroup = overallDim.group().reduceCount(function(d) { return d.identification_date; });
159+
// var overallGroup = overallDim.group().reduceCount(function(d) { return d.identification_date; });
160+
var overallGroup = overallDim.group().reduce(reduceFieldsAdd(fields), reduceFieldsRemove(fields), reduceFieldsInitial(fields));
161+
120162

163+
console.log(overallDim.top(Infinity));
164+
console.log(overallGroup.top(Infinity));
121165
overallVolumeChart
122166
.x(d3.time.scale().domain([min, max]))
123167
.dimension(overallDim)

0 commit comments

Comments
 (0)