Commit df7f13c5 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

consistent option names

parent 1d021df4
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -168,6 +168,15 @@ std::vector<double> scale_untranslate(
ReturnCode scale_configure_kind(
    const Expr* expr,
    ScaleConfig* domain) {
  if (expr && expr_is_list(expr)) {
    expr = expr_get_list(expr);
  } else {
    return errorf(
        ERROR,
        "invalid argument; expected a list but got: {}",
        expr_inspect(expr)); // FIXME
  }

  for (; expr; expr = expr_next(expr)) {
    if (expr_is_value(expr, "linear")) {
      domain->kind = ScaleKind::LINEAR;
+35 −33
Original line number Diff line number Diff line
@@ -216,31 +216,33 @@ ReturnCode build(
    const Expr* expr,
    ElementRef* elem) {
  /* set defaults from environment */
  auto config = std::make_shared<PlotAreaConfig>();
  auto c = std::make_shared<PlotAreaConfig>();

  /* parse properties */
  auto config_rc = expr_walk_map(expr_next(expr), {
    {"data-x", bind(&data_load, _1, &config->x)},
    {"data-y", bind(&data_load, _1, &config->y)},
    {"xoffsetdata", bind(&data_load, _1, &config->xoffset)},
    {"yoffsetdata", bind(&data_load, _1, &config->yoffset)},
    {"range-x-min", bind(&expr_to_float64_opt, _1, &config->scale_x.min)},
    {"range-x-max", bind(&expr_to_float64_opt, _1, &config->scale_x.max)},
    {"scale-x", bind(&scale_configure_kind, _1, &config->scale_x)},
    {"scale_x-padding", bind(&expr_to_float64, _1, &config->scale_x.padding)},
    {"range-y-min", bind(&expr_to_float64_opt, _1, &config->scale_y.min)},
    {"range-y-max", bind(&expr_to_float64_opt, _1, &config->scale_y.max)},
    {"scale-y", bind(&scale_configure_kind, _1, &config->scale_y)},
    {"scale_y-padding", bind(&expr_to_float64, _1, &config->scale_y.padding)},
    {"data-x", bind(&data_load, _1, &c->x)},
    {"data-y", bind(&data_load, _1, &c->y)},
    {"data-x-offset", bind(&data_load, _1, &c->xoffset)},
    {"data-y-offset", bind(&data_load, _1, &c->yoffset)},
    {"range-x", bind(&expr_to_float64_opt_pair, _1, &c->scale_x.min, &c->scale_x.max)},
    {"range-x-min", bind(&expr_to_float64_opt, _1, &c->scale_x.min)},
    {"range-x-max", bind(&expr_to_float64_opt, _1, &c->scale_x.max)},
    {"range-y", bind(&expr_to_float64_opt_pair, _1, &c->scale_y.min, &c->scale_y.max)},
    {"range-y-min", bind(&expr_to_float64_opt, _1, &c->scale_y.min)},
    {"range-y-max", bind(&expr_to_float64_opt, _1, &c->scale_y.max)},
    {"scale-x", bind(&scale_configure_kind, _1, &c->scale_x)},
    {"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", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &c->colors)},
    {"colors", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &c->colors)},
    {
      "direction",
      expr_to_enum_fn<Direction>(&config->direction, {
      expr_to_enum_fn<Direction>(&c->direction, {
        { "horizontal", Direction::HORIZONTAL },
        { "vertical", Direction::VERTICAL },
      })
    },
    {"color", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &config->colors)},
    {"colors", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &config->colors)},
  });

  if (!config_rc) {
@@ -248,53 +250,53 @@ ReturnCode build(
  }

  /* check configuraton */
  if (config->x.size() != config->y.size()) {
  if (c->x.size() != c->y.size()) {
    return error(
        ERROR,
        "the length of the 'xs' and 'ys' properties must be equal");
        "the length of the 'data-x' and 'data-y' properties must be equal");
  }

  if (!config->xoffset.empty() &&
      config->xoffset.size() != config->x.size()) {
  if (!c->xoffset.empty() &&
      c->xoffset.size() != c->x.size()) {
    return error(
        ERROR,
        "the length of the 'xs' and 'x-offsets' properties must be equal");
        "the length of the 'data-x' and 'data-x-offset' properties must be equal");
  }

  if (!config->yoffset.empty() &&
      config->yoffset.size() != config->y.size()) {
  if (!c->yoffset.empty() &&
      c->yoffset.size() != c->y.size()) {
    return error(
        ERROR,
        "the length of the 'ys' and 'y-offsets' properties must be equal");
        "the length of the 'data-y' and 'data-y-offset' properties must be equal");
  }

  /* scale autoconfig */
  for (const auto& v : config->x) {
  for (const auto& v : c->x) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_x);
      scale_fit(v.value, &c->scale_x);
    }
  }

  for (const auto& v : config->xoffset) {
  for (const auto& v : c->xoffset) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_x);
      scale_fit(v.value, &c->scale_x);
    }
  }

  for (const auto& v : config->y) {
  for (const auto& v : c->y) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_y);
      scale_fit(v.value, &c->scale_y);
    }
  }

  for (const auto& v : config->yoffset) {
  for (const auto& v : c->yoffset) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_y);
      scale_fit(v.value, &c->scale_y);
    }
  }

  *elem = std::make_shared<Element>();
  (*elem)->draw = bind(&draw, config, _1, _2);
  (*elem)->draw = bind(&draw, c, _1, _2);
  return OK;
}

