aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/static/new/javascript/box_plot.js
diff options
context:
space:
mode:
Diffstat (limited to 'gn2/wqflask/static/new/javascript/box_plot.js')
-rw-r--r--gn2/wqflask/static/new/javascript/box_plot.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/gn2/wqflask/static/new/javascript/box_plot.js b/gn2/wqflask/static/new/javascript/box_plot.js
new file mode 100644
index 00000000..566a8eb8
--- /dev/null
+++ b/gn2/wqflask/static/new/javascript/box_plot.js
@@ -0,0 +1,80 @@
+// Generated by CoffeeScript 1.8.0
+var Box_Plot, root;
+
+root = typeof exports !== "undefined" && exports !== null ? exports : this;
+
+Box_Plot = (function() {
+ function Box_Plot(sample_list, sample_group) {
+ this.sample_list = sample_list;
+ this.sample_group = sample_group;
+ this.get_samples();
+ this.margin = {
+ top: 10,
+ right: 50,
+ bottom: 20,
+ left: 50
+ };
+ this.plot_width = 200 - this.margin.left - this.margin.right;
+ this.plot_height = 500 - this.margin.top - this.margin.bottom;
+ this.min = d3.min(this.sample_vals);
+ this.max = d3.max(this.sample_vals);
+ this.svg = this.create_svg();
+ this.enter_data();
+ }
+
+ Box_Plot.prototype.get_samples = function() {
+ var sample;
+ return this.sample_vals = (function() {
+ var _i, _len, _ref, _results;
+ _ref = this.sample_list;
+ _results = [];
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ sample = _ref[_i];
+ if (sample.value !== null) {
+ _results.push(sample.value);
+ }
+ }
+ return _results;
+ }).call(this);
+ };
+
+ Box_Plot.prototype.create_svg = function() {
+ var svg;
+ svg = d3.box().whiskers(this.inter_quartile_range(1.5)).width(this.plot_width - 30).height(this.plot_height - 30).domain([this.min, this.max]);
+ return svg;
+ };
+
+ Box_Plot.prototype.enter_data = function() {
+ return d3.select("#box_plot").selectAll("svg").data([this.sample_vals]).enter().append("svg:svg").attr("class", "box").attr("width", this.plot_width).attr("height", this.plot_height).append("svg:g").call(this.svg);
+ };
+
+ Box_Plot.prototype.inter_quartile_range = function(k) {
+ return (function(_this) {
+ return function(d, i) {
+ var inter_quartile_range, j, q1, q3;
+ console.log("iqr d:", d);
+ q1 = d.quartiles[0];
+ q3 = d.quartiles[2];
+ inter_quartile_range = (q3 - q1) * k;
+ console.log("iqr:", inter_quartile_range);
+ i = 0;
+ j = d.length;
+ console.log("d[-1]:", d[1]);
+ console.log("q1 - iqr:", q1 - inter_quartile_range);
+ while (d[i] < q1 - inter_quartile_range) {
+ i++;
+ }
+ while (d[j] > q3 + inter_quartile_range) {
+ j--;
+ }
+ console.log("[i, j]", [i, j]);
+ return [i, j];
+ };
+ })(this);
+ };
+
+ return Box_Plot;
+
+})();
+
+root.Box_Plot = Box_Plot;