* @brief Picks a {1,2,5}*10^n step for a given range and target tick count. */
| 1196 | * @brief Picks a {1,2,5}*10^n step for a given range and target tick count. |
| 1197 | */ |
| 1198 | Widgets::Waterfall::AxisTicks Widgets::Waterfall::computeFreqTicks(double maxFreq, int targetCount) |
| 1199 | { |
| 1200 | AxisTicks out{{}, 1.0, maxFreq}; |
| 1201 | if (!std::isfinite(maxFreq) || maxFreq <= 0.0) |
| 1202 | return out; |
| 1203 | |
| 1204 | const double target = std::max(2, targetCount); |
| 1205 | const double raw = maxFreq / target; |
| 1206 | const double base = fastPow10(std::floor(std::log10(raw))); |
| 1207 | const double cands[] = {1.0, 2.0, 5.0, 10.0}; |
| 1208 | |
| 1209 | double step = base; |
| 1210 | for (double c : cands) { |
| 1211 | if (raw <= c * base) { |
| 1212 | step = c * base; |
| 1213 | break; |
| 1214 | } |
| 1215 | } |
| 1216 | |
| 1217 | out.step = step; |
| 1218 | out.displayMax = std::ceil(maxFreq / step) * step; |
| 1219 | for (double v = 0.0; v <= out.displayMax + 1e-6; v += step) |
| 1220 | out.values.push_back(v); |
| 1221 | |
| 1222 | return out; |
| 1223 | } |
| 1224 | |
| 1225 | /** |
| 1226 | * @brief Same algorithm as computeFreqTicks but for the seconds axis. |