Commit 14c419bc authored by Paul Asmuth's avatar Paul Asmuth
Browse files

colors! :)

parent ed1c3430
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -15,6 +15,7 @@
#include <fnordmetric/base/series.h>
#include <fnordmetric/ui/axisdefinition.h>
#include <fnordmetric/ui/canvas.h>
#include <fnordmetric/ui/colorpalette.h>
#include <fnordmetric/ui/domain.h>
#include <fnordmetric/ui/drawable.h>
#include <fnordmetric/ui/rendertarget.h>
@@ -129,6 +130,7 @@ protected:
  DomainAdapter y_domain_;
  SeriesJoin3D<TX, TY, TY> data_;
  std::vector<Series3D<TX, TY, TY>*> series_;
  ColorPalette color_palette_;
};

template <typename TX_, typename TY_>
@@ -204,6 +206,10 @@ void BarChart3D<TX, TY, TZ>::addSeries(Series3D<TX, TY, TZ>* series) {
      y_domain->addValue(max);
    }
  }

  if (!series->hasProperty(Series::P_COLOR)) {
    color_palette_.setNextColor(series);
  }
}

template <typename TX, typename TY, typename TZ>
@@ -386,9 +392,7 @@ const std::string& BarChart3D<TX, TY, TZ>::seriesColor(
    RAISE(util::RuntimeException, "invalid series index");
  }

  static const std::string col = "#06c";
  return col;
  //return series_[series_index]->getProperty(Series::P_COLOR);
  return series_[series_index]->getProperty(Series::P_COLOR);
}

template <typename TX, typename TY>
@@ -401,7 +405,6 @@ void BarChart2D<TX, TY>::addSeries(Series2D<TX, TY>* series) {
  auto series3d = new Series3D<TX, TY, TY>(); // FIXPAUL: never free'd!

  for (const auto& point : series->getData()) {
    // FIXPAUL copy properties
    if (point.y() > 0) {
      series3d->addDatum(
          Series::Coord<TX>(point.x()),
@@ -415,6 +418,12 @@ void BarChart2D<TX, TY>::addSeries(Series2D<TX, TY>* series) {
    }
  }

  if (series->hasProperty(Series::P_COLOR)) {
    series3d->setDefaultProperty(
        Series::P_COLOR,
        series->getProperty(Series::P_COLOR));
  }

  BarChart3D<TX, TY, TY>::addSeries(series3d);
}

+2 −2
Original line number Diff line number Diff line
@@ -20,8 +20,8 @@ namespace fnordmetric {
namespace ui {

Canvas::Canvas() :
    width_(1024),
    height_(500) {}
    width_(750),
    height_(300) {}

void Canvas::render(RenderTarget* target) const {
  // FIXPAUL: initialize from rendertarget

colorpalette.h

0 → 100644
+44 −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/>.
 */
#ifndef _FNORDMETRIC_UI_COLORPALETTE_H
#define _FNORDMETRIC_UI_COLORPALETTE_H
#include <stdlib.h>

namespace fnordmetric {
namespace ui {

class ColorPalette {
public:

  ColorPalette(
      const std::vector<std::string>& colors = std::vector<std::string>{
          "color1",
          "color2",
          "color3",
          "color4",
          "color5",
          "color6"}) :
          colors_(colors),
          color_index_(0) {}

  void setNextColor(Series* series) {
    series->setDefaultProperty(
        Series::P_COLOR,
        colors_[color_index_++ % colors_.size()]);
  }

protected:
  std::vector<std::string> colors_;
  size_t color_index_;
};

}
}
#endif