Commit 83a37f4a authored by Paul Asmuth's avatar Paul Asmuth
Browse files

wire up legend positions

parent b570e211
Loading
Loading
Loading
Loading
+87 −26
Original line number Diff line number Diff line
@@ -384,8 +384,25 @@ void Canvas::renderOutsideLegends(
    RenderTarget* target,
    Viewport* viewport) const {
  for (const auto& legend : legends_) {
    if (legend->placement() != LegendDefinition::LEGEND_OUTSIDE) {
      continue;
    }

    target->beginGroup("legend");

    switch (legend->verticalPosition()) {
      case LegendDefinition::LEGEND_TOP: {
        switch (legend->horizontalPosition()) {
          case LegendDefinition::LEGEND_LEFT:
            renderLeftLegend(
                target,
                viewport,
                legend.get(),
                kLegendOutsideHorizPadding,
                false,
                true);
            break;
          case LegendDefinition::LEGEND_RIGHT:
            renderRightLegend(
                target,
                viewport,
@@ -393,8 +410,17 @@ void Canvas::renderOutsideLegends(
                kLegendOutsideHorizPadding,
                false,
                true);
    viewport->setPaddingTop(viewport->paddingTop() + kLegendOutsideVertPadding);
            break;
          }

        viewport->setPaddingTop(
            viewport->paddingTop() + kLegendOutsideVertPadding);
        break;
      }

      case LegendDefinition::LEGEND_BOTTOM: {
        switch (legend->horizontalPosition()) {
          case LegendDefinition::LEGEND_LEFT:
            renderLeftLegend(
                target,
                viewport,
@@ -402,7 +428,24 @@ void Canvas::renderOutsideLegends(
                kLegendOutsideHorizPadding,
                true,
                true);
    viewport->setPaddingBottom(viewport->paddingBottom() + kLegendOutsideVertPadding);
            break;
          case LegendDefinition::LEGEND_RIGHT:
            renderRightLegend(
                target,
                viewport,
                legend.get(),
                kLegendOutsideHorizPadding,
                true,
                true);
            break;

          }

        viewport->setPaddingBottom(
            viewport->paddingBottom() + kLegendOutsideVertPadding);
        break;
      }
    }

    target->finishGroup();
  }
@@ -414,18 +457,36 @@ void Canvas::renderInsideLegends(
  auto orig_padding = viewport->padding();

  for (const auto& legend : legends_) {
    if (legend->placement() != LegendDefinition::LEGEND_INSIDE) {
      continue;
    }

    target->beginGroup("legend");

    viewport->setPaddingTop(viewport->paddingTop() + kLegendInsideVertPadding);
    viewport->setPaddingBottom(
        viewport->paddingBottom() + kLegendInsideVertPadding);

    switch (legend->horizontalPosition()) {
      case LegendDefinition::LEGEND_LEFT:
        renderLeftLegend(
            target,
            viewport,
            legend.get(),
        kLegendInsideHorizPadding,
        true,
            kLegendOutsideHorizPadding,
            legend->verticalPosition() == LegendDefinition::LEGEND_BOTTOM,
            false);
        break;
      case LegendDefinition::LEGEND_RIGHT:
        renderRightLegend(
            target,
            viewport,
            legend.get(),
            kLegendOutsideHorizPadding,
            legend->verticalPosition() == LegendDefinition::LEGEND_BOTTOM,
            false);
        break;
      }

    target->finishGroup();
  }
@@ -445,7 +506,7 @@ void Canvas::renderRightLegend(
  double height;
  if (bottom) {
    height = viewport->paddingTop() + viewport->innerHeight()  -
      kLegendLineHeight * 0.2f;
      kLegendLineHeight * 0.3f;
  } else {
    height = viewport->paddingTop();
  }
@@ -519,7 +580,7 @@ void Canvas::renderLeftLegend(
  double height;
  if (bottom) {
    height = viewport->paddingTop() + viewport->innerHeight()  -
      kLegendLineHeight * 0.2f;
      kLegendLineHeight * 0.3f;
  } else {
    height = viewport->paddingTop();
  }
+8 −8
Original line number Diff line number Diff line
@@ -26,15 +26,15 @@ public:
  static const int kAxisPadding = 0; // FIXPAUL make configurable
  static const int kTickLength = 5; // FIXPAUL make configurable
  static const int kAxisLabelHeight = 20; // FIXPAUL make configurable
  static const int kAxisLabelWidth = 50.0f; // FIXPAUL make configurable
  static const int kAxisTitleLength = 20.0f; // FIXPAUL make configurable
  static const int kAxisLabelWidth = 50; // FIXPAUL make configurable
  static const int kAxisTitleLength = 20; // FIXPAUL make configurable
  static const int kCharWidth = 6.0f; // FIXPAUL make configurable
  static const int kLegendLabelPadding = 20.0f; // FIXPAUL make configurable
  static const int kLegendLineHeight = 20.0f; // FIXPAUL make configurable
  static const int kLegendInsideVertPadding = 10.0f;
  static const int kLegendInsideHorizPadding = 15.0f;
  static const int kLegendOutsideVertPadding = 10.0f;
  static const int kLegendOutsideHorizPadding = 25.0f;
  static const int kLegendLabelPadding = 20; // FIXPAUL make configurable
  static const int kLegendLineHeight = 20; // FIXPAUL make configurable
  static const int kLegendInsideVertPadding = 10;
  static const int kLegendInsideHorizPadding = 15;
  static const int kLegendOutsideVertPadding = 10;
  static const int kLegendOutsideHorizPadding = 25;
  static const int kLegendPointY = 6;
  static const int kLegendPointWidth = 8;
  static const int kLegendPointSize = 3;
+12 −0
Original line number Diff line number Diff line
@@ -56,6 +56,18 @@ public:
    return entries;
  }

  kVerticalPosition verticalPosition() const {
    return vert_pos_;
  }

  kHorizontalPosition horizontalPosition() const {
    return horiz_pos_;
  }

  kPlacement placement() const {
    return placement_;
  }

protected:
  kVerticalPosition vert_pos_;
  kHorizontalPosition horiz_pos_;