fix(plot): single-rounding clock labels, log-axis fits that refuse non-positive data
This commit is contained in:
1 parent
93fc06f050
commit
606e40a9f1
7 files changed
+258
-73
No files matched your search
@@ -1019,17 +1019,23 @@ Expected: FAIL to compile — `plot/plot/ticks.hpp` not found.
|
||||
`src/plot/ticks.cpp` — the nice-number algorithm:
|
||||
|
||||
```cpp
|
||||
// generate_ticks(range, px, min_px, out):
|
||||
// if (!(range.span() > 0) || px <= 0) { out.clear(); return; }
|
||||
// generate_ticks(range, px, min_px, out, bool include_minors = false):
|
||||
// if (!(range.span() > 0) || px <= 0 || !isfinite(span) || min > max) { out.clear(); return; }
|
||||
// const f64 target_count = std::max(1.0, f64(px) / f64(min_px));
|
||||
// const f64 raw_step = range.span() / target_count;
|
||||
// const f64 mag = std::pow(10.0, std::floor(std::log10(raw_step)));
|
||||
// const f64 norm = raw_step / mag; // in [1, 10)
|
||||
// const f64 step = mag * (norm <= 1.5 ? 1.0 : norm <= 3.0 ? 2.0 : norm <= 7.0 ? 5.0 : 10.0);
|
||||
// // ROUND UP, not to nearest. Rounding to nearest can exceed target_count and
|
||||
// // break the "at most px/min_px + 2 ticks" bound that the tests assert.
|
||||
// const f64 step = mag * (norm <= 1.0 ? 1.0 : norm <= 2.0 ? 2.0 : norm <= 5.0 ? 5.0 : 10.0);
|
||||
// f64 first = std::ceil(range.min / step) * step;
|
||||
// for (f64 v = first; v <= range.max + step * 1e-9; v += step) out.push_back({v, true, {}});
|
||||
// // minor ticks: step/5 (or step/4 when step starts with 2, step/5 when with 5), same loop.
|
||||
// // hard guard: if (out.size() > 256) out.resize(256);
|
||||
// // include_minors defaults to false because minors share this same vector: a
|
||||
// // caller that wants only majors must not have to filter, and the "every value
|
||||
// // is a multiple of the major step" assertions only hold for the majors-only
|
||||
// // form. Grid rendering passes true.
|
||||
// // minor ticks: step/5 (step/4 for a step beginning with 2), same loop.
|
||||
// // hard guard: 256 entries maximum INCLUDING minors.
|
||||
```
|
||||
Labels are assigned by `format_si` unless the axis is a time axis, in which case `format_time` is used. Ticks whose label would be non-finite or absurdly long (> 12 chars) fall back to `%.3g`.
|
||||
|
||||
|
||||
Reference in new issue
Block a user