@jbrowse/plugin-wiggle
Version:
JBrowse 2 wiggle adapters, tracks, etc.
40 lines (39 loc) • 1.77 kB
JavaScript
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { set1 } from '@jbrowse/core/ui/colors';
import { randomColor } from '@jbrowse/core/util/color';
import { Button } from '@mui/material';
export default function SetColorDialogRowPalettizer({ setCurrLayout, currLayout, }) {
if (!currLayout.length || !currLayout[0]) {
return null;
}
const fields = Object.keys(currLayout[0]).filter(f => f !== 'name' &&
f !== 'color' &&
f !== 'source' &&
f !== 'label' &&
f !== 'id' &&
f !== 'HP');
return (_jsxs("div", { children: ["Create color palette based on...", fields.map(r => (_jsx(Button, { variant: "contained", color: "inherit", onClick: () => {
const map = new Map();
for (const row of currLayout) {
const val = map.get(row[r]);
if (!val) {
map.set(row[r], 1);
}
else {
map.set(row[r], val + 1);
}
}
const ret = Object.fromEntries([...map.entries()]
.sort((a, b) => a[1] - b[1])
.map((r, idx) => [r[0], set1[idx] || randomColor(r[0])]));
setCurrLayout(currLayout.map(row => ({
...row,
color: ret[row[r]],
})));
}, children: r }, r))), _jsx(Button, { onClick: () => {
setCurrLayout(currLayout.map(row => ({
...row,
color: undefined,
})));
}, children: "Clear colors" })] }));
}