diff --git a/web/src/Components/Bridging/BridgeContainer.tsx b/web/src/Components/Bridging/BridgeContainer.tsx index 5c541ef..9de7c07 100644 --- a/web/src/Components/Bridging/BridgeContainer.tsx +++ b/web/src/Components/Bridging/BridgeContainer.tsx @@ -7,6 +7,7 @@ import { ErrorToast } from '../Common/Toast' import InputContainer from './InputContainer' import { findGraphData } from '../../Utils' import ParticleSizeDistributionGraph from './ParticleSizeDistributionGraph' +import CumulativeGraph from './CumulativeGraph' export default ({ bridges, mode, setMode, bridgeValue, setValue }) => { const [sizeFractions, setSizeFractions] = useState([]) @@ -88,7 +89,7 @@ export default ({ bridges, mode, setMode, bridgeValue, setValue }) => { bridgeValueHelperText={bridgeValueHelperText} />
- +
diff --git a/web/src/Components/Bridging/BridgeGraph.tsx b/web/src/Components/Bridging/BridgeGraph.tsx index 7b9880b..2f7706f 100644 --- a/web/src/Components/Bridging/BridgeGraph.tsx +++ b/web/src/Components/Bridging/BridgeGraph.tsx @@ -1,48 +1,10 @@ -import React, { useContext, useEffect, useState } from 'react' -import { Area, AreaChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' -import { ParticleSizeContext } from '../../Context' -import { findGraphData } from '../../Utils' +import { Area, AreaChart, CartesianGrid, Legend, Tooltip, XAxis, YAxis } from 'recharts' import { graphColors } from './styles' -export function BridgeGraph({ bridges, sizeFractions }) { - const [graphData, setGraphData] = useState([]) - const [particleFromPercentage, setParticleFromPercentage] = useState('') - const [particleToPercentage, setParticleToPercentage] = useState('') - const particleRange = useContext(ParticleSizeContext) - - useEffect(() => { - setParticleFromPercentage(particleSizeOffsetPercentage(particleRange.from)) - if (particleRange.to > sizeFractions[sizeFractions.length - 1]) { - setParticleToPercentage(sizeFractions[sizeFractions.length - 1]) - } else { - setParticleToPercentage(particleSizeOffsetPercentage(particleRange.to)) - } - }, [particleRange, sizeFractions]) - - function particleSizeOffsetPercentage(offsetSize) { - const index = sizeFractions.findIndex(size => size > offsetSize) - if (index === -1) return '' - const percentage = Math.round(index / sizeFractions.length) * 100 - return `${percentage}%` - } - - useEffect(() => { - const newGraphData = findGraphData(sizeFractions, bridges) - setGraphData(newGraphData) - }, [bridges, sizeFractions]) - +export function BridgeGraph({ graphData, bridges }) { return (
- - {/* Defines a gradient applied to the areaPlot to highlight selected particle size range*/} - - - - - - - - + - + {Object.entries(bridges).map(([name, cumulative], index) => ( diff --git a/web/src/Components/Bridging/CumulativeGraph.tsx b/web/src/Components/Bridging/CumulativeGraph.tsx new file mode 100644 index 0000000..ff5b84d --- /dev/null +++ b/web/src/Components/Bridging/CumulativeGraph.tsx @@ -0,0 +1,38 @@ +import React, { useContext, useEffect, useState } from 'react' +import { Area, AreaChart, CartesianGrid, Legend, ResponsiveContainer, Tooltip, XAxis, YAxis } from 'recharts' +import { ParticleSizeContext } from '../../Context' +import { findGraphData } from '../../Utils' +import { graphColors } from './styles' +import BridgeGraph from './BridgeGraph' + +export function CumulativeGraph({ bridges, sizeFractions }) { + const [graphData, setGraphData] = useState([]) + const [particleFromPercentage, setParticleFromPercentage] = useState('') + const [particleToPercentage, setParticleToPercentage] = useState('') + const particleRange = useContext(ParticleSizeContext) + + useEffect(() => { + setParticleFromPercentage(particleSizeOffsetPercentage(particleRange.from)) + if (particleRange.to > sizeFractions[sizeFractions.length - 1]) { + setParticleToPercentage(sizeFractions[sizeFractions.length - 1]) + } else { + setParticleToPercentage(particleSizeOffsetPercentage(particleRange.to)) + } + }, [particleRange, sizeFractions]) + + function particleSizeOffsetPercentage(offsetSize) { + const index = sizeFractions.findIndex(size => size > offsetSize) + if (index === -1) return '' + const percentage = Math.round(index / sizeFractions.length) * 100 + return `${percentage}%` + } + + useEffect(() => { + const newGraphData = findGraphData(sizeFractions, bridges) + setGraphData(newGraphData) + }, [bridges, sizeFractions]) + + return +} + +export default CumulativeGraph diff --git a/web/src/Components/Bridging/ParticleSizeDistributionGraph.tsx b/web/src/Components/Bridging/ParticleSizeDistributionGraph.tsx index f2ab9e9..8c55cfa 100644 --- a/web/src/Components/Bridging/ParticleSizeDistributionGraph.tsx +++ b/web/src/Components/Bridging/ParticleSizeDistributionGraph.tsx @@ -4,6 +4,7 @@ import { ParticleSizeContext } from '../../Context' import { findGraphData } from '../../Utils' import { graphColors } from './styles' import { differentiateArrayObjects } from './utils' +import BridgeGraph from './BridgeGraph' export function ParticleSizeDistributionGraph({ bridges, sizeFractions }) { const [graphData, setGraphData] = useState([]) @@ -33,45 +34,7 @@ export function ParticleSizeDistributionGraph({ bridges, sizeFractions }) { setGraphData(diffentiated) }, [bridges, sizeFractions]) - return ( -
- - {/* Defines a gradient applied to the areaPlot to highlight selected particle size range*/} - - - - - - - - - - - - - - {Object.entries(bridges).map(([name, cumulative], index) => ( - - ))} - -
- ) + return } export default ParticleSizeDistributionGraph