@jbrowse/plugin-wiggle
Version:
JBrowse 2 wiggle adapters, tracks, etc.
41 lines (40 loc) • 1.34 kB
JavaScript
import { getConf } from '@jbrowse/core/configuration';
import { getContainingTrack, getContainingView, measureText, } from '@jbrowse/core/util';
export function moveUp(arr, sel, by = 1) {
const idxs = sel
.map(l => arr.findIndex(v => v.name === l))
.sort((a, b) => a - b);
let lastIdx = 0;
for (const old of idxs) {
const idx = Math.max(lastIdx, old - by);
if (idx >= lastIdx) {
arr.splice(idx, 0, arr.splice(old, 1)[0]);
}
lastIdx = lastIdx + 1;
}
return arr;
}
export function moveDown(arr, sel, by = 1) {
const idxs = sel
.map(l => arr.findIndex(v => v.name === l))
.sort((a, b) => b - a);
let lastIdx = arr.length - 1;
for (const old of idxs) {
const idx = Math.min(lastIdx, old + by);
if (idx <= lastIdx) {
arr.splice(idx, 0, arr.splice(old, 1)[0]);
}
lastIdx = lastIdx - 1;
}
return arr;
}
const trackLabelFontSize = 12.8;
export function getOffset(model) {
const { prefersOffset } = model;
const { trackLabels } = getContainingView(model);
const track = getContainingTrack(model);
const trackName = getConf(track, 'name');
return trackLabels === 'overlapping' && !prefersOffset
? measureText(trackName, trackLabelFontSize) + 100
: 10;
}