Commit e22e83d6 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

addGrid glue code

parent be37e545
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -90,6 +90,17 @@ public:
   */
   AxisDefinition* addAxis(AxisDefinition::kPosition position);

  /**
   * Add a grid to the chart.
   *
   * The returned pointer is owned by the canvas object and must not be freed
   * by the caller!
   *
   * @param vertical render vertical grid lines?
   * @param horizontal render horizonyal grid lines?
   */
  GridDefinition* addGrid(GridDefinition::kPlacement placement) override;

  /**
   * Get the {x,y} domain of this chart. Will raise an exception if z domain
   * is requested.
@@ -358,6 +369,24 @@ AxisDefinition* AreaChart3D<TX, TY, TZ>::addAxis(
  }
}

template <typename TX, typename TY, typename TZ>
GridDefinition* AreaChart3D<TX, TY, TZ>::addGrid(
    GridDefinition::kPlacement placement) {
  auto grid = canvas_->addGrid(placement);

  switch (placement) {

    case GridDefinition::GRID_VERTICAL:
      grid->setDomain(&y_domain_);
      return grid;

    case GridDefinition::GRID_HORIZONTAL:
      grid->setDomain(&x_domain_);
      return grid;

  }
}

template <typename TX, typename TY, typename TZ>
AnyDomain* AreaChart3D<TX, TY, TZ>::getDomain(
    AnyDomain::kDimension dimension) {
+42 −1
Original line number Diff line number Diff line
@@ -115,6 +115,17 @@ public:
   */
  AxisDefinition* addAxis(AxisDefinition::kPosition position) override;

  /**
   * Add a grid to the chart.
   *
   * The returned pointer is owned by the canvas object and must not be freed
   * by the caller!
   *
   * @param vertical render vertical grid lines?
   * @param horizontal render horizonyal grid lines?
   */
  GridDefinition* addGrid(GridDefinition::kPlacement placement) override;

  /**
   * Set the stacked property of this bar chart
   *
@@ -294,6 +305,36 @@ AxisDefinition* BarChart3D<TX, TY, TZ>::addAxis(
  }
}

template <typename TX, typename TY, typename TZ>
GridDefinition* BarChart3D<TX, TY, TZ>::addGrid(
    GridDefinition::kPlacement placement) {
  auto grid = canvas_->addGrid(placement);

  switch (placement) {

    case GridDefinition::GRID_VERTICAL:
      switch (orientation_) {
        case O_VERTICAL:
          grid->setDomain(&y_domain_);
          return grid;
        case O_HORIZONTAL:
          grid->setDomain(&x_domain_);
          return grid;
      }

    case GridDefinition::GRID_HORIZONTAL:
      switch (orientation_) {
        case O_VERTICAL:
          grid->setDomain(&x_domain_);
          return grid;
        case O_HORIZONTAL:
          grid->setDomain(&y_domain_);
          return grid;
      }

  }
}

template <typename TX, typename TY, typename TZ>
void BarChart3D<TX, TY, TZ>::render(
    RenderTarget* target,
+13 −3
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ public:
  }

  /**
   * Add an axis to this canvas. Usually axes are not specified manually using
   * Add an axis to this canvas. Usually axes are not specified manually via
   * this method but through one of the Chart subclasses. However it is safe
   * to call this method to explicitly define a custom axis.
   *
@@ -65,9 +65,9 @@ public:
  AxisDefinition* addAxis(AxisDefinition::kPosition position);

  /**
   * Add a a leged to this canvas. Usually axes are not specified manually using
   * Add a leged to this canvas. Usually legends are not specified manually via
   * this method but through one of the Chart subclasses. However it is safe
   * to call this method to explicitly define a custom axis.
   * to call this method to explicitly define a custom legend.
   *
   * The returned pointer is owned by the canvas instance and must not be freed
   * by the caller.
@@ -78,6 +78,16 @@ public:
      LegendDefinition::kPlacement placement,
      const std::string& title);

  /**
   * Add a grid to this canvas. Usually grids are not specified manually via
   * this method but through one of the Chart subclasses. However it is safe
   * to call this method to explicitly define a custom grid.
   *
   * The returned pointer is owned by the canvas instance and must not be freed
   * by the caller.
   */
  GridDefinition* addGrid(GridDefinition::kPlacement placement);

  /**
   * Return the legend or nullptr
   */
+13 −7
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@
#include <functional>
#include <fnordmetric/base/series.h>
#include <fnordmetric/ui/axisdefinition.h>
#include <fnordmetric/ui/griddefinition.h>
#include <fnordmetric/ui/legenddefinition.h>
#include <fnordmetric/ui/viewport.h>

@@ -50,17 +51,22 @@ public:

  /**
   * Add a grid to the chart.
   *
   * The returned pointer is owned by the canvas object and must not be freed
   * by the caller!
   *
   * @param vertical render vertical grid lines?
   * @param horizontal render horizonyal grid lines?
   */
  void addGrid(bool horizontal, bool vertical) {
    RAISE(
        util::RuntimeException,
        "grid not implemented: horizontal=%s, vertical=%s",
        horizontal ? "true" : "false",
        vertical ? "true" : "false");
  }
  virtual GridDefinition* addGrid(GridDefinition::kPlacement placement) = 0;

  /**
   * Add a legend to the chart.
   *
   * The returned pointer is owned by the canvas object and must not be freed
   * by the caller!
   *
   * FIXPAUL params
   */
  LegendDefinition* addLegend(
      LegendDefinition::kVerticalPosition vert_pos,

griddefinition.cc

0 → 100644
+18 −0
Original line number Diff line number Diff line
/**
 * This file is part of the "FnordMetric" project
 *   Copyright (c) 2011-2014 Paul Asmuth, Google Inc.
 *
 * FnordMetric is free software: you can redistribute it and/or modify it under
 * the terms of the GNU General Public License v3.0. You should have received a
 * copy of the GNU General Public License along with this program. If not, see
 * <http://www.gnu.org/licenses/>.
 */
#include <fnordmetric/ui/griddefinition.h>

namespace fnordmetric {
namespace ui {

GridDefinition::GridDefinition(kPlacement placement) : placement_(placement) {}

}
}
Loading