Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean Up MetaSUB Dashboard #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
130 changes: 66 additions & 64 deletions src/contrib/metasub/components/samplesunburst.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,71 +9,73 @@ interface SampleSunburstPanelProps {
onClickAction: (taxonName: string) => void;
}


const SampleSunburstPanel = (props: SampleSunburstPanelProps) => {
const url =
'/contrib/metasub/sample_sunburst/' +
props.sampleUUID +
'?format=json&min_abundance=0.005';
const [{ data, loading, error }] = usePangeaAxios<SunburstTaxa>({
url: url,
method: 'GET',
});
if (loading) {
return (
<>
<Row>
<h1>Loading...</h1>
<h2>Sample Taxa</h2>
</Row>
</>
);
}
if (error) {
return (
<>
<Row>
<h1>Error</h1>
<h2>Sample Taxa</h2>
<p>{error}</p>
</Row>
</>
);
}
const plotData: Partial<Plotly.PlotData>[] = [
{
type: 'sunburst',
labels: data.taxa,
parents: data.parents,
values: data.abundances,
outsidetextfont: { size: 20, color: '#377eb8' },
leaf: { opacity: 0.4 },
marker: { line: { width: 2 } },
},
];
const layout = {
margin: { l: 0, r: 0, b: 0, t: 0 },
width: 350,
height: 350,
};
return (
<>
<Plot
data={plotData}
layout={layout}
onClick={e =>
props.onClickAction(
e.points[0]?.value
? e.points[0]?.label
? e.points[0]?.label
: ''
: '',
)
}
/>
<h5>Click a sample on the map to see it here.</h5>
<h5>Click a species here to see it on the map.</h5>
</>
);
// const url =
// '/contrib/metasub/sample_sunburst/' +
// props.sampleUUID +
// '?format=json&min_abundance=0.005';
// const [{ data, loading, error }] = usePangeaAxios<SunburstTaxa>({
// url: url,
// method: 'GET',
// });
// if (loading) {
// return (
// <>
// <Row>
// <h1>Loading...</h1>
// <h2>Sample Taxa</h2>
// </Row>
// </>
// );
// }
// if (error) {
// return (
// <>
// <Row>
// <h1>Error</h1>
// <h2>Sample Taxa</h2>
// <p>{error}</p>
// </Row>
// </>
// );
// }
// const plotData: Partial<Plotly.PlotData>[] = [
// {
// type: 'sunburst',
// labels: data.taxa,
// parents: data.parents,
// values: data.abundances,
// outsidetextfont: { size: 20, color: '#377eb8' },
// leaf: { opacity: 0.4 },
// marker: { line: { width: 2 } },
// },
// ];
// const layout = {
// margin: { l: 0, r: 0, b: 0, t: 0 },
// width: 350,
// height: 350,
// };
// return (
// <>
// <Plot
// data={plotData}
// layout={layout}
// onClick={e =>
// props.onClickAction(
// e.points[0]?.value
// ? e.points[0]?.label
// ? e.points[0]?.label
// : ''
// : '',
// )
// }
// />
// <h5>Click a sample on the map to see it here.</h5>
// <h5>Click a species here to see it on the map.</h5>
// </>
// );
return (<></>)
};

export default SampleSunburstPanel;
91 changes: 46 additions & 45 deletions src/contrib/metasub/components/taxonabundancepanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,57 @@ const generateUrl = (taxonName: string): string => {
};

const TaxaAbundancePanel = (props: TaxaAbundancePanelProps) => {
const [{ data, loading, error }, refetch] = usePangeaAxios<{
[key: string]: CitiesTaxonResult;
}>({ url: '', method: 'GET' }, { manual: true });
// const [{ data, loading, error }, refetch] = usePangeaAxios<{
// [key: string]: CitiesTaxonResult;
// }>({ url: '', method: 'GET' }, { manual: true });

React.useEffect(() => {
refetch({ url: generateUrl(props.taxonName) });
}, [props.taxonName]);
// React.useEffect(() => {
// refetch({ url: generateUrl(props.taxonName) });
// }, [props.taxonName]);

const currentData = ((data || {}).results || {})[props.taxonName];
// const currentData = ((data || {}).results || {})[props.taxonName];

if (loading || currentData === undefined) {
return (
<>
<Row>
<h1>Loading...</h1>
<h2>Taxon Abundance</h2>
</Row>
</>
);
}
// if (loading || currentData === undefined) {
// return (
// <>
// <Row>
// <h1>Loading...</h1>
// <h2>Taxon Abundance</h2>
// </Row>
// </>
// );
// }

if (error) {
return (
<>
<Row>
<h1>Error</h1>
<h2> MetaSUB Map</h2>
<p>{error}</p>
</Row>
</>
);
}
// if (error) {
// return (
// <>
// <Row>
// <h1>Error</h1>
// <h2> MetaSUB Map</h2>
// <p>{error}</p>
// </Row>
// </>
// );
// }

const cityAbundances: { [key: string]: CityTaxonAbundance } = currentData; //['results'][props.taxonName];
const plotData: Partial<Plotly.PlotData>[] = Object.keys(cityAbundances).map(
function(cityName: string): Partial<Plotly.PlotData> {
return {
y: cityAbundances[cityName].all_relative_abundances,
type: 'box',
name: cityAbundances[cityName].city_name,
};
},
);
const layout = {
title: '<i>' + props.taxonName + '</i> Abundance in Cities',
margin: { l: 20, r: 0, b: 0, t: 30 },
width: 700,
height: 400,
};
return <Plot data={plotData} layout={layout} />;
// const cityAbundances: { [key: string]: CityTaxonAbundance } = currentData; //['results'][props.taxonName];
// const plotData: Partial<Plotly.PlotData>[] = Object.keys(cityAbundances).map(
// function(cityName: string): Partial<Plotly.PlotData> {
// return {
// y: cityAbundances[cityName].all_relative_abundances,
// type: 'box',
// name: cityAbundances[cityName].city_name,
// };
// },
// );
// const layout = {
// title: '<i>' + props.taxonName + '</i> Abundance in Cities',
// margin: { l: 20, r: 0, b: 0, t: 30 },
// width: 700,
// height: 400,
// };
// return <Plot data={plotData} layout={layout} />;
return (<></>)
};

