Commit 571aaca7 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

draw range area chart :)

parent 0e0af57d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ point chart examples:
  * negative values
  * middle axis

--- stacked area charts
--> legend!
--- pie, scatter, bubble, gauges, heatmaps, boxplot, error bars 
--- sparklines? (multi svg output)
+63 −26
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ AreaChart::AreaChart(
    bool stacked /* = false */) :
    canvas_(canvas),
    x_domain_(x_domain),
    y_domain_(x_domain),
    y_domain_(y_domain),
    stacked_(stacked),
    num_series_(0) {}

@@ -51,6 +51,32 @@ void AreaChart::addSeries(
  areas_.emplace_back(area);
}

void AreaChart::addSeries(
    Series3D<double, double, double>* series,
    const std::string& border_style /* = kDefaultBorderStyle */,
    double border_width /* = kDefaultBorderWidth */,
    const std::string& point_style /* = kDefaultPointStyle */,
    double point_size /* = kDefaultPointSize */,
    bool smooth /* = false */) {
  Area area;
  area.color = seriesColor(series);
  area.border_style = border_style;
  area.border_width = border_width;
  area.point_style = point_style;
  area.point_size = point_size;
  area.smooth = smooth;

  // FIXPAUL: stacked
  for (const auto& spoint : series->getData()) {
    area.points.emplace_back(
        std::get<0>(spoint),
        std::get<1>(spoint),
        std::get<2>(spoint));
  }

  areas_.emplace_back(area);
}

AxisDefinition* AreaChart::addAxis(AxisDefinition::kPosition position) {
  switch (position) {
    case AxisDefinition::TOP:
@@ -171,6 +197,7 @@ void AreaChart::render(
  for (const auto& area : areas_) {
    std::vector<std::pair<double, double>> area_coords;
    std::vector<std::pair<double, double>> border_top_coords;
    std::vector<std::pair<double, double>> border_bottom_coords;
    std::vector<std::pair<double, double>> point_coords;

    for (int i = 0; i < area.points.size(); ++i) {
@@ -195,7 +222,7 @@ void AreaChart::render(
      area_coords.emplace_back(draw_x, draw_y1);

      if (std::get<1>(point) != 0) {
        border_top_coords.emplace_back(draw_x, draw_y1);
        border_bottom_coords.emplace_back(draw_x, draw_y1);
        point_coords.emplace_back(draw_x, draw_y1);
      }
    }
@@ -216,6 +243,16 @@ void AreaChart::render(
          area.smooth,
          area.color,
          "line");

      if (border_bottom_coords.size() > 0) {
        target->drawPath(
            border_bottom_coords,
            area.border_style,
            area.border_width,
            area.smooth,
            area.color,
            "line");
      }
    }

    if (area.point_style != "none") {
+22 −2
Original line number Diff line number Diff line
@@ -51,8 +51,8 @@ public:
      bool stacked = false);

  /**
   * Add a (x: string, y: double) series. This will draw with height 0 to y
   * for each x
   * Add a (x: string, y: double) series. This will draw an area that covers
   * the surface between height 0 and y for each x.
   *
   * @param series the series to add. does not transfer ownership
   * @param border_style the border style
@@ -70,6 +70,26 @@ public:
      double point_size = kDefaultPointSize,
      bool smooth = false);

  /**
   * Add a (x: string, y: double, z: double) series. This will draw an area that
   * covers the surface between height y and z for each x.
   *
   * @param series the series to add. does not transfer ownership
   * @param border_style the border style
   * @param border_width the line width
   * @param point_style the point style
   * @param point_width the point size
   * @param smooth smooth this area?
   * @param line_style the line style ({solid,dashed})
   */
  void addSeries(
      Series3D<double, double, double>* series,
      const std::string& border_style = kDefaultBorderStyle,
      double border_width = kDefaultBorderWidth,
      const std::string& point_style = kDefaultPointStyle,
      double point_size = kDefaultPointSize,
      bool smooth = false);

  /**
   * Add an axis to the chart. This method should only be called after all
   * series have been added to the chart.
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ LineChart::LineChart(
    NumericalDomain* y_domain /* = nullptr */) :
    canvas_(canvas),
    x_domain_(x_domain),
    y_domain_(x_domain),
    y_domain_(y_domain),
    num_series_(0) {}

void LineChart::addSeries(
+1 −1
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ PointChart::PointChart(
    NumericalDomain* y_domain /* = nullptr */) :
    canvas_(canvas),
    x_domain_(x_domain),
    y_domain_(x_domain),
    y_domain_(y_domain),
    num_series_(0) {}

void PointChart::addSeries(
Loading