This repository has been archived by the owner on Jan 22, 2024. It is now read-only.
/
index.js
104 lines (101 loc) · 3.42 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import pureNoFunc from "../../utils/pureNoFunc";
import "./style.css";
// import PropTypes from "prop-types";
import React from "react";
import { getAnnotationRangeType } from "ve-range-utils";
import AnnotationContainerHolder from "../AnnotationContainerHolder";
import AnnotationPositioner from "../AnnotationPositioner";
import Translation from "./Translation";
import getXStartAndWidthOfRowAnnotation from "../getXStartAndWidthOfRowAnnotation";
function Translations(props) {
let {
annotationRanges,
bpsPerRow,
charWidth,
annotationHeight,
spaceBetweenAnnotations,
getGaps,
...rest
} = props;
if (annotationRanges.length === 0) {
return null;
}
let maxAnnotationYOffset = 0;
const annotationsSVG = [];
annotationRanges.forEach(function(annotationRange) {
if (annotationRange.isJoinedLocation) return; //filter out joined locations, just show the overarching translation for CDS features ()
if (annotationRange.yOffset > maxAnnotationYOffset) {
//TODO: consider abstracting out the code to calculate the necessary height for the annotation container
maxAnnotationYOffset = annotationRange.yOffset;
}
const annotation = annotationRange.annotation;
const { gapsBefore, gapsInside } = getGaps(annotationRange);
const result = getXStartAndWidthOfRowAnnotation(
annotationRange,
bpsPerRow,
charWidth,
gapsBefore,
gapsInside
);
annotationsSVG.push(
<AnnotationPositioner
height={annotationHeight}
width={result.width}
className="veRowViewTranslations"
key={
"ve-translation-" + annotation.id + "start:" + annotationRange.start
}
top={
annotationRange.yOffset * (annotationHeight + spaceBetweenAnnotations)
}
left={result.xStart}
>
<Translation
annotationRange={annotationRange}
rangeType={getAnnotationRangeType(
annotationRange,
annotation,
annotation.forward
)}
{...getGaps(annotationRange)}
getGaps={getGaps}
widthInBps={annotationRange.end - annotationRange.start + 1}
charWidth={charWidth}
height={annotationHeight}
{...rest}
/>
</AnnotationPositioner>
);
// transform={"scale(" + transformX + ",.2) "}
// annotationsSVG = annotationsSVG.concat(translationSVG);
});
const containerHeight =
(maxAnnotationYOffset + 1) * (annotationHeight + spaceBetweenAnnotations);
// height={containerHeight}
return (
<AnnotationContainerHolder containerHeight={containerHeight}>
{annotationsSVG}
</AnnotationContainerHolder>
);
}
// Translations.propTypes = {
// annotationRanges: PropTypes.arrayOf(
// PropTypes.shape({
// start: PropTypes.number.isRequired,
// end: PropTypes.number.isRequired,
// yOffset: PropTypes.number.isRequired,
// annotation: PropTypes.shape({
// start: PropTypes.number.isRequired,
// end: PropTypes.number.isRequired,
// forward: PropTypes.bool.isRequired,
// id: PropTypes.string.isRequired
// })
// })
// ),
// charWidth: PropTypes.number.isRequired,
// bpsPerRow: PropTypes.number.isRequired,
// annotationHeight: PropTypes.number.isRequired,
// spaceBetweenAnnotations: PropTypes.number.isRequired,
// sequenceLength: PropTypes.number.isRequired
// };
export default pureNoFunc(Translations);