UNPKG

@rcsb/rcsb-saguaro-app

Version:
150 lines (149 loc) 7.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AnnotationsTrackFactory = void 0; const tslib_1 = require("tslib"); const RcsbAnnotationConfig_1 = require("../../../../RcsbAnnotationConfig/RcsbAnnotationConfig"); const AnnotationsTrackTitleFactory_1 = require("../TrackTitleFactoryImpl/AnnotationsTrackTitleFactory"); const Assertions_1 = require("../../../../RcsbUtils/Helpers/Assertions"); var assertDefined = Assertions_1.Assertions.assertDefined; class AnnotationsTrackFactory { constructor(trackTitleFactory) { this.trackTitleFactory = trackTitleFactory !== null && trackTitleFactory !== void 0 ? trackTitleFactory : new AnnotationsTrackTitleFactory_1.AnnotationsTrackTitleFactory(); } getTrack(annotations) { return tslib_1.__awaiter(this, void 0, void 0, function* () { let out; const type = annotations.getId(); const rcsbAnnotationConfig = annotations.getConfig(); let displayType; const annConfig = rcsbAnnotationConfig; if (annConfig != null) { displayType = annConfig === null || annConfig === void 0 ? void 0 : annConfig.display; } switch (displayType) { case "composite" /* RcsbFvDisplayTypes.COMPOSITE */: case "bond" /* RcsbFvDisplayTypes.BOND */: case "pin" /* RcsbFvDisplayTypes.PIN */: assertDefined(rcsbAnnotationConfig); out = buildRcsbFvRowConfigComposite(annotations, type, rcsbAnnotationConfig); break; case "area" /* RcsbFvDisplayTypes.AREA */: case "line" /* RcsbFvDisplayTypes.LINE */: assertDefined(rcsbAnnotationConfig); out = buildRcsbFvRowConfigArea(annotations, type, rcsbAnnotationConfig); break; case "block-area" /* RcsbFvDisplayTypes.BLOCK_AREA */: assertDefined(rcsbAnnotationConfig); out = buildRcsbFvRowConfigBlockArea(annotations, type, rcsbAnnotationConfig); break; default: out = buildRcsbFvRowConfigTrack(annotations, type, rcsbAnnotationConfig); break; } if (annConfig != null && typeof annConfig.height === "number") { out.trackHeight = annConfig.height; } return Object.assign(Object.assign({}, out), { titleFlagColor: yield this.trackTitleFactory.getTrackTitleFlagColor(annotations), rowTitle: yield this.trackTitleFactory.getTrackTitle(annotations), rowPrefix: yield this.trackTitleFactory.getTrackTitlePrefix(annotations) }); }); } } exports.AnnotationsTrackFactory = AnnotationsTrackFactory; function buildRcsbFvRowConfigArea(annotationTrack, type, rcsbAnnotationConfig) { var _a; const data = annotationTrack.values(); const annConfig = rcsbAnnotationConfig; const displayType = annConfig === null || annConfig === void 0 ? void 0 : annConfig.display; const displayColor = annConfig === null || annConfig === void 0 ? void 0 : annConfig.color; let min = annotationTrack.getRange().min; let max = annotationTrack.getRange().max; if (min >= 0) min = 0; else if (Math.abs(min) > Math.abs(max)) max = -min; else min = -max; const domain = (_a = annConfig === null || annConfig === void 0 ? void 0 : annConfig.domain) !== null && _a !== void 0 ? _a : [min, max]; return Object.assign(Object.assign({}, rcsbAnnotationConfig), { trackId: "annotationTrack_" + type, displayType: displayType, overlap: true, trackColor: "#F9F9F9", displayColor: displayColor, displayDomain: domain, interpolationType: "step" /* InterpolationTypes.STEP */, trackData: data }); } function buildRcsbFvRowConfigBlockArea(annotationTrack, type, rcsbAnnotationConfig) { var _a; const data = annotationTrack.values(); const annConfig = rcsbAnnotationConfig; const displayType = annConfig.display; const displayColor = (_a = annConfig.color) !== null && _a !== void 0 ? _a : RcsbAnnotationConfig_1.RcsbAnnotationConfig.randomRgba(); return Object.assign(Object.assign({}, rcsbAnnotationConfig), { trackId: "annotationTrack_" + type, displayType: displayType, overlap: true, trackColor: "#F9F9F9", displayColor: displayColor, displayDomain: [0, 1], interpolationType: "step" /* InterpolationTypes.STEP */, trackData: data }); } function buildRcsbFvRowConfigComposite(annotationTrack, type, rcsbAnnotationConfig) { var _a; const data = annotationTrack.values(); let out = undefined; const annConfig = rcsbAnnotationConfig; let altDisplayType = "block" /* RcsbFvDisplayTypes.BLOCK */; if (annConfig.display === "bond" /* RcsbFvDisplayTypes.BOND */.toString()) { altDisplayType = "bond" /* RcsbFvDisplayTypes.BOND */; data.forEach(d => { d.isEmpty = true; }); } const displayColor = (_a = annConfig.color) !== null && _a !== void 0 ? _a : RcsbAnnotationConfig_1.RcsbAnnotationConfig.randomRgba(); const pin = new Array(); const nonPin = new Array(); data.forEach(d => { if (d.end !== null && d.end !== d.begin) { nonPin.push(d); } else { pin.push(d); } }); if (pin.length > 0 && nonPin.length > 0) { const displayConfig = new Array(); displayConfig.push({ displayData: nonPin, displayType: altDisplayType, displayColor: displayColor }); displayConfig.push({ displayData: pin, displayType: "pin" /* RcsbFvDisplayTypes.PIN */, displayColor: displayColor }); out = { displayType: "composite" /* RcsbFvDisplayTypes.COMPOSITE */, trackColor: "#F9F9F9", trackId: "annotationTrack_" + type, displayConfig: displayConfig }; } else if (pin.length > 0) { altDisplayType = "pin" /* RcsbFvDisplayTypes.PIN */; } if (out == undefined) { out = { trackId: "annotationTrack_" + type, displayType: altDisplayType, trackColor: "#F9F9F9", displayColor: displayColor, trackData: data }; } return out; } function buildRcsbFvRowConfigTrack(annotationTrack, type, rcsbAnnotationConfig) { const data = annotationTrack.values(); let displayType = "block" /* RcsbFvDisplayTypes.BLOCK */; if (data.length > 0 && data[0].end == null) { displayType = "pin" /* RcsbFvDisplayTypes.PIN */; } let displayColor = RcsbAnnotationConfig_1.RcsbAnnotationConfig.randomRgba(); const annConfig = rcsbAnnotationConfig; if (annConfig != null) { displayType = annConfig.display; if (annConfig.color) displayColor = annConfig.color; } else { console.warn("Annotation config type " + type + " not found. Using random config"); } return Object.assign(Object.assign({}, rcsbAnnotationConfig), { trackId: "annotationTrack_" + type, displayType: displayType, trackColor: "#F9F9F9", displayColor: displayColor, trackData: data }); }