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

Added second graph #210

Merged
merged 30 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
12bd291
fix: vertical
pbullhove Feb 28, 2024
0c1ff7b
refactor: turn into typescdript
pbullhove Apr 2, 2024
0b93a78
refactor: rename and refactor
pbullhove Apr 2, 2024
4c394fd
refactor: remove unused code
pbullhove Apr 2, 2024
f871b7f
fix: horizontal layout finished
pbullhove Apr 2, 2024
8b416d9
fix: horisontal
pbullhove Apr 2, 2024
3a6eb00
feat: added volume per micron
pbullhove Apr 2, 2024
e617585
fix: target pro
pbullhove Apr 2, 2024
553636b
fix: run pre-commit
pbullhove Apr 2, 2024
9c091f3
fix: ylabel margin issue
pbullhove Apr 2, 2024
615ee33
refactor: extract into one
pbullhove Apr 2, 2024
19b1a37
fix: sodmfsd
pbullhove Apr 2, 2024
a5a285e
Revert "refactor: extract into one"
pbullhove Apr 2, 2024
bd1feaa
refactor: more clean
pbullhove Apr 2, 2024
c341a4d
refactor: move
pbullhove Apr 2, 2024
7f1d2fd
fix: further stuff
pbullhove Apr 3, 2024
5ed5354
fix: responsive container etc
pbullhove Apr 3, 2024
981969b
fix: use minwidth on responsive container instead
pbullhove Apr 3, 2024
a33f505
refactor: move around to make structure more clear
pbullhove Apr 3, 2024
2dbd1f2
refactor: typign
pbullhove Apr 3, 2024
081808e
fix: end of day
pbullhove Apr 3, 2024
afa043b
refactor: move logic up out of single-use components
pbullhove Apr 4, 2024
bbe8478
fix: move up again
pbullhove Apr 4, 2024
7bc0005
fix: make graph smooth transition again
pbullhove Apr 4, 2024
e5c8d56
chore: upgrade deps
pbullhove Apr 4, 2024
b102654
feat: dynamic labels for the input field
pbullhove Apr 4, 2024
095c93e
feat: better buttons
pbullhove Apr 4, 2024
c1960d7
refactor: rename
pbullhove Apr 4, 2024
b038b8c
feat: more styling
pbullhove Apr 4, 2024
f9b2f38
fix: target prod
pbullhove Apr 4, 2024
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.

128 changes: 128 additions & 0 deletions web/src/Components/Bridging/BridgeContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
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}
yAxis={'Cumulative Volume (%)'}
sizeFractions={sizeFractions}
bridges={bridges}
/>
<BridgeGraph graphData={volumeData} yAxis={'Volume (%)'} sizeFractions={sizeFractions} bridges={bridges} />
</div>
</div>
)
}
Loading
Loading