Commit 2e1ca841 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add support for setting the background grid stroke style

parent 6e30975c
Loading
Loading
Loading
Loading
+12 −13
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include "graphics/brush.h"
#include "scale.h"
#include "color_reader.h"
#include "style.h"
#include "style_reader.h"
#include "sexpr_conv.h"
#include "sexpr_util.h"

@@ -39,8 +41,7 @@ struct GridlineDefinition {
  ScaleConfig scale_y;
  ScaleLayoutFn layout_x;
  ScaleLayoutFn layout_y;
  Measure line_width;
  Color line_color;
  StrokeStyle stroke_style;
};

ReturnCode draw(
@@ -52,14 +53,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);

  const auto& bbox = layout.content_box;

  StrokeStyle style;
  style.line_width = config->line_width;
  style.color = config->line_color;

  ScaleLayout slayout_x;
  config->layout_x(config->scale_x, format_noop(), &slayout_x);

@@ -73,7 +70,7 @@ ReturnCode draw(
        layer,
        Point(line_x, bbox.y),
        Point(line_x, bbox.y + bbox.h),
        style);
        config->stroke_style);
  }

  for (const auto& tick : slayout_y.positions) {
@@ -83,7 +80,7 @@ ReturnCode draw(
        layer,
        Point(bbox.x, line_y),
        Point(bbox.x + bbox.w, line_y),
        style);
        config->stroke_style);
  }

  return OK;
@@ -92,8 +89,8 @@ ReturnCode draw(
ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {
  /* set defaults from environment */
  auto c = std::make_shared<GridlineDefinition>();
  c->line_width = from_pt(1);
  c->line_color = Color::fromRGB(.9, .9, .9); // TODO
  c->stroke_style.line_width = from_pt(1, env.dpi);
  c->stroke_style.color = Color::fromRGB(.9, .9, .9);

  /* parse properties */
  auto config_rc = expr_walk_map(expr_next(expr), {
@@ -109,8 +106,10 @@ ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {
    {"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->line_color)},
    {"stroke", bind(&measure_read, _1, &c->line_width)},
    {"color", bind(&color_read, env, _1, &c->stroke_style.color)},
    {"stroke-color", bind(&color_read, env, _1, &c->stroke_style.color)},
    {"stroke-width", bind(&measure_read, _1, &c->stroke_style.line_width)},
    {"stroke-style", bind(&stroke_style_read, env, _1, &c->stroke_style)},
  });

  if (!config_rc) {
+22 −6
Original line number Diff line number Diff line
@@ -34,15 +34,31 @@ properties:
        examples: |
          ;; set the stroke to 2px solid
          stroke (2px solid)
      - name: color
      - name: stroke-style
        desc: |
          Set the grids's color. See the
          [color](#FIXME) page for more details on valid values.
          Set the grid's stroke style. See the
          [stroke-style](#FIXME) page for more details on valid values.
        desc_code: |
          color <color>
          stroke (<stroke-style>)
        examples: |
          ;; set the color to #333
          color #333
          ;; set the stroke to dashed
          stroke-style dashed
      - name: stroke-width
        desc: |
          Set the grid's stroke width. See the
          [Typographic Units](#FIXME) page for more details on valid values.
        desc_code: |
          stroke-width <measure>
        examples: |
          ;; set the stroke width to 2pt
          stroke-width 2pt
      - name: stroke-color
        desc: |
          Set the grid's stroke color.
        desc_code: |
          stroke-color <color>
      - name: color
        alias: stroke-color

  - title: "Scale Options"
    anchor: scale-options
+9 −0
Original line number Diff line number Diff line
@@ -52,6 +52,15 @@ properties:
        examples: |
          ;; set the stroke to dashed
          stroke-style dashed
      - name: stroke-width
        desc: |
          Set the line's stroke width. See the
          [Typographic Units](#FIXME) page for more details on valid values.
        desc_code: |
          stroke-width <measure>
        examples: |
          ;; set the stroke width to 2pt
          stroke-width 2pt
      - name: stroke-color
        desc: |
          Set the stroke color.
+2 −1
Original line number Diff line number Diff line
@@ -25,7 +25,8 @@
      bar-stroke-width .8pt
      bar-fill hatch)
    grid (
      color #ccc
      stroke-color #000
      stroke-style dashed
      tick-placement-x (categorical-bounds)
      tick-placement-y (none))
    legend-top (
+7 −7
Original line number Diff line number Diff line
<svg xmlns="http://www.w3.org/2000/svg" width="2000.000000" height="540.000000" viewBox="0 0 2000 540">
  <rect width="2000.000000" height="540.000000" fill="#ffffff"/>
  <path stroke-width="2.777778" stroke="#cccccc" fill="none" d="M109.344 92.8889 L109.344 441 "/>
  <path stroke-width="2.777778" stroke="#cccccc" fill="none" d="M406.229 92.8889 L406.229 441 "/>
  <path stroke-width="2.777778" stroke="#cccccc" fill="none" d="M703.115 92.8889 L703.115 441 "/>
  <path stroke-width="2.777778" stroke="#cccccc" fill="none" d="M1000 92.8889 L1000 441 "/>
  <path stroke-width="2.777778" stroke="#cccccc" fill="none" d="M1296.89 92.8889 L1296.89 441 "/>
  <path stroke-width="2.777778" stroke="#cccccc" fill="none" d="M1593.77 92.8889 L1593.77 441 "/>
  <path stroke-width="2.777778" stroke="#cccccc" fill="none" d="M1890.66 92.8889 L1890.66 441 "/>
  <path stroke-width="2.777778" stroke="#000000" fill="none" d="M109.344 92.8889 L109.344 441 " stroke-dasharray="5.55556 5.55556 " stroke-dashoffset="0.000000"/>
  <path stroke-width="2.777778" stroke="#000000" fill="none" d="M406.229 92.8889 L406.229 441 " stroke-dasharray="5.55556 5.55556 " stroke-dashoffset="0.000000"/>
  <path stroke-width="2.777778" stroke="#000000" fill="none" d="M703.115 92.8889 L703.115 441 " stroke-dasharray="5.55556 5.55556 " stroke-dashoffset="0.000000"/>
  <path stroke-width="2.777778" stroke="#000000" fill="none" d="M1000 92.8889 L1000 441 " stroke-dasharray="5.55556 5.55556 " stroke-dashoffset="0.000000"/>
  <path stroke-width="2.777778" stroke="#000000" fill="none" d="M1296.89 92.8889 L1296.89 441 " stroke-dasharray="5.55556 5.55556 " stroke-dashoffset="0.000000"/>
  <path stroke-width="2.777778" stroke="#000000" fill="none" d="M1593.77 92.8889 L1593.77 441 " stroke-dasharray="5.55556 5.55556 " stroke-dashoffset="0.000000"/>
  <path stroke-width="2.777778" stroke="#000000" fill="none" d="M1890.66 92.8889 L1890.66 441 " stroke-dasharray="5.55556 5.55556 " stroke-dashoffset="0.000000"/>
  <path stroke-width="2.222222" stroke="#000000" fill="none" d="M218.509 210.376 L218.509 249.539 L249.064 249.539 L249.064 210.376 Z"/>
  <path stroke-width="2.222222" stroke="#000000" fill="none" d="M515.394 114.646 L515.394 232.133 L545.95 232.133 L545.95 114.646 Z"/>
  <path stroke-width="2.222222" stroke="#000000" fill="none" d="M812.28 197.322 L812.28 210.376 L842.835 210.376 L842.835 197.322 Z"/>
Loading