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

legenddefinition

parent ae4e1a06
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -390,5 +390,16 @@ AxisDefinition* Canvas::addAxis(AxisDefinition::kPosition position) {
  return axes_.back().get();
}

LegendDefinition* Canvas::addLegend(
    LegendDefinition::kVerticalPosition vert_pos,
    LegendDefinition::kHorizontalPosition horiz_pos,
    LegendDefinition::kPlacement placement,
    const std::string& title) {
  legends_.emplace_back(
      new LegendDefinition(vert_pos, horiz_pos, placement, title));
  return legends_.back().get();
}


}
}
+17 −1
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <tuple>
#include <fnordmetric/ui/axisdefinition.h>
#include <fnordmetric/ui/drawable.h>
#include <fnordmetric/ui/legenddefinition.h>

namespace fnordmetric {
namespace ui {
@@ -53,6 +54,20 @@ public:
   */
  AxisDefinition* addAxis(AxisDefinition::kPosition position);

  /**
   * Add a a leged to this canvas. Usually axes are not specified manually using
   * this method but through one of the Chart subclasses. However it is safe
   * to call this method to explicitly define a custom axis.
   *
   * The returned pointer is owned by the canvas instance and must not be freed
   * by the caller.
   */
  LegendDefinition* addLegend(
      LegendDefinition::kVerticalPosition vert_pos,
      LegendDefinition::kHorizontalPosition horiz_pos,
      LegendDefinition::kPlacement placement,
      const std::string& title);

  /**
   * Render the contents of this canvas to the provided render target
   *
@@ -140,6 +155,7 @@ protected:
  int width_;
  int height_;
  std::vector<std::unique_ptr<AxisDefinition>> axes_;
  std::vector<std::unique_ptr<LegendDefinition>> legends_;
  std::vector<std::unique_ptr<Drawable>> drawables_;
};

+9 −0
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
 * <http://www.gnu.org/licenses/>.
 */
#include <string>
#include <fnordmetric/ui/canvas.h>
#include <fnordmetric/ui/drawable.h>

namespace fnordmetric {
@@ -21,5 +22,13 @@ void Drawable::setSubtitle(const std::string& subtitle) {
  printf("SUBTITLE: %s\n", subtitle.c_str());
}

LegendDefinition* Drawable::addLegend(
    LegendDefinition::kVerticalPosition vert_pos,
    LegendDefinition::kHorizontalPosition horiz_pos,
    LegendDefinition::kPlacement placement,
    const std::string& title) {
  canvas_->addLegend(vert_pos, horiz_pos, placement, title);
}

}
}
+6 −29
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/legenddefinition.h>
#include <fnordmetric/ui/viewport.h>

namespace fnordmetric {
@@ -24,22 +25,6 @@ class Canvas;
class Drawable {
  friend class Canvas;
public:
  enum kLegendVerticalPosition {
    LEGEND_TOP = 0,
    LEGEND_BOTTOM = 1
  };

  enum kLegendHorizontalPosition {
    LEGEND_LEFT = 0,
    LEGEND_RIGHT = 1
  };

  enum kLegendPlacement {
    LEGEND_INSIDE = 0,
    LEGEND_OUTSIDE = 1
  };


  Drawable(Canvas* canvas) : canvas_(canvas) {}
  virtual ~Drawable() {}

@@ -77,19 +62,11 @@ public:
  /**
   * Add a legend to the chart.
   */
  void addLegend(
      kLegendVerticalPosition vert_pos,
      kLegendHorizontalPosition horiz_pos,
      kLegendPlacement placement,
      const std::string& title) {
    RAISE(
        util::RuntimeException,
        "legend not implemented: horiz=%i, vert=%i placement=%i title=%s",
        vert_pos,
        horiz_pos,
        placement,
        title.c_str());
  }
  LegendDefinition* addLegend(
      LegendDefinition::kVerticalPosition vert_pos,
      LegendDefinition::kHorizontalPosition horiz_pos,
      LegendDefinition::kPlacement placement,
      const std::string& title);

  /**
   * Get the {x,y,z} domain of this chart. May raise an exception if the chart

legenddefinition.cc

0 → 100644
+26 −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/legenddefinition.h>

namespace fnordmetric {
namespace ui {

LegendDefinition::LegendDefinition(
    kVerticalPosition vert_pos,
    kHorizontalPosition horiz_pos,
    kPlacement placement,
    const std::string& title) :
    vert_pos_(vert_pos),
    horiz_pos_(horiz_pos),
    placement_(placement),
    title_ (title) {}

}
}
Loading