A simple formatter for logarithmic ticks with an arbitrary base. Expects positive `tick.value` and renders labels as `b^n`, where `b` is the provided base.
(mark: Tick, base: f64)
| 57 | if log_step >= 0.0 { |
| 58 | format!("{:.0}", mark.value) |
| 59 | } else { |
| 60 | let decimal_places = (-log_step).ceil() as usize; |
| 61 | format!("{:.*}", decimal_places, mark.value) |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /// A simple formatter for logarithmic ticks with an arbitrary base. |
| 66 | /// |
| 67 | /// Expects positive `tick.value` and renders labels as `b^n`, where `b` is the provided base. |
| 68 | pub fn log_formatter(mark: Tick, base: f64) -> String { |
| 69 | if !mark.value.is_finite() || mark.value <= 0.0 { |
| 70 | return String::new(); |
| 71 | } |
| 72 | let exp = mark.value.log(base).round() as i32; |
| 73 |