Commit 512d4707 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

consistent interfaces

parent 2259bc3c
Loading
Loading
Loading
Loading
+26 −7
Original line number Diff line number Diff line
@@ -13,8 +13,10 @@
namespace fnordmetric {
namespace ui {

double LineChart::kDefaultLineWidth = 2.0f;
char LineChart::kDefaultLineStyle[] = "solid";
double LineChart::kDefaultLineWidth = 2.0f;
char LineChart::kDefaultPointStyle[] = "none";
double LineChart::kDefaultPointSize = 3.0f;

LineChart::LineChart(
    Canvas* canvas,
@@ -27,13 +29,17 @@ LineChart::LineChart(

void LineChart::addSeries(
      Series2D<double, double>* series,
      const std::string& line_style /* = kDefaultLineStyle */,
      double line_width /* = kDefaultLineWidth */,
      bool smooth /* = false */,
      const std::string& line_style /* = kDefaultLineStyle */) {
      const std::string& point_style /* = kDefaultLineStyle */,
      double point_size /* = kDefaultPointsize */,
      bool smooth /* = false */) {
  Line line;
  line.color = seriesColor(series);
  line.width = line_width;
  line.style = line_style;
  line.line_style = line_style;
  line.line_width = line_width;
  line.point_style = point_style;
  line.point_size = point_size;
  line.smooth = smooth;

  for (const auto& spoint : series->getData()) {
@@ -162,6 +168,7 @@ void LineChart::render(

  for (const auto& line : lines_) {
    std::vector<std::pair<double, double>> coords;

    for (const auto& point : line.points) {
      coords.emplace_back(
          padding_left + x_domain->scale(point.first) * inner_width,
@@ -170,11 +177,23 @@ void LineChart::render(

    target->drawPath(
      coords,
      line.style,
      line.width,
      line.line_style,
      line.line_width,
      line.smooth,
      line.color,
      "line");

    if (line.point_style != "none") {
      for (const auto& point : coords) {
        target->drawPoint(
          point.first,
          point.second,
          line.point_style,
          line.point_size,
          line.color,
          "point");
      }
    }
  }

  target->finishGroup();
+11 −5
Original line number Diff line number Diff line
@@ -29,8 +29,10 @@ class Domain;
 */
class LineChart : public Drawable {
public:
  static double kDefaultLineWidth;
  static char kDefaultLineStyle[];
  static double kDefaultLineWidth;
  static char kDefaultPointStyle[];
  static double kDefaultPointSize;

  /**
   * Create a new line chart
@@ -55,9 +57,11 @@ public:
   */
  void addSeries(
      Series2D<double, double>* series,
      const std::string& line_style = kDefaultLineStyle,
      double line_width = kDefaultLineWidth,
      bool smooth = false,
      const std::string& line_style = kDefaultLineStyle);
      const std::string& point_style = kDefaultLineStyle,
      double point_size = kDefaultPointSize,
      bool smooth = false);

  /**
   * Add an axis to the chart. This method should only be called after all
@@ -83,8 +87,10 @@ protected:

  struct Line {
    std::vector<std::pair<double, double>> points;
    double width;
    std::string style;
    std::string line_style;
    double line_width;
    std::string point_style;
    double point_size;
    std::string color;
    bool smooth;
  };
+3 −7
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public:
    //testSimplePointChart();
    //testVariableSizePointChart();
    //testSimpleLineChart();
    //testPointLineChart();
    testPointLineChart();
    //testMultiChart();
    testSimpleAreaChart();
  }
@@ -693,15 +693,11 @@ public:
    ui::Canvas canvas;

    auto line_chart = canvas.addChart<LineChart>(&x_domain, &y_domain);
    line_chart->addSeries(&series1);
    line_chart->addSeries(&series2);
    line_chart->addSeries(&series1, "solid", 2, "circle", 4);
    line_chart->addSeries(&series2, "solid", 2, "circle", 4);
    line_chart->addAxis(AxisDefinition::BOTTOM);
    line_chart->addAxis(AxisDefinition::LEFT);

    auto point_chart = canvas.addChart<PointChart>(&x_domain, &y_domain);
    point_chart->addSeries(&series1, "circle", 4);
    point_chart->addSeries(&series2, "circle", 4);

    auto svg = canvas.renderSVG();
  }