Commit 1f443929 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

split out domainprovider, cleanups

parent 7b43978a
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -129,8 +129,8 @@ protected:
      RenderTarget* target,
      Viewport* viewport) const override;

  DomainAdapter x_domain_;
  DomainAdapter y_domain_;
  DomainProvider x_domain_;
  DomainProvider y_domain_;
  std::vector<Area> areas_;
  ColorPalette color_palette_;
};
+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@ AxisDefinition::AxisDefinition(

AxisDefinition::AxisDefinition(
    kPosition axis_position,
    DomainAdapter* domain) :
    DomainProvider* domain) :
    position_(axis_position),
    domain_(domain),
    has_ticks_(false),
@@ -94,7 +94,7 @@ bool AxisDefinition::hasTitle() const {
  return title_.length() > 0;
}

void AxisDefinition::setDomain(DomainAdapter* domain) {
void AxisDefinition::setDomain(DomainProvider* domain) {
  domain_ = domain;
}

+5 −4
Original line number Diff line number Diff line
@@ -12,7 +12,8 @@
#include <utility>
#include <string>
#include <vector>
#include "domain.h"
#include <fnordmetric/ui/domain.h>
#include <fnordmetric/ui/domainprovider.h>

namespace fnordmetric {
namespace ui {
@@ -52,7 +53,7 @@ public:
   * @param axis_position the position of the axis ({TOP,RIGHT,BOTTOM,LEFT})
   * @param domain the domain. does not transfer ownership
   */
  AxisDefinition(kPosition axis_position, DomainAdapter* domain);
  AxisDefinition(kPosition axis_position, DomainProvider* domain);

  /**
   * Add a "tick" to this axis
@@ -133,11 +134,11 @@ public:
  /**
   * Set the domain for this axis
   */
  void setDomain(DomainAdapter* domain);
  void setDomain(DomainProvider* domain);

protected:
  kPosition position_;
  DomainAdapter* domain_;
  DomainProvider* domain_;
  std::string title_;
  std::vector<double> ticks_;
  bool has_ticks_;
+2 −2
Original line number Diff line number Diff line
@@ -164,8 +164,8 @@ protected:
  void stackData(SeriesJoin3D<TX, TY, TZ>* target) const;
  const std::string& seriesColor(size_t series_index) const;

  DomainAdapter x_domain_;
  DomainAdapter y_domain_;
  DomainProvider x_domain_;
  DomainProvider y_domain_;
  SeriesJoin3D<TX, TY, TY> data_;
  std::vector<Series3D<TX, TY, TY>*> series_;
  ColorPalette color_palette_;
+0 −62
Original line number Diff line number Diff line
@@ -388,68 +388,6 @@ protected:
  std::vector<T> categories_;
};

class DomainAdapter {
public:
  DomainAdapter(
      AnyDomain* domain = nullptr) :
      domain_(domain),
      free_on_destroy_(false) {};

  ~DomainAdapter() {
    if (free_on_destroy_) {
      delete domain_;
    }
  }

  AnyDomain* get() const {
    return domain_;
  }

  template <typename T>
  T* getAs() const {
    T* domain = dynamic_cast<T*>(domain_);

    if (domain == nullptr) {
      RAISE(util::RuntimeException, "can't convert domain to requested type");
    }

    return domain;
  }

  bool empty() const {
    return domain_ == nullptr;
  }

  void reset(AnyDomain* domain, bool free_on_destroy = false) {
    if (free_on_destroy_) {
      delete domain_;
    }

    domain_ = domain;
    free_on_destroy_ = free_on_destroy;
  }

  const std::vector<double> getTicks() const {
    if (empty()) {
      return std::vector<double>{};
    } else {
      return domain_->getTicks();
    }
  }

  const std::vector<std::pair<double, std::string>> getLabels() const {
    if (empty()) {
      return std::vector<std::pair<double, std::string>>{};
    } else {
      return domain_->getLabels();
    }
  }

protected:
  AnyDomain* domain_;
  bool free_on_destroy_;
};

}
}
#endif
Loading