MCPcopy Create free account
hub / github.com/donkeyteethUX/iced_plot / nice_step

Function nice_step

src/ticks.rs:142–155  ·  view source on GitHub ↗

Calculate a "nice" step size for grid lines based on the desired number of divisions. Returns a value that is a multiple of 1, 2, 5, or 10 times a power of 10.

(raw: f64)

Source from the content-addressed store, hash-verified

140 let start_exp = lo.log(base).ceil() as i32;
141 let end_exp = hi.log(base).floor() as i32;
142 if start_exp > end_exp {
143 return Vec::new();
144 }
145
146 let max_ticks_for_spacing = (size_px / 30.0).ceil() + 1.0;
147 let skip = ((end_exp - start_exp + 1) as f64 / max_ticks_for_spacing).ceil() as i32;
148
149 let mut out = Vec::with_capacity((end_exp - start_exp + 1) as usize);
150 for (i, exp) in (start_exp..=end_exp).enumerate() {
151 if i as i32 % skip != 0 {
152 continue;
153 }
154
155 let value = base.powi(exp);
156 if value.is_finite() {
157 out.push(Tick::new(value, base, TickWeight::Major));
158 }

Callers 1

default_tick_producerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected