diff --git a/clustergrammer.js b/clustergrammer.js index bae34fe0..6b3027ca 100644 --- a/clustergrammer.js +++ b/clustergrammer.js @@ -16392,7 +16392,7 @@ var Clustergrammer = var calc_cat_cluster_breakdown = __webpack_require__(277); var underscore = __webpack_require__(3); - var cat_breakdown_bar_groups = __webpack_require__(293); + var cat_breakdown_bars = __webpack_require__(296); var cat_breakdown_values = __webpack_require__(295); module.exports = function make_cat_breakdown_graph(params, inst_rc, inst_data, dendro_info, selector, tooltip = false) { @@ -16416,15 +16416,10 @@ var Clustergrammer = var cluster_info_container = d3.select(selector + ' .cluster_info_container'); // loop through cat_breakdown data - var super_string = ': '; - var paragraph_string = '
'; var width = 370; - var bar_offset = 23; - var bar_width = params.viz.cat_bar_width; - var bar_height = params.viz.cat_bar_height; - var max_string_length = 25; var title_height = 27; var shift_tooltip_left = 177; + var bar_offset = 23; // these are the indexes where the number-of-nodes and the number of downsampled // nodes are stored @@ -16476,120 +16471,43 @@ var Clustergrammer = var main_dendro_svg = cluster_info_container.append('div').style('margin-top', '5px').classed('cat_graph', true).append('svg').style('height', svg_height + 'px').style('width', width + 'px'); + cluster_info_container.style('margin-bottom', '5px'); + // make background main_dendro_svg.append('rect').classed('cat_background', true).attr('height', svg_height + 'px').attr('width', width + 'px').attr('fill', 'white').attr('opacity', 1); - // the total amout to shift down the next category - var shift_down = title_height; - // limit the category-types cat_breakdown = cat_breakdown.slice(0, max_cats); - underscore.each(cat_breakdown, function (cat_data) { - - var max_bar_value = cat_data.bar_data[0][bars_index]; - - // offset the count column based on how large the counts are - var digit_offset_scale = d3.scale.linear().domain([0, 100000]).range([20, 30]); + // shift the position of the numbers based on the size of the number + // offset the count column based on how large the counts are + var digit_offset_scale = d3.scale.linear().domain([0, 100000]).range([20, 30]); - // only keep the top max_bars categories - cat_data.bar_data = cat_data.bar_data.slice(0, max_bars); - - cluster_info_container.style('margin-bottom', '5px'); - - var cat_graph_group = main_dendro_svg.append('g').classed('cat_graph_group', true).attr('transform', 'translate(10, ' + shift_down + ')'); - - // shift down based on number of bars - shift_down = shift_down + title_height * (cat_data.bar_data.length + 1); + // the total amout to shift down the next category + var shift_down = title_height; - var inst_title = cat_data.type_name; - // ensure that title is not too long - if (inst_title.length >= max_string_length) { - inst_title = inst_title.slice(0, max_string_length) + '..'; - } + underscore.each(cat_breakdown, function (cat_data) { - // make title - cat_graph_group.append('text').classed('cat_graph_title', true).text(inst_title).style('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif').style('font-weight', 800); + var max_bar_value = cat_data.bar_data[0][bars_index]; - // shift the position of the numbers based on the size of the number var count_offset = digit_offset_scale(max_bar_value); - // Count Title - cat_graph_group.append('text').text('Count').attr('transform', function () { - var inst_x = bar_width + count_offset; - var inst_translate = 'translate(' + inst_x + ', 0)'; - return inst_translate; - }); - - // Percentage Title - cat_graph_group.append('text').text('Pct').attr('transform', function () { - var inst_x = bar_width + count_offset + 60; - var inst_translate = 'translate(' + inst_x + ', 0)'; - return inst_translate; - }); - - // Percentage Title - cat_graph_group.append('text').text('P-val').attr('transform', function () { - var inst_x = bar_width + count_offset + 115; - var inst_translate = 'translate(' + inst_x + ', 0)'; - return inst_translate; - }); - - // Count Downsampled Title - if (is_downsampled) { - cat_graph_group.append('text').text('Clusters').attr('transform', function () { - var inst_x = bar_width + offset_ds_count; - var inst_translate = 'translate(' + inst_x + ', 0)'; - return inst_translate; - }); - } - - var line_y = 4; - cat_graph_group.append('line').attr('x1', 0).attr('x2', bar_width).attr('y1', line_y).attr('y2', line_y).attr('stroke', 'blue').attr('stroke-width', 1).attr('opacity', 1.0); + var cat_graph_group = main_dendro_svg.append('g').classed('cat_graph_group', true).attr('transform', 'translate(10, ' + shift_down + ')'); var cat_bar_container = cat_graph_group.append('g').classed('cat_bar_container', true).attr('transform', 'translate(0, 10)'); - cat_breakdown_bar_groups(); - // make bar groups (hold bar and text) var cat_bar_groups = cat_bar_container.selectAll('g').data(cat_data.bar_data).enter().append('g').attr('transform', function (d, i) { var inst_y = i * bar_offset; return 'translate(0,' + inst_y + ')'; }); - // bar length is max when all nodes in cluster are of - // a single cat - var bar_scale = d3.scale.linear().domain([0, max_bar_value]).range([0, bar_width]); - - // make bars - cat_bar_groups.append('rect').attr('height', bar_height + 'px').attr('width', function (d) { - var inst_width = bar_scale(d[bars_index]); - return inst_width + 'px'; - }).attr('fill', function (d) { - // cat color is stored in the third element - return d[3]; - }).attr('opacity', params.viz.cat_colors.opacity).attr('stroke', 'grey').attr('stroke-width', '0.5px'); - - // make bar labels - cat_bar_groups.append('text').classed('bar_labels', true).text(function (d) { - var inst_text = d[1]; - if (inst_text.indexOf(super_string) > 0) { - inst_text = inst_text.split(super_string)[1]; - } - if (inst_text.indexOf(paragraph_string) > 0) { - // required for Enrichr category names (needs improvements) - inst_text = inst_text.split(paragraph_string)[0]; - } - // ensure that bar name is not too long - if (inst_text.length >= max_string_length) { - inst_text = inst_text.slice(0, max_string_length) + '..'; - } - return inst_text; - }).attr('transform', function () { - return 'translate(5, ' + 0.75 * bar_height + ')'; - }).attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif').attr('font-weight', 400).attr('text-anchor', 'right'); + cat_breakdown_bars(params, cat_data, cat_graph_group, title_height, bars_index, max_bars, cat_bar_groups); - cat_breakdown_values(params, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total); + cat_breakdown_values(params, cat_graph_group, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total); + + // shift down based on number of bars + shift_down = shift_down + title_height * (cat_data.bar_data.length + 1); }); // reposition tooltip @@ -30008,23 +29926,48 @@ var Clustergrammer = }; /***/ }), -/* 293 */ -/***/ (function(module, exports) { - - module.exports = function cat_breakdown_bar_groups() {}; - -/***/ }), +/* 293 */, /* 294 */, /* 295 */ /***/ (function(module, exports) { - module.exports = function cat_breakdown_values(params, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total) { + module.exports = function cat_breakdown_values(params, cat_graph_group, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total) { var bar_width = params.viz.cat_bar_width; var bar_height = params.viz.cat_bar_height; var offset_ds_count = 150; var binom_pval_index = 6; + // Count Title + cat_graph_group.append('text').text('Count').attr('transform', function () { + var inst_x = bar_width + count_offset; + var inst_translate = 'translate(' + inst_x + ', 0)'; + return inst_translate; + }); + + // Percentage Title + cat_graph_group.append('text').text('Pct').attr('transform', function () { + var inst_x = bar_width + count_offset + 60; + var inst_translate = 'translate(' + inst_x + ', 0)'; + return inst_translate; + }); + + // Percentage Title + cat_graph_group.append('text').text('P-val').attr('transform', function () { + var inst_x = bar_width + count_offset + 115; + var inst_translate = 'translate(' + inst_x + ', 0)'; + return inst_translate; + }); + + // Count Downsampled Title + if (is_downsampled) { + cat_graph_group.append('text').text('Clusters').attr('transform', function () { + var inst_x = bar_width + offset_ds_count; + var inst_translate = 'translate(' + inst_x + ', 0)'; + return inst_translate; + }); + } + // Counts ///////////////////////////// var shift_count_num = 35; @@ -30086,6 +30029,70 @@ var Clustergrammer = } }; +/***/ }), +/* 296 */ +/***/ (function(module, exports) { + + module.exports = function cat_breakdown_bars(params, cat_data, cat_graph_group, title_height, bars_index, max_bars, cat_bar_groups) { + + var paragraph_string = '
'; + var super_string = ': '; + + var bar_width = params.viz.cat_bar_width; + var bar_height = params.viz.cat_bar_height; + + var max_string_length = 25; + + var max_bar_value = cat_data.bar_data[0][bars_index]; + + // only keep the top max_bars categories + cat_data.bar_data = cat_data.bar_data.slice(0, max_bars); + + var inst_title = cat_data.type_name; + // ensure that title is not too long + if (inst_title.length >= max_string_length) { + inst_title = inst_title.slice(0, max_string_length) + '..'; + } + + // make title + cat_graph_group.append('text').classed('cat_graph_title', true).text(inst_title).style('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif').style('font-weight', 800); + + var line_y = 4; + cat_graph_group.append('line').attr('x1', 0).attr('x2', bar_width).attr('y1', line_y).attr('y2', line_y).attr('stroke', 'blue').attr('stroke-width', 1).attr('opacity', 1.0); + + // bar length is max when all nodes in cluster are of + // a single cat + var bar_scale = d3.scale.linear().domain([0, max_bar_value]).range([0, bar_width]); + + // make bars + cat_bar_groups.append('rect').attr('height', bar_height + 'px').attr('width', function (d) { + var inst_width = bar_scale(d[bars_index]); + return inst_width + 'px'; + }).attr('fill', function (d) { + // cat color is stored in the third element + return d[3]; + }).attr('opacity', params.viz.cat_colors.opacity).attr('stroke', 'grey').attr('stroke-width', '0.5px'); + + // make bar labels + cat_bar_groups.append('text').classed('bar_labels', true).text(function (d) { + var inst_text = d[1]; + if (inst_text.indexOf(super_string) > 0) { + inst_text = inst_text.split(super_string)[1]; + } + if (inst_text.indexOf(paragraph_string) > 0) { + // required for Enrichr category names (needs improvements) + inst_text = inst_text.split(paragraph_string)[0]; + } + // ensure that bar name is not too long + if (inst_text.length >= max_string_length) { + inst_text = inst_text.slice(0, max_string_length) + '..'; + } + return inst_text; + }).attr('transform', function () { + return 'translate(5, ' + 0.75 * bar_height + ')'; + }).attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif').attr('font-weight', 400).attr('text-anchor', 'right'); + }; + /***/ }) /******/ ]); //# sourceMappingURL=clustergrammer.js.map \ No newline at end of file diff --git a/src/categories/cat_breakdown_bar_groups.js b/src/categories/cat_breakdown_bar_groups.js deleted file mode 100644 index 1709155c..00000000 --- a/src/categories/cat_breakdown_bar_groups.js +++ /dev/null @@ -1,4 +0,0 @@ -module.exports = function cat_breakdown_bar_groups(){ - - -}; \ No newline at end of file diff --git a/src/categories/cat_breakdown_bars.js b/src/categories/cat_breakdown_bars.js new file mode 100644 index 00000000..56963d4d --- /dev/null +++ b/src/categories/cat_breakdown_bars.js @@ -0,0 +1,92 @@ +module.exports = function cat_breakdown_bars(params, cat_data, cat_graph_group, title_height, bars_index, max_bars, cat_bar_groups){ + + var paragraph_string = '
'; + var super_string = ': '; + + var bar_width = params.viz.cat_bar_width; + var bar_height = params.viz.cat_bar_height; + + var max_string_length = 25; + + var max_bar_value = cat_data.bar_data[0][bars_index]; + + // only keep the top max_bars categories + cat_data.bar_data = cat_data.bar_data.slice(0, max_bars); + + var inst_title = cat_data.type_name; + // ensure that title is not too long + if (inst_title.length >= max_string_length){ + inst_title = inst_title.slice(0, max_string_length) + '..'; + } + + // make title + cat_graph_group + .append('text') + .classed('cat_graph_title', true) + .text(inst_title) + .style('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif') + .style('font-weight', 800); + + + + var line_y = 4; + cat_graph_group + .append('line') + .attr('x1', 0) + .attr('x2', bar_width) + .attr('y1', line_y) + .attr('y2', line_y) + .attr('stroke', 'blue') + .attr('stroke-width', 1) + .attr('opacity', 1.0); + + + // bar length is max when all nodes in cluster are of + // a single cat + var bar_scale = d3.scale.linear() + .domain([0, max_bar_value]) + .range([0, bar_width]); + + // make bars + cat_bar_groups + .append('rect') + .attr('height', bar_height+'px') + .attr('width', function(d){ + var inst_width = bar_scale(d[bars_index]); + return inst_width +'px'; + }) + .attr('fill', function(d){ + // cat color is stored in the third element + return d[3]; + }) + .attr('opacity', params.viz.cat_colors.opacity) + .attr('stroke', 'grey') + .attr('stroke-width', '0.5px'); + + // make bar labels + cat_bar_groups + .append('text') + .classed('bar_labels', true) + .text(function(d){ + var inst_text = d[1]; + if (inst_text.indexOf(super_string) > 0){ + inst_text = inst_text.split(super_string)[1]; + } + if (inst_text.indexOf(paragraph_string) > 0){ + // required for Enrichr category names (needs improvements) + inst_text = inst_text.split(paragraph_string)[0]; + } + // ensure that bar name is not too long + if (inst_text.length >= max_string_length){ + inst_text = inst_text.slice(0,max_string_length) + '..'; + } + return inst_text; + }) + .attr('transform', function(){ + return 'translate(5, ' + 0.75 * bar_height + ')' ; + }) + .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif') + .attr('font-weight', 400) + .attr('text-anchor', 'right'); + +}; \ No newline at end of file diff --git a/src/categories/cat_breakdown_values.js b/src/categories/cat_breakdown_values.js index 76b507ab..828d49d6 100644 --- a/src/categories/cat_breakdown_values.js +++ b/src/categories/cat_breakdown_values.js @@ -1,4 +1,4 @@ -module.exports = function cat_breakdown_values(params, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total){ +module.exports = function cat_breakdown_values(params, cat_graph_group, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total){ var bar_width = params.viz.cat_bar_width; @@ -6,6 +6,49 @@ module.exports = function cat_breakdown_values(params, cat_bar_groups, num_nodes var offset_ds_count = 150; var binom_pval_index = 6; + + // Count Title + cat_graph_group + .append('text') + .text('Count') + .attr('transform', function(){ + var inst_x = bar_width + count_offset; + var inst_translate = 'translate('+ inst_x +', 0)'; + return inst_translate; + }); + + // Percentage Title + cat_graph_group + .append('text') + .text('Pct') + .attr('transform', function(){ + var inst_x = bar_width + count_offset + 60; + var inst_translate = 'translate('+ inst_x +', 0)'; + return inst_translate; + }); + + // Percentage Title + cat_graph_group + .append('text') + .text('P-val') + .attr('transform', function(){ + var inst_x = bar_width + count_offset + 115; + var inst_translate = 'translate('+ inst_x +', 0)'; + return inst_translate; + }); + + // Count Downsampled Title + if (is_downsampled){ + cat_graph_group + .append('text') + .text('Clusters') + .attr('transform', function(){ + var inst_x = bar_width + offset_ds_count ; + var inst_translate = 'translate('+ inst_x +', 0)'; + return inst_translate; + }); + } + // Counts ///////////////////////////// var shift_count_num = 35; diff --git a/src/categories/make_cat_breakdown_graph.js b/src/categories/make_cat_breakdown_graph.js index b0cbc12e..3d4cfc4c 100644 --- a/src/categories/make_cat_breakdown_graph.js +++ b/src/categories/make_cat_breakdown_graph.js @@ -1,6 +1,6 @@ var calc_cat_cluster_breakdown = require('./calc_cat_cluster_breakdown'); var underscore = require('underscore'); -var cat_breakdown_bar_groups = require('./cat_breakdown_bar_groups'); +var cat_breakdown_bars = require('./cat_breakdown_bars'); var cat_breakdown_values = require('./cat_breakdown_values'); module.exports = function make_cat_breakdown_graph(params, inst_rc, inst_data, dendro_info, selector, tooltip=false){ @@ -24,15 +24,10 @@ module.exports = function make_cat_breakdown_graph(params, inst_rc, inst_data, d var cluster_info_container = d3.select( selector + ' .cluster_info_container'); // loop through cat_breakdown data - var super_string = ': '; - var paragraph_string = '
'; var width = 370; - var bar_offset = 23; - var bar_width = params.viz.cat_bar_width; - var bar_height = params.viz.cat_bar_height; - var max_string_length = 25; var title_height = 27; var shift_tooltip_left = 177; + var bar_offset = 23; // these are the indexes where the number-of-nodes and the number of downsampled // nodes are stored @@ -92,6 +87,10 @@ module.exports = function make_cat_breakdown_graph(params, inst_rc, inst_data, d .style('height', svg_height+'px') .style('width', width+'px'); + cluster_info_container + .style('margin-bottom', '5px'); + + // make background main_dendro_svg .append('rect') @@ -101,173 +100,51 @@ module.exports = function make_cat_breakdown_graph(params, inst_rc, inst_data, d .attr('fill', 'white') .attr('opacity', 1); - // the total amout to shift down the next category - var shift_down = title_height; // limit the category-types cat_breakdown = cat_breakdown.slice(0, max_cats); - underscore.each(cat_breakdown, function(cat_data){ + // shift the position of the numbers based on the size of the number + // offset the count column based on how large the counts are + var digit_offset_scale = d3.scale.linear() + .domain([0,100000]).range([20, 30]); - var max_bar_value = cat_data.bar_data[0][bars_index]; + // the total amout to shift down the next category + var shift_down = title_height; - // offset the count column based on how large the counts are - var digit_offset_scale = d3.scale.linear() - .domain([0,100000]).range([20, 30]); + underscore.each(cat_breakdown, function(cat_data){ - // only keep the top max_bars categories - cat_data.bar_data = cat_data.bar_data.slice(0, max_bars); + var max_bar_value = cat_data.bar_data[0][bars_index]; - cluster_info_container - .style('margin-bottom', '5px'); + var count_offset = digit_offset_scale(max_bar_value); var cat_graph_group = main_dendro_svg .append('g') .classed('cat_graph_group', true) .attr('transform', 'translate(10, '+ shift_down + ')'); - // shift down based on number of bars - shift_down = shift_down + title_height * (cat_data.bar_data.length + 1); - - var inst_title = cat_data.type_name; - // ensure that title is not too long - if (inst_title.length >= max_string_length){ - inst_title = inst_title.slice(0, max_string_length) + '..'; - } - - // make title - cat_graph_group - .append('text') - .classed('cat_graph_title', true) - .text(inst_title) - .style('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif') - .style('font-weight', 800); - - // shift the position of the numbers based on the size of the number - var count_offset = digit_offset_scale(max_bar_value); - - // Count Title - cat_graph_group - .append('text') - .text('Count') - .attr('transform', function(){ - var inst_x = bar_width + count_offset; - var inst_translate = 'translate('+ inst_x +', 0)'; - return inst_translate; - }); - - // Percentage Title - cat_graph_group - .append('text') - .text('Pct') - .attr('transform', function(){ - var inst_x = bar_width + count_offset + 60; - var inst_translate = 'translate('+ inst_x +', 0)'; - return inst_translate; - }); - - // Percentage Title - cat_graph_group - .append('text') - .text('P-val') - .attr('transform', function(){ - var inst_x = bar_width + count_offset + 115; - var inst_translate = 'translate('+ inst_x +', 0)'; - return inst_translate; - }); - - // Count Downsampled Title - if (is_downsampled){ - cat_graph_group - .append('text') - .text('Clusters') - .attr('transform', function(){ - var inst_x = bar_width + offset_ds_count ; - var inst_translate = 'translate('+ inst_x +', 0)'; - return inst_translate; + var cat_bar_container = cat_graph_group + .append('g') + .classed('cat_bar_container', true) + .attr('transform', 'translate(0, 10)'); + + // make bar groups (hold bar and text) + var cat_bar_groups = cat_bar_container + .selectAll('g') + .data(cat_data.bar_data) + .enter() + .append('g') + .attr('transform', function(d, i){ + var inst_y = i * bar_offset; + return 'translate(0,'+ inst_y +')'; }); - } - - var line_y = 4; - cat_graph_group - .append('line') - .attr('x1', 0) - .attr('x2', bar_width) - .attr('y1', line_y) - .attr('y2', line_y) - .attr('stroke', 'blue') - .attr('stroke-width', 1) - .attr('opacity', 1.0); - - var cat_bar_container = cat_graph_group - .append('g') - .classed('cat_bar_container', true) - .attr('transform', 'translate(0, 10)'); - - cat_breakdown_bar_groups(); - // make bar groups (hold bar and text) - var cat_bar_groups = cat_bar_container - .selectAll('g') - .data(cat_data.bar_data) - .enter() - .append('g') - .attr('transform', function(d, i){ - var inst_y = i * bar_offset; - return 'translate(0,'+ inst_y +')'; - }); - - // bar length is max when all nodes in cluster are of - // a single cat - var bar_scale = d3.scale.linear() - .domain([0, max_bar_value]) - .range([0, bar_width]); - - // make bars - cat_bar_groups - .append('rect') - .attr('height', bar_height+'px') - .attr('width', function(d){ - var inst_width = bar_scale(d[bars_index]); - return inst_width +'px'; - }) - .attr('fill', function(d){ - // cat color is stored in the third element - return d[3]; - }) - .attr('opacity', params.viz.cat_colors.opacity) - .attr('stroke', 'grey') - .attr('stroke-width', '0.5px'); - - // make bar labels - cat_bar_groups - .append('text') - .classed('bar_labels', true) - .text(function(d){ - var inst_text = d[1]; - if (inst_text.indexOf(super_string) > 0){ - inst_text = inst_text.split(super_string)[1]; - } - if (inst_text.indexOf(paragraph_string) > 0){ - // required for Enrichr category names (needs improvements) - inst_text = inst_text.split(paragraph_string)[0]; - } - // ensure that bar name is not too long - if (inst_text.length >= max_string_length){ - inst_text = inst_text.slice(0,max_string_length) + '..'; - } - return inst_text; - }) - .attr('transform', function(){ - return 'translate(5, ' + 0.75 * bar_height + ')' ; - }) - .attr('font-family', '"Helvetica Neue", Helvetica, Arial, sans-serif') - .attr('font-weight', 400) - .attr('text-anchor', 'right'); + cat_breakdown_bars(params, cat_data, cat_graph_group, title_height, bars_index, max_bars, cat_bar_groups); + cat_breakdown_values(params, cat_graph_group, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total); - cat_breakdown_values(params, cat_bar_groups, num_nodes_index, is_downsampled, count_offset, bars_index, cluster_total); - + // shift down based on number of bars + shift_down = shift_down + title_height * (cat_data.bar_data.length + 1); });