From 9a51526c4838bbdea73862bba9bd8c631786da0f Mon Sep 17 00:00:00 2001 From: Christoph Beger Date: Thu, 5 Nov 2020 11:02:57 +0100 Subject: [PATCH] Show untagged content below disease plot --- app/helpers/human_diseases_helper.rb | 34 ++++++++++++------- .../human_diseases/_overview_plot.html.erb | 18 ++++++---- 2 files changed, 33 insertions(+), 19 deletions(-) diff --git a/app/helpers/human_diseases_helper.rb b/app/helpers/human_diseases_helper.rb index e355dd9f0d..14d0b20e33 100644 --- a/app/helpers/human_diseases_helper.rb +++ b/app/helpers/human_diseases_helper.rb @@ -58,19 +58,27 @@ def get_transitive_related_resources(resource, limit = nil) end def get_human_diseases_plot_data() - Rails.cache.fetch('human_diseases_plot_data', expires_in: 12.hours) do - HumanDisease.all.order(:id).map do |c| - { - id: c.id.to_s, - title: c.title, - parent: c.parents.first ? c.parents.first.id.to_s : '', - projects: c.projects.count, - # assays: c.assays.count, # currently not in use - publications: c.publications.count, - models: c.models.count, - data_files: c.data_files.count, - } - end + Rails.cache.fetch('human_diseases_data', expires_in: 12.hours) do + { + tagged: + HumanDisease.all.order(:id).map do |c| + { + id: c.id.to_s, + title: c.title, + parent: c.parents.first ? c.parents.first.id.to_s : '', + projects: c.projects.count, + publications: c.publications.count, + models: c.models.count, + data_files: c.data_files.count, + } + end, + untagged: { + projects: Project.left_outer_joins(:human_diseases).where(human_diseases: { id: nil }).count(), + publications: Publication.left_outer_joins(:human_diseases).where(human_diseases: { id: nil }).count(), + models: Model.where(human_disease: nil).count(), + data_files: DataFile.left_outer_joins(:human_diseases).where(human_diseases: { id: nil }).count(), + }, + } end end end diff --git a/app/views/human_diseases/_overview_plot.html.erb b/app/views/human_diseases/_overview_plot.html.erb index 1725ef9f1c..4cc1690add 100644 --- a/app/views/human_diseases/_overview_plot.html.erb +++ b/app/views/human_diseases/_overview_plot.html.erb @@ -1,5 +1,7 @@ <% - dataframe = get_human_diseases_plot_data() + data = get_human_diseases_plot_data() + tagged = data[:tagged] + untagged = data[:untagged] %>
+ + Untagged:
+ <%= untagged.map{ |key, value| key.to_s.humanize + ': ' + value.to_s }.join(', ') %> +
@@ -32,11 +38,11 @@ <% plots.each do |plot| %> { type: 'sunburst', - ids: [ <%== dataframe.map{ |c| '"' + c[:id] + '"' }.join(', ') %> ], - labels: [ <%== dataframe.map{ |c| '"' + + '"' }.join(', ') %> ], - parents: [ <%== dataframe.map{ |c| '"' + c[:parent] + '"' }.join(', ') %> ], - values: [ <%== dataframe.map{ |c| c[plot[:key]] }.join(', ') %> ], - hovertext: [ <%== dataframe.map{ |c| '"' + c[:title] + '"' }.join(', ') %> ], + ids: [ <%== tagged.map{ |c| '"' + c[:id] + '"' }.join(', ') %> ], + labels: [ <%== tagged.map{ |c| '"' + + '"' }.join(', ') %> ], + parents: [ <%== tagged.map{ |c| '"' + c[:parent] + '"' }.join(', ') %> ], + values: [ <%== tagged.map{ |c| c[plot[:key]] }.join(', ') %> ], + hovertext: [ <%== tagged.map{ |c| '"' + c[:title] + '"' }.join(', ') %> ], outsidetextfont: { size: 20, color: '#377eb8' }, leaf: { opacity: 1 }, marker: { line: { width: 2 } },