Skip to content

Commit

Permalink
fix: adjust formatting of dial total value
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Feist committed Dec 9, 2021
1 parent 2920f6e commit 531ba22
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 13 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 1.3.7

* Adjust value of Dial total_value so that it does not show
zero for a value that is less than 0.1

## 1.3.6

* Correct filenames for the habitat country CSVs - must be plural.
Expand Down
4 changes: 0 additions & 4 deletions app/helpers/countries_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ def protected_percentage(dataset)
end
end

def total_value(dataset)
@country.protection_stats[dataset[:id]] ? @country.protection_stats[dataset[:id]]['total_value'].round(1) : 0
end

def habitat_with_data
@red_list_data.find { |habitat| habitat['data'].present? }
end
Expand Down
27 changes: 19 additions & 8 deletions app/helpers/proportion_protected_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
module ProportionProtectedHelper
def global_proportion_protected_html(dataset)
total_value = habitat_protection(dataset[:id])['total_value']

t('shared.proportion_protected.card.percentage',
percentage: habitat_protection(dataset[:id])['protected_percentage'],
area: number_with_delimiter(
habitat_protection(dataset[:id])['total_value'],
delimiter: ','
)
).html_safe
area: total_value_formatted(total_value),
area_unrounded: number_with_delimiter(total_value, delimiter: ',')).html_safe
end

def country_proportion_protected_status_html(dataset)
Expand All @@ -20,10 +19,12 @@ def country_proportion_protected_status_html(dataset)
end

def country_proportion_protected_html(dataset)
total_value = @country.protection_stats[dataset[:id]] ? @country.protection_stats[dataset[:id]]['total_value'] : 0

t('shared.proportion_protected.card.percentage',
percentage: protected_percentage(dataset),
area: number_with_delimiter(total_value(dataset), delimiter: ',')
).html_safe
area: total_value_formatted(total_value),
area_unrounded: number_with_delimiter(total_value, delimiter: ',')).html_safe
end

def proportion_protected_percentage(dataset)
Expand All @@ -37,4 +38,14 @@ def proportion_protected_icon_class(dataset)
def proportion_protected_card_modifier(dataset)
current_page?('/') ? 'present' : dataset_status(dataset)
end
end

def total_value_formatted(value)
if value.zero?
0
elsif value < 0.1
format('%.2e', value)
else
number_with_delimiter(value.round(1), delimiter: ',')
end
end
end
2 changes: 1 addition & 1 deletion config/locales/shared/proportion_protected/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ en:
note: '<strong>Note:</strong> This outlines the proportion of each habitat that is known to occur within protected areas. However, the level of protection and whether or not these habitats are explicitly and effectively protected is unknown.'
last_updated: '<strong>Last updated:</strong> %{last_updated}'
card:
percentage: '<strong>%{percentage}%</strong> of %{area} km<sup>2</sup>'
percentage: '<strong>%{percentage}%</strong> of <span title="%{area_unrounded}">%{area}</span> km<sup>2</sup>'

0 comments on commit 531ba22

Please sign in to comment.