Add color() aggregate function.
If you do something like
group=date,ver;count(*),color(ver)
then the fourth column will receive a series of integers where a particular
'ver' is mapped consistently to a particular value. This can be useful for
specifying the color field in a tree chart.
diff --git a/render.js b/render.js
index 1b2f290..d742cc9 100644
--- a/render.js
+++ b/render.js
@@ -238,12 +238,10 @@
}
return outgrid;
}
-
-
- var agg_types = {
- count: T_NUM,
- sum: T_NUM
- };
+
+
+ var colormap = {};
+ var next_color = 0;
var agg_funcs = {
@@ -312,6 +310,16 @@
acc += parseFloat(l[i]);
}
return acc;
+ },
+
+ color: function(l) {
+ for (var i in l) {
+ var v = l[i];
+ if (!(v in colormap)) {
+ colormap[v] = ++next_color;
+ }
+ return colormap[v];
+ }
}
};
agg_funcs.count.return_type = T_NUM;