Commit 1433f5e5 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

integrate linechart with new legend interface

parent ee29f84d
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -81,11 +81,6 @@ struct LegendConfig {

using LegendMap = std::unordered_map<std::string, LegendConfig>;

void legend_items_add(
    const std::string& key,
    LegendItemGroup item_group,
    LegendItemMap* map);

ReturnCode legend_configure(
    const Document& doc,
    const plist::Property& prop,
@@ -108,5 +103,10 @@ ReturnCode legend_draw(
    const Rectangle& bbox,
    Layer* layer);

void legend_items_add(
    const std::string& key,
    LegendItemGroup item_group,
    LegendItemMap* map);

} // namespace plotfx
+26 −1
Original line number Diff line number Diff line
@@ -73,6 +73,26 @@ ReturnCode draw(
  return OK;
}

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

  for (const auto& g : config.groups) {
    LegendItem li;
    li.title = g.key;
    li.color = config.colors.empty()
        ? Color{}
        : config.colors[g.begin % config.colors.size()];

    legend_items.items.emplace_back(li);
  }

  legend_items_add(legend_key, legend_items, legend);
  return OK;
}

ReturnCode configure(
    const plist::PropertyList& plist,
    const DataContext& data,
@@ -147,7 +167,7 @@ ReturnCode configure(
    config->groups.emplace_back(g);
  }

  /* return element */
  /* setup config */
  config->x = domain_translate(*domain_x, *data_x);
  config->y = domain_translate(*domain_y, *data_y);
  config->line_width = measure_or(line_width, from_pt(kDefaultLineWidthPT, doc.dpi));
@@ -156,6 +176,11 @@ ReturnCode configure(
      color_default,
      groups_to_colors(config->groups, color_palette));

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

  return OK;
}

+7 −9
Original line number Diff line number Diff line
@@ -3,20 +3,18 @@ height: 480px;

plot {
  data: csv('tests/testdata/city_temperatures.csv');
  x: $1;
  y: $2;
  group: $0;
  x: var(month);
  y: var(temperature);
  group: var(city);

  axis-x-format: string;
  axis-y-min: -10;
  axis-y-max: 32;

  legend {
    position: bottom center inside;
  }

  layer {
    type: lines;
    line-color: $0;
  }

  legend {
    position: bottom center inside;
  }
}
+7 −9
Original line number Diff line number Diff line
@@ -3,20 +3,18 @@ height: 480px;

plot {
  data: csv('tests/testdata/city_temperatures.csv');
  x: $1;
  y: $2;
  group: $0;
  x: var(month);
  y: var(temperature);
  group: var(city);

  axis-x-format: string;
  axis-y-min: -10;
  axis-y-max: 32;

  legend {
    position: bottom left inside;
  }

  layer {
    type: lines;
    line-color: $0;
  }

  legend {
    position: bottom left inside;
  }
}
+7 −9
Original line number Diff line number Diff line
@@ -3,20 +3,18 @@ height: 480px;

plot {
  data: csv('tests/testdata/city_temperatures.csv');
  x: $1;
  y: $2;
  group: $0;
  x: var(month);
  y: var(temperature);
  group: var(city);

  axis-x-format: string;
  axis-y-min: -10;
  axis-y-max: 32;

  legend {
    position: bottom right inside;
  }

  layer {
    type: lines;
    line-color: $0;
  }

  legend {
    position: bottom right inside;
  }
}
Loading