Commit 00994f14 authored by Paul Asmuth's avatar Paul Asmuth
Browse files

Merge branch 'feature/legend_barchart' of github.com:plotfx/plotfx

parents a555a840 41f1cea4
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -134,4 +134,12 @@
  <path fill="#80699b" d="M929.211038 258.628571 L929.211038 342.457143 L938.78992 342.457143 L938.78992 258.628571 "/>
  <path fill="#80699b" d="M1019.238122 306.131429 L1019.238122 342.457143 L1028.817003 342.457143 L1028.817003 306.131429 "/>
  <path fill="#80699b" d="M1109.265205 333.142857 L1109.265205 342.457143 L1118.844087 342.457143 L1118.844087 333.142857 "/>
  <path fill="#4572a7" d="M102.5375 75.2 M92.5375 75.2 a5.0 5.0 0 1 0 10.0 0 a5.0 5.0 0 1 0 -10.0 0 "/>
  <text x="109.037500" y="80.200000" fill="#333333" font-size="14.666667" font-family="Arial,Helvetica,'Helvetica Neue',sans-serif">New York</text>
  <path fill="#aa4643" d="M213.721875 75.2 M203.721875 75.2 a5.0 5.0 0 1 0 10.0 0 a5.0 5.0 0 1 0 -10.0 0 "/>
  <text x="220.221875" y="80.200000" fill="#333333" font-size="14.666667" font-family="Arial,Helvetica,'Helvetica Neue',sans-serif">北京市   </text>
  <path fill="#89a54e" d="M308.15625 75.2 M298.15625 75.2 a5.0 5.0 0 1 0 10.0 0 a5.0 5.0 0 1 0 -10.0 0 "/>
  <text x="314.656250" y="80.200000" fill="#333333" font-size="14.666667" font-family="Arial,Helvetica,'Helvetica Neue',sans-serif">Москва</text>
  <path fill="#80699b" d="M407.45 75.2 M397.45 75.2 a5.0 5.0 0 1 0 10.0 0 a5.0 5.0 0 1 0 -10.0 0 "/>
  <text x="413.950000" y="80.200000" fill="#333333" font-size="14.666667" font-family="Arial,Helvetica,'Helvetica Neue',sans-serif">Berlin</text>
</svg>
 No newline at end of file
+6 −0
Original line number Diff line number Diff line
@@ -64,4 +64,10 @@
  <path fill="#89a54e" d="M532.293055 136.938079 L532.293055 435.6 L572.057174 435.6 L572.057174 136.938079 "/>
  <path fill="#89a54e" d="M812.585243 147.976171 L812.585243 435.6 L852.349361 435.6 L852.349361 147.976171 "/>
  <path fill="#89a54e" d="M1092.87743 170.143488 L1092.87743 435.6 L1132.641549 435.6 L1132.641549 170.143488 "/>
  <path fill="#4572a7" d="M122.115625 45.466667 M112.115625 45.466667 a5.0 5.0 0 1 0 10.0 0 a5.0 5.0 0 1 0 -10.0 0 "/>
  <text x="128.615625" y="50.466667" fill="#333333" font-size="14.666667" font-family="Arial,Helvetica,'Helvetica Neue',sans-serif">2008</text>
  <path fill="#aa4643" d="M203.940625 45.466667 M193.940625 45.466667 a5.0 5.0 0 1 0 10.0 0 a5.0 5.0 0 1 0 -10.0 0 "/>
  <text x="210.440625" y="50.466667" fill="#333333" font-size="14.666667" font-family="Arial,Helvetica,'Helvetica Neue',sans-serif">2009</text>
  <path fill="#89a54e" d="M285.765625 45.466667 M275.765625 45.466667 a5.0 5.0 0 1 0 10.0 0 a5.0 5.0 0 1 0 -10.0 0 "/>
  <text x="292.265625" y="50.466667" fill="#333333" font-size="14.666667" font-family="Arial,Helvetica,'Helvetica Neue',sans-serif">2010</text>
</svg>
 No newline at end of file
+1 −1
Original line number Diff line number Diff line
@@ -132,7 +132,7 @@ ReturnCode configure_layer(

  if (type == "bars")
    layer_builder = elem_builder<bars::PlotBarsConfig>(
        bind(&bars::configure, _1, _2, _3, scales, _4),
        bind(&bars::configure, _1, _2, _3, scales, legend_items, _4),
        &bars::draw);

  if (type == "labels")
+32 −0
Original line number Diff line number Diff line
@@ -231,11 +231,33 @@ ReturnCode draw(
  }
}

ReturnCode build_legend(
    const PlotBarsConfig& 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.empty() ? title : g.key;
    li.color = config.colors.empty()
        ? Color{}
        : config.colors[g.index[0] % 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,
    const Document& doc,
    const DomainMap& scales,
    LegendItemMap* legend,
    PlotBarsConfig* config) {
  SeriesRef data_x = find_maybe(data.defaults, "x");
  SeriesRef data_xoffset;
@@ -247,6 +269,10 @@ 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;

  Direction direction = Direction::VERTICAL;

  std::optional<Color> color;
@@ -266,6 +292,7 @@ ReturnCode configure(
    {"color", configure_color_opt(&color)},
    {"colors", configure_series_fn(data, &colors)},
    {"labels", configure_series_fn(data, &data_labels)},
    {"title", bind(&configure_string, _1, &title)},
  };

  if (auto rc = parseAll(plist, pdefs); !rc) {
@@ -345,6 +372,11 @@ ReturnCode configure(
    config->labels = *data_labels;
  }

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

  return OK;
}

+1 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ ReturnCode configure(
    const DataContext& data,
    const Document& doc,
    const DomainMap& scales,
    LegendItemMap* legend,
    PlotBarsConfig* config);

} // namespace bars
Loading