Skip to content
Permalink
Browse files

Extract chart configuration into separate class

  • Loading branch information...
lauft committed Mar 3, 2019
1 parent 40ea90c commit e2bd07635732cf19310600f05d2554e8b7932620
Showing with 55 additions and 11 deletions.
  1. +1 −0 src/CMakeLists.txt
  2. +5 −9 src/Chart.cpp
  3. +2 −1 src/Chart.h
  4. +39 −0 src/ChartConfig.h
  5. +8 −1 src/commands/CmdChart.cpp
@@ -7,6 +7,7 @@ include_directories (${CMAKE_SOURCE_DIR}

set (timew_SRCS CLI.cpp CLI.h
Chart.cpp Chart.h
ChartConfig.h
Database.cpp Database.h
Datafile.cpp Datafile.h
Exclusion.cpp Exclusion.h
@@ -37,15 +37,11 @@
#include <Chart.h>

////////////////////////////////////////////////////////////////////////////////
Chart::Chart (
const bool with_label_month,
const bool with_label_week,
const bool with_label_weekday,
const bool with_label_day) :
with_label_month(with_label_month),
with_label_week(with_label_week),
with_label_weekday(with_label_weekday),
with_label_day(with_label_day)
Chart::Chart (ChartConfig configuration) :
with_label_month(configuration.with_label_month),
with_label_week(configuration.with_label_week),
with_label_weekday(configuration.with_label_weekday),
with_label_day(configuration.with_label_day)
{ }

std::string Chart::render (
@@ -30,11 +30,12 @@
#include <Composite.h>
#include <Interval.h>
#include <map>
#include "ChartConfig.h"

class Chart
{
public:
Chart(bool, bool, bool, bool);
explicit Chart (ChartConfig configuration);

std::string render (const Interval&, const std::vector <Interval>&, const std::vector <Range>&, const std::map <Datetime, std::string>&, const std::map <std::string, Color>&, const Color&, const Color&, const Color&, const Color&, bool, bool, bool, bool, bool, bool, bool, int, int, int);

@@ -0,0 +1,39 @@
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2019, Thomas Lauf, Paul Beckingham, Federico Hernandez.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
// https://www.opensource.org/licenses/mit-license.php
//
////////////////////////////////////////////////////////////////////////////////

#ifndef INCLUDED_CHARTCONFIG
#define INCLUDED_CHARTCONFIG

class ChartConfig
{
public:
bool with_label_month;
bool with_label_week;
bool with_label_weekday;
bool with_label_day;
};

#endif
@@ -27,6 +27,7 @@
#include <Duration.h>
#include <Range.h>
#include <Chart.h>
#include <ChartConfig.h>
#include <commands.h>
#include <timew.h>
#include <shared.h>
@@ -145,7 +146,13 @@ int renderChart (
auto axis_type = rules.get ("reports." + type + ".axis");
const auto with_internal_axis = axis_type == "internal";

Chart chart(with_month, with_week, with_weekday, with_day);
ChartConfig configuration {};
configuration.with_label_month = with_month;
configuration.with_label_week = with_week;
configuration.with_label_weekday = with_weekday;
configuration.with_label_day = with_day;

Chart chart (configuration);

std::cout << chart.render (filter, tracked, exclusions, holidays, tag_colors, color_today, color_holiday, color_label, color_exclusion, show_intervals, determine_hour_range, with_ids, with_summary, with_holidays, with_totals, with_internal_axis, minutes_per_char, spacing, num_lines);

0 comments on commit e2bd076

Please sign in to comment.
You can’t perform that action at this time.