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

Fix overflow issue for mobile graph display #250

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Changes from 1 commit
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
23 changes: 17 additions & 6 deletions src/pages/gapsPatterns/GapsPatternsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ function GapsByHour({ lineRef, operatorRef, fromDate, toDate }: BusLineStatistic
...hourlyData.map((entry) => entry.actual_rides),
)

const isSmallScreen = window.innerWidth < 992
const widgetWidth =
window.innerWidth - (isSmallScreen ? (window.innerWidth < 768 ? 120 : 179) : 500)
const barSize = isSmallScreen ? 10 : 20

return (
lineRef > 0 && (
<div className="widget">
Expand All @@ -89,16 +94,16 @@ function GapsByHour({ lineRef, operatorRef, fromDate, toDate }: BusLineStatistic

<ComposedChart
layout="vertical"
width={500}
width={widgetWidth}
moshefortgang marked this conversation as resolved.
Show resolved Hide resolved
height={hourlyData.length * 50}
data={hourlyData}
margin={{
top: 20,
right: 20,
right: isSmallScreen ? 5 : 20,
bottom: 20,
left: 20,
left: isSmallScreen ? 5 : 20,
}}
barGap={-20}>
barGap={-barSize}>
<CartesianGrid stroke="#f5f5f5" />
<XAxis
type="number"
Expand All @@ -123,15 +128,21 @@ function GapsByHour({ lineRef, operatorRef, fromDate, toDate }: BusLineStatistic
/>
<Tooltip content={<CustomTooltip />} />
<Legend />
<Bar dataKey="actual_rides" barSize={20} radius={9} xAxisId={1} opacity={30}>
<Bar dataKey="actual_rides" barSize={barSize} radius={9} xAxisId={1} opacity={30}>
{hourlyData.map((entry, index) => (
<Cell
key={`cell-${index}`}
fill={mapColorByExecution(entry.planned_rides, entry.actual_rides)}
/>
))}
</Bar>
<Bar dataKey="planned_rides" barSize={20} fill="#413ea055" radius={9} xAxisId={0} />
<Bar
dataKey="planned_rides"
barSize={barSize}
fill="#413ea055"
radius={9}
xAxisId={0}
/>
</ComposedChart>
</>
)}
Expand Down
Loading