-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathHighlights.tsx
More file actions
91 lines (85 loc) · 2.41 KB
/
Copy pathHighlights.tsx
File metadata and controls
91 lines (85 loc) · 2.41 KB
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
import * as React from "react";
import { InputRefFunc } from "../SelectionHandler";
import { NameRange } from "../elements";
import { highlight as highlightStyle } from "../style";
import { FindXAndWidthElementType } from "./SeqBlock";
/**
* Render rectangles around highlighted ranges.
*/
export const Highlights = (props: {
compYDiff: number;
findXAndWidth: FindXAndWidthElementType;
firstBase: number;
highlights: NameRange[];
indexYDiff: number;
inputRef: InputRefFunc;
lastBase: number;
lineHeight: number;
listenerOnly: boolean;
seqBlockRef: unknown;
}) => (
<>
{/* We use two LinearFindBlocks here because we want to span both the top and bottom strand for a highlight */}
{props.highlights.map((h, i) => (
// TODO: what's going on here, why does this lead to duplicates
<SingleHighlight key={`linear-highlight-${h.id}-${props.listenerOnly}`} {...props} highlight={h} index={i} />
))}
</>
);
const SingleHighlight = (props: {
compYDiff: number;
findXAndWidth: FindXAndWidthElementType;
firstBase: number;
highlight: NameRange;
highlights: NameRange[];
index: number;
indexYDiff: number;
inputRef: InputRefFunc;
lastBase: number;
lineHeight: number;
listenerOnly: boolean;
seqBlockRef: unknown;
}) => {
const { width, x } = props.findXAndWidth(props.index, props.highlight, props.highlights);
let fill = highlightStyle.fill;
if (props.listenerOnly) {
fill = "transparent";
} else if (props.highlight.color?.length) {
fill = props.highlight.color;
}
const rectProps = {
className: "la-vz-highlight",
height: props.lineHeight,
id: props.highlight.id,
stroke: props.listenerOnly ? "none" : "rgba(0, 0, 0, 0.5)",
style: { ...highlightStyle, fill },
width: width,
x: x,
};
return (
<>
<rect
key={`linear-highlight-${props.highlight.id}-top`}
ref={props.inputRef(props.highlight.id, {
ref: props.highlight.id,
...props.highlight,
type: "HIGHLIGHT",
viewer: "LINEAR",
})}
{...rectProps}
y={props.indexYDiff}
/>
<rect
key={`linear-highlight-${props.highlight.id}-bottom`}
ref={props.inputRef(props.highlight.id, {
ref: props.highlight.id,
...props.highlight,
type: "HIGHLIGHT",
viewer: "LINEAR",
})}
{...rectProps}
y={props.compYDiff}
/>
</>
);
};