-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathMouseEvents.jsx
124 lines (117 loc) · 3.79 KB
/
MouseEvents.jsx
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import React, { useEffect, useMemo, useRef, useState } from "react";
import { GoslingComponent } from "gosling.js";
function MouseEvents() {
const gosRef = useRef();
const [position, setPosition] = useState();
const [data, setData] = useState([]);
useEffect(() => {
if (!gosRef.current) return;
const localRef = gosRef.current;
localRef.api.subscribe("click", (_, eventData) => {
const { genomicPosition: p } = eventData;
setPosition(`${p.chromosome}:${p.position}`);
setData(eventData.data);
});
localRef.api.subscribe("rangeSelect", (_, eventData) => {
if (!eventData || !eventData.genomicRange) {
// range selection cleared
setPosition("N/A");
setData([]);
} else {
const { genomicRange: p } = eventData;
if (p.length === 2)
setPosition(
`${p[0].chromosome}:${p[0].position}-${p[1].chromosome}:${p[1].position}`
);
setData(
eventData.data.length > 10
? eventData.data.slice(0, 10)
: eventData.data
);
}
});
}, []);
const goslingComponent = useMemo(
() => (
<GoslingComponent
ref={gosRef}
spec={{
xDomain: { chromosome: "chr3", interval: [52168000, 52890000] },
tracks: [
{
title: "Group Marks By Gene",
template: "gene",
data: {
url: "https://server.gosling-lang.org/api/v1/tileset_info/?d=gene-annotation",
type: "beddb",
genomicFields: [
{ index: 1, name: "start" },
{ index: 2, name: "end" },
],
valueFields: [
{ index: 5, name: "strand", type: "nominal" },
{ index: 3, name: "name", type: "nominal" },
],
exonIntervalFields: [
{ index: 12, name: "start" },
{ index: 13, name: "end" },
],
},
encoding: {
startPosition: { field: "start" },
endPosition: { field: "end" },
strandColor: { field: "strand", range: ["gray"] },
strandRow: { field: "strand" },
opacity: { value: 0.4 },
geneHeight: { value: 20 },
geneLabel: { field: "name" },
geneLabelFontSize: { value: 20 },
geneLabelColor: { field: "strand", range: ["gray"] },
geneLabelStroke: { value: "white" },
geneLabelStrokeThickness: { value: 4 },
geneLabelOpacity: { value: 1 },
type: { field: "type" },
},
tooltip: [{ field: "name", type: "nominal" }],
width: 600,
height: 60,
experimental: {
mouseEvents: {
mouseOver: true,
rangeSelect: true,
groupMarksByField: "name",
},
},
style: {
mouseOver: {
arrange: "behind",
color: "#E0E0E0",
stroke: "#E0E0E0",
strokeWidth: 4,
},
select: {
arrange: "behind",
color: "#B9D4FA",
stroke: "#B9D4FA",
strokeWidth: 4,
},
},
},
],
}}
/>
),
[]
);
return (
<div>
<div style={{ marginTop: 30, marginLeft: 60 }}>
Hold down the alt or option key to select a range. <br />
Selected Position: <b>{position ? position : "N/A"}</b>
</div>
{goslingComponent}
{/* Rest of the code */}
</div>
);
}
export default MouseEvents;