UNPKG

@rcsb/rcsb-saguaro

Version:
53 lines (52 loc) 1.89 kB
import { RcsbAbstractDisplay } from "./RcsbAbstractDisplay"; import { RcsbD3BondManager } from "../RcsbD3/RcsbD3DisplayManager/RcsbD3BondManager"; import { RcsbD3Constants } from "../RcsbD3/RcsbD3Constants"; import { RcsbD3ScaleFactory } from "../RcsbD3/RcsbD3ScaleFactory"; export class RcsbBondDisplay extends RcsbAbstractDisplay { constructor(boardId, trackId) { super(boardId, trackId); this.yScale = RcsbD3ScaleFactory.getLinearScale(); this.radius = 5; this._yDomain = [0, 1]; this.definedScale = false; this.rcsbD3BondManager = new RcsbD3BondManager(); } setScale() { if (typeof this.height() === "number" && this._yDomain.length == 2 && typeof this._yDomain[0] === "number" && typeof this._yDomain[1] === "number") { this.yScale .domain(this._yDomain) .range([this.radius, this.height() - this.radius]); this.definedScale = true; } else { throw "FATAL ERROR: d3 scale unknown format"; } } enter(e) { e.append(RcsbD3Constants.LINE); e.append(RcsbD3Constants.CIRCLE).classed(RcsbD3Constants.BOND_BEGIN, true); e.append(RcsbD3Constants.CIRCLE).classed(RcsbD3Constants.BOND_END, true); } plot(elements) { super.plot(elements); if (!this.definedScale) this.setScale(); const config = { elements: elements, radius: this.radius, xScale: this.xScale, yScale: this.yScale, height: this.height(), color: this._displayColor }; this.rcsbD3BondManager.plot(config); } move() { const config = { xScale: this.xScale, yScale: this.yScale, height: this.height(), }; this.rcsbD3BondManager.move(config); } }