export default TaxaAbundancePanel;
105 changes: 53 additions & 52 deletions src/contrib/metasub/components/taxonabundancepanelmaterial.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,63 +17,64 @@ const generateUrl = (taxonName: string): string => {
};

const TaxaMaterialAbundancePanel = (props: TaxaMaterialAbundancePanelProps) => {
const [{ data, loading, error }, refetch] = usePangeaAxios<{
[key: string]: SurfacesTaxonResult;
}>({ url: '', method: 'GET' }, { manual: true });
// const [{ data, loading, error }, refetch] = usePangeaAxios<{
// [key: string]: SurfacesTaxonResult;
// }>({ url: '', method: 'GET' }, { manual: true });

React.useEffect(() => {
refetch({ url: generateUrl(props.taxonName) });
}, [props.taxonName]);
// React.useEffect(() => {
// refetch({ url: generateUrl(props.taxonName) });
// }, [props.taxonName]);

const currentData = ((data || {}).results || {})[props.taxonName];
// const currentData = ((data || {}).results || {})[props.taxonName];

if (loading || currentData === undefined) {
return (
<>
<Row>
<h1>Loading...</h1>
<h2>Taxon Abundance</h2>
</Row>
</>
);
}
// if (loading || currentData === undefined) {
// return (
// <>
// <Row>
// <h1>Loading...</h1>
// <h2>Taxon Abundance</h2>
// </Row>
// </>
// );
// }

if (error) {
return (
<>
<Row>
<h1>Error</h1>
<h2>Taxon Abundance</h2>
<p>{error}</p>
</Row>
</>
);
}
// if (error) {
// return (
// <>
// <Row>
// <h1>Error</h1>
// <h2>Taxon Abundance</h2>
// <p>{error}</p>
// </Row>
// </>
// );
// }

const surfaceAbundances: {
[key: string]: SurfaceTaxonAbundance;
} = currentData; //['results'][props.taxonName];
const plotData: Partial<Plotly.PlotData>[] = Object.keys(surfaceAbundances)
.filter(function(surfaceName: string): boolean {
return (
surfaceName.length > 0 &&
surfaceAbundances[surfaceName].all_relative_abundances.length >= 10
);
})
.map(function(surfaceName: string): Partial<Plotly.PlotData> {
return {
y: surfaceAbundances[surfaceName].all_relative_abundances,
type: 'box',
name: surfaceAbundances[surfaceName].material_name,
};
});
const layout = {
title: '<i>' + props.taxonName + '</i> Abundance on Surfaces',
margin: { l: 20, r: 0, b: 0, t: 30 },
width: 700,
height: 400,
};
return <Plot data={plotData} layout={layout} />;
// const surfaceAbundances: {
// [key: string]: SurfaceTaxonAbundance;
// } = currentData; //['results'][props.taxonName];
// const plotData: Partial<Plotly.PlotData>[] = Object.keys(surfaceAbundances)
// .filter(function(surfaceName: string): boolean {
// return (
// surfaceName.length > 0 &&
// surfaceAbundances[surfaceName].all_relative_abundances.length >= 10
// );
// })
// .map(function(surfaceName: string): Partial<Plotly.PlotData> {
// return {
// y: surfaceAbundances[surfaceName].all_relative_abundances,
// type: 'box',
// name: surfaceAbundances[surfaceName].material_name,
// };
// });
// const layout = {
// title: '<i>' + props.taxonName + '</i> Abundance on Surfaces',
// margin: { l: 20, r: 0, b: 0, t: 30 },
// width: 700,
// height: 400,
// };
// return <Plot data={plotData} layout={layout} />;
return (<></>)
};

export default TaxaMaterialAbundancePanel;
Loading