Permalink
Browse files

actual histogram sorting

  • Loading branch information...
1 parent eefd6b9 commit 2aca8dae4bf3d35a113f1a2b8240cf0813493dc4 @maxogden committed Jun 9, 2012
Showing with 2,949 additions and 7 deletions.
  1. +30 −4 attachments/script/application.js
  2. +140 −3 attachments/script/bundle.js
  3. +5 −0 node_modules/csv/Makefile
  4. +2 −0 node_modules/csv/index.js
  5. +446 −0 node_modules/csv/lib/csv.js
  6. +15 −0 node_modules/csv/license.md
  7. +55 −0 node_modules/csv/package.json
  8. +251 −0 node_modules/csv/readme.md
  9. +3 −0 node_modules/csv/samples/columns.in
  10. +22 −0 node_modules/csv/samples/columns.js
  11. +3 −0 node_modules/csv/samples/duplicate-headers.in
  12. +43 −0 node_modules/csv/samples/duplicate-headers.js
  13. +28 −0 node_modules/csv/samples/sample-stdin.js
  14. +10 −0 node_modules/csv/samples/sample-stdout.js
  15. +2 −0 node_modules/csv/samples/sample.in
  16. +27 −0 node_modules/csv/samples/sample.js
  17. 0 node_modules/csv/samples/sample.out
  18. +2 −0 node_modules/csv/samples/transform.in
  19. +15 −0 node_modules/csv/samples/transform.js
  20. +38 −0 node_modules/csv/test/buffer.coffee
  21. +21 −0 node_modules/csv/test/buffer/same.in
  22. +21 −0 node_modules/csv/test/buffer/same.out
  23. +28 −0 node_modules/csv/test/buffer/smaller.in
  24. +28 −0 node_modules/csv/test/buffer/smaller.out
  25. +97 −0 node_modules/csv/test/columns.coffee
  26. +2 −0 node_modules/csv/test/columns/in_named.in
  27. +2 −0 node_modules/csv/test/columns/in_named.out
  28. +3 −0 node_modules/csv/test/columns/in_true.in
  29. +2 −0 node_modules/csv/test/columns/in_true.out
  30. +2 −0 node_modules/csv/test/columns/out_named.in
  31. +2 −0 node_modules/csv/test/columns/out_named.out
  32. +2 −0 node_modules/csv/test/columns/out_no_transform.in
  33. +2 −0 node_modules/csv/test/columns/out_no_transform.out
  34. +49 −0 node_modules/csv/test/delimiter.coffee
  35. +2 −0 node_modules/csv/test/delimiter/empty_value.in
  36. +2 −0 node_modules/csv/test/delimiter/empty_value.out
  37. +2 −0 node_modules/csv/test/delimiter/tab_to_coma.in
  38. +2 −0 node_modules/csv/test/delimiter/tab_to_coma.out
  39. +36 −0 node_modules/csv/test/escape.coffee
  40. +2 −0 node_modules/csv/test/escape/backslash.in
  41. +2 −0 node_modules/csv/test/escape/backslash.out
  42. +2 −0 node_modules/csv/test/escape/default.in
  43. +2 −0 node_modules/csv/test/escape/default.out
  44. +98 −0 node_modules/csv/test/fromto.coffee
  45. +2 −0 node_modules/csv/test/fromto/array_to_stream.out
  46. +2 −0 node_modules/csv/test/fromto/null.out
  47. +2 −0 node_modules/csv/test/fromto/sample.in
  48. +2 −0 node_modules/csv/test/fromto/sample.out
  49. +2 −0 node_modules/csv/test/fromto/string_to_stream.in
  50. +2 −0 node_modules/csv/test/fromto/string_to_stream.out
  51. +43 −0 node_modules/csv/test/header.coffee
  52. +2 −0 node_modules/csv/test/header/defwcols.in
  53. +3 −0 node_modules/csv/test/header/defwcols.out
  54. +3 −0 node_modules/csv/test/header/truercols_defwcols.in
  55. +3 −0 node_modules/csv/test/header/truercols_defwcols.out
  56. +60 −0 node_modules/csv/test/lineBreaks.coffee
  57. +1 −0 node_modules/csv/test/lineBreaks/custom.out
  58. +2 −0 node_modules/csv/test/lineBreaks/lineBreaks.in
  59. +1 −0 node_modules/csv/test/lineBreaks/mac.out
  60. +1 −0 node_modules/csv/test/lineBreaks/unicode.out
  61. +2 −0 node_modules/csv/test/lineBreaks/unix.out
  62. +2 −0 node_modules/csv/test/lineBreaks/windows.out
  63. +111 −0 node_modules/csv/test/quotes.coffee
  64. +3 −0 node_modules/csv/test/quotes/delimiter.in
  65. +3 −0 node_modules/csv/test/quotes/delimiter.out
  66. +2 −0 node_modules/csv/test/quotes/empty_value.in
  67. +2 −0 node_modules/csv/test/quotes/empty_value.out
  68. +2 −0 node_modules/csv/test/quotes/in_field.in
  69. +2 −0 node_modules/csv/test/quotes/in_field.out
  70. +2 −0 node_modules/csv/test/quotes/invalid.in
  71. +7 −0 node_modules/csv/test/quotes/linebreak.in
  72. +7 −0 node_modules/csv/test/quotes/linebreak.out
  73. +2 −0 node_modules/csv/test/quotes/quoted.in
  74. +2 −0 node_modules/csv/test/quotes/quoted.out
  75. +2 −0 node_modules/csv/test/quotes/regular.in
  76. +2 −0 node_modules/csv/test/quotes/regular.out
  77. +1 −0 node_modules/csv/test/quotes/unclosed.in
  78. +19 −0 node_modules/csv/test/reader.coffee
  79. +98 −0 node_modules/csv/test/transform.coffee
  80. +6 −0 node_modules/csv/test/transform/null.in
  81. +3 −0 node_modules/csv/test/transform/null.out
  82. +2 −0 node_modules/csv/test/transform/object.in
  83. +2 −0 node_modules/csv/test/transform/object.out
  84. +2 −0 node_modules/csv/test/transform/reorder.in
  85. +2 −0 node_modules/csv/test/transform/reorder.out
  86. +2 −0 node_modules/csv/test/transform/string.in
  87. +1 −0 node_modules/csv/test/transform/string.out
  88. +2 −0 node_modules/csv/test/transform/types.in
  89. +2 −0 node_modules/csv/test/transform/types.out
  90. +2 −0 node_modules/csv/test/transform/undefined.in
  91. 0 node_modules/csv/test/transform/undefined.out
  92. +56 −0 node_modules/csv/test/trim.coffee
  93. +3 −0 node_modules/csv/test/trim/ltrim.in
  94. +3 −0 node_modules/csv/test/trim/ltrim.out
  95. +3 −0 node_modules/csv/test/trim/notrim.in
  96. +3 −0 node_modules/csv/test/trim/notrim.out
  97. +3 −0 node_modules/csv/test/trim/rtrim.in
  98. +3 −0 node_modules/csv/test/trim/rtrim.out
  99. +3 −0 node_modules/csv/test/trim/trim.in
  100. +3 −0 node_modules/csv/test/trim/trim.out
  101. +98 −0 node_modules/csv/test/write.coffee
  102. +7 −0 node_modules/csv/test/write/string_preserve.out
  103. +1 −0 node_modules/csv/test/write/write.out
  104. +3 −0 node_modules/lump/.travis.yml
  105. +134 −0 node_modules/lump/README.markdown
  106. +6 −0 node_modules/lump/example/lump.js
  107. +15 −0 node_modules/lump/example/records.json
  108. +14 −0 node_modules/lump/example/stream.js
  109. +68 −0 node_modules/lump/index.js
  110. +4 −0 node_modules/lump/node_modules/pathway/.travis.yml
  111. +72 −0 node_modules/lump/node_modules/pathway/README.markdown
  112. +21 −0 node_modules/lump/node_modules/pathway/example/fn.js
  113. +11 −0 node_modules/lump/node_modules/pathway/example/path.js
  114. +36 −0 node_modules/lump/node_modules/pathway/index.js
  115. +4 −0 node_modules/lump/node_modules/pathway/node_modules/concat-map/.travis.yml
  116. +60 −0 node_modules/lump/node_modules/pathway/node_modules/concat-map/README.markdown
  117. +6 −0 node_modules/lump/node_modules/pathway/node_modules/concat-map/example/map.js
  118. +9 −0 node_modules/lump/node_modules/pathway/node_modules/concat-map/index.js
  119. +50 −0 node_modules/lump/node_modules/pathway/node_modules/concat-map/package.json
  120. +39 −0 node_modules/lump/node_modules/pathway/node_modules/concat-map/test/map.js
  121. +52 −0 node_modules/lump/node_modules/pathway/package.json
  122. +20 −0 node_modules/lump/node_modules/pathway/test/boolean.js
  123. +27 −0 node_modules/lump/node_modules/pathway/test/fn.js
  124. +9 −0 node_modules/lump/node_modules/pathway/test/nested.js
  125. +16 −0 node_modules/lump/node_modules/pathway/test/path.js
  126. +56 −0 node_modules/lump/package.json
  127. +40 −0 node_modules/lump/test/lump.js
  128. +15 −0 node_modules/lump/test/records.json
