Skip to content

Commit

Permalink
feat: custom tooltip for bridge graph
Browse files Browse the repository at this point in the history
  • Loading branch information
soofstad committed Apr 8, 2024
1 parent 70cc978 commit ca433a5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
3 changes: 1 addition & 2 deletions web/src/Components/Bridging/BridgeContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ export default ({ bridges, mode, setMode, bridgeValue, setValue }: BridgeContain

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

Expand Down
22 changes: 20 additions & 2 deletions web/src/Components/Bridging/Graphs/BridgeGraph.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
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 { bridgeColor, graphColors } from '../styles'
import { Bridge, GraphData } from '../../../Types'
import { Typography } from '@equinor/eds-core-react'
Expand All @@ -14,6 +13,25 @@ type BridgeGraphProps = {
showBridge?: boolean
}

const CustomTooltip = ({ active, payload, label }) => {
if (active && payload && payload.length) {
console.log(payload)
console.log(label)
return (
<div style={{ backgroundColor: 'white', border: '1px solid gray', padding: '5px', borderRadius: '2px' }}>
<div style={{ opacity: '50%' }}>{`Particle size : ${label}µm`}</div>
<div style={{ marginTop: '15px' }}>
{payload.map((graphData: any) => (
<div style={{ color: graphData.color }}>{`${graphData.name}: ${graphData.value}%`}</div>
))}
</div>
</div>
)
}

return null
}

export function BridgeGraph({ title, graphData, sizeFractions, bridges, showBridge = true }: BridgeGraphProps) {
const [particleFromPercentage, setParticleFromPercentage] = useState<string>('0%')
const [particleToPercentage, setParticleToPercentage] = useState<string>('100%')
Expand Down Expand Up @@ -68,7 +86,7 @@ export function BridgeGraph({ title, graphData, sizeFractions, bridges, showBrid
height={70}
/>
<YAxis type='number' allowDataOverflow width={75} label={{ value: 'Volume (%)', angle: '270' }} />
<Tooltip />
<Tooltip content={CustomTooltip} />
<Legend verticalAlign='bottom' align='center' height={legendHeight} />
{Object.entries(bridges).map(([name, cumulative], index) => (
<Area
Expand Down

0 comments on commit ca433a5

Please sign in to comment.