taxonium-component
Version:
React component for exploring large phylogenetic trees in the browser
88 lines (87 loc) • 4.01 kB
JavaScript
import { s as y, am as oo, an as eo, R as T, u as g, ao as S, ap as u } from "./JBrowsePanel-ClL6pWQW.js";
function to(n, x) {
const i = n.toHsl(), l = i.l * (1 + x);
return S.colord({
...i,
l: g.clamp(l, 0, 100)
});
}
function no(n, x) {
const i = n.toHsl(), l = i.l * (1 - x);
return S.colord({
...i,
l: g.clamp(l, 0, 100)
});
}
const b = 0.3, W = 2;
function so(n, x) {
const { features: i, bpPerPx: l, regions: X, scaleOpts: E, height: R, config: P, ticks: _, displayCrossHatches: q, offset: I = 0, colorCallback: h, inverted: B, stopToken: k } = x, d = X[0], D = (d.end - d.start) / l, N = R - I * 2, J = y.readConfObject(P, "filled"), K = y.readConfObject(P, "clipColor"), Y = y.readConfObject(P, "summaryScoreMode"), A = y.readConfObject(P, "bicolorPivotValue"), C = y.readConfObject(P, "minSize"), G = oo({ ...E, range: [0, N], inverted: B }), Q = eo(E.scaleType), L = G.domain(), O = L[0], H = L[1], m = (o) => g.clamp(N - (G(o) || 0), 0, N) + I, U = (o) => m(Q) - m(o), w = (o) => J ? U(o) : Math.max(C, 1);
let M = !1, j = Number.NEGATIVE_INFINITY;
const F = [], V = O < A && H > A;
let c = performance.now();
if (Y === "whiskers") {
let o, r;
c = performance.now();
for (const e of i.values()) {
performance.now() - c > 400 && (T.checkStopToken(k), c = performance.now());
const [t, f] = g.featureSpanPx(e, d, l);
if (e.get("summary")) {
const a = Math.max(f - t + b, C), s = e.get("maxScore"), p = h(e, s), v = V ? p : p === o ? r : r = to(S.colord(p), 0.4).toHex();
u(t, m(s), a, w(s), n, v), o = p;
}
}
r = void 0, o = void 0, c = performance.now();
for (const e of i.values()) {
performance.now() - c > 400 && (T.checkStopToken(k), c = performance.now());
const [t, f] = g.featureSpanPx(e, d, l), a = e.get("score"), s = e.get("maxScore"), p = e.get("minScore"), v = e.get("summary"), z = h(e, a), Z = V && v ? z === o ? r : r = S.colord(h(e, s)).mix(S.colord(h(e, p))).toString() : z, $ = Math.max(f - t + b, C);
(Math.floor(t) !== Math.floor(j) || f - t > 1) && (F.push(e), j = t), M = M || a < O || a > H, u(t, m(a), $, w(a), n, Z), o = z;
}
r = void 0, o = void 0, c = performance.now();
for (const e of i.values()) {
performance.now() - c > 400 && (T.checkStopToken(k), c = performance.now());
const [t, f] = g.featureSpanPx(e, d, l);
if (e.get("summary")) {
const a = e.get("minScore"), s = h(e, a), p = Math.max(f - t + b, C), v = V ? s : s === o ? r : r = no(S.colord(s), 0.4).toHex();
u(t, m(a), p, w(a), n, v), o = s;
}
}
} else {
c = performance.now();
for (const o of i.values()) {
performance.now() - c > 400 && (T.checkStopToken(k), c = performance.now());
const [r, e] = g.featureSpanPx(o, d, l);
(Math.floor(r) !== Math.floor(j) || e - r > 1) && (F.push(o), j = r);
const t = o.get("score"), f = h(o, t);
M = M || t < O || t > H;
const a = Math.max(e - r + b, C);
if (Y === "max") {
const s = o.get("summary") ? o.get("maxScore") : t;
u(r, m(s), a, w(s), n, f);
} else if (Y === "min") {
const s = o.get("summary") ? o.get("minScore") : t;
u(r, m(s), a, w(s), n, f);
} else
u(r, m(t), a, w(t), n, f);
}
}
if (n.save(), M) {
n.fillStyle = K, c = performance.now();
for (const o of i.values()) {
performance.now() - c > 400 && (T.checkStopToken(k), c = performance.now());
const [r, e] = g.featureSpanPx(o, d, l), t = e - r + b, f = o.get("score");
f > H ? u(r, I, t, W, n) : f < O && E.scaleType !== "log" && u(r, R, t, W, n);
}
}
if (n.restore(), q) {
n.lineWidth = 1, n.strokeStyle = "rgba(200,200,200,0.5)";
for (const o of _.values)
n.beginPath(), n.moveTo(0, Math.round(m(o))), n.lineTo(D, Math.round(m(o))), n.stroke();
}
return {
reducedFeatures: F
};
}
export {
so as drawXY
};
//# sourceMappingURL=drawXY--seM3KmP.js.map