Skip to content

Add bar chart support (figure.bar()) #2

Description

@MoonFlowww

Summary

Add a bar() API for vertical (and optionally horizontal) bar charts — the standard matplotlib plt.bar() / plt.barh() equivalent.

Motivation

Bar charts are the go-to visualization for comparing benchmark results across named implementations (e.g., "impl A vs impl B vs impl C" measured in nanoseconds). This is one of the core use-cases stated in the project motivation.

Proposed API

// Vertical bars
std::vector<double> positions = {0, 1, 2, 3};
std::vector<double> heights   = {120.5, 98.3, 140.1, 88.7};
figure.bar(positions.data(), heights.data(), 4)
      .color(sepia::Color{100, 180, 255})
      .width(0.6)   // bar width in data units
      .label("throughput (ops/s)");

// Horizontal bars
figure.barh(positions.data(), heights.data(), 4)
      .label("latency (ns)");

Implementation Notes

  • New BarEntry struct (or reuse PlotEntry with a PlotType enum tag)
  • Rendering: for each bar, call canvas.fill_rect() from y=0 (or x=0 for barh) to the data value, transformed through CoordTransform
  • Need to store bar width (in data units) separately from line width
  • Baseline is configurable (default 0.0) to support waterfall-style charts later
  • TickEngine already produces nice tick labels — axis labels should auto-fit to bar positions

Acceptance Criteria

  • bar() renders filled rectangles at correct screen coordinates
  • barh() renders horizontal variant
  • Bar width configurable in data-space units
  • Multiple bar series can be overlaid (grouped bars via offset positions)
  • Example added to examples/bar_chart.cpp

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions