mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-11 12:53:59 +00:00
fix(chart): pass series index to data-table keys (#1150)
This commit is contained in:
1 parent
505cae34c8
commit
6b19e445f4
3 files changed
+32
-2
No files matched your search
@@ -70,7 +70,7 @@ pub(super) fn draw(ctx: &mut Ctx, chart: &Chart, data: &ChartData, plot: Bx, lay
|
||||
let y = top + (layout.headers as f32 + i as f32 + 0.5) * layout.row_height;
|
||||
let name_x = if settings.show_keys { x0 + 25.0 } else { x0 + 4.0 };
|
||||
if settings.show_keys {
|
||||
let swatch = match plot_kind(chart, series) {
|
||||
let swatch = match plot_kind(chart, series, i) {
|
||||
ChartKind::Line | ChartKind::LineStacked => Swatch::Line,
|
||||
ChartKind::LineMarkers => Swatch::LineMarker,
|
||||
_ => Swatch::Box,
|
||||
|
||||
@@ -1,6 +1,35 @@
|
||||
use super::*;
|
||||
use gridcraft_model::ChartDataTable;
|
||||
|
||||
#[test]
|
||||
fn combo_table_keys_use_each_series_index() {
|
||||
let mut c = chart(ChartKind::Combo);
|
||||
c.legend = LegendPos::None;
|
||||
c.data_labels = false;
|
||||
c.data_table = Some(ChartDataTable::default());
|
||||
let mut d = sample(c.kind);
|
||||
// The public renderer also accepts Combo series: the first defaults to columns, later ones to lines.
|
||||
for s in &mut d.series {
|
||||
s.kind = ChartKind::Combo;
|
||||
}
|
||||
let p = render(&c, &d, 900.0, 500.0, &ApproxMeasure);
|
||||
assert_sane(&p, 900.0, 500.0);
|
||||
let header_y = p
|
||||
.iter()
|
||||
.find_map(|p| match p {
|
||||
Prim::Text { text, y, .. } if text == "Q1" => Some(*y),
|
||||
_ => None,
|
||||
})
|
||||
.unwrap();
|
||||
for (i, s) in d.series.iter().enumerate() {
|
||||
let boxes = p.iter().filter(|p| matches!(p, Prim::Rect { y, fill: Some(f), .. } if *f == s.color && *y > header_y)).count();
|
||||
let lines =
|
||||
p.iter().filter(|p| matches!(p, Prim::Line { pts, color, .. } if *color == s.color && pts.iter().all(|p| p[1] > header_y))).count();
|
||||
assert_eq!(boxes, usize::from(i == 0), "series {i}: column key");
|
||||
assert_eq!(lines, usize::from(i > 0), "series {i}: line key");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tables_draw_source_values_for_every_supported_chart_kind() {
|
||||
for kind in ALL_KINDS {
|
||||
|
||||
Reference in new issue
Block a user