MCPcopy Create free account
hub / github.com/antirez/ds4 / nice_step

Function nice_step

speed-bench/plot_speed.py:38–49  ·  view source on GitHub ↗

Return a readable tick spacing close to span / target_ticks.

(span, target_ticks)

Source from the content-addressed store, hash-verified

36
37
38def nice_step(span, target_ticks):
39 """Return a readable tick spacing close to span / target_ticks."""
40 if span <= 0:
41 return 1.0
42
43 raw = span / target_ticks
44 magnitude = 10 ** math.floor(math.log10(raw))
45 normalized = raw / magnitude
46 for step in (1, 2, 2.5, 5, 10):
47 if normalized <= step:
48 return step * magnitude
49 return 10 * magnitude
50
51
52def fmt_tick(value):

Callers 1

render_svgFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected