Skip to content

Commit

Permalink
Legend data clarification
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed Jul 3, 2024
1 parent 79e5b9c commit bfae18c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions components/Legend/Legend.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,31 @@ import { deepCompare2d1d } from "utils/data/compareArrayElements"
import { upcertColorFilter } from "utils/state/map"
import { useAppDispatch, useAppSelector } from "utils/state/store"
import { LegendProps } from "./types"
import CountyList from "../CountyFilterSelector/county_list.json"

const findName = (id: string) => {
const state = CountyList.find((state) => state.statefp === id.slice(0, 2))
const county = id.length > 2 ? state?.counties?.find((county: any) => county.fips === id) : undefined

switch(id.length) {
case 2:
return state?.state || 'Unknown'
case 5:
return `${county?.name || 'Unknown County'}, ${state?.state || 'Unknown State'}`
default:
const tractNum = id.slice(5)
return `Tract ${tractNum} in ${county?.name || 'Unknown County'}`
}
}

export const Legend: React.FC<LegendProps> = ({ column, isBivariate, colors, breaks }) => {
const colorFilter = useAppSelector((state) => state.map.colorFilter)
const highlight = useAppSelector((state) => state.map.highlight)
const higlightValue = useAppSelector((state) => state.map.highlightValue)
const highlightColor = useAppSelector((state) => state.map.highlightColor)
const idFilter = useAppSelector((state) => state.map.idFilter)
const filterInfo = idFilter?.length ? `* Data for ${findName(idFilter)}` : 'National Data'

const dispatch = useAppDispatch()

const [legendtooltip, setLegendTooltip] = useState<number[]>([])
Expand Down Expand Up @@ -93,6 +112,9 @@ export const Legend: React.FC<LegendProps> = ({ column, isBivariate, colors, bre
)}
</div>
<HighlightLegend highlight={highlight} value={higlightValue} color={highlightColor} />
<p className="text-xs text-right pt-4">
{filterInfo}
</p>
</div>
)
} else {
Expand All @@ -112,6 +134,9 @@ export const Legend: React.FC<LegendProps> = ({ column, isBivariate, colors, bre
))}
<p style={{ maxWidth: "35ch", fontSize: "0.75rem" }}>{/* <i>{currentDataSpec?.attribution}</i> */}</p>
<HighlightLegend highlight={highlight} value={higlightValue} color={highlightColor}/>
<p className="text-xs text-right pt-4">
{filterInfo}
</p>
</div>
)
}
Expand Down

0 comments on commit bfae18c

Please sign in to comment.