@jbrowse/plugin-wiggle
Version:
JBrowse 2 wiggle adapters, tracks, etc.
46 lines (45 loc) • 1.5 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.moveUp = moveUp;
exports.moveDown = moveDown;
exports.getOffset = getOffset;
const configuration_1 = require("@jbrowse/core/configuration");
const util_1 = require("@jbrowse/core/util");
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;
}
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;
function getOffset(model) {
const { prefersOffset } = model;
const { trackLabels } = (0, util_1.getContainingView)(model);
const track = (0, util_1.getContainingTrack)(model);
const trackName = (0, configuration_1.getConf)(track, 'name');
return trackLabels === 'overlapping' && !prefersOffset
? (0, util_1.measureText)(trackName, trackLabelFontSize) + 100
: 10;
}