Commit b867596b authored by Paul Asmuth's avatar Paul Asmuth
Browse files

Legend#addEntry

parent 83a37f4a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -242,6 +242,7 @@ void AreaChart3D<TX, TY, TZ>::addSeries(Series3D<TX, TY, TZ>* series) {

  // FIXPAUL: stacked areas, missing data
  areas_.emplace_back(area);
  Drawable::addSeries(series);
}

template <typename TX, typename TY, typename TZ>
+2 −0
Original line number Diff line number Diff line
@@ -240,6 +240,8 @@ void BarChart3D<TX, TY, TZ>::addSeries(Series3D<TX, TY, TZ>* series) {
  if (!series->hasProperty(Series::P_COLOR)) {
    color_palette_.setNextColor(series);
  }

  Drawable::addSeries(series);
}

template <typename TX, typename TY, typename TZ>
+17 −8
Original line number Diff line number Diff line
@@ -524,7 +524,8 @@ void Canvas::renderRightLegend(
    estimateTextLength(title) + kLegendLabelPadding;

  for (const auto& entry : legend->entries()) {
    auto this_len = estimateTextLength(entry.first) + kLegendLabelPadding;
    auto this_len = estimateTextLength(std::get<0>(entry)) +
        kLegendLabelPadding;

    /* line wrap */
    if (lx - this_len < lx_boundary) {
@@ -538,13 +539,13 @@ void Canvas::renderRightLegend(
        bottom ?
            height - kLegendPointSize * 0.4f :
            height + kLegendPointSize * 2.0f,
        "circle",
        std::get<2>(entry),
        kLegendPointSize,
        entry.second,
        std::get<1>(entry),
        "point");

    target->drawText(
      entry.first,
      std::get<0>(entry),
      lx - kLegendPointWidth,
      height,
      "end",
@@ -598,7 +599,8 @@ void Canvas::renderLeftLegend(
      horiz_padding - estimateTextLength(title) - kLegendLabelPadding;

  for (const auto& entry : legend->entries()) {
    auto this_len = estimateTextLength(entry.first) + kLegendLabelPadding;
    auto this_len = estimateTextLength(std::get<0>(entry)) + 
        kLegendLabelPadding;

    /* line wrap */
    if (lx + this_len > lx_boundary) {
@@ -613,13 +615,13 @@ void Canvas::renderLeftLegend(
        bottom ?
            height - kLegendPointSize * 0.4f :
            height + kLegendPointSize * 2.0f,
        "circle",
        std::get<2>(entry),
        kLegendPointSize,
        entry.second,
        std::get<1>(entry),
        "point");

    target->drawText(
      entry.first,
      std::get<0>(entry),
      lx + kLegendPointWidth,
      height,
      "start",
@@ -665,6 +667,13 @@ LegendDefinition* Canvas::addLegend(
  return legends_.back().get();
}

LegendDefinition* Canvas::legend() const {
  if (legends_.size() == 0) {
    return nullptr;
  } else {
    return legends_.back().get();
  }
}

}
}
+5 −0
Original line number Diff line number Diff line
@@ -78,6 +78,11 @@ public:
      LegendDefinition::kPlacement placement,
      const std::string& title);

  /**
   * Return the legend or nullptr
   */
  LegendDefinition* legend() const;

  /**
   * Render the contents of this canvas to the provided render target
   *
+23 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@
namespace fnordmetric {
namespace ui {

Drawable::Drawable(Canvas* canvas) : canvas_(canvas) {}

void Drawable::setTitle(const std::string& title) {
  printf("TITLE: %s\n", title.c_str());
}
@@ -28,6 +30,27 @@ LegendDefinition* Drawable::addLegend(
    LegendDefinition::kPlacement placement,
    const std::string& title) {
  canvas_->addLegend(vert_pos, horiz_pos, placement, title);
  updateLegend();
}

void Drawable::addSeries(Series* series) {
  all_series_.push_back(series);
  updateLegend();
}

void Drawable::updateLegend() {
  auto legend = canvas_->legend();

  if (legend == nullptr) {
    return;
  }

  for (const auto& series : all_series_) {
    legend->addEntry(
        series->name(),
        series->getProperty(Series::P_COLOR),
        "circle");
  }
}

}
Loading