@rcsb/rcsb-saguaro
Version:
RCSB 1D Feature Viewer
111 lines (110 loc) • 4.42 kB
JavaScript
import { select } from "d3-selection";
import { RcsbD3Constants } from "../RcsbD3Constants";
export class RcsbD3BondManager {
constructor() {
this.beginCircleElements = select(RcsbD3Constants.EMPTY);
this.endCircleElements = select(RcsbD3Constants.EMPTY);
this.lineElements = select(RcsbD3Constants.EMPTY);
}
plot(config) {
const elements = config.elements;
const xScale = config.xScale;
const yScale = config.yScale;
const height = config.height;
const color = config.color != undefined ? config.color : "#CCCCCC";
const radius = config.radius;
this.lineElements = elements.select(RcsbD3Constants.LINE);
this.lineElements.attr(RcsbD3Constants.STROKE_WIDTH, 2)
.attr(RcsbD3Constants.STROKE, (d) => {
if (d.color === undefined) {
return color;
}
else {
return d.color;
}
})
.attr(RcsbD3Constants.X1, (d) => {
var _a;
return (_a = xScale(d.begin)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.Y1, (d) => {
var _a;
return height - ((_a = yScale(0.5)) !== null && _a !== void 0 ? _a : 0);
})
.attr(RcsbD3Constants.X2, (d) => {
var _a;
if (d.end == undefined)
throw "Element end position not found";
return (_a = xScale(d.end)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.Y2, (d) => {
var _a;
return height - ((_a = yScale(0.5)) !== null && _a !== void 0 ? _a : 0);
});
this.beginCircleElements = elements.select(RcsbD3Constants.CIRCLE + "." + RcsbD3Constants.BOND_BEGIN);
this.beginCircleElements.attr(RcsbD3Constants.CX, (d) => {
var _a;
return (_a = xScale(d.begin)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.CY, (d) => {
var _a;
return height - ((_a = yScale(0.5)) !== null && _a !== void 0 ? _a : 0);
})
.attr(RcsbD3Constants.R, radius)
.attr(RcsbD3Constants.FILL, (d) => {
if (typeof d.color === "string")
return d.color;
return color;
});
this.endCircleElements = elements.select(RcsbD3Constants.CIRCLE + "." + RcsbD3Constants.BOND_END);
this.endCircleElements.attr(RcsbD3Constants.CX, (d) => {
var _a;
if (d.end == undefined)
throw "Element end position not found";
return (_a = xScale(d.end)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.CY, (d) => {
var _a;
return height - ((_a = yScale(0.5)) !== null && _a !== void 0 ? _a : 0);
})
.attr(RcsbD3Constants.R, radius)
.attr(RcsbD3Constants.FILL, (d) => {
if (typeof d.color === "string")
return d.color;
return color;
});
}
move(config) {
const xScale = config.xScale;
const yScale = config.yScale;
const height = config.height;
this.lineElements.attr(RcsbD3Constants.X1, (d) => {
var _a;
return (_a = xScale(d.begin)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.X2, (d) => {
var _a;
if (d.end == undefined)
throw "Missing bond end property";
return (_a = xScale(d.end)) !== null && _a !== void 0 ? _a : 0;
});
this.beginCircleElements.attr(RcsbD3Constants.CX, (d) => {
var _a;
return (_a = xScale(d.begin)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.CY, (d) => {
var _a;
return height - ((_a = yScale(0.5)) !== null && _a !== void 0 ? _a : 0);
});
this.endCircleElements.attr(RcsbD3Constants.CX, (d) => {
var _a;
if (d.end == undefined)
throw "Missing bond end property";
return (_a = xScale(d.end)) !== null && _a !== void 0 ? _a : 0;
})
.attr(RcsbD3Constants.CY, (d) => {
var _a;
return height - ((_a = yScale(0.5)) !== null && _a !== void 0 ? _a : 0);
});
}
}