aboutsummaryrefslogtreecommitdiff
path: root/gn2/wqflask/static/new/javascript/box_plot.js
blob: 566a8eb8226960937a786513eb0c6014a03c5aac (plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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;