Skip to content

Commit

Permalink
Present NaN values in commercial performance tables as '-'
Browse files Browse the repository at this point in the history
  • Loading branch information
phil-l-brockwell committed Nov 12, 2024
1 parent 735eb1e commit 84c2492
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ class window.FinancialSummaryTableBase

row.find("td:eq(#{i + 1})").text(value)


renderTableGrowth: () =>
turnoverGrowthRow = @tableGrowth.find("tr[data-type='fs-turnover-growth']")

Expand All @@ -70,11 +69,12 @@ class window.FinancialSummaryTableBase
@showFinancials = false
turnoverGrowthRow.find("td:gt(0)").text("-")
else
presentPercentageValue = @._presentPercentageValue
turnoverValues.each (i, value) ->
if i > 0
previousValue = turnoverValues[i - 1]
growth = ((value - previousValue) / previousValue) * 100
turnoverGrowthRow.find("td:eq(#{i + 1})").text(parseInt(growth).toLocaleString())
turnoverGrowthRow.find("td:eq(#{i + 1})").text(presentPercentageValue(parseInt(growth)).toLocaleString())
else
turnoverGrowthRow.find("td:eq(#{i + 1})").text("-")

Expand All @@ -98,4 +98,8 @@ class window.FinancialSummaryTableBase
lastYear = turnoverValues[turnoverValues.length - 1]
diff = lastYear - firstYear
totalTurnoverGrowth.text(diff.toLocaleString())
totalTurnoverGrowthPercentage.text(parseInt(diff / firstYear * 100).toLocaleString())
totalTurnoverGrowthPercentageValue = @._presentPercentageValue(parseInt(diff / firstYear * 100)).toLocaleString()
totalTurnoverGrowthPercentage.text(totalTurnoverGrowthPercentageValue)

_presentPercentageValue: (value) ->
if isNaN(value) then "-" else value
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ class FinancialSummaryTableTrade extends FinancialSummaryTableBase
@showFinancials = false
salesGrowthRow.find("td:gt(0)").text("-")
else
presentPercentageValue = @._presentPercentageValue
salesOverseasValues.each (i, value) ->
if i > 0
previousValue = salesOverseasValues[i - 1]
growth = ((value - previousValue) / previousValue) * 100
salesGrowthRow.find("td:eq(#{i + 1})").text(parseInt(growth).toLocaleString())
growth = presentPercentageValue(parseInt(((value - previousValue) / previousValue) * 100))
salesGrowthRow.find("td:eq(#{i + 1})").text(growth.toLocaleString())
else
salesGrowthRow.find("td:eq(#{i + 1})").text("-")

Expand All @@ -67,13 +68,14 @@ class FinancialSummaryTableTrade extends FinancialSummaryTableBase
@showFinancials = false
salesPercentRow.find("td:gt(0)").text("-")
else
presentPercentageValue = @._presentPercentageValue
salesOverseasValues.each (i, value) ->
if turnoverValues[i] > 0
value = (value / turnoverValues[i] * 100)
value = presentPercentageValue(parseInt(value / turnoverValues[i] * 100))
else
value = "-"

salesPercentRow.find("td:eq(#{i + 1})").text(parseInt(value).toLocaleString())
salesPercentRow.find("td:eq(#{i + 1})").text(value.toLocaleString())

renderTableSummary: () ->
totalOverseasGrowth = @tableSummary.find("td[data-type='fs-overall-overseas-sales-growth']")
Expand All @@ -95,7 +97,8 @@ class FinancialSummaryTableTrade extends FinancialSummaryTableBase
lastYear = overseasSalesValues[overseasSalesValues.length - 1]
diff = lastYear - firstYear
totalOverseasGrowth.text(diff.toLocaleString())
totalOverseasGrowthPercentage.text(parseInt(diff / firstYear * 100).toLocaleString())
totalOverseasGrowthPercentageValue = @._presentPercentageValue(parseInt(diff / firstYear * 100)).toLocaleString()
totalOverseasGrowthPercentage.text(totalOverseasGrowthPercentageValue)

$(document).ready ->
if $(".financial-summary-tables-trade").length > 0
Expand Down

0 comments on commit 84c2492

Please sign in to comment.