-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDiamond.tsx
More file actions
69 lines (60 loc) · 1.82 KB
/
Diamond.tsx
File metadata and controls
69 lines (60 loc) · 1.82 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
import { readConfObject } from '@jbrowse/core/configuration';
import { emphasize } from '@jbrowse/core/util/color';
import { observer } from 'mobx-react';
import React from 'react';
import { Feature } from '@jbrowse/core/util/simpleFeature';
const utrHeightFraction = 0.65
function isUTR(feature: Feature) {
return /(\bUTR|_UTR|untranslated[_\s]region)\b/.test(
feature.get('type') || '',
)
}
function Diamond(props) {
const {
feature,
bpPerPx,
region,
config,
featureLayout,
selected,
reversed,
} = props
const screenWidth = (region.end - region.start) / bpPerPx
const width = Math.max(featureLayout.absolute.width, 1)
const { left } = featureLayout.absolute
let { top, height } = featureLayout.absolute
if (isUTR(feature)) {
top += ((1 - utrHeightFraction) / 2) * height
height *= utrHeightFraction
}
// @ts-ignore
const color = readConfObject(config, (isUTR(feature) ? 'color3' : 'color1'), { feature })
let emphasizedColor
try {
emphasizedColor = emphasize(color, 0.3)
} catch (error) {
emphasizedColor = color
}
const color2 = readConfObject(config, 'color2', { feature })
if (left + width < 0) {
return null
}
const leftWithinBlock = Math.max(left, 0)
const diff = leftWithinBlock - left
const widthWithinBlock = Math.max(1, Math.min(width - diff, screenWidth))
return (
<>
<polygon
stroke={selected ? color2 : undefined}
fill={selected ? emphasizedColor : color}
points={[
[left + (width)/2, top].join(","),
[left + (width)/2 + (height/2), top + height / 2].join(","),
[left + (width)/2, top + height].join(","),
[left + (width)/2 - (height/2), top + height / 2].join(","),
].join(" ")}
/>
</>
)
}
export default observer(Diamond)