Skip to content

Commit 9aeb81d

Browse files
committed
Stub in eda scatterplot for phenotype dataset
1 parent 486270d commit 9aeb81d

File tree

2 files changed

+106
-0
lines changed

2 files changed

+106
-0
lines changed

packages/libs/web-common/src/components/DatasetGraph.jsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
import { safeHtml } from '@veupathdb/wdk-client/lib/Utils/ComponentUtils';
99
import ExternalResource from './ExternalResource';
1010
import { JbrowseIframe } from './JbrowseIframe';
11+
import { EdaScatterPlot } from './eda/EdaScatterPlot';
1112

1213
/**
1314
* Renders an Dataset graph with the provided rowData.
@@ -223,6 +224,25 @@ export default class DatasetGraph extends React.PureComponent {
223224
<div className="eupathdb-DatasetGraphContainer">
224225
<div className="eupathdb-DatasetGraph">
225226
{visibleGraphs.map((index) => {
227+
// Hardcoded to render an EDA Scatterplot
228+
// TODO Replace hardcoded values with rowData attributes.
229+
if (dataset_id === 'DS_d4745ea297') {
230+
return (
231+
<EdaScatterPlot
232+
datasetId={dataset_id}
233+
xAxisVariable={{
234+
entityId: 'genePhenotypeData',
235+
// Phenotype rank
236+
variableId: 'VAR_9f0d6627',
237+
}}
238+
yAxisVariable={{
239+
entityId: 'genePhenotypeData',
240+
// Mean Phenotype score
241+
variableId: 'VAR_40829b7e',
242+
}}
243+
/>
244+
);
245+
}
226246
let { height, width, visible_part } = graphs[index];
227247
let fullUrl = `${imgUrl}&vp=${visible_part}`;
228248
return (
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import ScatterPlot from '@veupathdb/components/lib/plots/ScatterPlot';
2+
import { isFaceted } from '@veupathdb/components/lib/types/guards';
3+
import {
4+
useDataClient,
5+
useFindEntityAndVariable,
6+
useStudyMetadata,
7+
} from '@veupathdb/eda/lib/core';
8+
import { DocumentationContainer } from '@veupathdb/eda/lib/core/components/docs/DocumentationContainer';
9+
import { scatterplotResponseToData } from '@veupathdb/eda/lib/core/components/visualizations/implementations/ScatterplotVisualization';
10+
import { useCachedPromise } from '@veupathdb/eda/lib/core/hooks/cachedPromise';
11+
import { VariableDescriptor } from '@veupathdb/eda/lib/core/types/variable';
12+
import { WorkspaceContainer } from '@veupathdb/eda/lib/workspace/WorkspaceContainer';
13+
import { edaServiceUrl } from '../../config';
14+
15+
interface Props {
16+
datasetId: string;
17+
xAxisVariable: VariableDescriptor;
18+
yAxisVariable: VariableDescriptor;
19+
}
20+
21+
/**
22+
* A simplified EDA ScatterPlot component.
23+
*
24+
* This will render a plot and a legend.
25+
*/
26+
export function EdaScatterPlot(props: Props) {
27+
const { datasetId } = props;
28+
return (
29+
<DocumentationContainer>
30+
<WorkspaceContainer studyId={datasetId} edaServiceUrl={edaServiceUrl}>
31+
<ScatterPlotAdapter {...props} />
32+
</WorkspaceContainer>
33+
</DocumentationContainer>
34+
);
35+
}
36+
37+
interface AdapterProps {
38+
xAxisVariable: VariableDescriptor;
39+
yAxisVariable: VariableDescriptor;
40+
}
41+
42+
function ScatterPlotAdapter(props: AdapterProps) {
43+
const { xAxisVariable, yAxisVariable } = props;
44+
const { id: studyId } = useStudyMetadata();
45+
const dataClient = useDataClient();
46+
const findEntityAndVariable = useFindEntityAndVariable();
47+
const data = useCachedPromise(
48+
async function getData() {
49+
const response = await dataClient.getScatterplot('xyrelationships', {
50+
studyId,
51+
filters: [],
52+
config: {
53+
outputEntityId: xAxisVariable.entityId,
54+
valueSpec: 'raw',
55+
xAxisVariable,
56+
yAxisVariable,
57+
// maxAllowedDataPoints: 1_000,
58+
},
59+
});
60+
return scatterplotResponseToData(response).dataSetProcess;
61+
},
62+
['ScatterPlotAdapter', studyId, xAxisVariable, yAxisVariable]
63+
);
64+
65+
const xAxisEntityAndVariable = findEntityAndVariable(xAxisVariable);
66+
const yAxisEntityAndVariable = findEntityAndVariable(yAxisVariable);
67+
68+
if (isFaceted(data.value)) {
69+
throw new Error('Received unexpected faceted data.');
70+
}
71+
72+
if (data.error) {
73+
return <div>Error: {String(data.error)}</div>;
74+
}
75+
76+
return (
77+
<ScatterPlot
78+
interactive
79+
showSpinner={data.pending}
80+
markerBodyOpacity={0.5}
81+
data={data.value}
82+
dependentAxisLabel={yAxisEntityAndVariable?.variable.displayName}
83+
independentAxisLabel={xAxisEntityAndVariable?.variable.displayName}
84+
/>
85+
);
86+
}

0 commit comments

Comments
 (0)