Commit 9ffedf4f authored by Paul Asmuth's avatar Paul Asmuth
Browse files

port the remaining plot elements to the new command API

parent 844b6aae
Loading
Loading
Loading
Loading
+5 −6
Original line number Diff line number Diff line
@@ -21,12 +21,11 @@ using std::bind;
namespace clip {

ReturnCode arrow_draw_default(
    Context* ctx,
    const Point& from,
    const Point& to,
    const Measure& size,
    const Color& color,
    const Page& page,
    DrawCommandList* drawlist) {
    const Color& color) {
  auto direction = normalize(sub(to, from));
  auto ortho = vec2{direction.y, direction.x * -1};

@@ -45,14 +44,14 @@ ReturnCode arrow_draw_default(
  FillStyle fill_style;
  fill_style.color = color;

  draw_line(drawlist, from, to, line_style);
  draw_path(drawlist, head_path, {}, fill_style);
  draw_line(ctx, from, to, line_style);
  draw_path(ctx, head_path, {}, fill_style);

  return OK;
}

Arrow arrow_create_default() {
  return bind(&arrow_draw_default, _1, _2, _3, _4, _5, _6);
  return bind(&arrow_draw_default, _1, _2, _3, _4, _5);
}

} // namespace clip
+2 −3
Original line number Diff line number Diff line
@@ -25,12 +25,11 @@ namespace clip {

using Arrow = std::function<
    ReturnCode (
        Context* ctx,
        const Point& from,
        const Point& to,
        const Measure& size,
        const Color& color,
        const Page& page,
        DrawCommandList* drawlist)>;
        const Color& color)>;

Arrow arrow_create_default();

+2 −0
Original line number Diff line number Diff line
@@ -176,6 +176,8 @@ int main(int argc, const char** argv) {
          "ERROR: unable to read input file ({}): {}\n",
          flag_in,
          rc.message);

      return EXIT_FAILURE;
    }
  }

+14 −0
Original line number Diff line number Diff line
@@ -13,9 +13,16 @@
 */
#pragma once
#include "command.h"
#include "plot/areas.h"
#include "plot/axis.h"
#include "plot/bars.h"
#include "plot/errorbars.h"
#include "plot/grid.h"
#include "plot/labels.h"
#include "plot/lines.h"
#include "plot/points.h"
#include "plot/rectangles.h"
#include "plot/vectors.h"
#include "figure/legend.h"

namespace clip {
@@ -27,9 +34,16 @@ const CommandMap COMMANDS = {
  {"set-dpi", CommandFn(&context_configure)},
  {"layout/add-margins", CommandFn(&layout_add_margins)},
  {"plot/add-axes", CommandFn(&elements::plot::axis::axis_add_all)},
  {"plot/draw-areas", CommandFn(&elements::plot::areas::areas_draw)},
  {"plot/draw-axis", CommandFn(&elements::plot::axis::axis_draw)},
  {"plot/draw-bars", CommandFn(&elements::plot::bars::bars_draw)},
  {"plot/draw-errorbars", CommandFn(&elements::plot::errorbars::errorbars_draw)},
  {"plot/draw-grid", CommandFn(&elements::plot::grid::draw_grid)},
  {"plot/draw-labels", CommandFn(&elements::plot::labels::labels_draw)},
  {"plot/draw-lines", CommandFn(&elements::plot::lines::draw_lines)},
  {"plot/draw-points", CommandFn(&elements::plot::points::points_draw)},
  {"plot/draw-rectangles", CommandFn(&elements::plot::rectangles::rectangles_draw)},
  {"plot/draw-vectors", CommandFn(&elements::plot::vectors::vectors_draw)},
  {"figure/draw-legend", CommandFn(&elements::legend::legend_draw)},
};

+12 −0
Original line number Diff line number Diff line
@@ -24,6 +24,18 @@ void draw_shape(Context* ctx, draw_cmd::Shape elem) {
  ctx->drawlist.emplace_back(std::move(elem));
}

void draw_path(
    Context* ctx,
    const Path& path,
    StrokeStyle stroke_style,
    FillStyle fill_style) {
  draw_cmd::Shape shape;
  shape.path = path;
  shape.stroke_style = stroke_style;
  shape.fill_style = fill_style;
  draw_shape(ctx, shape);
}

void draw_line(
    Context* ctx,
    vec2 from,
Loading