MCPcopy Create free account
hub / github.com/angular-rust/ux-charts / calculate_interval

Function calculate_interval

src/utils.rs:128–144  ·  view source on GitHub ↗

Calculates a nice axis interval given - the axis range [range] - the desired number of steps [targetSteps] - and the minimum interval [min_interval]

(range: f64, target_steps: usize, min_interval: Option<f64>)

Source from the content-addressed store, hash-verified

126/// - the desired number of steps [targetSteps]
127/// - and the minimum interval [min_interval]
128pub fn calculate_interval(range: f64, target_steps: usize, min_interval: Option<f64>) -> f64 {
129 let interval = range / target_steps as f64;
130 let mag = interval.log10().floor();
131 let mut mag_pow = f64::powf(10.0, mag);
132 if let Some(min_interval) = min_interval {
133 mag_pow = mag_pow.max(min_interval);
134 }
135 let mut msd = (interval / mag_pow).round();
136 if msd > 5. {
137 msd = 10.;
138 } else if msd > 2. {
139 msd = 5.;
140 } else if msd == 0. {
141 msd = 1.;
142 }
143 msd * mag_pow
144}
145
146pub fn calculate_max_text_width<C>(
147 ctx: &C,

Callers 3

Calls

no outgoing calls

Tested by

no test coverage detected