Extract function to calculate indent

This commit is contained in:
Thomas Lauf 2018-12-07 10:22:43 +01:00
parent f5bbe5e1bc
commit b00d097e3e

View file

@ -1,6 +1,6 @@
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// //
// Copyright 2015 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez. // Copyright 2016 - 2018, Thomas Lauf, Paul Beckingham, Federico Hernandez.
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@ -47,6 +47,8 @@ static void renderInterval (const std::string&, const Rules&, std:
std::string renderHolidays (const std::string&, const Rules&, const Interval&); std::string renderHolidays (const std::string&, const Rules&, const Interval&);
static std::string renderSummary (const std::string&, const Rules&, const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&, bool); static std::string renderSummary (const std::string&, const Rules&, const std::string&, const Interval&, const std::vector <Range>&, const std::vector <Interval>&, bool);
unsigned long getIndentSize (const std::string &type, const Rules &rules);
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
int CmdChartDay ( int CmdChartDay (
const CLI& cli, const CLI& cli,
@ -133,11 +135,7 @@ int renderChart (
renderAxis (type, renderAxis (type,
rules, rules,
palette, palette,
std::string ((rules.getBoolean ("reports." + type + ".month") ? 4 : 0) + std::string (getIndentSize (type, rules), ' '),
(rules.getBoolean ("reports." + type + ".week") ? 4 : 0) +
(rules.getBoolean ("reports." + type + ".day") ? 3 : 0) +
(rules.getBoolean ("reports." + type + ".weekday") ? 4 : 0),
' '),
first_hour, first_hour,
last_hour); last_hour);
@ -149,10 +147,7 @@ int renderChart (
bool ids = findHint (cli, ":ids"); bool ids = findHint (cli, ":ids");
// Determine how much space is occupied by the left-margin labels. // Determine how much space is occupied by the left-margin labels.
int indent = (rules.getBoolean ("reports." + type + ".month") ? 4 : 0) + auto indent = getIndentSize (type, rules);
(rules.getBoolean ("reports." + type + ".week") ? 4 : 0) +
(rules.getBoolean ("reports." + type + ".day") ? 3 : 0) +
(rules.getBoolean ("reports." + type + ".weekday") ? 4 : 0);
auto cell = rules.getInteger ("reports." + type + ".cell"); auto cell = rules.getInteger ("reports." + type + ".cell");
if (cell < 1) if (cell < 1)
@ -223,6 +218,14 @@ int renderChart (
return 0; return 0;
} }
unsigned long getIndentSize (const std::string &type, const Rules &rules)
{
return (rules.getBoolean ("reports." + type + ".month") ? 4 : 0) +
(rules.getBoolean ("reports." + type + ".week") ? 4 : 0) +
(rules.getBoolean ("reports." + type + ".day") ? 3 : 0) +
(rules.getBoolean ("reports." + type + ".weekday") ? 4 : 0);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Scan all tracked intervals, looking for the earliest and latest hour into // Scan all tracked intervals, looking for the earliest and latest hour into
// which an interval extends. // which an interval extends.