@haniffalab/cherita-react 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +5 -5
- package/README.md +1 -1
- package/babel.config.json +6 -0
- package/dist/components/Dotplot.js +125 -0
- package/dist/components/Heatmap.js +125 -0
- package/dist/components/ObsList.js +66 -0
- package/dist/components/VarList.js +123 -0
- package/dist/constants/constants.js +8 -0
- package/dist/context/DatasetContext.js +100 -0
- package/dist/index.js +47 -0
- package/dist/lib/components/Dotplot.js +125 -0
- package/dist/lib/components/Heatmap.js +125 -0
- package/dist/lib/components/ObsList.js +66 -0
- package/dist/lib/components/VarList.js +123 -0
- package/dist/lib/constants/constants.js +8 -0
- package/dist/lib/context/DatasetContext.js +100 -0
- package/package.json +52 -46
- package/src/index.js +6 -10
- package/src/lib/components/Dotplot.js +116 -0
- package/src/{Heatmap.js → lib/components/Heatmap.js} +115 -107
- package/src/{ObsList.js → lib/components/ObsList.js} +56 -53
- package/src/{VarList.js → lib/components/VarList.js} +114 -153
- package/src/{constants.js → lib/constants/constants.js} +20 -20
- package/src/{DatasetContext.js → lib/context/DatasetContext.js} +68 -68
- package/public/index.html +0 -10
- package/src/App.js +0 -30
package/src/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
<React.StrictMode>
|
|
8
|
-
<App dataset_url="https://storage.googleapis.com/haniffalab/test/breast_cancer-visium-anndata.zarr" />
|
|
9
|
-
</React.StrictMode>
|
|
10
|
-
);
|
|
1
|
+
export { ObsColsList } from "./lib/components/ObsList";
|
|
2
|
+
export { VarNamesList } from "./lib/components/VarList";
|
|
3
|
+
export { Heatmap } from "./lib/components/Heatmap";
|
|
4
|
+
export { Dotplot } from "./lib/components/Dotplot";
|
|
5
|
+
export { PLOTLY_COLORSCALES } from "./lib/constants/constants";
|
|
6
|
+
export { DatasetProvider } from "./lib/context/DatasetContext";
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import "bootstrap/dist/css/bootstrap.min.css";
|
|
2
|
+
import Dropdown from "react-bootstrap/Dropdown";
|
|
3
|
+
import { React, useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import Plot from "react-plotly.js";
|
|
5
|
+
import { useDataset, useDatasetDispatch } from "./DatasetContext";
|
|
6
|
+
import { PLOTLY_COLORSCALES } from "./lib/constants/constants";
|
|
7
|
+
|
|
8
|
+
export function DotplotControls() {
|
|
9
|
+
const dataset = useDataset();
|
|
10
|
+
const dispatch = useDatasetDispatch();
|
|
11
|
+
let [active, setActive] = useState(dataset.colorscale);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setActive(dataset.colorscale);
|
|
15
|
+
}, [dataset.colorscale]);
|
|
16
|
+
|
|
17
|
+
const colormapList = PLOTLY_COLORSCALES.map((item) => (
|
|
18
|
+
<Dropdown.Item
|
|
19
|
+
key={item}
|
|
20
|
+
active={active === item}
|
|
21
|
+
onClick={() => {
|
|
22
|
+
dispatch({
|
|
23
|
+
type: "colorscaleSelected",
|
|
24
|
+
colorscale: item,
|
|
25
|
+
});
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
{item}
|
|
29
|
+
</Dropdown.Item>
|
|
30
|
+
));
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Dropdown>
|
|
34
|
+
<Dropdown.Toggle id="dropdownColorscale" variant="light">
|
|
35
|
+
{dataset.colorscale}
|
|
36
|
+
</Dropdown.Toggle>
|
|
37
|
+
<Dropdown.Menu>{colormapList}</Dropdown.Menu>
|
|
38
|
+
</Dropdown>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function Dotplot() {
|
|
43
|
+
const dataset = useDataset();
|
|
44
|
+
const colorscale = useRef(dataset.colorscale);
|
|
45
|
+
let [data, setData] = useState([]);
|
|
46
|
+
let [layout, setLayout] = useState({});
|
|
47
|
+
let [hasSelections, setHasSelections] = useState(false);
|
|
48
|
+
|
|
49
|
+
const updateColorscale = useCallback((colorscale) => {
|
|
50
|
+
setLayout((l) => {
|
|
51
|
+
return {
|
|
52
|
+
...l,
|
|
53
|
+
coloraxis: { ...l.coloraxis, colorscale: colorscale },
|
|
54
|
+
};
|
|
55
|
+
});
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
useEffect(() => {
|
|
59
|
+
if (dataset.selectedObs && dataset.selectedMultiVar.length) {
|
|
60
|
+
setHasSelections(true);
|
|
61
|
+
fetch(new URL("dotplot", process.env.REACT_APP_API_URL), {
|
|
62
|
+
method: "POST",
|
|
63
|
+
mode: "cors",
|
|
64
|
+
headers: {
|
|
65
|
+
"Content-Type": "application/json",
|
|
66
|
+
Accept: "application/json",
|
|
67
|
+
},
|
|
68
|
+
body: JSON.stringify({
|
|
69
|
+
url: dataset.url,
|
|
70
|
+
selectedObs: dataset.selectedObs,
|
|
71
|
+
selectedMultiVar: dataset.selectedMultiVar,
|
|
72
|
+
}),
|
|
73
|
+
})
|
|
74
|
+
.then((response) => response.json())
|
|
75
|
+
.then((data) => {
|
|
76
|
+
setData(data.data);
|
|
77
|
+
setLayout(data.layout);
|
|
78
|
+
updateColorscale(colorscale.current);
|
|
79
|
+
});
|
|
80
|
+
} else {
|
|
81
|
+
setHasSelections(false);
|
|
82
|
+
}
|
|
83
|
+
}, [
|
|
84
|
+
dataset.url,
|
|
85
|
+
dataset.selectedObs,
|
|
86
|
+
dataset.selectedMultiVar,
|
|
87
|
+
updateColorscale,
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
console.log("update colorscale");
|
|
92
|
+
colorscale.current = dataset.colorscale;
|
|
93
|
+
updateColorscale(colorscale.current);
|
|
94
|
+
}, [dataset.colorscale, updateColorscale]);
|
|
95
|
+
|
|
96
|
+
if (hasSelections) {
|
|
97
|
+
return (
|
|
98
|
+
<div className="container text-center">
|
|
99
|
+
<h5>{dataset.url}</h5>
|
|
100
|
+
<DotplotControls />
|
|
101
|
+
<Plot
|
|
102
|
+
data={data}
|
|
103
|
+
layout={layout}
|
|
104
|
+
useResizeHandler={true}
|
|
105
|
+
style={{ width: "100%", height: "100%" }}
|
|
106
|
+
/>
|
|
107
|
+
</div>
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
return (
|
|
111
|
+
<div className="h-100">
|
|
112
|
+
<h5>{dataset.url}</h5>
|
|
113
|
+
<p>Select OBS and VAR</p>
|
|
114
|
+
</div>
|
|
115
|
+
);
|
|
116
|
+
}
|
|
@@ -1,107 +1,115 @@
|
|
|
1
|
-
import "bootstrap/dist/css/bootstrap.min.css";
|
|
2
|
-
import Dropdown from "react-bootstrap/Dropdown";
|
|
3
|
-
import { React, useEffect, useState } from "react";
|
|
4
|
-
import Plot from "react-plotly.js";
|
|
5
|
-
import { useDataset, useDatasetDispatch } from "./DatasetContext";
|
|
6
|
-
import { PLOTLY_COLORSCALES } from "./constants";
|
|
7
|
-
|
|
8
|
-
export function HeatmapControls() {
|
|
9
|
-
const dataset = useDataset();
|
|
10
|
-
const dispatch = useDatasetDispatch();
|
|
11
|
-
let [active, setActive] = useState(dataset.colorscale);
|
|
12
|
-
|
|
13
|
-
useEffect(() => {
|
|
14
|
-
setActive(dataset.colorscale);
|
|
15
|
-
}, [dataset.colorscale]);
|
|
16
|
-
|
|
17
|
-
const colormapList = PLOTLY_COLORSCALES.map((item) => (
|
|
18
|
-
<Dropdown.Item
|
|
19
|
-
key={item}
|
|
20
|
-
active={active === item}
|
|
21
|
-
onClick={() => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
</Dropdown.
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
let [data, setData] = useState([]);
|
|
46
|
-
let [layout, setLayout] = useState({});
|
|
47
|
-
let [hasSelections, setHasSelections] = useState(false);
|
|
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
|
-
|
|
1
|
+
import "bootstrap/dist/css/bootstrap.min.css";
|
|
2
|
+
import Dropdown from "react-bootstrap/Dropdown";
|
|
3
|
+
import { React, useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import Plot from "react-plotly.js";
|
|
5
|
+
import { useDataset, useDatasetDispatch } from "./DatasetContext";
|
|
6
|
+
import { PLOTLY_COLORSCALES } from "./lib/constants/constants";
|
|
7
|
+
|
|
8
|
+
export function HeatmapControls() {
|
|
9
|
+
const dataset = useDataset();
|
|
10
|
+
const dispatch = useDatasetDispatch();
|
|
11
|
+
let [active, setActive] = useState(dataset.colorscale);
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
setActive(dataset.colorscale);
|
|
15
|
+
}, [dataset.colorscale]);
|
|
16
|
+
|
|
17
|
+
const colormapList = PLOTLY_COLORSCALES.map((item) => (
|
|
18
|
+
<Dropdown.Item
|
|
19
|
+
key={item}
|
|
20
|
+
active={active === item}
|
|
21
|
+
onClick={() => {
|
|
22
|
+
dispatch({
|
|
23
|
+
type: "colorscaleSelected",
|
|
24
|
+
colorscale: item,
|
|
25
|
+
});
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
{item}
|
|
29
|
+
</Dropdown.Item>
|
|
30
|
+
));
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<Dropdown>
|
|
34
|
+
<Dropdown.Toggle id="dropdownColorscale" variant="light">
|
|
35
|
+
{dataset.colorscale}
|
|
36
|
+
</Dropdown.Toggle>
|
|
37
|
+
<Dropdown.Menu>{colormapList}</Dropdown.Menu>
|
|
38
|
+
</Dropdown>
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function Heatmap() {
|
|
43
|
+
const dataset = useDataset();
|
|
44
|
+
const colorscale = useRef(dataset.colorscale);
|
|
45
|
+
let [data, setData] = useState([]);
|
|
46
|
+
let [layout, setLayout] = useState({});
|
|
47
|
+
let [hasSelections, setHasSelections] = useState(false);
|
|
48
|
+
|
|
49
|
+
const updateColorscale = useCallback((colorscale) => {
|
|
50
|
+
setData((d) =>
|
|
51
|
+
d.map((i) => {
|
|
52
|
+
return { ...i, colorscale: colorscale };
|
|
53
|
+
})
|
|
54
|
+
);
|
|
55
|
+
}, []);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (dataset.selectedObs && dataset.selectedMultiVar.length) {
|
|
59
|
+
setHasSelections(true);
|
|
60
|
+
fetch(new URL("heatmap", process.env.REACT_APP_API_URL), {
|
|
61
|
+
method: "POST",
|
|
62
|
+
mode: "cors",
|
|
63
|
+
headers: {
|
|
64
|
+
"Content-Type": "application/json",
|
|
65
|
+
Accept: "application/json",
|
|
66
|
+
},
|
|
67
|
+
body: JSON.stringify({
|
|
68
|
+
url: dataset.url,
|
|
69
|
+
selectedObs: dataset.selectedObs,
|
|
70
|
+
selectedMultiVar: dataset.selectedMultiVar,
|
|
71
|
+
}),
|
|
72
|
+
})
|
|
73
|
+
.then((response) => response.json())
|
|
74
|
+
.then((data) => {
|
|
75
|
+
setData(data.data);
|
|
76
|
+
setLayout(data.layout);
|
|
77
|
+
updateColorscale(colorscale.current);
|
|
78
|
+
});
|
|
79
|
+
} else {
|
|
80
|
+
setHasSelections(false);
|
|
81
|
+
}
|
|
82
|
+
}, [
|
|
83
|
+
dataset.url,
|
|
84
|
+
dataset.selectedObs,
|
|
85
|
+
dataset.selectedMultiVar,
|
|
86
|
+
updateColorscale,
|
|
87
|
+
]);
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
console.log("update colorscale");
|
|
91
|
+
colorscale.current = dataset.colorscale;
|
|
92
|
+
updateColorscale(colorscale.current);
|
|
93
|
+
}, [dataset.colorscale, updateColorscale]);
|
|
94
|
+
|
|
95
|
+
if (hasSelections) {
|
|
96
|
+
return (
|
|
97
|
+
<div className="container text-center">
|
|
98
|
+
<h5>{dataset.url}</h5>
|
|
99
|
+
<HeatmapControls />
|
|
100
|
+
<Plot
|
|
101
|
+
data={data}
|
|
102
|
+
layout={layout}
|
|
103
|
+
useResizeHandler={true}
|
|
104
|
+
style={{ width: "100%", height: "100%" }}
|
|
105
|
+
/>
|
|
106
|
+
</div>
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
return (
|
|
110
|
+
<div className="h-100">
|
|
111
|
+
<h5>{dataset.url}</h5>
|
|
112
|
+
<p>Select OBS and VAR</p>
|
|
113
|
+
</div>
|
|
114
|
+
);
|
|
115
|
+
}
|
|
@@ -1,53 +1,56 @@
|
|
|
1
|
-
import "bootstrap/dist/css/bootstrap.min.css";
|
|
2
|
-
import "bootstrap/dist/js/bootstrap.bundle.min.js";
|
|
3
|
-
import { React, useEffect, useState } from "react";
|
|
4
|
-
import { useDataset, useDatasetDispatch } from "./DatasetContext";
|
|
5
|
-
|
|
6
|
-
export function ObsColsList() {
|
|
7
|
-
const dataset = useDataset();
|
|
8
|
-
const dispatch = useDatasetDispatch();
|
|
9
|
-
const [obsColsList, setObsColsList] = useState([]);
|
|
10
|
-
let [active, setActive] = useState(null);
|
|
11
|
-
|
|
12
|
-
useEffect(() => {
|
|
13
|
-
fetch(new URL("obs/cols", process.env.REACT_APP_API_URL), {
|
|
14
|
-
method: "POST",
|
|
15
|
-
mode: "cors",
|
|
16
|
-
headers: {
|
|
17
|
-
"Content-Type": "application/json",
|
|
18
|
-
Accept: "application/json",
|
|
19
|
-
},
|
|
20
|
-
body: JSON.stringify({ url: dataset.url }),
|
|
21
|
-
})
|
|
22
|
-
.then((response) => response.json())
|
|
23
|
-
.then((data) => {
|
|
24
|
-
setObsColsList(data);
|
|
25
|
-
});
|
|
26
|
-
}, [dataset.url]);
|
|
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
|
-
}
|
|
1
|
+
import "bootstrap/dist/css/bootstrap.min.css";
|
|
2
|
+
import "bootstrap/dist/js/bootstrap.bundle.min.js";
|
|
3
|
+
import { React, useEffect, useState } from "react";
|
|
4
|
+
import { useDataset, useDatasetDispatch } from "./DatasetContext";
|
|
5
|
+
|
|
6
|
+
export function ObsColsList() {
|
|
7
|
+
const dataset = useDataset();
|
|
8
|
+
const dispatch = useDatasetDispatch();
|
|
9
|
+
const [obsColsList, setObsColsList] = useState([]);
|
|
10
|
+
let [active, setActive] = useState(null);
|
|
11
|
+
|
|
12
|
+
useEffect(() => {
|
|
13
|
+
fetch(new URL("obs/cols", process.env.REACT_APP_API_URL), {
|
|
14
|
+
method: "POST",
|
|
15
|
+
mode: "cors",
|
|
16
|
+
headers: {
|
|
17
|
+
"Content-Type": "application/json",
|
|
18
|
+
Accept: "application/json",
|
|
19
|
+
},
|
|
20
|
+
body: JSON.stringify({ url: dataset.url }),
|
|
21
|
+
})
|
|
22
|
+
.then((response) => response.json())
|
|
23
|
+
.then((data) => {
|
|
24
|
+
setObsColsList(data);
|
|
25
|
+
});
|
|
26
|
+
}, [dataset.url]);
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
setActive(dataset.selectedObs);
|
|
30
|
+
}, [dataset.selectedObs]);
|
|
31
|
+
|
|
32
|
+
const obsList = obsColsList.map((item) => (
|
|
33
|
+
<button
|
|
34
|
+
type="button"
|
|
35
|
+
key={item}
|
|
36
|
+
className={`list-group-item list-grou-item-action ${
|
|
37
|
+
active === item && "active"
|
|
38
|
+
}`}
|
|
39
|
+
onClick={() => {
|
|
40
|
+
dispatch({
|
|
41
|
+
type: "obsSelected",
|
|
42
|
+
obs: item,
|
|
43
|
+
});
|
|
44
|
+
}}
|
|
45
|
+
>
|
|
46
|
+
{item}
|
|
47
|
+
</button>
|
|
48
|
+
));
|
|
49
|
+
|
|
50
|
+
return (
|
|
51
|
+
<div className="h-100">
|
|
52
|
+
<h5>{dataset.url}</h5>
|
|
53
|
+
<div className="list-group overflow-auto mh-100">{obsList}</div>
|
|
54
|
+
</div>
|
|
55
|
+
);
|
|
56
|
+
}
|