+4 −3
Original line number Diff line number Diff line
@@ -522,9 +522,10 @@ ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {

  {
    auto rc = expr_walk_map(expr_next(expr), {
      {"layout", bind(&scale_configure_layout, _1, &config->scale_layout)},
      {"min", bind(&expr_to_float64_opt, _1, &config->scale.min)},
      {"max", bind(&expr_to_float64_opt, _1, &config->scale.max)},
      {"ticks", bind(&scale_configure_layout, _1, &config->scale_layout)},
      {"range", bind(&expr_to_float64_opt_pair, _1, &config->scale.min, &config->scale.max)},
      {"range-min", bind(&expr_to_float64_opt, _1, &config->scale.min)},
      {"range-max", bind(&expr_to_float64_opt, _1, &config->scale.max)},
      {"scale", bind(&scale_configure_kind, _1, &config->scale)},
      {"scale-padding", bind(&expr_to_float64, _1, &config->scale.padding)},
      {"labels", bind(&data_load_strings, _1, &config->label_override)},
+39 −38
Original line number Diff line number Diff line
@@ -316,36 +316,36 @@ ReturnCode build(
    const Expr* expr,
    ElementRef* elem) {
  /* set defaults from environment */
  auto config = std::make_shared<PlotBarsConfig>();
  config->label_font = env.font;
  config->label_font_size = env.font_size;
  auto c = std::make_shared<PlotBarsConfig>();
  c->label_font = env.font;
  c->label_font_size = env.font_size;

  /* parse properties */
  auto config_rc = expr_walk_map(expr_next(expr), {
    {"data-x", bind(&data_load, _1, &config->x)},
    {"data-y", bind(&data_load, _1, &config->y)},
    {"xoffsetdata", bind(&data_load, _1, &config->xoffset)},
    {"yoffsetdata", bind(&data_load, _1, &config->yoffset)},
    {"range-x-min", bind(&expr_to_float64_opt, _1, &config->scale_x.min)},
    {"range-x-max", bind(&expr_to_float64_opt, _1, &config->scale_x.max)},
    {"scale-x", bind(&scale_configure_kind, _1, &config->scale_x)},
    {"scale_x-padding", bind(&expr_to_float64, _1, &config->scale_x.padding)},
    {"range-y-min", bind(&expr_to_float64_opt, _1, &config->scale_y.min)},
    {"range-y-max", bind(&expr_to_float64_opt, _1, &config->scale_y.max)},
    {"scale-y", bind(&scale_configure_kind, _1, &config->scale_y)},
    {"scale_y-padding", bind(&expr_to_float64, _1, &config->scale_y.padding)},
    {"size", bind(&data_load, _1, &config->sizes)},
    {"sizes", bind(&data_load, _1, &config->sizes)},
    {"data-x", bind(&data_load, _1, &c->x)},
    {"data-y", bind(&data_load, _1, &c->y)},
    {"data-x-offset", bind(&data_load, _1, &c->xoffset)},
    {"data-y-offset", bind(&data_load, _1, &c->yoffset)},
    {"range-x", bind(&expr_to_float64_opt_pair, _1, &c->scale_x.min, &c->scale_x.max)},
    {"range-x-min", bind(&expr_to_float64_opt, _1, &c->scale_x.min)},
    {"range-x-max", bind(&expr_to_float64_opt, _1, &c->scale_x.max)},
    {"range-y", bind(&expr_to_float64_opt_pair, _1, &c->scale_y.min, &c->scale_y.max)},
    {"range-y-min", bind(&expr_to_float64_opt, _1, &c->scale_y.min)},
    {"range-y-max", bind(&expr_to_float64_opt, _1, &c->scale_y.max)},
    {"scale-x", bind(&scale_configure_kind, _1, &c->scale_x)},
    {"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", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &c->colors)},
    {"colors", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &c->colors)},
    {
      "direction",
      expr_to_enum_fn<Direction>(&config->direction, {
      expr_to_enum_fn<Direction>(&c->direction, {
        { "horizontal", Direction::HORIZONTAL },
        { "vertical", Direction::VERTICAL },
      })
    },
    {"color", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &config->colors)},
    {"colors", expr_tov_fn<Color>(bind(&expr_to_color, _1, _2), &config->colors)},
    {"labels", bind(&data_load_strings, _1, &config->labels)},
    {"labels", bind(&data_load_strings, _1, &c->labels)},
  });

  if (!config_rc) {
@@ -353,53 +353,54 @@ ReturnCode build(
  }

  /* check configuraton */
  if (config->x.size() != config->y.size()) {
  if (c->x.size() != c->y.size()) {
    return error(
        ERROR,
        "the length of the 'xs' and 'ys' properties must be equal");
        "the length of the 'data-x' and 'data-y' properties must be equal");
  }

  if (!config->xoffset.empty() &&
      config->xoffset.size() != config->x.size()) {
  if (!c->xoffset.empty() &&
      c->xoffset.size() != c->x.size()) {
    return error(
        ERROR,
        "the length of the 'xs' and 'x-offsets' properties must be equal");
        "the length of the 'data-x' and 'data-x-offset' properties must be equal");
  }

  if (!config->yoffset.empty() &&
      config->yoffset.size() != config->y.size()) {
  if (!c->yoffset.empty() &&
      c->yoffset.size() != c->y.size()) {
    return error(
        ERROR,
        "the length of the 'ys' and 'y-offsets' properties must be equal");
        "the length of the 'data-y' and 'data-y-offset' properties must be equal");
  }


  /* scale autoconfig */
  for (const auto& v : config->x) {
  for (const auto& v : c->x) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_x);
      scale_fit(v.value, &c->scale_x);
    }
  }

  for (const auto& v : config->xoffset) {
  for (const auto& v : c->xoffset) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_x);
      scale_fit(v.value, &c->scale_x);
    }
  }

  for (const auto& v : config->y) {
  for (const auto& v : c->y) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_y);
      scale_fit(v.value, &c->scale_y);
    }
  }

  for (const auto& v : config->yoffset) {
  for (const auto& v : c->yoffset) {
    if (v.unit == Unit::USER) {
      scale_fit(v.value, &config->scale_y);
      scale_fit(v.value, &c->scale_y);
    }
  }

  *elem = std::make_shared<Element>();
  (*elem)->draw = bind(&draw, config, _1, _2);
  (*elem)->draw = bind(&draw, c, _1, _2);
  return OK;
}

