Commit 95cbf4a9 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

update examples

parent 4babdb97
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -75,13 +75,14 @@ ReturnCode draw(

ReturnCode build_legend(
    const PlotLinesConfig& config,
    const std::string& title,
    const std::string& legend_key,
    LegendItemMap* legend) {
  LegendItemGroup legend_items;

  for (const auto& g : config.groups) {
    LegendItem li;
    li.title = g.key;
    li.title = g.key.empty() ? title :g.key;
    li.color = config.colors.empty()
        ? Color{}
        : config.colors[g.begin % config.colors.size()];
@@ -107,6 +108,8 @@ ReturnCode configure(
  std::string scale_x = SCALE_DEFAULT_X;
  std::string scale_y = SCALE_DEFAULT_Y;

  std::string title;

  std::string legend_key = LEGEND_DEFAULT;

  std::optional<Color> color;
@@ -122,6 +125,7 @@ ReturnCode configure(
    {"y", configure_series_fn(data, &data_y)},
    {"y-scale", bind(&configure_string, _1, &scale_y)},
    {"group", configure_series_fn(data, &data_group)},
    {"title", bind(&configure_string, _1, &title)},
    {"color", configure_color_opt(&color)},
    {"colors", configure_series_fn(data, &colors)},
    {"stroke", bind(&configure_measure_rel, _1, doc.dpi, doc.font_size, &line_width)},
@@ -178,7 +182,7 @@ ReturnCode configure(
      groups_to_colors(config->groups, color_palette));

  /* build legend items */
  if (auto rc = build_legend(*config, legend_key, legend); !rc) {
  if (auto rc = build_legend(*config, title, legend_key, legend); !rc) {
    return rc;
  }

+16 −27
Original line number Diff line number Diff line
width: 1200px;
height: 480px;

plot {
  ymin: -30;
  ymax: 40;
  xdomain: categorical;
  xdomain-format: string;
  data: csv('tests/testdata/city_temperatures.csv');
  x: month;
  y: temperature;
  group: city;

  legend: inside bottom left;
  axis-y-min: -30;
  axis-y-max: 40;

  series {
    title: "New York";
    xs: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec;
    ys: -0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5;
    point-size: 3.3pt;
  }
  margin-right: 2.4em;

  series {
    title: "北京市   ";
    xs: Jan, Feb, Mar, Apr,  May,  Jun,  Jul,  Aug,  Sep,  Oct,  Nov, Dec;
    ys: -4, -1.4, 5.4, 13.5, 19.9, 24.3, 26.3, 24.9, 19.9, 13.1, 4.7, -1.8;
    point-size: 3.3pt;
  layer {
    type: lines;
  }

  series {
    title: "Москва";
    xs: Jan,  Feb,  Mar,  Apr, May,  Jun,  Jul,  Aug,  Sep,  Oct, Nov, Dec;
    ys: -7.4, -5.8, -0.1, 7.1, 14.7, 17.7, 20.6, 18.8, 12.6, 6.1, 1.1, -3.6;
    point-size: 3.3pt;
  layer {
    type: points;
  }

  series {
    title: "Berlin";
    xs: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec;
    ys: -0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0;
    point-size: 3.3pt;
  legend {
    position: bottom left inside;
  }

}
+119 −119

File changed.

Preview size limit exceeded, changes collapsed.

+18 −28
Original line number Diff line number Diff line
width: 1200px;
height: 480px;

plot {
  ymin: -10;
  ymax: 32;
  ydomain: inverted;
  xdomain: categorical;
  xdomain-format: string;
  legend: bottom left inside;
  data: csv('tests/testdata/city_temperatures.csv');
  x: month;
  y: temperature;
  group: city;

  series {
    title: "New York";
    xs: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec;
    ys: -0.2, 0.8, 5.7, 11.3, 17.0, 22.0, 24.8, 24.1, 20.1, 14.1, 8.6, 2.5;
    point-size: 3.3pt;
  }
  axis-y: inverted;
  axis-y-min: -10;
  axis-y-max: 32;

  series {
    title: "北京市   ";
    xs: Jan, Feb, Mar, Apr,  May,  Jun,  Jul,  Aug,  Sep,  Oct,  Nov, Dec;
    ys: -4, -1.4, 5.4, 13.5, 19.9, 24.3, 26.3, 24.9, 19.9, 13.1, 4.7, -1.8;
    point-size: 3.3pt;
  }
  margin-right: 2.4em;

  series {
    title: "Москва";
    xs: Jan,  Feb,  Mar,  Apr, May,  Jun,  Jul,  Aug,  Sep,  Oct, Nov, Dec;
    ys: -7.4, -5.8, -0.1, 7.1, 14.7, 17.7, 20.6, 18.8, 12.6, 6.1, 1.1, -3.6;
    point-size: 3.3pt;
  layer {
    type: lines;
  }

  series {
    title: "Berlin";
    xs: Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec;
    ys: -0.9, 0.6, 3.5, 8.4, 13.5, 17.0, 18.6, 17.9, 14.3, 9.0, 3.9, 1.0;
    point-size: 3.3pt;
  layer {
    type: points;
  }

  legend {
    position: bottom left inside;
  }
}
+119 −119

File changed.

Preview size limit exceeded, changes collapsed.

Loading