Commit 8bef873d authored by Paul Asmuth's avatar Paul Asmuth
Browse files

consistent configuration of typographic units

parent 41d461b3
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -38,14 +38,14 @@ ReturnCode build(
    {"data-x", bind(&expr_rewritev, _1, "data-x", &geom_opts)},
    {"data-y", bind(&expr_rewritev, _1, "data-y", &geom_opts)},
    {"data-color", bind(&expr_rewritev, _1, "data-color", &geom_opts)},
    {"data-size", bind(&expr_rewritev, _1, "data-size", &geom_opts)},
    {"data-shape", bind(&expr_rewritev, _1, "data-shape", &geom_opts)},
    {"size", bind(&expr_rewritev, _1, "size", &geom_opts)},
    {"sizes", bind(&expr_rewritev, _1, "sizes", &geom_opts)},
    {"size-map", bind(&expr_rewritev, _1, "size-map", &geom_opts)},
    {"color", bind(&expr_rewritev, _1, "color", &geom_opts)},
    {"color-map", bind(&expr_rewritev, _1, "color-map", &geom_opts)},
    {"marker-size", bind(&expr_rewritev, _1, "marker-size", &geom_opts)},
    {"marker-sizes", bind(&expr_rewritev, _1, "marker-sizes", &geom_opts)},
    {"marker-shape", bind(&expr_rewritev, _1, "marker-shape", &geom_opts)},
    {"marker-shapes", bind(&expr_rewritev, _1, "marker-shapes", &geom_opts)},
    {"labels", bind(&expr_rewritev, _1, "labels", &geom_opts)},
    {"label-font-size", bind(&expr_rewritev, _1, "label-font-size", &geom_opts)},

+2 −2
Original line number Diff line number Diff line
@@ -60,13 +60,13 @@ properties:
          point in the dataset at the points (x, y) coordinate.
        desc_code: |
          marker-sizes (<values>...)
          marker-sizes (csv <file> <column>)
          data-size (csv <file> <column>)
        examples: |
          ;; list of static values
          marker-sizes (2pt 4pt 2pt)

          ;; load a csv file
          marker-sizes (csv myfile.csv mysizes)
          data-size (csv myfile.csv mysizes)

  - title: "Label Options"
    anchor: label-options
+26 −6
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ struct PlotPointsConfig {
  ScaleConfig scale_y;
  Color color;
  std::vector<Color> colors;
  Measure size;
  std::vector<Measure> sizes;
  Marker shape;
  std::vector<Marker> shapes;
  std::vector<std::string> labels;
  FontInfo label_font;
@@ -84,6 +86,11 @@ ReturnCode draw(
      &*config->sizes.begin(),
      &*config->sizes.end());

  convert_unit_typographic(
      layer->dpi,
      layer->font_size,
      &config->size);

  /* draw markers */
  for (size_t i = 0; i < config->x.size(); ++i) {
    auto sx = clip.x + config->x[i];
@@ -94,11 +101,11 @@ ReturnCode draw(
        : config->colors[i % config->colors.size()];

    auto size = config->sizes.empty()
        ? from_pt(kDefaultPointSizePT, layer->dpi)
        ? config->size
        : config->sizes[i % config->sizes.size()];

    auto shape = config->shapes.empty()
        ? marker_create_disk()
        ? config->shape
        : config->shapes[i % config->shapes.size()];

    if (auto rc = shape(Point(sx, sy), size, color, layer); !rc) {
@@ -144,6 +151,8 @@ ReturnCode build(
  /* set defaults from environment */
  auto c = std::make_shared<PlotPointsConfig>();
  c->color = env.foreground_color;
  c->size = from_pt(kDefaultPointSizePT);
  c->shape = marker_create_disk();
  c->label_font = env.font;
  c->label_font_size = env.font_size;

@@ -151,12 +160,15 @@ ReturnCode build(
  std::vector<std::string> data_x;
  std::vector<std::string> data_y;
  std::vector<std::string> data_colors;
  std::vector<std::string> data_sizes;
  ColorMap color_map;

  auto config_rc = expr_walk_map(expr_next(expr), {
    {"data-x", bind(&data_load_strings, _1, &data_x)},
    {"data-y", bind(&data_load_strings, _1, &data_y)},
    {"data-color", bind(&data_load_strings, _1, &data_colors)},
    {"data-size", bind(&data_load_strings, _1, &data_sizes)},
    {"data-shape", bind(&marker_configure_list, _1, &c->shapes)},
    {"limit-x", bind(&expr_to_float64_opt_pair, _1, &c->scale_x.min, &c->scale_x.max)},
    {"limit-x-min", bind(&expr_to_float64_opt, _1, &c->scale_x.min)},
    {"limit-x-max", bind(&expr_to_float64_opt, _1, &c->scale_x.max)},
@@ -167,10 +179,8 @@ 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)},
    {"marker-size", bind(&data_load, _1, &c->sizes)},
    {"marker-sizes", bind(&data_load, _1, &c->sizes)},
    {"marker-shape", bind(&marker_configure_list, _1, &c->shapes)},
    {"marker-shapes", bind(&marker_configure_list, _1, &c->shapes)},
    {"marker-size", bind(&measure_read, _1, &c->size)},
    {"marker-shape", bind(&marker_configure, _1, &c->shape)},
    {"color", bind(&color_read, env, _1, &c->color)},
    {"color-map", bind(&color_map_read, env, _1, &color_map)},
    {"labels", bind(&data_load_strings, _1, &c->labels)},
@@ -231,6 +241,16 @@ ReturnCode build(
    c->colors.push_back(color);
  }

  /* convert size data */
  for (const auto& value : data_sizes) {
    Measure m;
    if (auto rc = parse_measure(value, &m); !rc) {
      return rc;
    }

    c->sizes.push_back(m);
  }

  /* return element */
  *elem = std::make_shared<Element>();
  (*elem)->draw = bind(&draw, c, _1, _2);
+44 −12
Original line number Diff line number Diff line
@@ -42,7 +42,9 @@ properties:
        desc: |
          Set the 'color' dataset for the plot. The 'color' dataset will be used to
          calculate the color of points. The mapping of input values to colors
          is controlled by the `color-map` option.
          is controlled by the `color-map` option. If no explicit `color-map`
          option is provided, the values `data-color` will be interpreted as
          hex color codes.
        desc_code: |
          data-color (<values>...)
          data-color (csv <file> <column>)
@@ -52,6 +54,33 @@ properties:

          ;; load a csv file
          data-color (csv myfile.csv mycolors)
      - name: data-size
        desc: |
          Set the 'size' dataset for the plot. The 'size' dataset will be used to
          calculate the size of points. The mapping of input values to typographic
          units is controlled by the `size-map` option.
        desc_code: |
          data-size (<values>...)
          data-size (csv <file> <column>)
        examples: |
          ;; list of static values
          data-size (2pt 8pt 5pt)

          ;; load a csv file
          data-size (csv myfile.csv mysizes)
      - name: data-shape
        desc: |
          Set the 'shape' dataset for the plot. The 'shape' dataset will be used to
          choose the marker shape of points.
        desc_code: |
          data-size (<values>...)
          data-size (csv <file> <column>)
        examples: |
          ;; list of static values
          data-size (hexagon circle square)

          ;; load a csv file
          data-size (csv myfile.csv myshapes)
      - name: color
        desc: |
          Set the point color. Note that this value is only used if no data-colors
@@ -65,20 +94,23 @@ properties:
        desc_code: |
          color-map <color-map>
      - 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,
          Set the marker size for the plot. Note that this value is only used i
          no data-size option is specified.
        desc_code: |
          marker-sizes (<values>...)
          marker-sizes (csv <file> <column>)
          marker-size <measure>
        examples: |
          ;; list of static values
          marker-sizes (2pt 4pt 2pt)

          ;; load a csv file
          marker-sizes (csv myfile.csv mysizes)
          ;; set the marker size to 5pt
          marker-size 5pt
      - name: marker-shape
        desc: |
          Set the marker shape for the plot. Note that this value is only used i
          no data-shape option is specified.
        desc_code: |
          marker-shape (<marker-shape>)
        examples: |
          ;; set the marker shape to 'hexagon'
          marker-shape (hexagon)

  - title: "Label Options"
    anchor: label-options
+1 −1
Original line number Diff line number Diff line
(chart/scatterplot
    data-x (csv tests/testdata/point_example.csv x)
    data-y (csv tests/testdata/point_example.csv y)
    marker-sizes (csv tests/testdata/point_example.csv z)
    data-size (csv tests/testdata/point_example.csv z)
    labels (csv tests/testdata/point_example.csv z)
    scale-x-padding 15
    scale-y-padding 15
Loading