@rcsb/rcsb-saguaro
Version:
RCSB 1D Feature Viewer
58 lines (57 loc) • 1.92 kB
JavaScript
import { RcsbAbstractDisplay } from "./RcsbAbstractDisplay";
import { RcsbD3PinManager } from "../RcsbD3/RcsbD3DisplayManager/RcsbD3PinManager";
import { RcsbD3Constants } from "../RcsbD3/RcsbD3Constants";
import { RcsbD3ScaleFactory } from "../RcsbD3/RcsbD3ScaleFactory";
export class RcsbPinDisplay extends RcsbAbstractDisplay {
constructor() {
super(...arguments);
this.yScale = RcsbD3ScaleFactory.getLinearScale();
this.radius = 5;
this.labelShift = 10;
this.definedScale = false;
this.rcsbD3PinManager = new RcsbD3PinManager();
}
yDomain(domain) {
this._yDomain = domain;
}
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);
e.append(RcsbD3Constants.TEXT);
}
plot(elements) {
super.plot(elements);
if (!this.definedScale)
this.setScale();
const config = {
elements: elements,
radius: this.radius,
labelShift: this.labelShift,
xScale: this.xScale,
yScale: this.yScale,
height: this.height(),
color: this._displayColor
};
this.rcsbD3PinManager.plot(config);
}
move() {
const config = {
xScale: this.xScale,
labelShift: this.labelShift,
yScale: this.yScale,
height: this.height(),
};
this.rcsbD3PinManager.move(config);
}
}