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

New graph and many other small UI changes #213

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
web/node_modules
/.idea/
/api/.venv/
**/build
**/__pycache__/**
log.txt
.env
Expand Down
172 changes: 0 additions & 172 deletions web/src/Components/Bridging/BridgeContainer.jsx

This file was deleted.

134 changes: 134 additions & 0 deletions web/src/Components/Bridging/BridgeContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
import { useContext, useEffect, useState } from 'react'
import { FractionsAPI } from '../../Api'
import { BridgingOption, CeramicDiscsValues } from '../../Enums'
import { AuthContext } from 'react-oauth2-code-pkce'
import { ErrorToast } from '../Common/Toast'
import InputContainer from './InputContainer'
import { findGraphData } from '../../Utils'
import { Bridge, GraphData } from '../../Types'
import BridgeGraph from './Graphs/BridgeGraph'
import { differentiateArrayObjects } from './utils'

type BridgeContainerProps = {
bridges: Bridge
mode: BridgingOption
setMode: (mode: BridgingOption) => void
bridgeValue: number
setValue: (value: number) => void
}

export default ({ bridges, mode, setMode, bridgeValue, setValue }: BridgeContainerProps) => {
const [sizeFractions, setSizeFractions] = useState([])
const [unit, setUnit] = useState('mD')
const [bridgeValueHelperText, setBridgeValueHelperText] = useState(undefined)
const [bridgeValueVariant, setBridgeValueVariant] = useState(undefined)
const [optimalBridgeGraphData, setOptimalBridgeGraphData] = useState([])
const [volumeData, setVolumeData] = useState([])
const [cumulativeVolumeData, setCumulativeVolumeData] = useState([])
const { token } = useContext(AuthContext)

// Load size fractions once on first render
useEffect(() => {
FractionsAPI.getFractionsApi(token)
.then(response => {
setSizeFractions(response.data.size_fractions)
})
.catch(error => {
ErrorToast(`${error.response.data}`, error.response.status)
console.error('fetch error' + error)
})
}, [])

useEffect(() => {
if (bridges['Bridge'].length && sizeFractions.length) {
const x = findGraphData(sizeFractions, { Bridge: bridges['Bridge'] })
setOptimalBridgeGraphData(x)
}
}, [bridges, sizeFractions])

function onBridgeOptionChange(event) {
switch (event.target.value) {
case BridgingOption.PERMEABILITY:
setMode(BridgingOption.PERMEABILITY)
setUnit('mD')
break
case BridgingOption.AVERAGE_PORESIZE:
setMode(BridgingOption.AVERAGE_PORESIZE)
setUnit('microns')
break

case BridgingOption.MAXIMUM_PORESIZE:
setMode(BridgingOption.MAXIMUM_PORESIZE)
setUnit('microns')
break
case BridgingOption.CERAMIC_DISCS:
setMode(BridgingOption.CERAMIC_DISCS)
setUnit('microns')
setValue(parseInt(CeramicDiscsValues[0]))
break
default:
return
}
}

function onBridgeValueChange(value) {
const newBridgeValue = parseInt(value)
// TODO: Setting invalid values on parent is not good
setValue(newBridgeValue)

if (Math.sign(newBridgeValue) !== 1) {
setBridgeValueHelperText('Value must be an integer bigger than 0')
setBridgeValueVariant('error')
return
}

setBridgeValueVariant(undefined)
setBridgeValueHelperText(undefined)
}

useEffect(() => {
const cumulative = findGraphData(sizeFractions, bridges)
const differentiated = differentiateArrayObjects(cumulative)
setCumulativeVolumeData(cumulative)
setVolumeData(differentiated)
}, [sizeFractions, bridges])

return (
<div style={{ overflow: 'auto' }}>
<div
style={{
display: 'flex',
alignItems: 'center',
backgroundColor: 'white',
overflow: 'auto',
padding: '0.5rem',
borderRadius: '0.5rem',
}}
>
<InputContainer
mode={mode}
onBridgeOptionChange={onBridgeOptionChange}
onBridgeValueChange={onBridgeValueChange}
optimalBridgeGraphData={optimalBridgeGraphData}
unit={unit}
bridgeValue={bridgeValue}
bridgeValueVariant={bridgeValueVariant}
bridgeValueHelperText={bridgeValueHelperText}
/>
<BridgeGraph
graphData={cumulativeVolumeData}
title={'Cumulative Frequency'}
sizeFractions={sizeFractions}
bridges={bridges}
/>
<BridgeGraph
graphData={volumeData}
title={'Relative Frequency'}
sizeFractions={sizeFractions}
bridges={bridges}
showBridge={false}
/>
</div>
</div>
)
}
Loading
Loading