@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
136 lines (135 loc) • 4.42 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const mobx_state_tree_1 = require("mobx-state-tree");
const Base1DUtils_1 = require("./Base1DUtils");
const calculateDynamicBlocks_1 = __importDefault(require("./calculateDynamicBlocks"));
const calculateStaticBlocks_1 = __importDefault(require("./calculateStaticBlocks"));
const index_1 = require("./index");
const mst_1 = require("./types/mst");
function x() { }
const Base1DView = mobx_state_tree_1.types
.model('Base1DView', {
id: mst_1.ElementId,
displayedRegions: mobx_state_tree_1.types.optional(mobx_state_tree_1.types.frozen(), []),
bpPerPx: 0,
offsetPx: 0,
interRegionPaddingWidth: mobx_state_tree_1.types.optional(mobx_state_tree_1.types.number, 0),
minimumBlockWidth: mobx_state_tree_1.types.optional(mobx_state_tree_1.types.number, 0),
})
.volatile(() => ({
features: undefined,
volatileWidth: 0,
}))
.actions(self => ({
setDisplayedRegions(regions) {
self.displayedRegions = (0, mobx_state_tree_1.cast)(regions);
},
setBpPerPx(val) {
self.bpPerPx = val;
},
setVolatileWidth(width) {
self.volatileWidth = width;
},
}))
.views(self => ({
get width() {
return self.volatileWidth;
},
get assemblyNames() {
return [...new Set(self.displayedRegions.map(r => r.assemblyName))];
},
get displayedRegionsTotalPx() {
return this.totalBp / self.bpPerPx;
},
get maxOffset() {
const leftPadding = 10;
return this.displayedRegionsTotalPx - leftPadding;
},
get minOffset() {
const rightPadding = 30;
return -this.width + rightPadding;
},
get totalBp() {
return (0, index_1.sum)(self.displayedRegions.map(a => a.end - a.start));
},
}))
.views(self => ({
get dynamicBlocks() {
return (0, calculateDynamicBlocks_1.default)(self);
},
get staticBlocks() {
return (0, calculateStaticBlocks_1.default)(self);
},
get currBp() {
return (0, index_1.sum)(this.dynamicBlocks.map(a => a.end - a.start));
},
}))
.views(self => ({
pxToBp(px) {
return (0, Base1DUtils_1.pxToBp)(self, px);
},
bpToPx({ refName, coord, regionNumber, }) {
var _a;
return (_a = (0, Base1DUtils_1.bpToPx)({ refName, coord, regionNumber, self })) === null || _a === void 0 ? void 0 : _a.offsetPx;
},
}))
.actions(self => ({
setFeatures(features) {
self.features = features;
},
showAllRegions() {
self.bpPerPx = self.totalBp / self.width;
self.offsetPx = 0;
},
zoomOut() {
this.zoomTo(self.bpPerPx * 2);
},
zoomIn() {
this.zoomTo(self.bpPerPx / 2);
},
zoomTo(bpPerPx, offset = self.width / 2) {
const newBpPerPx = (0, index_1.clamp)(bpPerPx, 'minBpPerPx' in self ? self.minBpPerPx : 0, 'maxBpPerPx' in self
? self.maxBpPerPx
: Number.POSITIVE_INFINITY);
const oldBpPerPx = self.bpPerPx;
if (Math.abs(oldBpPerPx - newBpPerPx) < 0.000001) {
return oldBpPerPx;
}
self.bpPerPx = newBpPerPx;
self.offsetPx = (0, index_1.clamp)(Math.round(((self.offsetPx + offset) * oldBpPerPx) / newBpPerPx - offset), self.minOffset, self.maxOffset);
return self.bpPerPx;
},
scrollTo(offsetPx) {
const newOffsetPx = (0, index_1.clamp)(offsetPx, self.minOffset, self.maxOffset);
self.offsetPx = newOffsetPx;
return newOffsetPx;
},
centerAt(coord, refName, regionNumber) {
if (!refName) {
return;
}
const centerPx = self.bpToPx({
refName,
coord,
regionNumber,
});
if (centerPx) {
this.scrollTo(Math.round(centerPx - self.width / 2));
}
},
scroll(distance) {
const oldOffsetPx = self.offsetPx;
const newOffsetPx = (0, index_1.clamp)(self.offsetPx + distance, self.minOffset, self.maxOffset);
self.offsetPx = newOffsetPx;
return newOffsetPx - oldOffsetPx;
},
}))
.actions(self => ({
moveTo(start, end) {
(0, Base1DUtils_1.moveTo)(self, start, end);
},
}));
exports.default = Base1DView;
;