aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArtem Tarasov2015-05-15 14:37:42 +0300
committerArtem Tarasov2015-05-15 14:37:42 +0300
commitecf2fead7c7b0e15ed8e8a8d1d16e816a0005e64 (patch)
tree8d66f3bd20942a9fb61fd4901453b7bae5ab27c7
parent41b246998130411cd5179e331f631519af3156db (diff)
downloadgenenetwork2-ecf2fead7c7b0e15ed8e8a8d1d16e816a0005e64.tar.gz
wip
-rwxr-xr-xwqflask/wqflask/database.py23
-rwxr-xr-xwqflask/wqflask/static/new/javascript/bar_chart.coffee34
-rwxr-xr-xwqflask/wqflask/static/new/javascript/bar_chart.js925
-rwxr-xr-xwqflask/wqflask/static/new/javascript/show_trait.coffee82
-rwxr-xr-xwqflask/wqflask/static/new/javascript/show_trait.js83
5 files changed, 621 insertions, 526 deletions
diff --git a/wqflask/wqflask/database.py b/wqflask/wqflask/database.py
index 159c5d6c..110b82d2 100755
--- a/wqflask/wqflask/database.py
+++ b/wqflask/wqflask/database.py
@@ -13,10 +13,27 @@ db_session = scoped_session(sessionmaker(autocommit=False,
Base = declarative_base()
Base.query = db_session.query_property()
-#import logging
+from sqlalchemy import event
+from sqlalchemy.engine import Engine
+import logging
+import time
#
-#logging.basicConfig()
-#logging.getLogger('sqlalchemy.engine').setLevel(logging.INFO)
+logging.basicConfig()
+logger = logging.getLogger('sqlalchemy.engine')
+logger.setLevel(logging.INFO)
+
+@event.listens_for(Engine, "before_cursor_execute")
+def before_cursor_execute(conn, cursor, statement,
+ parameters, context, executemany):
+ conn.info.setdefault('query_start_time', []).append(time.time())
+ logger.info("Start Query: %s", statement)
+
+@event.listens_for(Engine, "after_cursor_execute")
+def after_cursor_execute(conn, cursor, statement,
+ parameters, context, executemany):
+ total = time.time() - conn.info['query_start_time'].pop(-1)
+ logger.info("Query Complete!")
+ logger.info("Total Time: %f", total)
def init_db():
# import all modules here that might define models so that
diff --git a/wqflask/wqflask/static/new/javascript/bar_chart.coffee b/wqflask/wqflask/static/new/javascript/bar_chart.coffee
index c83de64e..acc4ac46 100755
--- a/wqflask/wqflask/static/new/javascript/bar_chart.coffee
+++ b/wqflask/wqflask/static/new/javascript/bar_chart.coffee
@@ -136,6 +136,21 @@ class Bar_Chart
@open_trait_selection()
)
+ # takes a dict: name -> value and rebuilds the graph
+ redraw: (samples_dict) ->
+ updated_samples = []
+ for [name, val, attr] in @full_sample_list
+ if name of samples_dict
+ updated_samples.push [name, samples_dict[name], attr]
+
+ @samples = updated_samples
+ # TODO: update underscore.js and replace the below with an _.unzip call
+ @sample_names = (x[0] for x in @samples)
+ @sample_vals = (x[1] for x in @samples)
+ @sample_attr_vals = (x[2] for x in @samples)
+
+ @rebuild_bar_graph(if @sort_by == 'name' then @samples else @sorted_samples())
+
rebuild_bar_graph: (samples) ->
console.log("samples:", samples)
@svg.selectAll(".bar")
@@ -170,13 +185,11 @@ class Bar_Chart
# return @trait_color_dict[d[0]]
# #return @attr_color_dict["collection_trait"][trimmed_samples[d[0]]]
#)
- sample_names = (sample[0] for sample in samples)
- console.log("sample_names2:", sample_names)
- x_scale = d3.scale.ordinal()
- .domain(sample_names)
- .rangeRoundBands([0, @range], 0.1, 0)
+ @create_scales()
$('.bar_chart').find('.x.axis').remove()
- @add_x_axis(x_scale)
+ $('.bar_chart').find('.y.axis').remove()
+ @add_x_axis()
+ @add_y_axis()
get_attr_color_dict: (vals) ->
@attr_color_dict = {}
@@ -273,6 +286,8 @@ class Bar_Chart
@attributes = (key for key of @sample_list[0]["extra_attributes"])
console.log("attributes:", @attributes)
@sample_attr_vals = []
+ # WTF??? how can they be zipped later???
+ # TODO find something with extra_attributes for testing
if @attributes.length > 0
for sample in @sample_list
attr_vals = {}
@@ -280,6 +295,7 @@ class Bar_Chart
attr_vals[attribute] = sample["extra_attributes"][attribute]
@sample_attr_vals.push(attr_vals)
@samples = _.zip(@sample_names, @sample_vals, @sample_attr_vals)
+ @full_sample_list = @samples.slice() # keeps attributes across redraws
get_distinct_attr_vals: () ->
@distinct_attr_vals = {}
@@ -314,14 +330,14 @@ class Bar_Chart
create_graph: () ->
#@add_border()
- @add_x_axis(@x_scale)
+ @add_x_axis()
@add_y_axis()
@add_bars()
add_x_axis: (scale) ->
xAxis = d3.svg.axis()
- .scale(scale)
+ .scale(@x_scale)
.orient("bottom");
@svg.append("g")
@@ -488,4 +504,4 @@ class Bar_Chart
#for sample in samples
# if samples[sample] in distinct_values
-root.Bar_Chart = Bar_Chart \ No newline at end of file
+root.Bar_Chart = Bar_Chart
diff --git a/wqflask/wqflask/static/new/javascript/bar_chart.js b/wqflask/wqflask/static/new/javascript/bar_chart.js
index f5ed544b..4dba3793 100755
--- a/wqflask/wqflask/static/new/javascript/bar_chart.js
+++ b/wqflask/wqflask/static/new/javascript/bar_chart.js
@@ -1,494 +1,533 @@
-// Generated by CoffeeScript 1.8.0
-var Bar_Chart, root,
- __hasProp = {}.hasOwnProperty,
- __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
+// Generated by CoffeeScript 1.9.2
+(function() {
+ var Bar_Chart, root,
+ hasProp = {}.hasOwnProperty,
+ indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
-root = typeof exports !== "undefined" && exports !== null ? exports : this;
+ root = typeof exports !== "undefined" && exports !== null ? exports : this;
-Bar_Chart = (function() {
- function Bar_Chart(sample_list) {
- var longest_sample_name, sample;
- this.sample_list = sample_list;
- this.sort_by = "name";
- this.get_samples();
- console.log("sample names:", this.sample_names);
- if (this.sample_attr_vals.length > 0) {
- this.get_distinct_attr_vals();
- this.get_attr_color_dict(this.distinct_attr_vals);
- }
- longest_sample_name = d3.max((function() {
- var _i, _len, _ref, _results;
- _ref = this.sample_names;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- sample = _ref[_i];
- _results.push(sample.length);
+ Bar_Chart = (function() {
+ function Bar_Chart(sample_list1) {
+ var longest_sample_name, sample;
+ this.sample_list = sample_list1;
+ this.sort_by = "name";
+ this.get_samples();
+ console.log("sample names:", this.sample_names);
+ if (this.sample_attr_vals.length > 0) {
+ this.get_distinct_attr_vals();
+ this.get_attr_color_dict(this.distinct_attr_vals);
}
- return _results;
- }).call(this));
- this.margin = {
- top: 20,
- right: 20,
- bottom: longest_sample_name * 7,
- left: 40
- };
- this.plot_width = this.sample_vals.length * 20 - this.margin.left - this.margin.right;
- this.range = this.sample_vals.length * 20;
- this.plot_height = 500 - this.margin.top - this.margin.bottom;
- this.x_buffer = this.plot_width / 20;
- this.y_buffer = this.plot_height / 20;
- this.y_min = d3.min(this.sample_vals);
- this.y_max = d3.max(this.sample_vals) * 1.1;
- this.svg = this.create_svg();
- this.plot_height -= this.y_buffer;
- this.create_scales();
- this.create_graph();
- d3.select("#color_attribute").on("change", (function(_this) {
- return function() {
- _this.attribute = $("#color_attribute").val();
- console.log("attr_color_dict:", _this.attr_color_dict);
- if (_this.sort_by = "name") {
- _this.svg.selectAll(".bar").data(_this.sorted_samples()).transition().duration(1000).style("fill", function(d) {
- if (_this.attribute === "None") {
- return "steelblue";
- } else {
- return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
- }
- }).select("title").text(function(d) {
- return d[1];
- });
- } else {
- _this.svg.selectAll(".bar").data(_this.samples).transition().duration(1000).style("fill", function(d) {
- if (_this.attribute === "None") {
- return "steelblue";
- } else {
- return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
- }
- });
+ longest_sample_name = d3.max((function() {
+ var j, len, ref, results;
+ ref = this.sample_names;
+ results = [];
+ for (j = 0, len = ref.length; j < len; j++) {
+ sample = ref[j];
+ results.push(sample.length);
}
- _this.draw_legend();
- return _this.add_legend(_this.attribute, _this.distinct_attr_vals[_this.attribute]);
- };
- })(this));
- $(".sort_by_value").on("click", (function(_this) {
- return function() {
- console.log("sorting by value");
- _this.sort_by = "value";
- if (_this.attributes.length > 0) {
- _this.attribute = $("#color_attribute").val();
- }
- return _this.rebuild_bar_graph(_this.sorted_samples());
+ return results;
+ }).call(this));
+ this.margin = {
+ top: 20,
+ right: 20,
+ bottom: longest_sample_name * 7,
+ left: 40
};
- })(this));
- $(".sort_by_name").on("click", (function(_this) {
- return function() {
- console.log("sorting by name");
- _this.sort_by = "name";
- if (_this.attributes.length > 0) {
+ this.plot_width = this.sample_vals.length * 20 - this.margin.left - this.margin.right;
+ this.range = this.sample_vals.length * 20;
+ this.plot_height = 500 - this.margin.top - this.margin.bottom;
+ this.x_buffer = this.plot_width / 20;
+ this.y_buffer = this.plot_height / 20;
+ this.y_min = d3.min(this.sample_vals);
+ this.y_max = d3.max(this.sample_vals) * 1.1;
+ this.svg = this.create_svg();
+ this.plot_height -= this.y_buffer;
+ this.create_scales();
+ this.create_graph();
+ d3.select("#color_attribute").on("change", (function(_this) {
+ return function() {
_this.attribute = $("#color_attribute").val();
- }
- return _this.rebuild_bar_graph(_this.samples);
- };
- })(this));
- d3.select("#color_by_trait").on("click", (function(_this) {
- return function() {
- return _this.open_trait_selection();
- };
- })(this));
- }
+ console.log("attr_color_dict:", _this.attr_color_dict);
+ if (_this.sort_by = "name") {
+ _this.svg.selectAll(".bar").data(_this.sorted_samples()).transition().duration(1000).style("fill", function(d) {
+ if (_this.attribute === "None") {
+ return "steelblue";
+ } else {
+ return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
+ }
+ }).select("title").text(function(d) {
+ return d[1];
+ });
+ } else {
+ _this.svg.selectAll(".bar").data(_this.samples).transition().duration(1000).style("fill", function(d) {
+ if (_this.attribute === "None") {
+ return "steelblue";
+ } else {
+ return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
+ }
+ });
+ }
+ _this.draw_legend();
+ return _this.add_legend(_this.attribute, _this.distinct_attr_vals[_this.attribute]);
+ };
+ })(this));
+ $(".sort_by_value").on("click", (function(_this) {
+ return function() {
+ console.log("sorting by value");
+ _this.sort_by = "value";
+ if (_this.attributes.length > 0) {
+ _this.attribute = $("#color_attribute").val();
+ }
+ return _this.rebuild_bar_graph(_this.sorted_samples());
+ };
+ })(this));
+ $(".sort_by_name").on("click", (function(_this) {
+ return function() {
+ console.log("sorting by name");
+ _this.sort_by = "name";
+ if (_this.attributes.length > 0) {
+ _this.attribute = $("#color_attribute").val();
+ }
+ return _this.rebuild_bar_graph(_this.samples);
+ };
+ })(this));
+ d3.select("#color_by_trait").on("click", (function(_this) {
+ return function() {
+ return _this.open_trait_selection();
+ };
+ })(this));
+ }
- Bar_Chart.prototype.rebuild_bar_graph = function(samples) {
- var sample, sample_names, x_scale;
- console.log("samples:", samples);
- this.svg.selectAll(".bar").data(samples).transition().duration(1000).style("fill", (function(_this) {
- return function(d) {
- if (_this.attributes.length === 0 && (_this.trait_color_dict != null)) {
- console.log("SAMPLE:", d[0]);
- console.log("CHECKING:", _this.trait_color_dict[d[0]]);
- return _this.trait_color_dict[d[0]];
- } else if (_this.attributes.length > 0 && _this.attribute !== "None") {
- console.log("@attribute:", _this.attribute);
- console.log("d[2]", d[2]);
- console.log("the_color:", _this.attr_color_dict[_this.attribute][d[2][_this.attribute]]);
- return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
- } else {
- return "steelblue";
+ Bar_Chart.prototype.redraw = function(samples_dict) {
+ var attr, j, len, name, ref, ref1, updated_samples, val, x;
+ updated_samples = [];
+ ref = this.full_sample_list;
+ for (j = 0, len = ref.length; j < len; j++) {
+ ref1 = ref[j], name = ref1[0], val = ref1[1], attr = ref1[2];
+ if (name in samples_dict) {
+ updated_samples.push([name, samples_dict[name], attr]);
}
- };
- })(this)).attr("y", (function(_this) {
- return function(d) {
- return _this.y_scale(d[1]);
- };
- })(this)).attr("height", (function(_this) {
- return function(d) {
- return _this.plot_height - _this.y_scale(d[1]);
- };
- })(this)).select("title").text((function(_this) {
- return function(d) {
- return d[1];
- };
- })(this));
- sample_names = (function() {
- var _i, _len, _results;
- _results = [];
- for (_i = 0, _len = samples.length; _i < _len; _i++) {
- sample = samples[_i];
- _results.push(sample[0]);
}
- return _results;
- })();
- console.log("sample_names2:", sample_names);
- x_scale = d3.scale.ordinal().domain(sample_names).rangeRoundBands([0, this.range], 0.1, 0);
- $('.bar_chart').find('.x.axis').remove();
- return this.add_x_axis(x_scale);
- };
-
- Bar_Chart.prototype.get_attr_color_dict = function(vals) {
- var color, color_range, distinct_vals, i, key, this_color_dict, value, _i, _j, _len, _len1, _results;
- this.attr_color_dict = {};
- console.log("vals:", vals);
- _results = [];
- for (key in vals) {
- if (!__hasProp.call(vals, key)) continue;
- distinct_vals = vals[key];
- this.min_val = d3.min(distinct_vals);
- this.max_val = d3.max(distinct_vals);
- this_color_dict = {};
- if (distinct_vals.length < 10) {
- color = d3.scale.category10();
- for (i = _i = 0, _len = distinct_vals.length; _i < _len; i = ++_i) {
- value = distinct_vals[i];
- this_color_dict[value] = color(i);
+ this.samples = updated_samples;
+ this.sample_names = (function() {
+ var k, len1, ref2, results;
+ ref2 = this.samples;
+ results = [];
+ for (k = 0, len1 = ref2.length; k < len1; k++) {
+ x = ref2[k];
+ results.push(x[0]);
}
- } else {
- console.log("distinct_values:", distinct_vals);
- if (_.every(distinct_vals, (function(_this) {
- return function(d) {
- if (isNaN(d)) {
- return false;
- } else {
- return true;
- }
- };
- })(this))) {
- color_range = d3.scale.linear().domain([min_val, max_val]).range([0, 255]);
- for (i = _j = 0, _len1 = distinct_vals.length; _j < _len1; i = ++_j) {
- value = distinct_vals[i];
- console.log("color_range(value):", parseInt(color_range(value)));
- this_color_dict[value] = d3.rgb(parseInt(color_range(value)), 0, 0);
- }
+ return results;
+ }).call(this);
+ this.sample_vals = (function() {
+ var k, len1, ref2, results;
+ ref2 = this.samples;
+ results = [];
+ for (k = 0, len1 = ref2.length; k < len1; k++) {
+ x = ref2[k];
+ results.push(x[1]);
}
- }
- _results.push(this.attr_color_dict[key] = this_color_dict);
- }
- return _results;
- };
+ return results;
+ }).call(this);
+ this.sample_attr_vals = (function() {
+ var k, len1, ref2, results;
+ ref2 = this.samples;
+ results = [];
+ for (k = 0, len1 = ref2.length; k < len1; k++) {
+ x = ref2[k];
+ results.push(x[2]);
+ }
+ return results;
+ }).call(this);
+ return this.rebuild_bar_graph(this.sort_by === 'name' ? this.samples : this.sorted_samples());
+ };
- Bar_Chart.prototype.draw_legend = function() {
- var svg_html;
- $('#legend-left').html(this.min_val);
- $('#legend-right').html(this.max_val);
- svg_html = '<svg height="10" width="90"> <rect x="0" width="15" height="10" style="fill: rgb(0, 0, 0);"></rect> <rect x="15" width="15" height="10" style="fill: rgb(50, 0, 0);"></rect> <rect x="30" width="15" height="10" style="fill: rgb(100, 0, 0);"></rect> <rect x="45" width="15" height="10" style="fill: rgb(150, 0, 0);"></rect> <rect x="60" width="15" height="10" style="fill: rgb(200, 0, 0);"></rect> <rect x="75" width="15" height="10" style="fill: rgb(255, 0, 0);"></rect> </svg>';
- console.log("svg_html:", svg_html);
- return $('#legend-colors').html(svg_html);
- };
+ Bar_Chart.prototype.rebuild_bar_graph = function(samples) {
+ console.log("samples:", samples);
+ this.svg.selectAll(".bar").data(samples).transition().duration(1000).style("fill", (function(_this) {
+ return function(d) {
+ if (_this.attributes.length === 0 && (_this.trait_color_dict != null)) {
+ console.log("SAMPLE:", d[0]);
+ console.log("CHECKING:", _this.trait_color_dict[d[0]]);
+ return _this.trait_color_dict[d[0]];
+ } else if (_this.attributes.length > 0 && _this.attribute !== "None") {
+ console.log("@attribute:", _this.attribute);
+ console.log("d[2]", d[2]);
+ console.log("the_color:", _this.attr_color_dict[_this.attribute][d[2][_this.attribute]]);
+ return _this.attr_color_dict[_this.attribute][d[2][_this.attribute]];
+ } else {
+ return "steelblue";
+ }
+ };
+ })(this)).attr("y", (function(_this) {
+ return function(d) {
+ return _this.y_scale(d[1]);
+ };
+ })(this)).attr("height", (function(_this) {
+ return function(d) {
+ return _this.plot_height - _this.y_scale(d[1]);
+ };
+ })(this)).select("title").text((function(_this) {
+ return function(d) {
+ return d[1];
+ };
+ })(this));
+ this.create_scales();
+ $('.bar_chart').find('.x.axis').remove();
+ $('.bar_chart').find('.y.axis').remove();
+ this.add_x_axis();
+ return this.add_y_axis();
+ };
- Bar_Chart.prototype.get_trait_color_dict = function(samples, vals) {
- var color, color_range, distinct_vals, i, key, sample, this_color_dict, value, _i, _j, _len, _len1, _results;
- this.trait_color_dict = {};
- console.log("vals:", vals);
- for (key in vals) {
- if (!__hasProp.call(vals, key)) continue;
- distinct_vals = vals[key];
- this_color_dict = {};
- this.min_val = d3.min(distinct_vals);
- this.max_val = d3.max(distinct_vals);
- if (distinct_vals.length < 10) {
- color = d3.scale.category10();
- for (i = _i = 0, _len = distinct_vals.length; _i < _len; i = ++_i) {
- value = distinct_vals[i];
- this_color_dict[value] = color(i);
- }
- } else {
- console.log("distinct_values:", distinct_vals);
- if (_.every(distinct_vals, (function(_this) {
- return function(d) {
- if (isNaN(d)) {
- return false;
- } else {
- return true;
- }
- };
- })(this))) {
- color_range = d3.scale.linear().domain([d3.min(distinct_vals), d3.max(distinct_vals)]).range([0, 255]);
- for (i = _j = 0, _len1 = distinct_vals.length; _j < _len1; i = ++_j) {
+ Bar_Chart.prototype.get_attr_color_dict = function(vals) {
+ var color, color_range, distinct_vals, i, j, k, key, len, len1, results, this_color_dict, value;
+ this.attr_color_dict = {};
+ console.log("vals:", vals);
+ results = [];
+ for (key in vals) {
+ if (!hasProp.call(vals, key)) continue;
+ distinct_vals = vals[key];
+ this.min_val = d3.min(distinct_vals);
+ this.max_val = d3.max(distinct_vals);
+ this_color_dict = {};
+ if (distinct_vals.length < 10) {
+ color = d3.scale.category10();
+ for (i = j = 0, len = distinct_vals.length; j < len; i = ++j) {
value = distinct_vals[i];
- console.log("color_range(value):", parseInt(color_range(value)));
- this_color_dict[value] = d3.rgb(parseInt(color_range(value)), 0, 0);
+ this_color_dict[value] = color(i);
+ }
+ } else {
+ console.log("distinct_values:", distinct_vals);
+ if (_.every(distinct_vals, (function(_this) {
+ return function(d) {
+ if (isNaN(d)) {
+ return false;
+ } else {
+ return true;
+ }
+ };
+ })(this))) {
+ color_range = d3.scale.linear().domain([min_val, max_val]).range([0, 255]);
+ for (i = k = 0, len1 = distinct_vals.length; k < len1; i = ++k) {
+ value = distinct_vals[i];
+ console.log("color_range(value):", parseInt(color_range(value)));
+ this_color_dict[value] = d3.rgb(parseInt(color_range(value)), 0, 0);
+ }
}
}
+ results.push(this.attr_color_dict[key] = this_color_dict);
}
- }
- _results = [];
- for (sample in samples) {
- if (!__hasProp.call(samples, sample)) continue;
- value = samples[sample];
- _results.push(this.trait_color_dict[sample] = this_color_dict[value]);
- }
- return _results;
- };
+ return results;
+ };
- Bar_Chart.prototype.convert_into_colors = function(values) {
- var color_range, i, value, _i, _len, _results;
- color_range = d3.scale.linear().domain([d3.min(values), d3.max(values)]).range([0, 255]);
- _results = [];
- for (i = _i = 0, _len = values.length; _i < _len; i = ++_i) {
- value = values[i];
- console.log("color_range(value):", color_range(parseInt(value)));
- _results.push(this_color_dict[value] = d3.rgb(color_range(parseInt(value)), 0, 0));
- }
- return _results;
- };
+ Bar_Chart.prototype.draw_legend = function() {
+ var svg_html;
+ $('#legend-left').html(this.min_val);
+ $('#legend-right').html(this.max_val);
+ svg_html = '<svg height="10" width="90"> <rect x="0" width="15" height="10" style="fill: rgb(0, 0, 0);"></rect> <rect x="15" width="15" height="10" style="fill: rgb(50, 0, 0);"></rect> <rect x="30" width="15" height="10" style="fill: rgb(100, 0, 0);"></rect> <rect x="45" width="15" height="10" style="fill: rgb(150, 0, 0);"></rect> <rect x="60" width="15" height="10" style="fill: rgb(200, 0, 0);"></rect> <rect x="75" width="15" height="10" style="fill: rgb(255, 0, 0);"></rect> </svg>';
+ console.log("svg_html:", svg_html);
+ return $('#legend-colors').html(svg_html);
+ };
- Bar_Chart.prototype.get_samples = function() {
- var attr_vals, attribute, key, sample, _i, _j, _len, _len1, _ref, _ref1;
- this.sample_names = (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.name);
- }
- }
- return _results;
- }).call(this);
- 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);
+ Bar_Chart.prototype.get_trait_color_dict = function(samples, vals) {
+ var color, color_range, distinct_vals, i, j, k, key, len, len1, results, sample, this_color_dict, value;
+ this.trait_color_dict = {};
+ console.log("vals:", vals);
+ for (key in vals) {
+ if (!hasProp.call(vals, key)) continue;
+ distinct_vals = vals[key];
+ this_color_dict = {};
+ this.min_val = d3.min(distinct_vals);
+ this.max_val = d3.max(distinct_vals);
+ if (distinct_vals.length < 10) {
+ color = d3.scale.category10();
+ for (i = j = 0, len = distinct_vals.length; j < len; i = ++j) {
+ value = distinct_vals[i];
+ this_color_dict[value] = color(i);
+ }
+ } else {
+ console.log("distinct_values:", distinct_vals);
+ if (_.every(distinct_vals, (function(_this) {
+ return function(d) {
+ if (isNaN(d)) {
+ return false;
+ } else {
+ return true;
+ }
+ };
+ })(this))) {
+ color_range = d3.scale.linear().domain([d3.min(distinct_vals), d3.max(distinct_vals)]).range([0, 255]);
+ for (i = k = 0, len1 = distinct_vals.length; k < len1; i = ++k) {
+ value = distinct_vals[i];
+ console.log("color_range(value):", parseInt(color_range(value)));
+ this_color_dict[value] = d3.rgb(parseInt(color_range(value)), 0, 0);
+ }
+ }
}
}
- return _results;
- }).call(this);
- this.attributes = (function() {
- var _results;
- _results = [];
- for (key in this.sample_list[0]["extra_attributes"]) {
- _results.push(key);
+ results = [];
+ for (sample in samples) {
+ if (!hasProp.call(samples, sample)) continue;
+ value = samples[sample];
+ results.push(this.trait_color_dict[sample] = this_color_dict[value]);
}
- return _results;
- }).call(this);
- console.log("attributes:", this.attributes);
- this.sample_attr_vals = [];
- if (this.attributes.length > 0) {
- _ref = this.sample_list;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- sample = _ref[_i];
- attr_vals = {};
- _ref1 = this.attributes;
- for (_j = 0, _len1 = _ref1.length; _j < _len1; _j++) {
- attribute = _ref1[_j];
- attr_vals[attribute] = sample["extra_attributes"][attribute];
- }
- this.sample_attr_vals.push(attr_vals);
+ return results;
+ };
+
+ Bar_Chart.prototype.convert_into_colors = function(values) {
+ var color_range, i, j, len, results, value;
+ color_range = d3.scale.linear().domain([d3.min(values), d3.max(values)]).range([0, 255]);
+ results = [];
+ for (i = j = 0, len = values.length; j < len; i = ++j) {
+ value = values[i];
+ console.log("color_range(value):", color_range(parseInt(value)));
+ results.push(this_color_dict[value] = d3.rgb(color_range(parseInt(value)), 0, 0));
}
- }
- return this.samples = _.zip(this.sample_names, this.sample_vals, this.sample_attr_vals);
- };
+ return results;
+ };
- Bar_Chart.prototype.get_distinct_attr_vals = function() {
- var attribute, sample, _i, _len, _ref, _results;
- this.distinct_attr_vals = {};
- _ref = this.sample_attr_vals;
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- sample = _ref[_i];
- _results.push((function() {
- var _ref1, _results1;
- _results1 = [];
- for (attribute in sample) {
- if (!this.distinct_attr_vals[attribute]) {
- this.distinct_attr_vals[attribute] = [];
+ Bar_Chart.prototype.get_samples = function() {
+ var attr_vals, attribute, j, k, key, len, len1, ref, ref1, sample;
+ this.sample_names = (function() {
+ var j, len, ref, results;
+ ref = this.sample_list;
+ results = [];
+ for (j = 0, len = ref.length; j < len; j++) {
+ sample = ref[j];
+ if (sample.value !== null) {
+ results.push(sample.name);
}
- if (_ref1 = sample[attribute], __indexOf.call(this.distinct_attr_vals[attribute], _ref1) < 0) {
- _results1.push(this.distinct_attr_vals[attribute].push(sample[attribute]));
- } else {
- _results1.push(void 0);
+ }
+ return results;
+ }).call(this);
+ this.sample_vals = (function() {
+ var j, len, ref, results;
+ ref = this.sample_list;
+ results = [];
+ for (j = 0, len = ref.length; j < len; j++) {
+ sample = ref[j];
+ if (sample.value !== null) {
+ results.push(sample.value);
}
}
- return _results1;
- }).call(this));
- }
- return _results;
- };
-
- Bar_Chart.prototype.create_svg = function() {
- var svg;
- svg = d3.select("#bar_chart").append("svg").attr("class", "bar_chart").attr("width", this.plot_width + this.margin.left + this.margin.right).attr("height", this.plot_height + this.margin.top + this.margin.bottom).append("g").attr("transform", "translate(" + this.margin.left + "," + this.margin.top + ")");
- return svg;
- };
-
- Bar_Chart.prototype.create_scales = function() {
- this.x_scale = d3.scale.ordinal().domain(this.sample_names).rangeRoundBands([0, this.range], 0.1, 0);
- return this.y_scale = d3.scale.linear().domain([this.y_min * 0.75, this.y_max]).range([this.plot_height, this.y_buffer]);
- };
-
- Bar_Chart.prototype.create_graph = function() {
- this.add_x_axis(this.x_scale);
- this.add_y_axis();
- return this.add_bars();
- };
+ return results;
+ }).call(this);
+ this.attributes = (function() {
+ var results;
+ results = [];
+ for (key in this.sample_list[0]["extra_attributes"]) {
+ results.push(key);
+ }
+ return results;
+ }).call(this);
+ console.log("attributes:", this.attributes);
+ this.sample_attr_vals = [];
+ if (this.attributes.length > 0) {
+ ref = this.sample_list;
+ for (j = 0, len = ref.length; j < len; j++) {
+ sample = ref[j];
+ attr_vals = {};
+ ref1 = this.attributes;
+ for (k = 0, len1 = ref1.length; k < len1; k++) {
+ attribute = ref1[k];
+ attr_vals[attribute] = sample["extra_attributes"][attribute];
+ }
+ this.sample_attr_vals.push(attr_vals);
+ }
+ }
+ this.samples = _.zip(this.sample_names, this.sample_vals, this.sample_attr_vals);
+ return this.full_sample_list = this.samples.slice();
+ };
- Bar_Chart.prototype.add_x_axis = function(scale) {
- var xAxis;
- xAxis = d3.svg.axis().scale(scale).orient("bottom");
- return this.svg.append("g").attr("class", "x axis").attr("transform", "translate(0," + this.plot_height + ")").call(xAxis).selectAll("text").style("text-anchor", "end").style("font-size", "12px").attr("dx", "-.8em").attr("dy", "-.3em").attr("transform", (function(_this) {
- return function(d) {
- return "rotate(-90)";
- };
- })(this));
- };
+ Bar_Chart.prototype.get_distinct_attr_vals = function() {
+ var attribute, j, len, ref, results, sample;
+ this.distinct_attr_vals = {};
+ ref = this.sample_attr_vals;
+ results = [];
+ for (j = 0, len = ref.length; j < len; j++) {
+ sample = ref[j];
+ results.push((function() {
+ var ref1, results1;
+ results1 = [];
+ for (attribute in sample) {
+ if (!this.distinct_attr_vals[attribute]) {
+ this.distinct_attr_vals[attribute] = [];
+ }
+ if (ref1 = sample[attribute], indexOf.call(this.distinct_attr_vals[attribute], ref1) < 0) {
+ results1.push(this.distinct_attr_vals[attribute].push(sample[attribute]));
+ } else {
+ results1.push(void 0);
+ }
+ }
+ return results1;
+ }).call(this));
+ }
+ return results;
+ };
- Bar_Chart.prototype.add_y_axis = function() {
- var yAxis;
- yAxis = d3.svg.axis().scale(this.y_scale).orient("left").ticks(5);
- return this.svg.append("g").attr("class", "y axis").call(yAxis).append("text").attr("transform", "rotate(-90)").attr("y", 6).attr("dy", ".71em").style("text-anchor", "end");
- };
+ Bar_Chart.prototype.create_svg = function() {
+ var svg;
+ svg = d3.select("#bar_chart").append("svg").attr("class", "bar_chart").attr("width", this.plot_width + this.margin.left + this.margin.right).attr("height", this.plot_height + this.margin.top + this.margin.bottom).append("g").attr("transform", "translate(" + this.margin.left + "," + this.margin.top + ")");
+ return svg;
+ };
- Bar_Chart.prototype.add_bars = function() {
- return this.svg.selectAll(".bar").data(this.samples).enter().append("rect").style("fill", "steelblue").attr("class", "bar").attr("x", (function(_this) {
- return function(d) {
- return _this.x_scale(d[0]);
- };
- })(this)).attr("width", this.x_scale.rangeBand()).attr("y", (function(_this) {
- return function(d) {
- return _this.y_scale(d[1]);
- };
- })(this)).attr("height", (function(_this) {
- return function(d) {
- return _this.plot_height - _this.y_scale(d[1]);
- };
- })(this)).append("svg:title").text((function(_this) {
- return function(d) {
- return d[1];
- };
- })(this));
- };
+ Bar_Chart.prototype.create_scales = function() {
+ this.x_scale = d3.scale.ordinal().domain(this.sample_names).rangeRoundBands([0, this.range], 0.1, 0);
+ return this.y_scale = d3.scale.linear().domain([this.y_min * 0.75, this.y_max]).range([this.plot_height, this.y_buffer]);
+ };
- Bar_Chart.prototype.sorted_samples = function() {
- var sample_list, sorted;
- sample_list = _.zip(this.sample_names, this.sample_vals, this.sample_attr_vals);
- sorted = _.sortBy(sample_list, (function(_this) {
- return function(sample) {
- return sample[1];
- };
- })(this));
- console.log("sorted:", sorted);
- return sorted;
- };
+ Bar_Chart.prototype.create_graph = function() {
+ this.add_x_axis();
+ this.add_y_axis();
+ return this.add_bars();
+ };
- Bar_Chart.prototype.add_legend = function(attribute, distinct_vals) {
- var legend, legend_rect, legend_text;
- legend = this.svg.append("g").attr("class", "legend").attr("height", 100).attr("width", 100).attr('transform', 'translate(-20,50)');
- legend_rect = legend.selectAll('rect').data(distinct_vals).enter().append("rect").attr("x", this.plot_width - 65).attr("width", 10).attr("height", 10).attr("y", (function(_this) {
- return function(d, i) {
- return i * 20;
- };
- })(this)).style("fill", (function(_this) {
- return function(d) {
- console.log("TEST:", _this.attr_color_dict[attribute][d]);
- return _this.attr_color_dict[attribute][d];
- };
- })(this));
- return legend_text = legend.selectAll('text').data(distinct_vals).enter().append("text").attr("x", this.plot_width - 52).attr("y", (function(_this) {
- return function(d, i) {
- return i * 20 + 9;
- };
- })(this)).text((function(_this) {
- return function(d) {
- return d;
- };
- })(this));
- };
+ Bar_Chart.prototype.add_x_axis = function(scale) {
+ var xAxis;
+ xAxis = d3.svg.axis().scale(this.x_scale).orient("bottom");
+ return this.svg.append("g").attr("class", "x axis").attr("transform", "translate(0," + this.plot_height + ")").call(xAxis).selectAll("text").style("text-anchor", "end").style("font-size", "12px").attr("dx", "-.8em").attr("dy", "-.3em").attr("transform", (function(_this) {
+ return function(d) {
+ return "rotate(-90)";
+ };
+ })(this));
+ };
- Bar_Chart.prototype.open_trait_selection = function() {
- return $('#collections_holder').load('/collections/list?color_by_trait #collections_list', (function(_this) {
- return function() {
- $.colorbox({
- inline: true,
- href: "#collections_holder"
- });
- return $('a.collection_name').attr('onClick', 'return false');
- };
- })(this));
- };
+ Bar_Chart.prototype.add_y_axis = function() {
+ var yAxis;
+ yAxis = d3.svg.axis().scale(this.y_scale).orient("left").ticks(5);
+ return this.svg.append("g").attr("class", "y axis").call(yAxis).append("text").attr("transform", "rotate(-90)").attr("y", 6).attr("dy", ".71em").style("text-anchor", "end");
+ };
- Bar_Chart.prototype.color_by_trait = function(trait_sample_data) {
- var distinct_values, trimmed_samples;
- console.log("BXD1:", trait_sample_data["BXD1"]);
- console.log("trait_sample_data:", trait_sample_data);
- trimmed_samples = this.trim_values(trait_sample_data);
- distinct_values = {};
- distinct_values["collection_trait"] = this.get_distinct_values(trimmed_samples);
- this.get_trait_color_dict(trimmed_samples, distinct_values);
- console.log("TRAIT_COLOR_DICT:", this.trait_color_dict);
- console.log("SAMPLES:", this.samples);
- if (this.sort_by = "value") {
- this.svg.selectAll(".bar").data(this.samples).transition().duration(1000).style("fill", (function(_this) {
+ Bar_Chart.prototype.add_bars = function() {
+ return this.svg.selectAll(".bar").data(this.samples).enter().append("rect").style("fill", "steelblue").attr("class", "bar").attr("x", (function(_this) {
return function(d) {
- console.log("this color:", _this.trait_color_dict[d[0]]);
- return _this.trait_color_dict[d[0]];
+ return _this.x_scale(d[0]);
};
- })(this)).select("title").text((function(_this) {
+ })(this)).attr("width", this.x_scale.rangeBand()).attr("y", (function(_this) {
+ return function(d) {
+ return _this.y_scale(d[1]);
+ };
+ })(this)).attr("height", (function(_this) {
+ return function(d) {
+ return _this.plot_height - _this.y_scale(d[1]);
+ };
+ })(this)).append("svg:title").text((function(_this) {
return function(d) {
return d[1];
};
})(this));
- return this.draw_legend();
- } else {
- this.svg.selectAll(".bar").data(this.sorted_samples()).transition().duration(1000).style("fill", (function(_this) {
+ };
+
+ Bar_Chart.prototype.sorted_samples = function() {
+ var sample_list, sorted;
+ sample_list = _.zip(this.sample_names, this.sample_vals, this.sample_attr_vals);
+ sorted = _.sortBy(sample_list, (function(_this) {
+ return function(sample) {
+ return sample[1];
+ };
+ })(this));
+ console.log("sorted:", sorted);
+ return sorted;
+ };
+
+ Bar_Chart.prototype.add_legend = function(attribute, distinct_vals) {
+ var legend, legend_rect, legend_text;
+ legend = this.svg.append("g").attr("class", "legend").attr("height", 100).attr("width", 100).attr('transform', 'translate(-20,50)');
+ legend_rect = legend.selectAll('rect').data(distinct_vals).enter().append("rect").attr("x", this.plot_width - 65).attr("width", 10).attr("height", 10).attr("y", (function(_this) {
+ return function(d, i) {
+ return i * 20;
+ };
+ })(this)).style("fill", (function(_this) {
return function(d) {
- console.log("this color:", _this.trait_color_dict[d[0]]);
- return _this.trait_color_dict[d[0]];
+ console.log("TEST:", _this.attr_color_dict[attribute][d]);
+ return _this.attr_color_dict[attribute][d];
};
- })(this)).select("title").text((function(_this) {
+ })(this));
+ return legend_text = legend.selectAll('text').data(distinct_vals).enter().append("text").attr("x", this.plot_width - 52).attr("y", (function(_this) {
+ return function(d, i) {
+ return i * 20 + 9;
+ };
+ })(this)).text((function(_this) {
return function(d) {
- return d[1];
+ return d;
};
})(this));
- return this.draw_legend();
- }
- };
+ };
- Bar_Chart.prototype.trim_values = function(trait_sample_data) {
- var sample, trimmed_samples, _i, _len, _ref;
- trimmed_samples = {};
- _ref = this.sample_names;
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- sample = _ref[_i];
- if (sample in trait_sample_data) {
- trimmed_samples[sample] = trait_sample_data[sample];
+ Bar_Chart.prototype.open_trait_selection = function() {
+ return $('#collections_holder').load('/collections/list?color_by_trait #collections_list', (function(_this) {
+ return function() {
+ $.colorbox({
+ inline: true,
+ href: "#collections_holder"
+ });
+ return $('a.collection_name').attr('onClick', 'return false');
+ };
+ })(this));
+ };
+
+ Bar_Chart.prototype.color_by_trait = function(trait_sample_data) {
+ var distinct_values, trimmed_samples;
+ console.log("BXD1:", trait_sample_data["BXD1"]);
+ console.log("trait_sample_data:", trait_sample_data);
+ trimmed_samples = this.trim_values(trait_sample_data);
+ distinct_values = {};
+ distinct_values["collection_trait"] = this.get_distinct_values(trimmed_samples);
+ this.get_trait_color_dict(trimmed_samples, distinct_values);
+ console.log("TRAIT_COLOR_DICT:", this.trait_color_dict);
+ console.log("SAMPLES:", this.samples);
+ if (this.sort_by = "value") {
+ this.svg.selectAll(".bar").data(this.samples).transition().duration(1000).style("fill", (function(_this) {
+ return function(d) {
+ console.log("this color:", _this.trait_color_dict[d[0]]);
+ return _this.trait_color_dict[d[0]];
+ };
+ })(this)).select("title").text((function(_this) {
+ return function(d) {
+ return d[1];
+ };
+ })(this));
+ return this.draw_legend();
+ } else {
+ this.svg.selectAll(".bar").data(this.sorted_samples()).transition().duration(1000).style("fill", (function(_this) {
+ return function(d) {
+ console.log("this color:", _this.trait_color_dict[d[0]]);
+ return _this.trait_color_dict[d[0]];
+ };
+ })(this)).select("title").text((function(_this) {
+ return function(d) {
+ return d[1];
+ };
+ })(this));
+ return this.draw_legend();
}
- }
- console.log("trimmed_samples:", trimmed_samples);
- return trimmed_samples;
- };
+ };
+
+ Bar_Chart.prototype.trim_values = function(trait_sample_data) {
+ var j, len, ref, sample, trimmed_samples;
+ trimmed_samples = {};
+ ref = this.sample_names;
+ for (j = 0, len = ref.length; j < len; j++) {
+ sample = ref[j];
+ if (sample in trait_sample_data) {
+ trimmed_samples[sample] = trait_sample_data[sample];
+ }
+ }
+ console.log("trimmed_samples:", trimmed_samples);
+ return trimmed_samples;
+ };
+
+ Bar_Chart.prototype.get_distinct_values = function(samples) {
+ var distinct_values;
+ distinct_values = _.uniq(_.values(samples));
+ console.log("distinct_values:", distinct_values);
+ return distinct_values;
+ };
- Bar_Chart.prototype.get_distinct_values = function(samples) {
- var distinct_values;
- distinct_values = _.uniq(_.values(samples));
- console.log("distinct_values:", distinct_values);
- return distinct_values;
- };
+ return Bar_Chart;
- return Bar_Chart;
+ })();
-})();
+ root.Bar_Chart = Bar_Chart;
-root.Bar_Chart = Bar_Chart;
+}).call(this);
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.coffee b/wqflask/wqflask/static/new/javascript/show_trait.coffee
index 1d3123ba..4bfc8690 100755
--- a/wqflask/wqflask/static/new/javascript/show_trait.coffee
+++ b/wqflask/wqflask/static/new/javascript/show_trait.coffee
@@ -64,36 +64,6 @@ $ ->
sample_lists = js_data.sample_lists
sample_group_types = js_data.sample_group_types
- #if $("#update_bar_chart").length
- # $("#update_bar_chart.btn-group").button()
- root.bar_chart = new Bar_Chart(sample_lists[0])
- root.histogram = new Histogram(sample_lists[0])
- new Box_Plot(sample_lists[0])
-
- $('.bar_chart_samples_group').change ->
- $('#bar_chart').remove()
- $('#bar_chart_container').append('<div id="bar_chart"></div>')
- group = $(this).val()
- if group == "samples_primary"
- root.bar_chart = new Bar_Chart(sample_lists[0])
- else if group == "samples_other"
- root.bar_chart = new Bar_Chart(sample_lists[1])
- else if group == "samples_all"
- all_samples = sample_lists[0].concat sample_lists[1]
- root.bar_chart = new Bar_Chart(all_samples)
-
- $('.box_plot_samples_group').change ->
- $('#box_plot').remove()
- $('#box_plot_container').append('<div id="box_plot"></div>')
- group = $(this).val()
- if group == "samples_primary"
- new Box_Plot(sample_lists[0])
- else if group == "samples_other"
- new Box_Plot(sample_lists[1])
- else if group == "samples_all"
- all_samples = sample_lists[0].concat sample_lists[1]
- new Box_Plot(all_samples)
-
d3.select("#select_compare_trait").on("click", =>
$('.scatter-matrix-container').remove()
open_trait_selection()
@@ -158,6 +128,11 @@ $ ->
console.log("Calling change_stats_value")
change_stats_value(sample_sets, category, row.vn, row.digits)
+ redraw_histogram = ->
+ root.histogram.redraw(_.values(root.selected_samples[root.histogram_group]))
+
+ redraw_bar_chart = ->
+ root.bar_chart.redraw(root.selected_samples[root.bar_chart_group])
make_table = ->
header = "<thead><tr><th>&nbsp;</th>"
@@ -213,6 +188,11 @@ $ ->
samples_other: new Stats([])
samples_all: new Stats([])
+ root.selected_samples = # maps: sample name -> value
+ samples_primary: {}
+ samples_other: {}
+ samples_all: {}
+
console.log("at beginning:", sample_sets)
tables = ['samples_primary', 'samples_other']
@@ -232,15 +212,22 @@ $ ->
real_value = parseFloat(real_value)
sample_sets[table].add_value(real_value)
+ root.selected_samples[table][name] = real_value
console.log("checking name of:", name)
if not (name of already_seen)
console.log("haven't seen")
sample_sets['samples_all'].add_value(real_value)
+ root.selected_samples['samples_all'][name] = real_value
already_seen[name] = true
console.log("towards end:", sample_sets)
- root.histogram.redraw(sample_sets['samples_primary'].the_values)
update_stat_values(sample_sets)
+ console.log("redrawing histogram")
+ redraw_histogram()
+
+ console.log("redrawing bar chart")
+ redraw_bar_chart()
+
show_hide_outliers = ->
console.log("FOOBAR in beginning of show_hide_outliers")
label = $('#show_hide_outliers').val()
@@ -427,11 +414,36 @@ $ ->
console.log("after registering block_outliers")
_.mixin(_.str.exports()); # Add string fuctions directly to underscore
- $('#edit_sample_lists').change(edit_data_change)
- console.log("loaded")
- #console.log("basic_table is:", basic_table)
- # Add back following two lines later
+
+ root.histogram_group = 'samples_primary'
+ root.histogram = new Histogram(sample_lists[0])
+ $('.histogram_samples_group').change ->
+ root.histogram_group = $(this).val()
+ redraw_histogram()
+
+ root.bar_chart_group = 'samples_primary'
+ root.bar_chart = new Bar_Chart(sample_lists[0])
+ $('.bar_chart_samples_group').change ->
+ root.bar_chart_group = $(this).val()
+ redraw_bar_chart()
+
+ new Box_Plot(sample_lists[0])
+
+ $('.box_plot_samples_group').change ->
+ $('#box_plot').remove()
+ $('#box_plot_container').append('<div id="box_plot"></div>')
+ group = $(this).val()
+ if group == "samples_primary"
+ new Box_Plot(sample_lists[0])
+ else if group == "samples_other"
+ new Box_Plot(sample_lists[1])
+ else if group == "samples_all"
+ all_samples = sample_lists[0].concat sample_lists[1]
+ new Box_Plot(all_samples)
+
make_table()
edit_data_change() # Set the values at the beginning
+
+ $('#edit_sample_lists').change(edit_data_change)
#$("#all-mean").html('foobar8')
console.log("end")
diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js
index 9323862a..26c0a275 100755
--- a/wqflask/wqflask/static/new/javascript/show_trait.js
+++ b/wqflask/wqflask/static/new/javascript/show_trait.js
@@ -56,40 +56,9 @@
];
$(function() {
- var block_by_attribute_value, block_by_index, block_outliers, change_stats_value, create_value_dropdown, edit_data_change, export_sample_table_data, get_sample_table_data, hide_no_value, hide_tabs, make_table, on_corr_method_change, open_trait_selection, populate_sample_attributes_values_dropdown, process_id, reset_samples_table, sample_group_types, sample_lists, show_hide_outliers, stats_mdp_change, update_stat_values;
+ var block_by_attribute_value, block_by_index, block_outliers, change_stats_value, create_value_dropdown, edit_data_change, export_sample_table_data, get_sample_table_data, hide_no_value, hide_tabs, make_table, on_corr_method_change, open_trait_selection, populate_sample_attributes_values_dropdown, process_id, redraw_bar_chart, redraw_histogram, reset_samples_table, sample_group_types, sample_lists, show_hide_outliers, stats_mdp_change, update_stat_values;
sample_lists = js_data.sample_lists;
sample_group_types = js_data.sample_group_types;
- root.bar_chart = new Bar_Chart(sample_lists[0]);
- root.histogram = new Histogram(sample_lists[0]);
- new Box_Plot(sample_lists[0]);
- $('.bar_chart_samples_group').change(function() {
- var all_samples, group;
- $('#bar_chart').remove();
- $('#bar_chart_container').append('<div id="bar_chart"></div>');
- group = $(this).val();
- if (group === "samples_primary") {
- return root.bar_chart = new Bar_Chart(sample_lists[0]);
- } else if (group === "samples_other") {
- return root.bar_chart = new Bar_Chart(sample_lists[1]);
- } else if (group === "samples_all") {
- all_samples = sample_lists[0].concat(sample_lists[1]);
- return root.bar_chart = new Bar_Chart(all_samples);
- }
- });
- $('.box_plot_samples_group').change(function() {
- var all_samples, group;
- $('#box_plot').remove();
- $('#box_plot_container').append('<div id="box_plot"></div>');
- group = $(this).val();
- if (group === "samples_primary") {
- return new Box_Plot(sample_lists[0]);
- } else if (group === "samples_other") {
- return new Box_Plot(sample_lists[1]);
- } else if (group === "samples_all") {
- all_samples = sample_lists[0].concat(sample_lists[1]);
- return new Box_Plot(all_samples);
- }
- });
d3.select("#select_compare_trait").on("click", (function(_this) {
return function() {
$('.scatter-matrix-container').remove();
@@ -169,6 +138,12 @@
}
return results;
};
+ redraw_histogram = function() {
+ return root.histogram.redraw(_.values(root.selected_samples[root.histogram_group]));
+ };
+ redraw_bar_chart = function() {
+ return root.bar_chart.redraw(root.selected_samples[root.bar_chart_group]);
+ };
make_table = function() {
var header, i, key, len, ref, ref1, row, row_line, table, the_id, the_rows, value;
header = "<thead><tr><th>&nbsp;</th>";
@@ -238,6 +213,11 @@
samples_other: new Stats([]),
samples_all: new Stats([])
};
+ root.selected_samples = {
+ samples_primary: {},
+ samples_other: {},
+ samples_all: {}
+ };
console.log("at beginning:", sample_sets);
tables = ['samples_primary', 'samples_other'];
for (i = 0, len = tables.length; i < len; i++) {
@@ -255,18 +235,23 @@
console.log("in the iffy if");
real_value = parseFloat(real_value);
sample_sets[table].add_value(real_value);
+ root.selected_samples[table][name] = real_value;
console.log("checking name of:", name);
if (!(name in already_seen)) {
console.log("haven't seen");
sample_sets['samples_all'].add_value(real_value);
+ root.selected_samples['samples_all'][name] = real_value;
already_seen[name] = true;
}
}
}
}
console.log("towards end:", sample_sets);
- root.histogram.redraw(sample_sets['samples_primary'].the_values);
- return update_stat_values(sample_sets);
+ update_stat_values(sample_sets);
+ console.log("redrawing histogram");
+ redraw_histogram();
+ console.log("redrawing bar chart");
+ return redraw_bar_chart();
};
show_hide_outliers = function() {
var label;
@@ -460,10 +445,36 @@
$('#block_outliers').click(block_outliers);
console.log("after registering block_outliers");
_.mixin(_.str.exports());
- $('#edit_sample_lists').change(edit_data_change);
- console.log("loaded");
+ root.histogram_group = 'samples_primary';
+ root.histogram = new Histogram(sample_lists[0]);
+ $('.histogram_samples_group').change(function() {
+ root.histogram_group = $(this).val();
+ return redraw_histogram();
+ });
+ root.bar_chart_group = 'samples_primary';
+ root.bar_chart = new Bar_Chart(sample_lists[0]);
+ $('.bar_chart_samples_group').change(function() {
+ root.bar_chart_group = $(this).val();
+ return redraw_bar_chart();
+ });
+ new Box_Plot(sample_lists[0]);
+ $('.box_plot_samples_group').change(function() {
+ var all_samples, group;
+ $('#box_plot').remove();
+ $('#box_plot_container').append('<div id="box_plot"></div>');
+ group = $(this).val();
+ if (group === "samples_primary") {
+ return new Box_Plot(sample_lists[0]);
+ } else if (group === "samples_other") {
+ return new Box_Plot(sample_lists[1]);
+ } else if (group === "samples_all") {
+ all_samples = sample_lists[0].concat(sample_lists[1]);
+ return new Box_Plot(all_samples);
+ }
+ });
make_table();
edit_data_change();
+ $('#edit_sample_lists').change(edit_data_change);
return console.log("end");
});