From 33b10be4e506083e906ac1ef102db3a132aeb4e2 Mon Sep 17 00:00:00 2001 From: Zachary Sloan Date: Thu, 5 Dec 2013 23:56:48 +0000 Subject: Now trims selected trait's values by the samples of the primary trait and gets their distinct values Created function that creates a dictionary of distinct values and their corresponding colors --- .../wqflask/static/new/javascript/bar_chart.coffee | 41 ++++++++++++++++-- wqflask/wqflask/static/new/javascript/bar_chart.js | 48 ++++++++++++++++++++-- .../javascript/get_traits_from_collection.coffee | 4 +- .../new/javascript/get_traits_from_collection.js | 2 +- .../static/new/javascript/show_trait.coffee | 5 ++- .../wqflask/static/new/javascript/show_trait.js | 6 ++- 6 files changed, 92 insertions(+), 14 deletions(-) (limited to 'wqflask') diff --git a/wqflask/wqflask/static/new/javascript/bar_chart.coffee b/wqflask/wqflask/static/new/javascript/bar_chart.coffee index d18cadd2..05955188 100644 --- a/wqflask/wqflask/static/new/javascript/bar_chart.coffee +++ b/wqflask/wqflask/static/new/javascript/bar_chart.coffee @@ -123,7 +123,7 @@ class Bar_Chart ) d3.select("#color_by_trait").on("click", => - @color_by_trait() + @open_trait_selection() ) @@ -138,6 +138,8 @@ class Bar_Chart this_color_dict[value] = color(i) else console.log("distinct_values:", distinct_vals) + #Check whether all values are numbers, and if they are get a corresponding + #color gradient if _.every(distinct_vals, (d) => if isNaN(d) return false @@ -147,13 +149,24 @@ class Bar_Chart color_range = d3.scale.linear() .domain([d3.min(distinct_vals), d3.max(distinct_vals)]) - .range([0,4]) + .range([0,255]) for value, i in distinct_vals console.log("color_range(value):", color_range(parseInt(value))) - this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value))) + this_color_dict[value] = d3.rgb(color_range(parseInt(value)),0, 0) + #this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value))) #this_color_dict[value] = "rgb(0, 0, " + color_range(parseInt(value)) + ")" @attr_color_dict[key] = this_color_dict + convert_into_colors: (values) -> + color_range = d3.scale.linear() + .domain([d3.min(values), + d3.max(values)]) + .range([0,255]) + for value, i in values + console.log("color_range(value):", color_range(parseInt(value))) + this_color_dict[value] = d3.rgb(color_range(parseInt(value)),0, 0) + #this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value))) + get_samples: () -> @sample_names = (sample.name for sample in @sample_list when sample.value != null) @sample_vals = (sample.value for sample in @sample_list when sample.value != null) @@ -305,7 +318,7 @@ class Bar_Chart return d ) - color_by_trait: () -> + open_trait_selection: () -> $('#collections_holder').load('/collections/list?color_by_trait #collections_list', => $.colorbox( inline: true @@ -318,6 +331,26 @@ class Bar_Chart # console.log("contents:", $(element).contents()) # $(element).contents().unwrap() ) + + color_by_trait: (trait_sample_data) -> + console.log("BXD1:", trait_sample_data["BXD1"]) + console.log("trait_sample_data:", trait_sample_data) + trimmed_samples = @trim_values(trait_sample_data) + @get_distinct_values(trimmed_samples) + + trim_values: (trait_sample_data) -> + trimmed_samples = {} + for sample in @sample_names + if sample of trait_sample_data + trimmed_samples[sample] = trait_sample_data[sample] + console.log("trimmed_samples:", trimmed_samples) + return trimmed_samples + get_distinct_values: (samples) -> + distinct_values = _.uniq(_.values(samples)) + #distinct_values = [] + #for sample in samples + # if samples[sample] in distinct_values + console.log("distinct_values:", distinct_values) root.Bar_Chart = Bar_Chart \ No newline at end of file diff --git a/wqflask/wqflask/static/new/javascript/bar_chart.js b/wqflask/wqflask/static/new/javascript/bar_chart.js index e4279d41..05625dc9 100644 --- a/wqflask/wqflask/static/new/javascript/bar_chart.js +++ b/wqflask/wqflask/static/new/javascript/bar_chart.js @@ -126,7 +126,7 @@ } }); d3.select("#color_by_trait").on("click", function() { - return _this.color_by_trait(); + return _this.open_trait_selection(); }); } @@ -156,11 +156,11 @@ return true; } })) { - color_range = d3.scale.linear().domain([d3.min(distinct_vals), d3.max(distinct_vals)]).range([0, 4]); + 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) { value = distinct_vals[i]; console.log("color_range(value):", color_range(parseInt(value))); - this_color_dict[value] = d3.rgb("lightblue").darker(color_range(parseInt(value))); + this_color_dict[value] = d3.rgb(color_range(parseInt(value)), 0, 0); } } } @@ -169,6 +169,18 @@ 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.get_samples = function() { var attr_vals, attribute, key, sample, _i, _j, _len, _len1, _ref, _ref1; this.sample_names = (function() { @@ -320,7 +332,7 @@ }); }; - Bar_Chart.prototype.color_by_trait = function() { + Bar_Chart.prototype.open_trait_selection = function() { var _this = this; return $('#collections_holder').load('/collections/list?color_by_trait #collections_list', function() { $.colorbox({ @@ -331,6 +343,34 @@ }); }; + Bar_Chart.prototype.color_by_trait = function(trait_sample_data) { + var 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); + return this.get_distinct_values(trimmed_samples); + }; + + 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]; + } + } + 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)); + return console.log("distinct_values:", distinct_values); + }; + return Bar_Chart; })(); diff --git a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee index 23499ac5..43a518b3 100644 --- a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee +++ b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.coffee @@ -32,9 +32,9 @@ trait_click = () -> ) color_by_trait = (trait_sample_data, textStatus, jqXHR) -> - root.trait_sample_data = trait_sample_data + #trait_sample_data = trait_sample_data #console.log('in color_by_trait:', trait_sample_data) - + root.bar_chart.color_by_trait(trait_sample_data) process_traits = (trait_data, textStatus, jqXHR) -> console.log('in process_traits with trait_data:', trait_data) diff --git a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js index b4c2c200..137a6ce8 100644 --- a/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js +++ b/wqflask/wqflask/static/new/javascript/get_traits_from_collection.js @@ -39,7 +39,7 @@ }; color_by_trait = function(trait_sample_data, textStatus, jqXHR) { - return root.trait_sample_data = trait_sample_data; + return root.bar_chart.color_by_trait(trait_sample_data); }; process_traits = function(trait_data, textStatus, jqXHR) { diff --git a/wqflask/wqflask/static/new/javascript/show_trait.coffee b/wqflask/wqflask/static/new/javascript/show_trait.coffee index 7d23345f..82b85436 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.coffee +++ b/wqflask/wqflask/static/new/javascript/show_trait.coffee @@ -1,3 +1,5 @@ +root = exports ? this + console.log("start_b") # this is our isNumber, do not confuse with the underscore.js one @@ -62,7 +64,8 @@ $ -> sample_lists = js_data.sample_lists sample_group_types = js_data.sample_group_types - new Bar_Chart(sample_lists[0]) + root.bar_chart = new Bar_Chart(sample_lists[0]) + new Box_Plot(sample_lists[0]) diff --git a/wqflask/wqflask/static/new/javascript/show_trait.js b/wqflask/wqflask/static/new/javascript/show_trait.js index 718e365a..320f705b 100644 --- a/wqflask/wqflask/static/new/javascript/show_trait.js +++ b/wqflask/wqflask/static/new/javascript/show_trait.js @@ -1,9 +1,11 @@ // Generated by CoffeeScript 1.6.1 (function() { - var Stat_Table_Rows, is_number, + var Stat_Table_Rows, is_number, root, __hasProp = {}.hasOwnProperty, __slice = [].slice; + root = typeof exports !== "undefined" && exports !== null ? exports : this; + console.log("start_b"); is_number = function(o) { @@ -59,7 +61,7 @@ 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, populate_sample_attributes_values_dropdown, process_id, 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; - new Bar_Chart(sample_lists[0]); + root.bar_chart = new Bar_Chart(sample_lists[0]); new Box_Plot(sample_lists[0]); $('.bar_chart_samples_group').change(function() { var all_samples, group; -- cgit v1.2.3