Commit 9cbd8c2c authored by Lauri Himanen's avatar Lauri Himanen Committed by Markus Scheidgen
Browse files

Updated the behaviour of the StructureViewer in ArchiveBrowser as per issue #431

parent b625e7fa
......@@ -4,7 +4,7 @@
"commit": "e98694e",
"private": true,
"dependencies": {
"@lauri-codes/materia": "0.0.6",
"@lauri-codes/materia": "0.0.7",
"@material-ui/core": "^4.0.0",
"@material-ui/icons": "^4.0.0",
"@material-ui/lab": "^4.0.0-alpha.49",
......
......@@ -4,6 +4,7 @@ import { makeStyles } from '@material-ui/core/styles'
import PropTypes from 'prop-types'
import {
Box,
Button,
Card,
CardContent,
Typography
......@@ -48,7 +49,7 @@ ErrorHandler.propTypes = ({
className: PropTypes.string
})
export function ErrorCard({message, className, classes}) {
export function ErrorCard({message, className, classes, actions}) {
const useStyles = makeStyles((theme) => {
return {
root: {
......@@ -66,9 +67,17 @@ export function ErrorCard({message, className, classes}) {
pos: {
marginBottom: 12
},
container: {
row: {
display: 'flex'
},
actions: {
display: 'flex',
justifyContent: 'flex-end'
},
column: {
display: 'flex',
flexDirection: 'column'
},
errorIcon: {
marginRight: theme.spacing(1)
}
......@@ -76,14 +85,26 @@ export function ErrorCard({message, className, classes}) {
})
const style = useStyles(classes)
console.log(actions)
return <Card className={clsx(style.root, className)}>
<CardContent className={[style.content, style['content:last-child']].join(' ')}>
<Box className={style.container}>
<Box className={style.row}>
<Error className={style.errorIcon}/>
<Typography className={style.title} color="error" gutterBottom>
{message}
</Typography>
<Box className={style.column}>
<Typography className={style.title} color="error" gutterBottom>
{message}
</Typography>
{actions
? <Box className={style.actions}>
{actions.map((action) => <Button key={action.label} onClick={action.onClick}>
{action.label}
</Button>
)}
</Box>
: ''
}
</Box>
</Box>
</CardContent>
</Card>
......@@ -92,5 +113,6 @@ export function ErrorCard({message, className, classes}) {
ErrorCard.propTypes = ({
message: PropTypes.string,
classes: PropTypes.object,
className: PropTypes.string
className: PropTypes.string,
actions: PropTypes.array
})
......@@ -361,6 +361,8 @@ QuantityValue.propTypes = ({
function Overview({section, def}) {
// States
const [mode, setMode] = useState('bs')
const [warningIgnored, setWarningIgnored] = useState(false)
// Styles
const useStyles = makeStyles(
{
......@@ -405,13 +407,6 @@ function Overview({section, def}) {
return ''
}
const nAtoms = section.atom_species.length
if (nAtoms >= 300) {
return <ErrorCard
message='Visualization is disabled due to large system size.'
className={style.error}
>
</ErrorCard>
}
// Loading exact same system, no need to reload visualizer
if (sectionPath === visualizedSystem.sectionPath && index === visualizedSystem.index) {
// Loading same system with different positions
......@@ -420,8 +415,19 @@ function Overview({section, def}) {
system = {
positions: convertSI(section.atom_positions, 'meter', {length: 'angstrom'}, false)
}
// Completely new system
// Loading a completely new system. When trying to visualize the system for
// the first time, check the system size and for large systems ask the user
// for permission.
} else {
const sizeLimit = 300
if (nAtoms >= sizeLimit && !warningIgnored) {
return <ErrorCard
message={`Visualization is by default disabled for systems with more than ${sizeLimit} atoms. Do you wish to enable visualization for this system with ${nAtoms} atoms?`}
className={style.error}
actions={[{label: 'Yes', onClick: e => setWarningIgnored(true)}]}
>
</ErrorCard>
}
system = {
'species': section.atom_species,
'cell': convertSI(section.lattice_vectors, 'meter', {length: 'angstrom'}, false),
......@@ -443,7 +449,7 @@ function Overview({section, def}) {
positionsOnly={positionsOnly}
></Structure>
</ErrorHandler>
// Band structure plot for section_k_band or section_k_band_normalized
// Band structure plot for section_k_band
} else if (def.name === 'section_k_band') {
return <>
{mode === 'bs'
......
......@@ -21,7 +21,7 @@ import {
import { StructureViewer } from '@lauri-codes/materia'
import Floatable from './Floatable'
export default function Structure({className, classes, system, options, viewer, captureName, aspectRatio, positionsOnly, sizeLimit}) {
export default function Structure({className, classes, system, options, viewer, captureName, aspectRatio, positionsOnly}) {
// States
const [anchorEl, setAnchorEl] = React.useState(null)
const [fullscreen, setFullscreen] = useState(false)
......@@ -122,7 +122,7 @@ export default function Structure({className, classes, system, options, viewer,
refViewer.current = new StructureViewer(undefined, viewerOptions)
} else {
refViewer.current = viewer
refViewer.current.setOptions(options, false, false)
refViewer.current.setOptions(viewerOptions, false, false)
}
if (refCanvas.current !== null) {
refViewer.current.changeHostElement(refCanvas.current, false, false)
......@@ -304,11 +304,9 @@ Structure.propTypes = {
options: PropTypes.object, // Viewer options
captureName: PropTypes.string, // Name of the file that the user can download
aspectRatio: PropTypes.number, // Fixed aspect ratio for the viewer canvas
sizeLimit: PropTypes.number, // Maximum number of atoms to attempt to display
positionsOnly: PropTypes.bool // Whether to update only positions. This is much faster than loading the entire structure.
}
Structure.defaultProps = {
aspectRatio: 4 / 3,
captureName: 'structure',
sizeLimit: 300
captureName: 'structure'
}
......@@ -1287,10 +1287,10 @@
resolved "https://registry.yarnpkg.com/@kyleshockey/object-assign-deep/-/object-assign-deep-0.4.2.tgz#84900f0eefc372798f4751b5262830b8208922ec"
integrity sha1-hJAPDu/DcnmPR1G1JigwuCCJIuw=
 
"@lauri-codes/materia@0.0.6":
version "0.0.6"
resolved "https://registry.yarnpkg.com/@lauri-codes/materia/-/materia-0.0.6.tgz#b1a64ef174fc0f4107940f9ca19ec8a2305d7376"
integrity sha512-RAC8iRS430f6pNum6zlK/PuFgENO1mOM1C1VSE6v+Hv1u8J9FDOyULvhyVuKdqOB6Gh6bmQikPBWX0+XGeFynw==
"@lauri-codes/materia@0.0.7":
version "0.0.7"
resolved "https://registry.yarnpkg.com/@lauri-codes/materia/-/materia-0.0.7.tgz#7580526874420641e26ab00bf0412d2a803d2cda"
integrity sha512-G3d4kRBNG4rYsLKceiW7Uhqy/uX0PFo70tsOIDZnOiNAICSIFF62LbYLDVHKgJf35xtyQM0kvM1WQGKgL9tmIw==
dependencies:
three "^0.119.1"
threejs-meshline "^2.0.11"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment