UNPKG

@jbrowse/core

Version:

JBrowse 2 core libraries used by plugins

67 lines (66 loc) 2.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const rbush_1 = __importDefault(require("rbush")); class PrecomputedLayout { constructor({ rectangles, totalHeight, maxHeightReached }) { this.rectangles = new Map(Object.entries(rectangles)); this.totalHeight = totalHeight; this.maxHeightReached = maxHeightReached; this.rbush = new rbush_1.default(); for (const [key, layout] of Object.entries(rectangles)) { this.rbush.insert({ minX: layout[0], minY: layout[1], maxX: layout[2], maxY: layout[3], name: key, }); } } addRect(id) { const rect = this.rectangles.get(id); if (!rect) { throw new Error(`id ${id} not found in precomputed feature layout`); } return rect[1]; } getRectangles() { return this.rectangles; } getTotalHeight() { return this.totalHeight; } collides(_rect, _top) { throw new Error('Method not implemented.'); } getByCoord(x, y) { const rect = { minX: x, minY: y, maxX: x + 1, maxY: y + 1 }; return this.rbush.collides(rect) ? this.rbush.search(rect)[0].name : undefined; } getByID(id) { return this.rectangles.get(id); } addRectToBitmap(_rect, _data) { throw new Error('Method not implemented.'); } discardRange(_left, _right) { throw new Error('Method not implemented.'); } serializeRegion(_region) { throw new Error('Method not implemented.'); } toJSON() { return { rectangles: Object.fromEntries(this.rectangles), totalHeight: this.totalHeight, maxHeightReached: false, containsNoTransferables: true, }; } } exports.default = PrecomputedLayout;