@@ -52,8 +52,8 @@ function getProfile(cb) {
function handleColumnHeaderClick(e) {
var key = $(e.currentTarget).find('.column-header-name').text()
createDimensions(key)
- app.dimensions[key].filterRange([0,1000000])
- var group = app.dimensions[key + " group"]
+ var group = app.dimensions[key].group
+ console.log(group.all())
var xmax = 0, ymax = 0
var data = _.map(group.all(), function(g) {
if (g.key > ymax) ymax = g.key
@@ -108,8 +108,34 @@ function handleColumnHeaderClick(e) {
}
function createDimensions(key) {
- app.dimensions[key] = app.crossfilter.dimension(function (d) { return +(d[key]) })
- app.dimensions[key + " group"] = app.dimensions[key].group(Math.floor)
+ var asc = app.crossfilter.dimension(function (d) { return +(d[key]) })
+ var desc = app.crossfilter.dimension(function (d) { return -1 * (+(d[key])) })
+ var sorter = new BucketSort(+(desc.top(1)[0][key]), +(asc.top(1)[0][key]), 100)
+ var buckets = app.crossfilter.dimension(function (d) {
+ return sorter.getBucket(+d[key])
+ })
+ var group = buckets.group()
+ app.dimensions[key] = {
+ asc: asc,
+ desc: desc,
+ buckets: buckets,
+ group: group
+ }
+}
+
+function BucketSort(min, max, size) {
+ var me = this
+ var step = (max - min) / size
+ me.buckets = []
+ _.times(size, function() {
+ me.buckets.push(min)
+ min += step
+ })
+}
+
+BucketSort.prototype.getBucket = function(value) {
+ var idx = _.sortedIndex(this.buckets, value)
+ return this.buckets[idx]
}
function handleCSVUpload() {
@@ -963,17 +963,17 @@ require.define("fs", function (require, module, exports, __dirname, __filename)
});
-require.define("/package.json", function (require, module, exports, __dirname, __filename) {
+require.define("/node_modules/csv/package.json", function (require, module, exports, __dirname, __filename) {
module.exports = {}
});
-require.define("/index.js", function (require, module, exports, __dirname, __filename) {
+require.define("/node_modules/csv/index.js", function (require, module, exports, __dirname, __filename) {
module.exports = require('./lib/csv');
});
-require.define("csv", function (require, module, exports, __dirname, __filename) {
+require.define("/node_modules/csv/lib/csv.js", function (require, module, exports, __dirname, __filename) {
// Module CSV - Copyright David Worms <open@adaltas.com> (BSD Licensed)
var EventEmitter = require('events').EventEmitter,
@@ -1422,3 +1422,140 @@ module.exports = function(){
};
});
+
+require.define("/node_modules/lump/package.json", function (require, module, exports, __dirname, __filename) {
+module.exports = {"main":"index.js"}
+});
+
+require.define("/node_modules/lump/index.js", function (require, module, exports, __dirname, __filename) {
+var Stream = require('stream');
+var util = require('util');
+var pathway = require('pathway');
+
+exports = module.exports = function (opts, size, path) {
+ if (size === undefined) {
+ // everything in opts
+ }
+ else if (Array.isArray(size)) {
+ opts = { data : opts, path : size };
+ }
+ else {
+ opts = { data : opts, size : size, path : path };
+ }
+
+ var data = opts.path ? pathway(opts.data, opts.path) : opts.data;
+ return computeLumps(data, opts.size);
+};
+
+exports.stream = function (opts) {
+ return new Lump(opts);
+};
+
+function Lump (opts, path) {
+ if (!opts) opts = {};
+ if (typeof opts === 'number') opts = { size : opts };
+ if (!opts.size) throw new Error('required parameter "size" not given');
+
+ this.writable = true;
+ this.size = opts.size;
+ this.path = path || opts.path || [];
+ this.data = [];
+}
+
+util.inherits(Lump, Stream);
+
+Lump.prototype.lumps = function () {
+ return computeLumps(this.data, this.size);
+};
+
+Lump.prototype.write = function (obj) {
+ var self = this;
+ var xs = pathway(obj, self.path);
+ self.data.push.apply(self.data, xs);
+};
+
+Lump.prototype.end = function () {
+ this.emit('end');
+};
+
+function computeLumps (data, size) {
+ var min = Math.min.apply(null, data);
+ var max = Math.max.apply(null, data);
+ var step = (max - min) / size;
+
+ var lumps = [];
+ var sorted = data.sort();
+ var ix = 0;
+
+ for (var x = min; x < max; x += step) {
+ var lump = { min : x, max : x + step, count : 0 };
+ for (; sorted[ix] < x + step; ix++) {
+ lump.count ++;
+ }
+ lumps.push(lump);
+ }
+ return lumps;
+}
+
+});
+
+require.define("/node_modules/lump/node_modules/pathway/package.json", function (require, module, exports, __dirname, __filename) {
+module.exports = {"main":"index.js"}
+});
+
+require.define("/node_modules/lump/node_modules/pathway/index.js", function (require, module, exports, __dirname, __filename) {
+var concatMap = require('concat-map');
+
+module.exports = function pathway (obj, path) {
+ return path.reduce(function (nodes, p, ip) {
+ if (typeof p === 'function') {
+ return withFilter(nodes, p)
+ }
+ else if (typeof p === 'boolean') {
+ return withFilter(nodes, function () { return p });
+ }
+ else if (isRegExp(p)) {
+ return withFilter(nodes, function (key) { return p.test(key) })
+ }
+ else {
+ return concatMap(nodes, function (node, ix) {
+ if (!node[p]) return [];
+ return [ node[p] ];
+ })
+ }
+ }, [ obj ]);
+};
+
+function withFilter (nodes, fn) {
+ return concatMap(nodes, function (node) {
+ if (typeof node !== 'object') return [];
+
+ return Object.keys(node)
+ .filter(function (key) { return fn(key, node[key]) })
+ .map(function (key) { return node[key] })
+ ;
+ });
+}
+
+function isRegExp (x) {
+ return Object.prototype.toString.call(x) === '[object RegExp]';
+}
+
+});
+
+require.define("/node_modules/lump/node_modules/pathway/node_modules/concat-map/package.json", function (require, module, exports, __dirname, __filename) {
+module.exports = {"main":"index.js"}
+});
+
+require.define("/node_modules/lump/node_modules/pathway/node_modules/concat-map/index.js", function (require, module, exports, __dirname, __filename) {
+module.exports = function (xs, fn) {
+ var res = [];
+ for (var i = 0; i < xs.length; i++) {
+ var x = fn(xs[i], i);
+ if (Array.isArray(x)) res.push.apply(res, x);
+ else res.push(x);
+ }
+ return res;
+};
+
+});

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
Oops, something went wrong.

0 comments on commit 2aca8da

Please sign in to comment.