Commit 2b40af33 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

Drawable#getDomain

parent 3e2ada2c
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -116,6 +116,16 @@ public:
   */
  void setStacked(bool stacked) override;

  /**
   * Get the {x,y,z} domain of this chart.
   *
   * The returned pointer is owned by the chart object and must not be freed
   * by the caller!
   *
   * @param dimension the dimension (x,y,z)
   */
  AnyDomain* getDomain(AnyDomain::kDimension dimension) override;

protected:

  void render(RenderTarget* target, Viewport* viewport) const override;
@@ -414,6 +424,18 @@ void BarChart3D<TX, TY, TZ>::setStacked(bool stacked) {
  }
}

template <typename TX, typename TY, typename TZ>
AnyDomain* BarChart3D<TX, TY, TZ>::getDomain(AnyDomain::kDimension dimension) {
  switch (dimension) {
    case AnyDomain::DIM_X:
      return x_domain_.get();

    case AnyDomain::DIM_Y:
    case AnyDomain::DIM_Z:
      return y_domain_.get();
  }
}

template <typename TX, typename TY>
BarChart2D<TX, TY>::BarChart2D(
    Canvas* canvas) :
+6 −0
Original line number Diff line number Diff line
@@ -23,6 +23,12 @@ namespace ui {
 */
class AnyDomain {
public:
  enum kDimension {
    DIM_X = 0,
    DIM_Y = 1,
    DIM_Z = 2
  };

  virtual ~AnyDomain() {}

  virtual const std::vector<double> getTicks() const = 0;
+13 −3
Original line number Diff line number Diff line
@@ -29,8 +29,7 @@ public:
  virtual ~Drawable() {}

  /**
   * Add an axis to the chart. This method should only be called after all
   * series have been added to the chart.
   * Add an axis to the chart.
   *
   * The returned pointer is owned by the canvas object and must not be freed
   * by the caller!
@@ -39,6 +38,17 @@ public:
   */
  virtual AxisDefinition* addAxis(AxisDefinition::kPosition position) = 0;

  /**
   * Get the {x,y,z} domain of this chart. May raise an exception if the chart
   * does not implement the requested domain.
   *
   * The returned pointer is owned by the canvas object and must not be freed
   * by the caller!
   *
   * @param dimension the dimension
   */
  virtual AnyDomain* getDomain(AnyDomain::kDimension dimension) = 0;

protected:

  virtual void render(RenderTarget* target, Viewport* viewport) const = 0;
+26 −0
Original line number Diff line number Diff line
@@ -78,6 +78,17 @@ public:
   */
   AxisDefinition* addAxis(AxisDefinition::kPosition position);

  /**
   * Get the {x,y} domain of this chart. Will raise an exception if z domain
   * is requested.
   *
   * The returned pointer is owned by the chart object and must not be freed
   * by the caller!
   *
   * @param dimension the dimension (x,y)
   */
  AnyDomain* getDomain(AnyDomain::kDimension dimension) override;

protected:

  void render(
@@ -212,6 +223,21 @@ AxisDefinition* LineChart2D<TX, TY>::addAxis(
  }
}

template <typename TX, typename TY>
AnyDomain* LineChart2D<TX, TY>::getDomain(AnyDomain::kDimension dimension) {
  switch (dimension) {
    case AnyDomain::DIM_X:
      return x_domain_.get();

    case AnyDomain::DIM_Y:
      return y_domain_.get();

    case AnyDomain::DIM_Z:
      RAISE(util::RuntimeException, "LineChart2D does not have a Y domain");
      return nullptr;
  }
}

}
}
#endif