Skip to content

Commit

Permalink
feat(web): ability to skip all-zero ranges for chart data
Browse files Browse the repository at this point in the history
  • Loading branch information
howeyc committed Jan 23, 2022
1 parent 901e42d commit c4377b7
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions ledger/cmd/webConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ type calculatedAccount struct {
type reportConfig struct {
Name string
Chart string
DateRange string `toml:"date_range"`
DateFreq string `toml:"date_freq"`
RangeBalanceType ledger.RangeType `toml:"range_balance_type"`
RangeBalanceSkipZero bool `toml:"range_balance_skip_zero"`
DateRange string `toml:"date_range"`
DateFreq string `toml:"date_freq"`
Accounts []string
ExcludeAccountTrans []string `toml:"exclude_account_trans"`
ExcludeAccountsSummary []string `toml:"exclude_account_summary"`
Expand Down
16 changes: 16 additions & 0 deletions ledger/cmd/webHandlerReport.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,9 +394,25 @@ func reportHandler(w http.ResponseWriter, r *http.Request, params httprouter.Par
rType = ledger.RangePartition
lData.ChartType = "StackedBar"
}
if rConf.RangeBalanceType != "" {
rType = rConf.RangeBalanceType
}

rangeBalances := ledger.BalancesByPeriod(rtrans, rPeriod, rType)
for _, rb := range rangeBalances {
if rConf.RangeBalanceSkipZero {
allZero := true
for _, acc := range rb.Balances {
if acc.Balance.Sign() != 0 {
allZero = false
break
}
}
if allZero {
continue
}
}

if lData.RangeStart.IsZero() {
lData.RangeStart = rb.Start
}
Expand Down

0 comments on commit c4377b7

Please sign in to comment.