Skip to content

Commit

Permalink
cleanup and tooltip for stores
Browse files Browse the repository at this point in the history
  • Loading branch information
nofurtherinformation committed May 22, 2024
1 parent daba800 commit 744fc13
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 12 deletions.
70 changes: 61 additions & 9 deletions components/Map/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import MapTooltip from "components/MapTooltip"
import { deepCompare2d1d } from "utils/data/compareArrayElements"
import { MemoryMonitor } from "components/dev/MemoryMonitor"
import { fetchCentroidById } from "utils/state/thunks"
import { formatterPresets } from "utils/display/formatValue"

export type MapProps = {
initialFilter?: string
Expand Down Expand Up @@ -141,15 +142,6 @@ export const Map: React.FC<MapProps> = ({ initialFilter, simpleMap = false, onCl
return color
}
const layers = [
new ScatterplotLayer({
id: "stores-locations-layer",
data: storesHaveGeo ? storeData : [],
getRadius: 5,
radiusUnits: "pixels",
getPosition: (d: any) => [d.STORE_LON, d.STORE_LAT],
getFillColor: [0, 255, 120],
pickable: false,
}),
new GeoJsonLayer({
// @ts-ignore
data: JSON.parse(clickedGeo?.geometry || "[]"),
Expand Down Expand Up @@ -207,6 +199,66 @@ export const Map: React.FC<MapProps> = ({ initialFilter, simpleMap = false, onCl
beforeId: "water",
pickable: true,
}),

new ScatterplotLayer({
id: "stores-locations-layer",
data: storesHaveGeo ? storeData : [],
getRadius: 5,
radiusUnits: "pixels",
getPosition: (d: any) => [d.STORE_LON, d.STORE_LAT],
getFillColor: [0, 255, 120],
onHover: (info: any, event: any) => {
if (info?.object) {
const x = event?.srcEvent?.clientX
const y = event?.srcEvent?.clientY
const id = info.object?.GEOID
const data = [{
section: "Store Info",
columns: [
{
label: "Store",
data: info.object?.COMPANY,
col: ""
},
{
label: "Address",
data: info.object?.['ADDRESS LINE 1'],
col: ""
},
{
label: "City",
data: info.object?.CITY,
col: ""
},
{
label: "State",
data: info.object?.STATE,
col: ""
},
{
label: "Zipcode",
data: info.object?.ZIPCODE,
col: ""
},
{
label: "Parent Company",
data: info.object?.["PARENT COMPANY"],
col: ""
},
{
label: "Percent of area sales",
data: formatterPresets.percent(info.object?.["PCT OF TRACT SALES"]),
col: ""
}
]
}]
dispatch(setTooltipInfo({ x, y, id, data }))
} else {
dispatch(setTooltipInfo(null))
}
},
pickable: true,
}),
]
const mapRef = useRef(null)
// const year = useAppSelector((state) => state.map.year)
Expand Down
1 change: 0 additions & 1 deletion components/ReportLayout/ReportLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export const ReportLayout: React.FC<ReportLayoutProps> = async ({
statText,
id
)
console.log(raceData)

return (
<div className="min-h-[100vh] bg-theme-canvas-500 p-4">
Expand Down
6 changes: 4 additions & 2 deletions utils/state/map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,12 @@ export const mapSlice = createSlice({
setTimeSeriesLoaded: (state, action: PayloadAction<keyof typeof timeSeriesConfig>) => {
state.timeseriesDatasets.push(action.payload)
},
setTooltipInfo: (state, action: PayloadAction<{ x: number; y: number; id: string } | null>) => {
setTooltipInfo: (state, action: PayloadAction<MapState['tooltip'] | null>) => {
state.tooltip = action.payload
const id = action.payload?.id
if (!!id && !globals?.globalDs?.tooltipResults[id]) {
if (action.payload?.data) {
// chill
} else if (!!id && !globals?.globalDs?.tooltipResults[id]) {
state.tooltipStatus = 'pending'
} else {
state.tooltipStatus = 'ready'
Expand Down

0 comments on commit 744fc13

Please sign in to comment.