Skip to content

Commit

Permalink
160 redo header of graph to include description (#168)
Browse files Browse the repository at this point in the history
  • Loading branch information
David-Duefrene committed Aug 29, 2023
1 parent 4486084 commit 6689790
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
10 changes: 6 additions & 4 deletions Components/ChartBox/ChartBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ import type { Dispatch, SetStateAction } from 'react'

import * as d3 from 'd3'

import Title from '../UI/Title/Title'

import ColorKey, { ColorRow } from './ColorKey/ColorKey'
import LineChart from './LineChart'
import { ChartBoxData, ChartData } from './types'

import styles from './ChartBox.module.sass'

interface ChartBoxProps {
data: ChartBoxData[],
data: ChartBoxData[]
title: string
lang?: Record<string, string>
}

const ChartBox = ({ data, title }: ChartBoxProps) => {
const ChartBox = ({ data, title, lang }: ChartBoxProps) => {
const svgRef = React.useRef(null)

const [ width, setWidth ]: [number, Dispatch<SetStateAction<number>>] = useState(1500)
Expand Down Expand Up @@ -62,7 +64,7 @@ const ChartBox = ({ data, title }: ChartBoxProps) => {

return (
<article>
<h1>{title}</h1>
<Title page={title} opts={lang} />
<div className={styles.ChartArea}>
<ColorKey>{linesColors}</ColorKey>
<svg className={styles.Chart} ref={svgRef} width={width + 120} height={height * 1.1} />
Expand Down
21 changes: 21 additions & 0 deletions Components/UI/Title/Title.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import type { ReactElement } from 'react'

import { useTranslation } from 'next-i18next'

interface TitleProps {
page: string
opts?:Record<string, string>
}

const Title = (props: TitleProps): ReactElement => {
const { page, opts } = props
const { t } = useTranslation(page)

return <>
<h1>{t('title', opts)}</h1>
<p>{t('headDescription', opts)}</p>
</>
}

export default Title

5 changes: 4 additions & 1 deletion pages/budget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import { useState } from 'react'
import { serverSideTranslations } from 'next-i18next/serverSideTranslations'

import useVariableInterpolation from '../util/useVariableInterpolation'

import ChartBox from '../Components/ChartBox/ChartBox'

import Header from '../Components/UI/Header/Header'

import ControlPanel from '../Components/UI/ControlPanel/ControlPanel'
import SelectionList from '../Components/UI/ControlPanel/SelectionList/SelectionList'
import Dropdown from '../Components/UI/ControlPanel/Dropdown/Dropdown'
Expand Down Expand Up @@ -88,7 +91,7 @@ const Budget = () => {
getTranslation={(c) => t(`${translatedSelection.toLowerCase()}.${c}`)}
/>
</ControlPanel>
<ChartBox data={chartData} title={t('title', { selection: translatedSelection })} />
<ChartBox data={chartData} title='budget' lang={{ selection: translatedSelection }} />
</main>
</>
)
Expand Down
5 changes: 3 additions & 2 deletions pages/population.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ import { useTranslation } from 'next-i18next'

import clientPromise from '../util/mongoClient'

import ChartBox from '../Components/ChartBox/ChartBox'

import Header from '../Components/UI/Header/Header'
import ControlPanel from '../Components/UI/ControlPanel/ControlPanel'
import ChartBox from '../Components/ChartBox/ChartBox'
import SelectionList from '../Components/UI/ControlPanel/SelectionList/SelectionList'

export const getServerSideProps = async ({ locale }: { locale: string }) => {
Expand Down Expand Up @@ -89,7 +90,7 @@ const Population = ({ countyJSON }: HomeProps) => {
<ControlPanel>
<SelectionList list={Object.keys(countyJSON)} selected={county} setSelected={setCounty} />
</ControlPanel>
<ChartBox data={dataSets} title={t('title')} />
<ChartBox data={dataSets} title='population' />
</main>
</>
)
Expand Down
2 changes: 1 addition & 1 deletion public/locales/en/population.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"title": "Colorado Population & Projected Growth",
"headTitle": "Colorado Population & Projected Growth Chart",
"headDescription": "a population and projected growth chart for the state of population chart for Colorado"
"headDescription": "A population and projected growth chart for the state of population chart for Colorado"
}

0 comments on commit 6689790

Please sign in to comment.