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

plot/axis: rename the 'labels' option to 'label-format', update docs

parent f8158234
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -65,8 +65,8 @@ ReturnCode build(
    {"axis-right", bind(&expr_rewritev, _1, "axis-right", &layout_opts)},
    {"axis-bottom", bind(&expr_rewritev, _1, "axis-bottom", &layout_opts)},
    {"axis-left", bind(&expr_rewritev, _1, "axis-left", &layout_opts)},
    {"axis-x-labels", bind(&expr_rewritev, _1, "axis-x-labels", &layout_opts)},
    {"axis-y-labels", bind(&expr_rewritev, _1, "axis-y-labels", &layout_opts)},
    {"axis-x-label-format", bind(&expr_rewritev, _1, "axis-x-label-format", &layout_opts)},
    {"axis-y-label-format", bind(&expr_rewritev, _1, "axis-y-label-format", &layout_opts)},
    {"axis-x-label-placement", bind(&expr_rewritev, _1, "axis-x-label-placement", &layout_opts)},
    {"axis-y-label-placement", bind(&expr_rewritev, _1, "axis-y-label-placement", &layout_opts)},
    {"axis-x-title", bind(&expr_rewritev, _1, "axis-x-title", &layout_opts)},
+2 −2
Original line number Diff line number Diff line
@@ -64,8 +64,8 @@ ReturnCode build(
    {"axis-right", bind(&expr_rewritev, _1, "axis-right", &layout_opts)},
    {"axis-bottom", bind(&expr_rewritev, _1, "axis-bottom", &layout_opts)},
    {"axis-left", bind(&expr_rewritev, _1, "axis-left", &layout_opts)},
    {"axis-x-labels", bind(&expr_rewritev, _1, "axis-x-labels", &layout_opts)},
    {"axis-y-labels", bind(&expr_rewritev, _1, "axis-y-labels", &layout_opts)},
    {"axis-x-label-format", bind(&expr_rewritev, _1, "axis-x-label-format", &layout_opts)},
    {"axis-y-label-format", bind(&expr_rewritev, _1, "axis-y-label-format", &layout_opts)},
    {"axis-x-label-placement", bind(&expr_rewritev, _1, "axis-x-label-placement", &layout_opts)},
    {"axis-y-label-placement", bind(&expr_rewritev, _1, "axis-y-label-placement", &layout_opts)},
    {"axis-x-title", bind(&expr_rewritev, _1, "axis-x-title", &layout_opts)},
+2 −2
Original line number Diff line number Diff line
@@ -326,8 +326,8 @@ ReturnCode build(
    {"axis-right", bind(&configure_axis, "left", 1, _1, &axes)},
    {"axis-bottom", bind(&configure_axis, "top", 2, _1, &axes)},
    {"axis-left", bind(&configure_axis, "right", 3, _1, &axes)},
    {"axis-x-labels", bind(&expr_rewritev, _1, "labels", &axis_x_opts)},
    {"axis-y-labels", bind(&expr_rewritev, _1, "labels", &axis_y_opts)},
    {"axis-x-label-format", bind(&expr_rewritev, _1, "label-format", &axis_x_opts)},
    {"axis-y-label-format", bind(&expr_rewritev, _1, "label-format", &axis_y_opts)},
    {
      "axis-x-label-placement",
      expr_calln_fn({
+55 −38
Original line number Diff line number Diff line
@@ -38,7 +38,7 @@ static const double kDefaultTickLengthPT = 4;

enum class AxisAlign {X, Y, TOP, RIGHT, BOTTOM, LEFT};

enum class AxisLabelAttach {BEGIN, CENTER, END};
enum class AxisLabelAttach {TOP, RIGHT, BOTTOM, LEFT};

struct AxisDefinition;

@@ -48,37 +48,49 @@ using AxisLabelPlacement = std::function<ReturnCode (

struct AxisDefinition {
  AxisDefinition();

  /* layout */
  AxisAlign align;

  /* scale */
  ScaleConfig scale;

  /* title */
  std::string title;
  FontInfo title_font;
  Measure title_font_size;
  Color title_color;
  double title_offset;
  Measure title_padding;
  FontInfo title_font;
  Measure title_font_size;
  double title_rotate;
  double title_offset;

  /* ticks */
  double tick_offset;
  Measure tick_length;
  ScaleLayoutFn tick_placement;

  /* labels */
  ScaleLayoutFn label_placement;
  double label_offset;
  AxisLabelAttach label_attach;
  StrokeStyle border_style;
  Formatter label_formatter;
  double label_rotate;
  AxisLabelAttach label_attach;
  double label_offset;
  Measure label_padding;
  double label_rotate;
  FontInfo label_font;
  Measure label_font_size;
  Color label_color;
  Measure tick_length;

  /* border */
  StrokeStyle border_style;
};

AxisDefinition::AxisDefinition() :
    align(AxisAlign::X),
    title_rotate(0.0),
    title_offset(0.0),
    title_rotate(0.0),
    tick_offset(0.0),
    label_rotate(0.0),
    label_offset(0.0) {}
    label_offset(0.0),
    label_rotate(0.0) {}

void axis_convert_units(AxisDefinition* config, const Layer& layer) {
  convert_unit_typographic(
@@ -340,23 +352,24 @@ static ReturnCode axis_draw_vertical(
    style.color = axis_config.label_color;
    style.font_size = axis_config.label_font_size;

    double a;
    auto a = axis_config.label_rotate;
    HAlign ax;
    VAlign ay;
    switch (axis_config.label_attach) {
      case AxisLabelAttach::BEGIN:
      case AxisLabelAttach::LEFT:
        a = axis_config.label_rotate;
        ax = HAlign::LEFT;
        ay = VAlign::CENTER;
        break;
      case AxisLabelAttach::CENTER:
        p.x += label_size * 0.5 * label_position;
        a = axis_config.label_rotate;
      case AxisLabelAttach::TOP:
        ax = HAlign::CENTER;
        ay = VAlign::CENTER;
        ay = VAlign::TOP;
        break;
      case AxisLabelAttach::END:
        a = axis_config.label_rotate;
      case AxisLabelAttach::BOTTOM:
        ax = HAlign::CENTER;
        ay = VAlign::BOTTOM;
        break;
      case AxisLabelAttach::RIGHT:
        ax = HAlign::RIGHT;
        ay = VAlign::CENTER;
        break;
@@ -479,23 +492,24 @@ static ReturnCode axis_draw_horizontal(
    style.color = axis_config.label_color;
    style.font_size = axis_config.label_font_size;

    double a;
    auto a = axis_config.label_rotate;
    HAlign ax;
    VAlign ay;
    switch (axis_config.label_attach) {
      case AxisLabelAttach::BEGIN:
      case AxisLabelAttach::LEFT:
        a = axis_config.label_rotate;
        ax = HAlign::LEFT;
        ay = VAlign::CENTER;
        break;
      case AxisLabelAttach::CENTER:
        p.y += label_size * 0.5 * label_position;
        a = axis_config.label_rotate;
      case AxisLabelAttach::TOP:
        ax = HAlign::CENTER;
        ay = VAlign::CENTER;
        ay = VAlign::TOP;
        break;
      case AxisLabelAttach::END:
        a = axis_config.label_rotate;
      case AxisLabelAttach::BOTTOM:
        ax = HAlign::CENTER;
        ay = VAlign::BOTTOM;
        break;
      case AxisLabelAttach::RIGHT:
        ax = HAlign::RIGHT;
        ay = VAlign::CENTER;
        break;
@@ -647,39 +661,39 @@ ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {

  switch (config->align) {
    case AxisAlign::X:
      config->label_attach = AxisLabelAttach::CENTER;
      config->label_attach = AxisLabelAttach::TOP;
      config->title_offset = 1;
      config->tick_offset = 0;
      config->label_offset = 1;
      break;
    case AxisAlign::TOP:
      config->label_attach = AxisLabelAttach::CENTER;
      config->label_attach = AxisLabelAttach::TOP;
      config->title_offset = 1;
      config->tick_offset = -1;
      config->label_offset = 1;
      break;
    case AxisAlign::BOTTOM:
      config->label_attach = AxisLabelAttach::CENTER;
      config->label_attach = AxisLabelAttach::BOTTOM;
      config->title_offset = -1;
      config->tick_offset = 1;
      config->label_offset = -1;
      break;
    case AxisAlign::Y:
      config->label_attach = AxisLabelAttach::BEGIN;
      config->label_attach = AxisLabelAttach::LEFT;
      config->title_offset = 1;
      config->title_rotate = -90;
      config->tick_offset = 0;
      config->label_offset = 1;
      break;
    case AxisAlign::LEFT:
      config->label_attach = AxisLabelAttach::BEGIN;
      config->label_attach = AxisLabelAttach::LEFT;
      config->title_offset = 1;
      config->title_rotate = -90;
      config->tick_offset = -1;
      config->label_offset = 1;
      break;
    case AxisAlign::RIGHT:
      config->label_attach = AxisLabelAttach::END;
      config->label_attach = AxisLabelAttach::RIGHT;
      config->title_offset = -1;
      config->title_rotate = -90;
      config->tick_offset = 1;
@@ -690,16 +704,18 @@ ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {
  {
    auto rc = expr_walk_map(expr_next(expr), {
      /* label options */
      {"labels", bind(&format_configure, _1, &config->label_formatter)},
      {"label-placement", bind(&scale_configure_layout, _1, &config->label_placement)},
      {"label-format", bind(&format_configure, _1, &config->label_formatter)},
      {
        "label-attach",
        expr_to_enum_fn<AxisLabelAttach>(&config->label_attach, {
          { "begin", AxisLabelAttach::BEGIN },
          { "center", AxisLabelAttach::CENTER },
          { "end", AxisLabelAttach::END },
          { "top", AxisLabelAttach::TOP },
          { "right", AxisLabelAttach::RIGHT },
          { "bottom", AxisLabelAttach::BOTTOM },
          { "left", AxisLabelAttach::LEFT },
        })
      },
      {"label-offset", bind(&expr_to_float64, _1, &config->label_offset)},
      {"label-padding", bind(&expr_to_measure, _1, &config->label_padding)},
      {"label-rotate", bind(&expr_to_float64, _1, &config->label_rotate)},
      {"label-font-size", bind(&expr_to_measure, _1, &config->label_font_size)},
@@ -720,6 +736,7 @@ ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {
      {"title", bind(&expr_to_string, _1, &config->title)},
      {"title-font-size", bind(&expr_to_measure, _1, &config->title_font_size)},
      {"title-color", bind(&expr_to_color, _1, &config->title_color)},
      {"title-offset", bind(&expr_to_float64, _1, &config->title_offset)},
      {"title-padding", bind(&expr_to_measure, _1, &config->title_padding)},
      {"title-rotate", bind(&expr_to_float64, _1, &config->title_rotate)},

+70 −34
Original line number Diff line number Diff line
@@ -34,30 +34,32 @@ properties:
          label-placement <label-placement>
        examples: |
          ;; subdivide the axis with 10 label-placement
      - name: labels
      - name: label-format
        desc: |
          The 'labels' option controls how axis labels are formatted.
        desc_code: |
          labels <labels>
        examples: |
          ;; use scientific labels for the top/bottom axes
          labels (scientific)
      - name: label-font-size
          label-format (scientific)
      - name: label-attach
        desc: |
          Set the label font size. See the [measure](#FIXME) page for more details on valid values.
          Controls how labels are attached to the axis. Useful in conjunction
          with the `label-rotate` option.
        desc_code: |
          label-font-size <measure>
          label-attach [top|right|bottom|left]
        examples: |
          ;; set the label font size to 14pt
          label-font-size 14pt
      - name: label-color
          ;; set label attach to left
          label-attach left
      - name: label-offset
        desc: |
          Set the label color. See the [color](#FIXME) page for more details on valid values.
          Controls to which side of the axis the labels are placed. Value is
          clamped to [-1, 1].
        desc_code: |
          label-color <color>
          label-offset <value>
        examples: |
          ;; set the label color to grey
          label-color #eee
          ;; center the labels
          label-offset 0
      - name: label-padding
        desc: |
          Set the label padding/spacing. See the [measure](#FIXME) page for more details on valid values.
@@ -74,26 +76,51 @@ properties:
        examples: |
          ;; rotate the label by 45deg clockwise
          label-rotate 45
      - name: label-attach
      - name: label-font-size
        desc: |
          Controls how labels are attached to the axis. Useful in conjunction
          with the `label-rotate` option.
          Set the label font size. See the [measure](#FIXME) page for more details on valid values.
        desc_code: |
          label-font-size <measure>
        examples: |
          ;; set the label font size to 14pt
          label-font-size 14pt
      - name: label-color
        desc: |
          Set the label color. See the [color](#FIXME) page for more details on valid values.
        desc_code: |
          label-attach [begin|center|end]
          label-color <color>
        examples: |
          ;; set label attach to center
          label-attach center
          ;; set the label color to grey
          label-color #eee

  - title: "Tick Options"
    anchor: tick-options
    properties:
      - name: tick-placement
        desc: |
          The 'label-placement' option controls the axis "tick" placement.
          The 'tick-placement' option controls where on the axis the "ticks" are
          placed.
        desc_code: |
          label-placement <label-placement>
          tick-placement <tick-placement>
        examples: |
          ;; subdivide the axis with 10 label-placement
          ;; subdivide the axis into 10 parts
      - name: tick-offset
        desc: |
          Controls to which side of the axis the ticks are drawn. Value is
          clamped to [-1, 1].
        desc_code: |
          tick-offset <value>
        examples: |
          ;; center the ticks
          ticks-offset 0
      - name: tick-length
        desc: |
          Controls the length of the ticks
        desc_code: |
          tick-length <measure>
        examples: |
          ;; set tick length to 1em
          ticks-length 1em

  - title: "Scale Options"
    anchor: scale-options
@@ -155,22 +182,15 @@ properties:
        examples: |
          ;; set the axis title to "Time"
          title "Time"
      - name: title-font-size
      - name: title-offset
        desc: |
          Set the title font size. See the [measure](#FIXME) page for more details on valid values.
          Controls to which side of the axis the title is placed. Value is
          clamped to [-1, 1].
        desc_code: |
          title-font-size <measure>
          title-offset <value>
        examples: |
          ;; set the title font size to 14pt
          title-font-size 14pt
      - name: title-color
        desc: |
          Set the title color. See the [color](#FIXME) page for more details on valid values.
        desc_code: |
          title-color <color>
        examples: |
          ;; set the title color to grey
          title-color #eee
          ;; center the title
          title-offset 0
      - name: title-padding
        desc: |
          Set the title padding/spacing. See the [measure](#FIXME) page for more details on valid values.
@@ -187,6 +207,22 @@ properties:
        examples: |
          ;; rotate the title by 45deg clockwise
          title-rotate 45
      - name: title-font-size
        desc: |
          Set the title font size. See the [measure](#FIXME) page for more details on valid values.
        desc_code: |
          title-font-size <measure>
        examples: |
          ;; set the title font size to 14pt
          title-font-size 14pt
      - name: title-color
        desc: |
          Set the title color. See the [color](#FIXME) page for more details on valid values.
        desc_code: |
          title-color <color>
        examples: |
          ;; set the title color to grey
          title-color #eee


  - title: "Border Options"
Loading