@rcsb/rcsb-saguaro
Version:
RCSB 1D Feature Viewer
90 lines (89 loc) • 3.83 kB
JavaScript
import { select } from "d3-selection";
import { axisLeft } from "d3-axis";
import { RcsbD3Constants } from "../RcsbD3Constants";
import * as classes from "../../../scss/RcsbBoard.module.scss";
export class RcsbD3VariantManager {
constructor() {
this.circleElements = select(RcsbD3Constants.EMPTY);
}
plot(config) {
this.circleElements = config.elements.append(RcsbD3Constants.CIRCLE);
this.circleElements.attr(RcsbD3Constants.CX, (d) => {
var _a;
if (d.begin == undefined)
throw "Position element not found";
return (_a = config.xScale(d.begin)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.CY, (d) => {
if (d.label == undefined)
throw "Variant value not found";
const y = config.yScale(d.label);
if (y == undefined)
throw "Variant value (" + d.value + ") not available";
return y;
})
.attr(RcsbD3Constants.R, config.radius)
.attr(RcsbD3Constants.FILL, (d) => {
if (typeof d.color === "string") {
return d.color;
}
else if (typeof config.color === "string") {
return config.color;
}
else {
console.warn("Config color noy found");
return "#CCCCCC";
}
});
RcsbD3VariantManager.includeAxis(config.trackG, config.xScale, config.yScale, config.height);
}
move(config) {
this.circleElements.attr(RcsbD3Constants.CX, (d) => {
var _a;
if (d.begin == undefined)
throw "Position element not found";
return (_a = config.xScale(d.begin)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.CY, (d) => {
if (d.label == undefined)
throw "Variant value not found";
const y = config.yScale(d.label);
if (y == undefined)
throw "Variant value (" + d.value + ") not available";
return y;
});
RcsbD3VariantManager.includeAxis(config.trackG, config.xScale, config.yScale, config.height);
}
static includeAxis(trackG, xScale, yScale, height) {
trackG.selectAll("." + classes.rcsbAxis).remove();
trackG.selectAll("." + classes.rcsbVariantGrid).remove();
trackG.append(RcsbD3Constants.G).classed(classes.rcsbVariantGrid, true);
yScale.domain().forEach((aa) => {
const aaY = yScale(aa);
if (aaY != undefined)
trackG.selectAll("." + classes.rcsbVariantGrid).append(RcsbD3Constants.LINE)
.attr(RcsbD3Constants.LINE, "stroke:#EEEEEE;")
.attr(RcsbD3Constants.X1, xScale.range()[0])
.attr(RcsbD3Constants.Y1, aaY)
.attr(RcsbD3Constants.X2, xScale.range()[1])
.attr(RcsbD3Constants.Y2, aaY);
else
console.warn("Variation (" + aa + ") not found");
});
trackG.selectAll("." + classes.rcsbElement).each(function () {
if (this.parentNode != undefined)
this.parentNode.append(this);
});
const variantAxis = axisLeft(yScale.getScale());
const gAxis = trackG.append(RcsbD3Constants.G);
gAxis.classed(classes.rcsbAxis, true)
.attr(RcsbD3Constants.TRANSFORM, "translate(20,0)")
.append(RcsbD3Constants.RECT)
.attr(RcsbD3Constants.FILL, "white")
.attr(RcsbD3Constants.X, -20)
.attr(RcsbD3Constants.Y, 0)
.attr(RcsbD3Constants.HEIGHT, height)
.attr(RcsbD3Constants.WIDTH, 15);
gAxis.call(variantAxis);
}
}