synapse-react-client
Version:
[](https://badge.fury.io/js/synapse-react-client) [](https://github.com/prettier/prettie
150 lines (149 loc) • 3.32 kB
JavaScript
import { jsx as m } from "react/jsx-runtime";
import g from "lodash-es/cloneDeep";
import h from "lodash-es/countBy";
import k from "lodash-es/noop";
import b from "lodash-es/uniq";
import { Plot as D } from "./Plot.js";
function w(a, r) {
const e = g(a);
if (!r)
return e;
r.backgroundColor && (e.plot_bgcolor = r.backgroundColor), e.yaxis.showgrid = !1, e.yaxis.zeroline = !0, e.yaxis.zerolinecolor = "#aeb5bc", e.yaxis.showticklabels = !1, e.xaxis.type === "log" ? (e.xaxis.tickformat = "f", e.xaxis.range = [-0.1, Math.log10(r.maxValue) + 0.1]) : e.xaxis.range = [
r.maxValue / 50 * -1,
r.maxValue + 30
], e.xaxis.visible = r.isXAxis, e.showlegend = r.isLegend, e.margin = {
t: 0,
b: r.isXAxis ? 50 : 0,
l: 0,
r: 0,
pad: 15
};
let o = 40;
return r.isLegend && (o = 35, e.margin.pad = 0, e.xaxis = {
visible: !1,
zeroline: !1,
showgrid: !1,
showline: !1,
range: [0, 1]
}, e.yaxis = {
visible: !1,
showline: !1
}), r.isXAxis && (e.yaxis = {
visible: !1,
showgrid: !1,
showline: !1
}, o = 50), e.height = o, e;
}
function L(a, r) {
const e = new Array(a.length);
return r.forEach((o) => {
const t = a.indexOf(o.y);
t !== -1 && (e[t] = o.x);
}), e;
}
function p(a) {
const r = [], e = (a - 1) / 2;
for (let o = 0; o < a; o++)
r.push(o - e);
return r;
}
function T(a) {
const r = h(a, (t) => t[0]), e = {}, o = {};
return Object.keys(a).forEach((t) => {
const s = a[t][0];
if (r[s] === 1)
e[t] = [0];
else {
o[s] == null && (o[s] = 0);
const i = p(r[s])[o[s]];
e[t] = [i], o[s] = o[s] + 1;
}
}), e;
}
function v(a, r, e, o) {
const t = e === void 0, s = b(a.map((n) => n.group)), x = [
"y-down",
"triangle-up",
"cross-thin-open",
"triangle-up-open-dot",
"star-square-open",
"diamond-x"
], i = s.reduce(
(n, c) => {
const l = t ? [-100] : L(
e,
a.filter((f) => f.group === c)
);
return { ...n, [c]: l };
},
{}
), u = T(i);
return s.map((n, c) => {
const l = i[n], f = u[n];
return {
type: "scatter",
x: l,
y: f,
text: [n],
hovertemplate: "%{x} %{text}<extra></extra>",
mode: "markers",
name: n,
marker: {
color: r.markerFill,
line: {
color: r.markerLine,
width: 1
},
symbol: o ? o[n] : x[c],
size: r.markerSize
}
};
});
}
const y = {
markerFill: "#515359",
markerLine: "#515359",
markerSize: 9,
backgroundColor: "transparent"
}, P = {
width: "100%",
height: "100%"
};
function V({
plotData: a,
optionsConfig: r,
layoutConfig: e,
label: o,
id: t,
xMax: s,
style: x = P,
markerSymbols: i,
plotStyle: u = y,
onClick: d,
isLegend: n = !1,
isXAxis: c = !1
}) {
const l = o ? [o] : void 0;
return /* @__PURE__ */ m(
D,
{
layout: w(e, {
isLegend: n,
isXAxis: c,
maxValue: s,
backgroundColor: u.backgroundColor
}),
style: x,
data: v(a, u, l, i),
config: r,
onClick: (f) => d ? d(f) : k
},
`dotPlot_${t}`
);
}
export {
V as default,
p as generateCenteredSequence,
T as getYDataForDotPlotOffset
};
//# sourceMappingURL=DotPlot.js.map