Skip to main content

data_units_per_px

Function data_units_per_px 

Source
pub fn data_units_per_px(bounds: &BoundingBox, viewport_px: (u32, u32)) -> f32
Expand description

Compute the scale factor to convert pixel-sized geometry into data units.

Many plot style controls (e.g. LineWidth) are expressed in pixels, but some geometry generators (like thick polyline extrusion) operate in data space. This helper provides a conservative conversion factor based on the current data bounds and viewport size:

[ \text{data_units_per_px} = \min\left(\frac{\Delta x}{w_{px}}, \frac{\Delta y}{h_{px}}\right) ]

Using the minimum axis scale avoids pathological over-thick extrusion when one data axis spans orders of magnitude more than the other (for example semilog/loglog plots). In those cases a max(...) conversion can turn a modest pixel width into a near-filled ribbon.