Commit 0f63937b authored by Laura Schlimmer's avatar Laura Schlimmer
Browse files

wire up tooltip/labels

parent 19448b1b
Loading
Loading
Loading
Loading
+31 −15
Original line number Diff line number Diff line
@@ -117,10 +117,12 @@ protected:
  struct Area {
    std::string color;
    std::string line_style;
    std::string series;
    double line_width;
    std::string point_style;
    double point_size;
    std::vector<std::tuple<TX, TY, TZ>> points;
    std::vector<std::string> labels;
  };

  void render(
@@ -235,6 +237,7 @@ void AreaChart3D<TX, TY, TZ>::addSeries(Series3D<TX, TY, TZ>* series) {

  // FIXPAUL catch conversion errors
  Area area;
  area.series = series->name();
  area.color = series->getProperty(Series::P_COLOR);
  area.line_style = series->getProperty(Series::P_LINE_STYLE);
  area.line_width = std::stod(series->getProperty(Series::P_LINE_WIDTH));
@@ -249,6 +252,9 @@ void AreaChart3D<TX, TY, TZ>::addSeries(Series3D<TX, TY, TZ>* series) {
        point.x(),
        point.y(),
        point.z());

    area.labels.emplace_back(
        series->labelFor(&point));
  }

  // FIXPAUL: stacked areas, missing data
@@ -266,7 +272,6 @@ void AreaChart3D<TX, TY, TZ>::render(
    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) {
      const auto& point = area.points[i];
@@ -279,7 +284,16 @@ void AreaChart3D<TX, TY, TZ>::render(

      area_coords.emplace_back(draw_x, draw_y2);
      border_top_coords.emplace_back(draw_x, draw_y2);
      point_coords.emplace_back(draw_x, draw_y2);

      target->drawPoint(
          draw_x,
          draw_y2,
          area.point_style,
          area.point_size,
          area.color,
          "point",
          area.labels[i],
          area.series);
    }

    for (int i = area.points.size() - 1; i >= 0; --i) {
@@ -294,7 +308,16 @@ void AreaChart3D<TX, TY, TZ>::render(

      if (std::get<1>(point) != 0) {
        border_bottom_coords.emplace_back(draw_x, draw_y1);
        point_coords.emplace_back(draw_x, draw_y1);

        target->drawPoint(
            draw_x,
            draw_y1,
            area.point_style,
            area.point_size,
            area.color,
            "point",
            area.labels[i],
            area.series);
      }
    }

@@ -325,18 +348,6 @@ void AreaChart3D<TX, TY, TZ>::render(
            "line");
      }
    }

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


@@ -433,6 +444,11 @@ void AreaChart2D<TX, TY>::addSeries(Series2D<TX, TY>* series) {
          Series::P_LABEL,
          &series3d->getData().back(),
          series->getProperty(Series::P_LABEL, &point));
    } else {
        series3d->setProperty(
          Series::P_LABEL,
          &series3d->getData().back(),
          series->labelFor(&point));
    }
  }

+9 −9
Original line number Diff line number Diff line
@@ -211,15 +211,15 @@ void LineChart2D<TX, TY>::render(
      auto ss_x = viewport->paddingLeft() + x * viewport->innerWidth();
      auto ss_y = viewport->paddingTop() + (1.0 - y) * viewport->innerHeight();

      if (point_style != "none") {
      target->drawPoint(
          ss_x,
          ss_y,
          point_style,
          point_size,
          color,
            "point");
      }
          "point",
          series->labelFor(&point),
          series->name());

      coords.emplace_back(ss_x, ss_y);
    }
+14 −9
Original line number Diff line number Diff line
@@ -220,15 +220,15 @@ void PointChart3D<TX, TY, TZ>::render(
      auto ss_x = viewport->paddingLeft() + x * viewport->innerWidth();
      auto ss_y = viewport->paddingTop() + (1.0 - y) * viewport->innerHeight();

      if (point_style != "none") {
      target->drawPoint(
          ss_x,
          ss_y,
          point_style,
          point.z(),
          color,
            "point");
      }
          "point",
          series->labelFor(&point),
          series->name());
    }
  }

@@ -332,6 +332,11 @@ void PointChart2D<TX, TY>::addSeries(Series2D<TX, TY>* series) {
          Series::P_LABEL,
          &series3d->getData().back(),
          series->getProperty(Series::P_LABEL, &point));
    } else {
        series3d->setProperty(
          Series::P_LABEL,
          &series3d->getData().back(),
          series->labelFor(&point));
    }
  }

+3 −1
Original line number Diff line number Diff line
@@ -53,7 +53,9 @@ public:
      const std::string& point_type,
      double point_size,
      const std::string& color,
      const std::string& class_name = "") = 0;
      const std::string& class_name = "",
      const std::string& label = "",
      const std::string& series = "") = 0;

  virtual void drawRect(
      double x,
+10 −4
Original line number Diff line number Diff line
@@ -135,18 +135,24 @@ public:
      const std::string& point_type,
      double point_size,
      const std::string& color,
      const std::string& class_name) override {
      const std::string& class_name /* = "" */,
      const std::string& label /* = "" */,
      const std::string& series /* = "" */) override {
    std::string class_str(class_name);
    class_str += " ";
    class_str += color;

    /* point_type: circle */
    // FIXPAUL escape label
    appendLine(
        "<circle cx='%f' cy='%f' r='%f' class='%s' />\n", 
        "<circle cx='%f' cy='%f' r='%f' class='%s' fm:label='%s' "
            "fm:series='%s'></circle>\n",
        x,
        y,
        point_size,
        class_str.c_str());
        point_type == "none" ? 0 : point_size,
        class_str.c_str(),
        label.c_str(),
        series.c_str());
  }

   void drawPath(