INNER CODE UNIT · JavaScript

niceLimit

oncologylab/fp-tools · src/fp_tools/resources/static_browser/app.js:81

function niceLimit(value) {
  const number = Math.max(Math.abs(finite(value)), 1e-9),
    power = 10 ** Math.floor(Math.log10(number)),
    scaled = number / power;
  return (scaled <= 1 ? 1 : scaled <= 2 ? 2 : scaled <= 5 ? 5 : 10) * power;
}
function niceTicks(min, max, count = 5) {
  if (!Number.isFinite(min) || !Number.isFinite(max) || min === max)
    return [min || 0];
  const step = niceStep(max - min, count - 1),
    start = Math.ceil(min / step) * step,
    end = Math.floor(max / step) * step,
    out = [];
  for (let value = start; value <= end + step * 0.25; value += step)
    out.push(Math.abs(value) < step / 1e6 ? 0 : value);
  return out.length ? out : [min, max];
}
function colorFor(motif) {

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…