laif-ds
Version:
Design System di Laif con componenti React basati su principi di Atomic Design
88 lines (87 loc) • 2.7 kB
JavaScript
"use client";
import E from "./nice.js";
import { transformer as v, copy as F } from "./continuous.js";
import { initRange as L } from "./init.js";
import d from "../../d3-array/src/ticks.js";
import j from "../../d3-format/src/formatSpecifier.js";
import { format as z } from "../../d3-format/src/defaultLocale.js";
function y(t) {
return Math.log(t);
}
function w(t) {
return Math.exp(t);
}
function I(t) {
return -Math.log(-t);
}
function R(t) {
return -Math.exp(-t);
}
function S(t) {
return isFinite(t) ? +("1e" + t) : t < 0 ? 0 : t;
}
function q(t) {
return t === 10 ? S : t === Math.E ? Math.exp : (n) => Math.pow(t, n);
}
function A(t) {
return t === Math.E ? Math.log : t === 10 && Math.log10 || t === 2 && Math.log2 || (t = Math.log(t), (n) => Math.log(n) / t);
}
function x(t) {
return (n, m) => -t(-n, m);
}
function B(t) {
const n = t(y, w), m = n.domain;
let l = 10, c, i;
function k() {
return c = A(l), i = q(l), m()[0] < 0 ? (c = x(c), i = x(i), t(I, R)) : t(y, w), n;
}
return n.base = function(o) {
return arguments.length ? (l = +o, k()) : l;
}, n.domain = function(o) {
return arguments.length ? (m(o), k()) : m();
}, n.ticks = (o) => {
const e = m();
let f = e[0], u = e[e.length - 1];
const M = u < f;
M && ([f, u] = [u, f]);
let r = c(f), g = c(u), a, h;
const p = o == null ? 10 : +o;
let s = [];
if (!(l % 1) && g - r < p) {
if (r = Math.floor(r), g = Math.ceil(g), f > 0) {
for (; r <= g; ++r)
for (a = 1; a < l; ++a)
if (h = r < 0 ? a / i(-r) : a * i(r), !(h < f)) {
if (h > u) break;
s.push(h);
}
} else for (; r <= g; ++r)
for (a = l - 1; a >= 1; --a)
if (h = r > 0 ? a / i(-r) : a * i(r), !(h < f)) {
if (h > u) break;
s.push(h);
}
s.length * 2 < p && (s = d(f, u, p));
} else
s = d(r, g, Math.min(g - r, p)).map(i);
return M ? s.reverse() : s;
}, n.tickFormat = (o, e) => {
if (o == null && (o = 10), e == null && (e = l === 10 ? "s" : ","), typeof e != "function" && (!(l % 1) && (e = j(e)).precision == null && (e.trim = !0), e = z(e)), o === 1 / 0) return e;
const f = Math.max(1, l * o / n.ticks().length);
return (u) => {
let M = u / i(Math.round(c(u)));
return M * l < l - 0.5 && (M *= l), M <= f ? e(u) : "";
};
}, n.nice = () => m(E(m(), {
floor: (o) => i(Math.floor(c(o))),
ceil: (o) => i(Math.ceil(c(o)))
})), n;
}
function C() {
const t = B(v()).domain([1, 10]);
return t.copy = () => F(t, C()).base(t.base()), L.apply(t, arguments), t;
}
export {
C as default,
B as loggish
};