Merge pull request #615 from MarekSpodBiedry:issue-543

This commit is contained in:
Brandon Thomas
2026-10-13 00:07:36 -04:00
2 changed files with 23 additions and 6 deletions
+6 -6
View File
@@ -267,8 +267,8 @@ fn draw_kind(ctx: &mut Ctx, chart: &Chart, data: &ChartData, area: Bx) {
Scatter | ScatterLines | Bubble => scatter(ctx, chart, data, area),
Histogram => histogram(ctx, chart, data, area),
Waterfall => waterfall(ctx, chart, data, area),
BoxWhisker => box_whisker(ctx, data, area),
Stock => stock(ctx, data, area),
BoxWhisker => box_whisker(ctx, chart, data, area),
Stock => stock(ctx, chart, data, area),
_ => cartesian(ctx, chart, data, area, false),
}
}
@@ -1574,12 +1574,12 @@ fn quantile(sorted: &[f64], q: f64) -> f64 {
a + (b - a) * frac
}
fn box_whisker(ctx: &mut Ctx, data: &ChartData, area: Bx) {
fn box_whisker(ctx: &mut Ctx, chart: &Chart, data: &ChartData, area: Bx) {
let labels: Vec<String> = data.series.iter().map(|s| s.name.clone()).collect();
let Some((lo, hi)) = value_range(data.series.iter().flat_map(|s| s.values.iter().flatten().copied())) else { return };
let ys = nice_scale(lo, hi, false);
let f = Fmt::new(data.series.first().map(|s| s.number_format.as_str()).unwrap_or("General"));
let plot = frame(ctx, area, CatAxis::Labels(&labels), &ValAxis { scale: ys, fmt: &f }, None, false, true);
let plot = frame(ctx, area, CatAxis::Labels(&labels), &ValAxis { scale: ys, fmt: &f }, None, false, chart.gridlines);
if !plot.ok() {
return;
}
@@ -1618,7 +1618,7 @@ fn box_whisker(ctx: &mut Ctx, data: &ChartData, area: Bx) {
// ---------------------------------------------------------------- stock
fn stock(ctx: &mut Ctx, data: &ChartData, area: Bx) {
fn stock(ctx: &mut Ctx, chart: &Chart, data: &ChartData, area: Bx) {
let ncat = data.categories.len().max(data.series.iter().map(|s| s.values.len()).max().unwrap_or(0)).min(MAX_CATS);
if ncat == 0 {
return;
@@ -1627,7 +1627,7 @@ fn stock(ctx: &mut Ctx, data: &ChartData, area: Bx) {
let Some((lo, hi)) = value_range(data.series.iter().flat_map(|s| s.values.iter().flatten().copied())) else { return };
let ys = nice_scale(lo, hi, false);
let f = Fmt::new(data.series.first().map(|s| s.number_format.as_str()).unwrap_or("General"));
let plot = frame(ctx, area, CatAxis::Labels(&labels), &ValAxis { scale: ys, fmt: &f }, None, false, true);
let plot = frame(ctx, area, CatAxis::Labels(&labels), &ValAxis { scale: ys, fmt: &f }, None, false, chart.gridlines);
if !plot.ok() {
return;
}
+17
View File
@@ -947,6 +947,23 @@ fn union_series_references() {
}
#[test]
fn box_and_stock_charts_honour_the_gridlines_flag() {
// Horizontal full-width lines in the gridline colour are the value-axis gridlines.
let grid: Rgba = [217, 217, 217, 255];
let is_grid = |p: &Prim| match p {
Prim::Line { color, pts, .. } => *color == grid && pts.len() == 2 && pts[0][1] == pts[1][1] && pts[1][0] - pts[0][0] > 200.0,
_ => false,
};
let grids = |prims: &[Prim]| prims.iter().filter(|p| is_grid(p)).count();
for kind in [ChartKind::BoxWhisker, ChartKind::Stock, ChartKind::ColumnClustered] {
let mut d = sample(kind);
d.series.push(series("Close", &[10000.0, 12000.0, 9000.0, 14000.0, 20000.0, 16000.0], [90, 90, 90, 255], kind));
let mut c = chart(kind);
let on = render(&c, &d, 500.0, 350.0, &ApproxMeasure);
c.gridlines = false;
let off = render(&c, &d, 500.0, 350.0, &ApproxMeasure);
assert!(grids(&on) > 0, "{kind:?}: gridlines on must draw lines");
assert_eq!(grids(&off), 0, "{kind:?}: gridlines off must hide them");
fn funnel_value_labels_follow_the_data_labels_flag() {
let data = ChartData {
categories: vec!["a".into(), "b".into(), "c".into()],