Skip to content

Commit

Permalink
Made dashboard more printable
Browse files Browse the repository at this point in the history
  • Loading branch information
rayceramsay committed Sep 3, 2024
1 parent b54292c commit f1c9234
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 12 deletions.
4 changes: 3 additions & 1 deletion frontend/pages/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,9 @@ export default function Dashboard() {

return (
<>
<Navbar />
<div className={styles.noPrint}>
<Navbar />
</div>
<main className={styles.wrapper}>
{pageError ? <DashboardErrorMessage message={pageError.message} /> : DashboardContent}
</main>
Expand Down
46 changes: 35 additions & 11 deletions frontend/src/components/admin/DashboardClickChart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'
import React, { useEffect, useState } from 'react'
import styles from '../../../styles/components/DashboardClickChart.module.css'
import Chart from 'react-google-charts'
import Image from 'next/image'

type ClickChartProps = {
data: [
Expand Down Expand Up @@ -62,16 +63,39 @@ export default function DashboardClickChart({ data, interval, type }: ClickChart
axisTitlesPosition: 'none',
}

// Get chart PNG for printing
const [chartWrapper, setChartWrapper] = useState<any>(null)
const [chartImageURI, setChartImageURI] = useState('')
useEffect(() => {
if (chartWrapper !== null) {
setChartImageURI(chartWrapper.getChart().getImageURI())
}
}, [chartWrapper])

return (
<div className={styles.chart}>
<div className={styles.chartTitle}>{title}</div>
{data.length ? (
<div className={styles.googleChartContainer}>
<Chart chartType='AreaChart' width='100%' height='100%' data={clickCounts} options={chartOptions} />
</div>
) : (
<div className={styles.noDataMessage}>No data</div>
)}
</div>
<>
<div className={styles.chart}>
<div className={styles.chartTitle}>{title}</div>
{data.length ? (
<>
<div className={styles.googleChartContainer}>
<Chart
chartType='AreaChart'
width='100%'
height='100%'
data={clickCounts}
options={chartOptions}
getChartWrapper={(wrapper) => setChartWrapper(wrapper)}
/>
</div>
<div className={styles.chartImageContainer}>
<Image src={chartImageURI} alt={`${title} Chart`} layout='fill' />
</div>
</>
) : (
<div className={styles.noDataMessage}>No data</div>
)}
</div>
</>
)
}
7 changes: 7 additions & 0 deletions frontend/styles/Dashboard.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,10 @@
align-items: end;
}
}

@media print {
.noPrint,
.dateLimitsForm {
display: none;
}
}
18 changes: 18 additions & 0 deletions frontend/styles/components/DashboardClickChart.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
padding: 2rem 2rem 1rem;
border: #333 1px solid;
border-radius: 1rem;
break-inside: avoid;
}

.chartTitle {
Expand Down Expand Up @@ -35,3 +36,20 @@
padding-bottom: 1rem;
font-style: italic;
}

.chartImageContainer {
display: none;
position: relative;
width: 100%;
height: 300px;
}

@media print {
.googleChartContainer {
display: none;
}

.chartImageContainer {
display: block;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
overflow-x: auto;
display: flex;
align-items: stretch;
break-inside: avoid;
}

.dataTable table {
Expand Down

0 comments on commit f1c9234

Please sign in to comment.