Repository navigation
Description
Zoomed histogram grid: nice-step bin widths with a target bin count
Today
A zoomed histogram snaps its viewport outward to a lattice of width
(hi - lo) / bins (_snap_range in flexviz/trace/_hist_helpers.py). The
grid stands still while the user pans, and a cross-filter never moves the bin
edges. Two things are still wrong:
- The bin count is
binsorbins + 1, because the viewport rarely starts on
a lattice line and covering it takes the two partial cells at the ends. A
zoom to[20, 70]withbins=12renders 13 bars over[16.67, 70.83]. - The width is
span / bins, an arbitrary number. Edges are not human
friendly, and any change of span, however small, changes the width and
re-bins everything.
Exact bins, a grid on a fixed lattice, and a freely placed viewport cannot
all hold at once. Rendering exactly bins lattice cells under a free
viewport leaves a gap of up to one bar at an edge.
Proposal
Keep the lattice, and pick the width from the 1, 2, 5 ladder nearest to
span / bins in log space. Then:
- edges are round numbers,
- the width changes only when
span / binscrosses a ladder step, so a small
zoom keeps the grid, - panning keeps every cell in place, as today,
- the cube sees fewer distinct keys, because many viewports share a width.
The bin count becomes a band around bins, roughly 0.7 * bins to
1.4 * bins + 1. This is what Mosaic and Vega do (their steps and
maxbins are targets). bins reads as "the bin count at full view, the
target once zoomed". The unzoomed grid over the data domain stays exact.
Scope
_snap_range: the width choice. Both histogram call sites, the 2D bounds,
and the cube target spec go through it. The client derives centers and
hover cells fromdomain,binsand the edge triples it already receives,
so no JS change.- Tests: the lattice tests in
test_hist_helpers.pyandtest_trace_hist.py,
and the browser cube tests that assertbinsorbins + 1. Architecture.mdand theadd_histogramdocstring: the meaning ofbins
and the bin-count band.
Temporal axes
The snap runs in physical units (microseconds, days), where a decimal ladder
gives widths like 200 seconds. Dates need their own ladder: seconds, 5, 15,
30 seconds, minutes, 5, 15, 30 minutes, hours, 6 hours, days, weeks. Months
are not uniform, so the ladder stops at weeks. Without it a temporal zoomed
grid keeps today's lattice, which is a consistent fallback, so the numeric
change can ship first and the temporal ladder follow as its own change.
Alternative
Snap the axis range itself to lattice lines, so a pan moves in whole-bin
steps. That gives exactly bins and a stable grid, at the cost of a
quantized pan: fine at 100 bins, coarse at 12.
Activity