Commit 7b9adae6 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

add 'border-{top,right,bottom,left}-{color,width}' properties'

parent 1140d0c5
Loading
Loading
Loading
Loading
+108 −57
Original line number Diff line number Diff line
width: 2000px;
height: 1080px;
width: 1920px;
height: 1200px;

background-color: #000;
margin: 2pt;

border-top-width: 4px;
border-right-width: 4px;
border-bottom-width: 4px;
border-left-width: 4px;

box {
  position: top;
  height: 100px;
  background-color: #eee;
  border-bottom-width: 1px;
  border-bottom-color: #ccc;
}

box {
  background-color: #fff;
  position: right;
  width: 600px;
  width: 570px;

  margin-top: 2em;
  margin-left: 1em;

  border-left-width: 1px;
  border-left-color: #ccc;

  box {
    position: top;
    height: 500px;
    height: 400px;

    scale-y-min: 0;
    scale-y-max: 140;

    scale-y-max: 60;
    scale-y-min: -40;
    scale-x-min: -60;
    scale-x-max: 60;

    gridlines {}

    areas {
      xs: csv('tests/testdata/measurement.csv', time);
      ys: csv('tests/testdata/measurement.csv', value2);
      colors: #06c;
    points {
      xs: csv('tests/testdata/point_example.csv', x);
      ys: csv('tests/testdata/point_example.csv', y);
      sizes: csv('tests/testdata/point_example.csv', z);
      labels: csv('tests/testdata/point_example.csv', z);
      colors: #4572a7, #aa4643;
      size: 2pt;
    }

    axis {
@@ -47,7 +70,7 @@ box {

  box {
    position: top;
    height: 500px;
    height: 400px;

    scale-y-min: 0;
    scale-y-max: 140;
@@ -82,10 +105,13 @@ box {

box {
  height: 250px;

  position: top;
  margin-top: 1em;
  margin-bottom: 1em;
  background-color: #fff;

  border-bottom-width: 1px;
  border-bottom-color: #ccc;

  box {
    width: 460px;
@@ -93,35 +119,46 @@ box {

    margin-left: .75em;

    scale-x-padding: 0.5;
    scale-y: log;
    scale-y-min: 0;
    scale-y-max: 55;
    scale-x-min: -3.5;
    scale-x-max: 3.5;

    bars {
      xs: csv(tests/testdata/histogram.csv, var0);
      ys: csv(tests/testdata/histogram.csv, var1);
      color: #888;
      size: 14pt;
      xs: -3, -2, -1, 0, 1, 2, 3;
      ys: 10, 28, 20, 26, 41, 44, 37;
      size: .6em;
      offset: .45em;
      color: #4572a7;
    }

    bars {
      xs: -3, -2, -1, 0, 1, 2, 3;
      ys: 12, 19, 23, 30, 35, 43, 33;
      size: .6em;
      offset: -.45em;
      color: #aa4643;
    }

    legend {
      position: top left inside;
      items: A, B;
      colors: #4572a7, #aa4643;
    }

    axis {
      position: bottom;
      layout: linear(1, align 1);
      layout: linear(1, align -3);
    }

    axis {
      position: top;
      layout: linear(1, align 1);
    }

    axis {
      position: left;
      width: 60px;
    }

    legend {
      position: top right inside;
      items: "New York";
      colors: #4572a7;
      layout: linear(10);
    }
  }

@@ -133,29 +170,39 @@ box {
    margin-right: .75em;

    scale-x-padding: 0.5;
    scale-y: log;
    scale-y-min: 5;
    scale-y-max: 60;

    bars {
      xs: csv(tests/testdata/histogram.csv, var0);
      ys: csv(tests/testdata/histogram.csv, var1);
      color: #888;
      size: 14pt;
    areas {
      xs: 0, 1, 2, 3, 4, 5, 6;
      ys: 10, 28, 20, 26, 41, 44, 37;
      size: .6em;
      offset: .45em;
      color: #4572a7;
    }

    areas {
      xs: 0, 1, 2, 3, 4, 5, 6;
      ys: 8, 19, 16, 23, 35, 29, 33;
      size: .6em;
      offset: -.45em;
      color: #aa4643;
    }

    legend {
      position: top left inside;
      items: A, B;
      colors: #4572a7, #aa4643;
    }

    axis {
      position: bottom;
      layout: linear(1, align 1);
      layout: discrete;
      labels: A, B, C, D, E, F, G;
    }

    axis {
      position: top;
      layout: linear(1, align 1);
    }

    legend {
      position: top right inside;
      items: "New York";
      colors: #4572a7;
    }
  }

@@ -166,34 +213,38 @@ box {
    margin-left: .75em;

    scale-x-padding: 0.5;
    scale-y: log;

    bars {
      xs: csv(tests/testdata/histogram.csv, var0);
      ys: csv(tests/testdata/histogram.csv, var1);
      color: #888;
      size: 14pt;
    scale-x-min: 0;
    scale-x-max: 200;
    scale-y-min: 0;
    scale-y-max: 280;

    points {
      xs: 10, 60, 160, 130, 150, 30, 115;
      ys: 80, 150, 180, 50, 80, 100, 190;
      sizes: 2pt, 9pt, 3pt, 6pt, 4pt, 3pt;
      colors: #4572a7, #aa4643;
    }

    legend {
      position: top left inside;
      items: A, B;
      colors: #4572a7, #aa4643;
    }

    axis {
      position: bottom;
      layout: linear(1, align 1);
      layout: linear(40);
    }

    axis {
      position: right;
      width: 60px;
      layout: linear(50);
    }

    axis {
      position: top;
      layout: linear(1, align 1);
    }

    legend {
      position: top right inside;
      items: "New York";
      colors: #4572a7;
    }
  }
}
@@ -201,8 +252,8 @@ box {
box {
  position: top;
  height: 280px;
  width: 1320px;
  margin-top: 1em;
  background-color: #fff;

  scale-y-min: 0;
  scale-y-max: 140;
@@ -235,8 +286,8 @@ box {
box {
  position: top;
  height: 220px;
  width: 1320px;
  margin-top: 1em;
  background-color: #fff;

  scale-y-min: 0;
  scale-y-max: 140;
@@ -263,8 +314,8 @@ box {
box {
  position: top;
  height: 280px;
  width: 1320px;
  margin-top: 1em;
  background-color: #fff;

  scale-y-min: 0;
  scale-y-max: 140;
+463 −419

File changed.

Preview size limit exceeded, changes collapsed.

+64 −2
Original line number Diff line number Diff line
@@ -43,6 +43,8 @@ ReturnCode draw(
    const BoxConfig& config,
    const LayoutInfo& layout,
    Layer* layer) {
  const auto bbox = layout.content_box;

  /* convert units  */
  auto margins = config.margins;
  for (auto& m : margins) {
@@ -51,7 +53,7 @@ ReturnCode draw(

  /* calculate margin box */
  auto margin_box = layout_margin_box(
      layout.content_box,
      bbox,
      margins[0],
      margins[1],
      margins[2],
@@ -59,7 +61,7 @@ ReturnCode draw(

  /* draw background */
  if (config.background) {
    const auto& bg_box = layout.content_box;
    const auto& bg_box = bbox;
    FillStyle bg_fill;
    bg_fill.color = *config.background;

@@ -71,6 +73,58 @@ ReturnCode draw(
        bg_fill);
  }

  /* draw top border  */
  if (config.borders[0].width > 0) {
    StrokeStyle border_style;
    border_style.line_width = config.borders[0].width;
    border_style.color = config.borders[0].color;

    strokeLine(
        layer,
        Point(bbox.x, bbox.y),
        Point(bbox.x + bbox.w, bbox.y),
        border_style);
  }

  /* draw right border  */
  if (config.borders[1].width > 0) {
    StrokeStyle border_style;
    border_style.line_width = config.borders[1].width;
    border_style.color = config.borders[1].color;

    strokeLine(
        layer,
        Point(bbox.x + bbox.w, bbox.y),
        Point(bbox.x + bbox.w, bbox.y + bbox.h),
        border_style);
  }

  /* draw top border  */
  if (config.borders[2].width > 0) {
    StrokeStyle border_style;
    border_style.line_width = config.borders[2].width;
    border_style.color = config.borders[2].color;

    strokeLine(
        layer,
        Point(bbox.x, bbox.y + bbox.h),
        Point(bbox.x + bbox.w, bbox.y + bbox.h),
        border_style);
  }

  /* draw left border  */
  if (config.borders[3].width > 0) {
    StrokeStyle border_style;
    border_style.line_width = config.borders[3].width;
    border_style.color = config.borders[3].color;

    strokeLine(
        layer,
        Point(bbox.x, bbox.y),
        Point(bbox.x, bbox.y + bbox.h),
        border_style);
  }

  /* layout and draw children */
  std::vector<ElementPlacement> children;
  for (const auto& c : config.children) {
@@ -131,6 +185,14 @@ ReturnCode configure(
    {"margin-right", bind(&configure_measure, _1, &config->margins[1])},
    {"margin-bottom", bind(&configure_measure, _1, &config->margins[2])},
    {"margin-left", bind(&configure_measure, _1, &config->margins[3])},
    {"border-top-color", bind(&configure_color, _1, &config->borders[0].color)},
    {"border-right-color", bind(&configure_color, _1, &config->borders[1].color)},
    {"border-bottom-color", bind(&configure_color, _1, &config->borders[2].color)},
    {"border-left-color", bind(&configure_color, _1, &config->borders[3].color)},
    {"border-top-width", bind(&configure_measure, _1, &config->borders[0].width)},
    {"border-right-width", bind(&configure_measure, _1, &config->borders[1].width)},
    {"border-bottom-width", bind(&configure_measure, _1, &config->borders[2].width)},
    {"border-left-width", bind(&configure_measure, _1, &config->borders[3].width)},
    {"scale-x", bind(&domain_configure, _1, &config->scale_x)},
    {"scale-x-min", bind(&configure_float_opt, _1, &config->scale_x.min)},
    {"scale-x-max", bind(&configure_float_opt, _1, &config->scale_x.max)},
+6 −0
Original line number Diff line number Diff line
@@ -36,6 +36,11 @@
namespace plotfx {
namespace box {

struct BoxBorderConfig {
  Color color;
  Measure width;
};

struct BoxConfig {
  std::vector<ElementRef> children;
  FontInfo font;
@@ -49,6 +54,7 @@ struct BoxConfig {
  ScaleLayoutFn scale_layout_x;
  ScaleLayoutFn scale_layout_y;
  std::array<Measure, 4> margins;
  std::array<BoxBorderConfig, 4> borders;
  LayoutSettings layout;
};