lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master cf0ef5e7: Fix defect introduced 20220419T1408


From: Greg Chicares
Subject: [lmi-commits] [lmi] master cf0ef5e7: Fix defect introduced 20220419T1408Z: PDF scaling too aggressive
Date: Wed, 27 Apr 2022 09:32:07 -0400 (EDT)

branch: master
commit cf0ef5e794b226716c943b9050638395c0ef3bf4
Author: Gregory W. Chicares <gchicares@sbcglobal.net>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Fix defect introduced 20220419T1408Z: PDF scaling too aggressive
    
    Tabular values printed on PDF illustrations are scaled to fit. Examples:
       130000000 --> 130,000,000 (values in dollars)
      1300000000 -->   1,300,000 (values in thousands)
    Commit dcbe94185cb77 of 20220419T1408Z changed many ledger values from
    dollars to cents, but defectively didn't adjust scaling, resulting in:
       130000000 -->     130,000 (values in thousands)
    whereas the former outcome:
       130000000 --> 130,000,000 (values in dollars)
    is preferable. Fixed by converting the extrema to dollars.
    
    Not all scalable vectors are actually represented as cents, although
    that would seem desirable.
---
 ledger.cpp | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/ledger.cpp b/ledger.cpp
index 0f4d162f..834ab73a 100644
--- a/ledger.cpp
+++ b/ledger.cpp
@@ -307,8 +307,18 @@ void Ledger::AutoScale()
         extrema.subsume(i.second.scalable_extrema());
         }
 
-    int const max_power = 9;
-    int const k = scale_power(max_power, extrema.minimum(), extrema.maximum());
+    // No plausible amount is too high to express as billions of dollars.
+    constexpr int max_power = 9;
+    // Convert cents to dollars. The extrema are of type 'double', and
+    // their values aren't necessarily integers. The quotients need to
+    // be rounded away from zero, because 999.99 and 1000.01 require
+    // different formatted widths; but that needn't be done here,
+    // because function scale_power() takes care of it.
+    int const k = scale_power
+        (max_power
+        ,extrema.minimum() / 100.0
+        ,extrema.maximum() / 100.0
+        );
 
     ledger_invariant_->apply_scale_factor(k);
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]