+20 −18
Original line number Diff line number Diff line
@@ -82,26 +82,28 @@ ReturnCode draw(

ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {
  /* set defaults from environment */
  auto config = std::make_shared<GridlineDefinition>();
  config->line_width = from_pt(1);
  config->line_color = Color::fromRGB(.9, .9, .9); // TODO
  config->layout_x = bind(&scale_layout_subdivide, _1, _2, 10);
  config->layout_y = bind(&scale_layout_subdivide, _1, _2, 10);
  auto c = std::make_shared<GridlineDefinition>();
  c->line_width = from_pt(1);
  c->line_color = Color::fromRGB(.9, .9, .9); // TODO
  c->layout_x = bind(&scale_layout_subdivide, _1, _2, 10);
  c->layout_y = bind(&scale_layout_subdivide, _1, _2, 10);

  /* parse properties */
  auto config_rc = expr_walk_map(expr_next(expr), {
    {"range-x-min", bind(&expr_to_float64_opt, _1, &config->scale_x.min)},
    {"range-x-max", bind(&expr_to_float64_opt, _1, &config->scale_x.max)},
    {"ticks-x", bind(&scale_configure_layout, _1, &config->layout_x)},
    {"scale-x", bind(&scale_configure_kind, _1, &config->scale_x)},
    {"scale_x-padding", bind(&expr_to_float64, _1, &config->scale_x.padding)},
    {"range-y-min", bind(&expr_to_float64_opt, _1, &config->scale_y.min)},
    {"range-y-max", bind(&expr_to_float64_opt, _1, &config->scale_y.max)},
    {"ticks-y", bind(&scale_configure_layout, _1, &config->layout_y)},
    {"scale-y", bind(&scale_configure_kind, _1, &config->scale_y)},
    {"scale_y-padding", bind(&expr_to_float64, _1, &config->scale_y.padding)},
    {"color", bind(&expr_to_color, _1, &config->line_color)},
    {"stroke", bind(&expr_to_measure, _1, &config->line_width)},
    {"range-x", bind(&expr_to_float64_opt_pair, _1, &c->scale_x.min, &c->scale_x.max)},
    {"range-x-min", bind(&expr_to_float64_opt, _1, &c->scale_x.min)},
    {"range-x-max", bind(&expr_to_float64_opt, _1, &c->scale_x.max)},
    {"range-y", bind(&expr_to_float64_opt_pair, _1, &c->scale_y.min, &c->scale_y.max)},
    {"range-y-min", bind(&expr_to_float64_opt, _1, &c->scale_y.min)},
    {"range-y-max", bind(&expr_to_float64_opt, _1, &c->scale_y.max)},
    {"ticks-x", bind(&scale_configure_layout, _1, &c->layout_x)},
    {"ticks-y", bind(&scale_configure_layout, _1, &c->layout_y)},
    {"scale-x", bind(&scale_configure_kind, _1, &c->scale_x)},
    {"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(&expr_to_color, _1, &c->line_color)},
    {"stroke", bind(&expr_to_measure, _1, &c->line_width)},
  });

  if (!config_rc) {
@@ -109,7 +111,7 @@ ReturnCode build(const Environment& env, const Expr* expr, ElementRef* elem) {
  }

  *elem = std::make_shared<Element>();
  (*elem)->draw = bind(&draw, config, _1, _2);
  (*elem)->draw = bind(&draw, c, _1, _2);
  return OK;
}

Loading