UNPKG

@rcsb/rcsb-saguaro

Version:
174 lines (173 loc) 6.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.RcsbBlockDisplay = void 0; const tslib_1 = require("tslib"); const RcsbAbstractDisplay_1 = require("./RcsbAbstractDisplay"); const d3_selection_1 = require("d3-selection"); const RcsbD3BlockManager_1 = require("../RcsbD3/RcsbD3DisplayManager/RcsbD3BlockManager"); const RcsbDataManager_1 = require("../../RcsbDataManager/RcsbDataManager"); const classes = tslib_1.__importStar(require("../../scss/RcsbBoard.module.scss")); const RcsbD3Constants_1 = require("../RcsbD3/RcsbD3Constants"); class RcsbBlockDisplay extends RcsbAbstractDisplay_1.RcsbAbstractDisplay { constructor() { super(...arguments); this.dx = 0.5; this.lines = (0, d3_selection_1.select)(RcsbD3Constants_1.RcsbD3Constants.EMPTY); this.circles = (0, d3_selection_1.select)(RcsbD3Constants_1.RcsbD3Constants.EMPTY); this.circleDecorators = new Array(); this.lineDecorators = new Array(); this.rcsbD3BlockManager = new RcsbD3BlockManager_1.RcsbD3BlockManager(); } enter(e) { e.append(RcsbD3Constants_1.RcsbD3Constants.RECT); } plot(elements) { super.plot(elements); const config = { elements: this.getElements(), dy: this.height() * (2 / 3), dx: this.dx, y_o: this.height() * (1 / 6), xScale: this.xScale, color: this._displayColor, height: this.height() }; this.rcsbD3BlockManager.plot(config); if (this.minRatio == 0 || this.getRatio() > this.minRatio) this.plotDecorators(elements.data()); else this.removeDecorators(); } move() { const config = { dx: this.dx, xScale: this.xScale, height: this.height() }; this.rcsbD3BlockManager.move(config); } processData(dataElems) { this.loadDecorators(dataElems); if (this.minRatio == 0 || this.getRatio() > this.minRatio) { const out = new RcsbDataManager_1.RcsbFvTrackData(); dataElems.forEach(d => { if (d.gaps != null && d.gaps.length > 0) { const G = d.gaps; out.push(Object.assign(Object.assign({}, d), { rectBegin: d.begin, rectEnd: G[0].begin })); d.gaps.forEach((g, n) => { if (n + 1 < G.length) { out.push(Object.assign(Object.assign({}, d), { rectBegin: g.end, rectEnd: G[n + 1].begin })); } else { out.push(Object.assign(Object.assign({}, d), { rectBegin: g.end, rectEnd: d.end })); } }); } else { out.push(d); } }); return out; } return dataElems; } static dataKey(d) { if (d.rectBegin && d.rectEnd) return d.rectBegin + ":" + d.rectEnd; return d.begin + ":" + d.end; } loadDecorators(features) { this.circleDecorators.length = 0; this.lineDecorators.length = 0; if (this.minRatio == 0 || this.getRatio() > this.minRatio) { features.filter(d => { return (d.openBegin || d.openEnd || d.gaps); }).forEach(d => { if (d.openBegin) { this.circleDecorators.push({ position: d.begin, shift: -1, color: d.color }); } if (d.openEnd && d.end != null) this.circleDecorators.push({ position: d.end, shift: 1, color: d.color }); if (d.gaps != null) d.gaps.forEach(g => { if (g.begin == g.end + 1) this.circleDecorators.push({ position: g.begin, shift: 1, color: d.color }); this.lineDecorators.push({ begin: g.begin, end: g.end, color: d.color }); if (!g.isConnected) { this.circleDecorators.push({ position: g.begin, shift: 1, color: d.color }); this.circleDecorators.push({ position: g.end, shift: -1, color: d.color }); } }); }); } } plotDecorators(features) { const lines = this.g.selectAll("." + classes.rcsbDecorator + "_line") .data(this.lineDecorators, (l) => { return l.begin + ":" + l.end; }); const newLines = lines.enter() .append("g").attr("class", classes.rcsbDecorator) .classed(classes.rcsbDecorator + "_line", true); newLines.append(RcsbD3Constants_1.RcsbD3Constants.LINE); lines.exit().remove(); this.lines = lines.merge(newLines); const circles = this.g.selectAll("." + classes.rcsbDecorator + "_circle") .data(this.circleDecorators, (c) => { return c.position.toString(); }); const newCircles = circles.enter() .append("g") .classed(classes.rcsbDecorator + "_circle", true); newCircles.append(RcsbD3Constants_1.RcsbD3Constants.CIRCLE); circles.exit().remove(); this.circles = circles.merge(newCircles); const circleConfig = { elements: this.circles, dy: this.height() * (2 / 3), dx: this.dx, xScale: this.xScale, color: this._displayColor, height: this.height() }; const lineConfig = { elements: this.lines, y_o: this.height() * (1 / 6), dy: this.height() * (2 / 3), dx: this.dx, xScale: this.xScale, color: this._displayColor, height: this.height() }; this.rcsbD3BlockManager.plotDecorators(circleConfig, lineConfig); } removeDecorators() { this.lines.remove(); this.circles.remove(); } } exports.RcsbBlockDisplay = RcsbBlockDisplay;