-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathMain.js
More file actions
93 lines (86 loc) · 3.7 KB
/
Main.js
File metadata and controls
93 lines (86 loc) · 3.7 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
92
93
import React from 'react'
import ReactDOM from 'react-dom'
import ReactGA from 'react-ga'
import ContainerLoader from './layout/ContainerLoader.js'
/**
* @param {Object} options
* @param {string | Object} options.target - a <div> id or a DOM element, as returned by ReactDOM.findDOMNode()
* @param {boolean} options.disableGoogleAnalytics - Disable Google Analytics
* @param {boolean} options.showControlMenu - Show menu with sorting, filtering and download options
* @param {function} options.fail - Callback to run if the AJAX request to the server fails. (jqXHR, textStatus)
* @param {function} options.render - Callback to run after each render
* @param {boolean} options.showAnatomogram - optionally hide the anatomogram
* @param {boolean} options.isWidget
* @param {string} options.atlasUrl - Atlas host and path with protocol and port
* @param {string} options.inProxy - Inbound proxy to pull assets from outside your domain
* @param {string} options.outProxy - Outbound proxy for links that take you outside the current domain
* @param {string} options.experiment
* @param {Object|string} options.query - Query object or relative URL endpoint to source data from:
* e.g. json/experiments/E-PROT-1, /json/genes/ENSG00000005801, /json/genesets/GO:0000001
* json/baseline_refexperiment?geneQuery=…, /json/baseline_experiments?geneQuery=…
* @param {string} options.query.species
* @param {{value: string, category: string}[]} options.query.gene
* @param {{value: string, category: string}[]} options.query.condition
* @param {string} options.query.source
*/
const DEFAULT_OPTIONS = {
showAnatomogram: true,
isWidget: true,
disableGoogleAnalytics: false,
showControlMenu: true,
atlasUrl: `https://www.ebi.ac.uk/gxa/`,
inProxy: ``,
outProxy: ``,
experiment: ``
}
const ExpressionAtlasHeatmap = options => (
// The wrapping div is important to determine the width of the heatmap and know if the labels are going to be
// rotated, so that we can set sensible margin sizes. See HeatmapCanvas.js
<div className={`gxaHeatmapContainer`}>
<ContainerLoader
{...DEFAULT_OPTIONS}
{...options}
source={
typeof options.query === `string` ?
{
endpoint: options.query,
params: {}
} :
{
endpoint: resolveEndpoint(options.experiment),
//the webapp wants "geneQuery" and "conditionQuery" as parameters but in the API offering query.gene and
// query.condition felt nicer
params:
options.query ?
Object.entries(options.query)
.map(p => [`gene`, `condition`].includes(p[0]) ? [p[0]+`Query`, p[1]] : p)
.reduce((acc,o)=>{ acc[o[0]]=o[1]; return acc}, {}) :
{}
}} />
</div>
)
const render = options => {
const { disableGoogleAnalytics = false, render = () => {}, target } = options
ReactDOM.render(
<ExpressionAtlasHeatmap {...options} />,
typeof target === `string` ? document.getElementById(target) : target,
render)
if (!disableGoogleAnalytics) {
ReactGA.initialize(`UA-37676851-1`, {
gaOptions: {
name: `atlas-highcharts-widget`
}
})
ReactGA.pageview(window.location.pathname)
}
}
function resolveEndpoint(experiment) {
return (
!experiment ?
`json/baseline_experiments` :
experiment === `reference` ?
`json/baseline_refexperiment` :
`json/experiments/${experiment}`
)
}
export {ExpressionAtlasHeatmap as default, render}