Commit 179dbe65 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

plot/lines: improved stroke style configuration, remove marker options

parent a04fce53
Loading
Loading
Loading
Loading
+31 −25
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@
#include "scale.h"
#include "layout.h"
#include "color_reader.h"
#include "marker.h"
#include "style.h"
#include "style_reader.h"
#include "graphics/path.h"
#include "graphics/brush.h"
#include "graphics/text.h"
@@ -41,9 +44,10 @@ struct PlotLinesConfig {
  ScaleConfig scale_x;
  ScaleConfig scale_y;
  std::vector<DataGroup> groups;
  Color color;
  std::vector<Measure> marker_sizes;
  Measure line_width;
  StrokeStyle stroke_style;
  Measure marker_size;
  Marker marker_shape;
  Color marker_color;
  std::vector<std::string> labels;
  FontInfo label_font;
  Color label_color;
@@ -81,14 +85,10 @@ ReturnCode draw(
  conv.font_size = layer->font_size;
  conv.parent_size = layer->font_size;

  measure_normalize(conv, &config->line_width);
  measure_normalize(conv, &config->stroke_style.line_width);
  measure_normalize(conv, &config->label_padding);
  measure_normalize(conv, &config->label_font_size);

  measure_normalizev(
      conv,
      &*config->marker_sizes.begin(),
      &*config->marker_sizes.end());
  measure_normalize(conv, &config->marker_size);

  /* draw lines */
  for (const auto& group : config->groups) {
@@ -108,20 +108,17 @@ ReturnCode draw(
      }
    }

    StrokeStyle style;
    style.line_width = config->line_width;
    style.color = config->color;
    strokePath(layer, clip, path, style);
    strokePath(layer, clip, path, config->stroke_style);
  }

  /* draw points */
  if (!config->marker_sizes.empty()) {
  if (config->marker_size > 0) {
    for (size_t i = 0; i < config->x.size(); ++i) {
      auto sx = clip.x + config->x[i];
      auto sy = clip.y + clip.h - config->y[i];

      const auto& color = config->color;
      auto size = config->marker_sizes[i % config->marker_sizes.size()];
      const auto& color = config->marker_color;
      auto size = config->marker_size;

      Path path;
      path.moveTo(sx + size, sy);
@@ -134,10 +131,7 @@ ReturnCode draw(
  for (size_t i = 0; i < config->labels.size(); ++i) {
    const auto& label_text = config->labels[i];

    auto label_offset  = config->marker_sizes.empty()
        ? 0
        : config->marker_sizes[i % config->marker_sizes.size()];

    auto label_offset  = config->marker_size;
    auto label_padding = label_offset + measure_or(
        config->label_padding,
        from_em(kDefaultLabelPaddingEM, config->label_font_size));
@@ -167,10 +161,12 @@ ReturnCode build(
    ElementRef* elem) {
  /* set defaults from environment */
  auto c = std::make_shared<PlotLinesConfig>();
  c->color = env.foreground_color;
  c->label_font = env.font;
  c->label_font_size = env.font_size;
  c->line_width = from_pt(kDefaultLineWidthPT);
  c->stroke_style.color = env.foreground_color;
  c->stroke_style.line_width = from_pt(kDefaultLineWidthPT);
  c->marker_shape = marker_create_disk();
  c->marker_color = env.foreground_color;

  /* parse properties */
  std::vector<std::string> data_x;
@@ -189,9 +185,19 @@ ReturnCode build(
    {"scale-y", bind(&scale_configure_kind, _1, &c->scale_y)},
    {"scale-x-padding", bind(&expr_to_float64, _1, &c->scale_x.padding)},
    {"scale-y-padding", bind(&expr_to_float64, _1, &c->scale_y.padding)},
    {"color", bind(&color_read, env, _1, &c->color)},
    {"stroke", bind(&measure_read, _1, &c->line_width)},
    {"marker-size", bind(&data_load, _1, &c->marker_sizes)},
    {
      "color",
      expr_calln_fn({
        bind(&color_read, env, _1, &c->stroke_style.color),
        bind(&color_read, env, _1, &c->marker_color),
      })
    },
    {"stroke-width", bind(&measure_read, _1, &c->stroke_style.line_width)},
    {"stroke-style", bind(&stroke_style_read, env, _1, &c->stroke_style)},
    {"stroke-color", bind(&color_read, env, _1, &c->stroke_style.color)},
    {"marker-size", bind(&measure_read, _1, &c->marker_size)},
    {"marker-shape", bind(&marker_configure, _1, &c->marker_shape)},
    {"marker-color", bind(&color_read, env, _1, &c->marker_color)},
    {"labels", bind(&data_load_strings, _1, &c->labels)},
    {"label-font-size", bind(&measure_read, _1, &c->label_font_size)},
    {"label-color", bind(&color_read, env, _1, &c->label_color)},
+28 −15
Original line number Diff line number Diff line
@@ -38,35 +38,48 @@ properties:

          ;; load a csv file
          data-y (csv myfile.csv mycolumn)
      - name: stroke
      - name: color
        desc: |
          Set the stroke and marker color.
        desc_code: |
          color <color>
      - name: stroke-style
        desc: |
          Set the line's stroke style. See the
          [stroke-style](#FIXME) page for more details on valid values.
        desc_code: |
          stroke (<stroke-style>)
        examples: |
          ;; set the stroke to 2px solid
          stroke (2px solid)
      - name: color
          ;; set the stroke to dashed
          stroke-style dashed
      - name: stroke-color
        desc: |
          Set the line color.
          Set the stroke color.
        desc_code: |
          color <color>
          stroke-color <color>
      - name: marker-shape
        desc: |
          Set the marker-shape for the plot. If set, a marker will be drawn for each
          point in the dataset at the points (x, y) coordinate.
        desc_code: |
          marker-shape (<marker-shape>)
        examples: |
          ;; set marker size to 'hexagon'
          marker-shape (hexagon)
      - name: marker-size
        alias: marker-sizes
      - name: marker-sizes
        desc: |
          Set the marker-sizes for the plot. If set, a marker will be drawn for each
          point in the dataset at the points (x, y) coordinate.
        desc_code: |
          marker-sizes (<values>...)
          data-size (csv <file> <column>)
          marker-size <measure>
        examples: |
          ;; list of static values
          marker-sizes (2pt 4pt 2pt)

          ;; load a csv file
          data-size (csv myfile.csv mysizes)
          ;; set marker size to 2pt
          marker-size 2pt
      - name: marker-color
        desc: |
          Set the marker color.
        desc_code: |
          marker-color <color>

  - title: "Label Options"
    anchor: label-options
+1 −1
Original line number Diff line number Diff line
<svg xmlns="http://www.w3.org/2000/svg" width="900.000000" height="480.000000" viewBox="0 0 900 480">
  <rect width="900.000000" height="480.000000" fill="#ffffff"/>
  <path fill="#eeeeee" d="M82.4313 14.6667 L885.333 14.6667 L885.333 435.6 L82.4313 435.6 L82.4313 14.6667 "/>
  <path fill="#eeeeee" d="M82.4313 14.6667 L885.333 14.6667 L885.333 435.6 L82.4313 435.6 Z"/>
  <path stroke-width="1.333333" stroke="#ffffff" fill="none" d="M82.4313 14.6667 L82.4313 435.6 "/>
  <path stroke-width="1.333333" stroke="#ffffff" fill="none" d="M162.721 14.6667 L162.721 435.6 "/>
  <path stroke-width="1.333333" stroke="#ffffff" fill="none" d="M243.012 14.6667 L243.012 435.6 "/>
+1 −1
Original line number Diff line number Diff line
@@ -17,7 +17,7 @@
    lines (
        data-x (10 20 30 40 50)
        data-y (1.23 10.32 -6.23 4.43 3.45)
        marker-size (3pt))
        marker-size 3pt)
    legend-overlay (
        position (bottom right)
        item-flow on
+1 −1
Original line number Diff line number Diff line
<svg xmlns="http://www.w3.org/2000/svg" width="960.000000" height="240.000000" viewBox="0 0 960 240">
  <rect width="960.000000" height="240.000000" fill="#ffffff"/>
  <path fill="#eeeeee" d="M54.9469 14.6667 L905.053 14.6667 L905.053 195.6 L54.9469 195.6 L54.9469 14.6667 "/>
  <path fill="#eeeeee" d="M54.9469 14.6667 L905.053 14.6667 L905.053 195.6 L54.9469 195.6 Z"/>
  <path stroke-width="1.333333" stroke="#ffffff" fill="none" d="M54.9469 14.6667 L54.9469 195.6 "/>
  <path stroke-width="1.333333" stroke="#ffffff" fill="none" d="M196.631 14.6667 L196.631 195.6 "/>
  <path stroke-width="1.333333" stroke="#ffffff" fill="none" d="M338.316 14.6667 L338.316 195.6 "/>
Loading