@jbrowse/core
Version:
JBrowse 2 core libraries used by plugins
111 lines (110 loc) • 3.22 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.InterRegionPaddingBlock = exports.ElidedBlock = exports.ContentBlock = exports.BaseBlock = exports.BlockSet = void 0;
const _1 = require(".");
class BlockSet {
constructor(blocks = []) {
this.blocks = blocks;
}
push(block) {
if (block.type === 'ElidedBlock' && this.blocks.length > 0) {
const lastBlock = this.blocks.at(-1);
if ((lastBlock === null || lastBlock === void 0 ? void 0 : lastBlock.type) === 'ElidedBlock') {
;
lastBlock.push(block);
return;
}
}
this.blocks.push(block);
}
getBlocks() {
return this.blocks;
}
getRegions() {
return this.blocks.map(block => block.toRegion());
}
map(func, thisarg) {
return this.blocks.map(func, thisarg);
}
forEach(func, thisarg) {
this.blocks.forEach(func, thisarg);
}
get length() {
return this.blocks.length;
}
get totalWidthPx() {
return this.blocks.length > 0
? (0, _1.sum)(this.blocks.map(blocks => blocks.widthPx))
: 0;
}
get totalWidthPxWithoutBorders() {
return this.blocks.length > 0
? (0, _1.sum)(this.blocks
.filter(block => block.variant !== 'boundary')
.map(blocks => blocks.widthPx))
: 0;
}
get offsetPx() {
return this.blocks.length > 0 ? this.blocks[0].offsetPx : 0;
}
get contentBlocks() {
return this.blocks.filter(block => block.type === 'ContentBlock');
}
get totalBp() {
return (0, _1.sum)(this.contentBlocks.map(block => block.end - block.start));
}
}
exports.BlockSet = BlockSet;
class BaseBlock {
constructor(data) {
this.type = 'BaseBlock';
this.widthPx = 0;
Object.assign(this, data);
this.assemblyName = data.assemblyName;
this.refName = data.refName;
this.start = data.start;
this.end = data.end;
this.key = data.key;
this.offsetPx = data.offsetPx;
}
toRegion() {
return {
refName: this.refName,
start: this.start,
end: this.end,
assemblyName: this.assemblyName,
reversed: this.reversed,
};
}
}
exports.BaseBlock = BaseBlock;
class ContentBlock extends BaseBlock {
constructor() {
super(...arguments);
this.type = 'ContentBlock';
}
}
exports.ContentBlock = ContentBlock;
class ElidedBlock extends BaseBlock {
constructor(data) {
super(data);
this.type = 'ElidedBlock';
this.elidedBlockCount = 0;
this.widthPx = data.widthPx;
}
push(otherBlock) {
this.elidedBlockCount += 1;
this.refName = '';
this.start = 0;
this.end = 0;
this.widthPx += otherBlock.widthPx;
}
}
exports.ElidedBlock = ElidedBlock;
class InterRegionPaddingBlock extends BaseBlock {
constructor() {
super(...arguments);
this.type = 'InterRegionPaddingBlock';
}
}
exports.InterRegionPaddingBlock = InterRegionPaddingBlock;