Skip to content

Commit

Permalink
revert gridded world data changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanrdsch committed Aug 15, 2024
1 parent a6b90f3 commit 06b5417
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 153 deletions.
18 changes: 2 additions & 16 deletions frontend/src/BubbleMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { Feature, GeoJsonProperties, Geometry } from 'geojson'
import { Map } from 'immutable'
import { GeoId, GeoMap } from './appSlice'
import BubbleLegend from './BubbleLegend'
import { countries, USACounties, features } from './ChoroplethMap'
import { countries, USACounties } from './ChoroplethMap'
import { getDomain } from './DataProcessor'
import EmptyMap from './EmptyMap'
import StateMap from './StateMap'
Expand All @@ -25,21 +25,7 @@ const makeRegionToRadius =

function BubbleMap({ map, data, legendTitle, color }: Props) {
const path = geoPath()
let regions
switch (map.region) {
case 'USA':
regions = USACounties(map.topoJson)
break
case 'World':
regions = countries(map.topoJson)
break
case 'GriddedWorld':
regions = features(map.topoJson)
break
default:
regions = USACounties(map.topoJson)
break
}
const regions = map.region === 'USA' ? USACounties(map.topoJson) : countries(map.topoJson)
const { max } = getDomain(data)
const valueToRadius = scaleSqrt([0, max], [0, 40])
const regionToRadius = makeRegionToRadius(valueToRadius, data)
Expand Down
19 changes: 1 addition & 18 deletions frontend/src/ChoroplethMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ export const USACounties = (map: TopoJson) =>
export const countries = (map: TopoJson) =>
feature(map, map.objects.countries as GeometryCollection<GeoJsonProperties>).features

export const features = (map: TopoJson) =>
feature(map, map.objects.features as GeometryCollection<GeoJsonProperties>).features

type Props = {
map: GeoMap
selectedMapVisualizations: MapVisualization[]
Expand Down Expand Up @@ -83,21 +80,7 @@ function ChoroplethMap(
const value = data.get(regionId)
return colorScheme(value as any) ?? MISSING_DATA_COLOR
}
let borders
switch (map.region) {
case 'USA':
borders = USACounties(map.topoJson)
break
case 'World':
borders = countries(map.topoJson)
break
case 'GriddedWorld':
borders = features(map.topoJson)
break
default:
borders = USACounties(map.topoJson)
break
}
const borders = map.region === 'USA' ? USACounties(map.topoJson) : countries(map.topoJson)
const legendTicks = getLegendTicks(selectedMapVisualizations, isNormalized)
const legendFormatter = getLegendFormatter(selectedMapVisualizations, isNormalized)
const getArrayOfData = () =>
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/CountryNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ export default function RegionNavigation() {
dispatch(selectRegion('USA'))
} else if (urlRegion === 2) {
dispatch(selectRegion('World'))
} else if (urlRegion === 3) {
dispatch(selectRegion('GriddedWorld'))
}
}, [dispatch, urlRegion])

Expand Down Expand Up @@ -57,9 +55,6 @@ export default function RegionNavigation() {
<MenuItem value="World" aria-label="world">
World
</MenuItem>
<MenuItem value="GriddedWorld" aria-label="gridded world">
World (Gridded)
</MenuItem>
<MenuItem value="USA" aria-label="usa">
USA
</MenuItem>
Expand Down
17 changes: 2 additions & 15 deletions frontend/src/EmptyMap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,8 @@ import { GeoMap } from './appSlice'
const path = geoPath()

function EmptyMap({ map, transform }: { map: GeoMap; transform?: string }) {
let geometry
switch (map.region) {
case 'USA':
geometry = map.topoJson.objects.nation
break
case 'World':
geometry = map.topoJson.objects.countries
break
case 'GriddedWorld':
geometry = map.topoJson.objects.features
break
default:
geometry = map.topoJson.objects.nation
break
}
const geometry =
map.region === 'USA' ? map.topoJson.objects.nation : map.topoJson.objects.countries
const borders = feature(
map.topoJson,
geometry as GeometryCollection<GeoJsonProperties>
Expand Down
25 changes: 2 additions & 23 deletions frontend/src/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ type TopoJsonFile =
| 'transmission-lines-topo.json'
| 'critical-habitats-topo.json'
| 'endangered-species-topo.json'
| 'gridded-world.json'

type OverlayMap = Record<OverlayName, TopoJsonFile>

Expand All @@ -38,24 +37,14 @@ const overlayToFile: OverlayMap = {
}
const usaFile: { name: TopoJsonFile; region: Region } = { name: 'usa.json', region: 'USA' }
const worldFile: { name: TopoJsonFile; region: Region } = { name: 'world.json', region: 'World' }
const griddedWorldFile: { name: TopoJsonFile; region: Region } = {
name: 'gridded-world.json',
region: 'GriddedWorld',
}

function Home() {
const dispatch = useDispatch()
const region = useSelector((state: RootState) => state.app.region)
const { data: tabs } = useGetTabsQuery(false)
const tab = useSelector(selectSelectedTab)
let mapRegion = 1
if (region === 'World') {
mapRegion = 2
} else if (region === 'GriddedWorld') {
mapRegion = 3
}
const { data: mapVisualizations } = useGetMapVisualizationsQuery({
geographyType: mapRegion,
geographyType: region === 'USA' ? 1 : 2,
})

const isNormalized = tab?.normalized ?? false
Expand All @@ -65,17 +54,7 @@ function Home() {
: []

useEffect(() => {
let file = usaFile
switch (region) {
case 'World':
file = worldFile
break
case 'GriddedWorld':
file = griddedWorldFile
break
default:
break
}
const file = region === 'USA' ? usaFile : worldFile
json<TopoJson>(file.name).then((topoJson) => {
dispatch(setMap(topoJson ? { topoJson, region } : undefined))
})
Expand Down
47 changes: 2 additions & 45 deletions frontend/src/MapControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,21 +157,7 @@ function MapControls({ data, isNormalized, maps }: Props) {

const countyId = useSelector((state: RootState) => state.app.county)
const zoomTo = useSelector((state: RootState) => state.app.zoomTo)
let region: Region
switch (maps[0]?.geography_type) {
case 1:
region = 'USA'
break
case 2:
region = 'World'
break
case 3:
region = 'GriddedWorld'
break
default:
region = 'USA'
break
}
const region: Region = maps[0]?.geography_type === 1 ? 'USA' : 'World'
const params = useParams()
const { tabId } = params

Expand Down Expand Up @@ -204,38 +190,9 @@ function MapControls({ data, isNormalized, maps }: Props) {
return undefined
}

// PLACEHOLDER
const GriddedWorldCsv = (sortedData: Map<number, number> | undefined) => {
const objectData = sortedData
?.map((value, id) => {
const cell = id
return { id, cell, value }
})
.valueSeq()
.toArray()
if (objectData) {
return csvFormat(objectData, ['id', 'cell', 'value'])
}
return undefined
}

const downloadData = () => {
const sortedData = data?.sortBy((_, id) => id)
let csv
switch (region) {
case 'USA':
csv = UsaCsv(sortedData)
break
case 'World':
csv = WorldCsv(sortedData)
break
case 'GriddedWorld':
csv = GriddedWorldCsv(sortedData)
break
default:
csv = UsaCsv(sortedData)
break
}
const csv = region === 'USA' ? UsaCsv(sortedData) : WorldCsv(sortedData)
if (csv) {
const blob = new Blob([csv], { type: 'text/plain;charset=utf-8' })
saveAs(blob, `${getFilename(maps, isNormalized)}.csv`)
Expand Down
1 change: 0 additions & 1 deletion frontend/src/MapVisualization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export enum MapType {
export enum GeographyType {
USA = 1,
World = 2,
GriddedWorld = 3,
}

export interface MapVisualizationPatch {
Expand Down
11 changes: 3 additions & 8 deletions frontend/src/appSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type OverlayName =
| 'Critical water habitats'
| 'Endangered species'
export type Overlay = { topoJson?: TopoJson; shouldShow: boolean }
export type Region = 'USA' | 'World' | 'GriddedWorld'
export type Region = 'USA' | 'World'
export type GeoMap = {
topoJson: TopoJson
region: Region
Expand Down Expand Up @@ -73,7 +73,7 @@ const initialState: AppState = {
'Endangered species': { shouldShow: false },
},
tab: undefined,
mapSelections: { USA: {}, World: {}, GriddedWorld: {} },
mapSelections: { USA: {}, World: {} },
dataWeights: {},
zoomTo: undefined,
detailedView: true,
Expand Down Expand Up @@ -259,12 +259,7 @@ const generateMapTransform = (zoomTo: number | undefined, map: GeoMap | undefine
// topoJson country id: "012", country id: 12
// topoJson state id: "01", state id: 1
const idLength = map.region === 'USA' ? 2 : 3
let zoomToId
if (map.region === 'USA' || map.region === 'World') {
zoomToId = String(zoomTo).padStart(idLength, '0')
} else {
zoomToId = String(zoomTo)
}
const zoomToId = String(zoomTo).padStart(idLength, '0')

const bounds = geoPath().bounds(features[zoomToId])
const dx = bounds[1][0] - bounds[0][0]
Expand Down
24 changes: 2 additions & 22 deletions frontend/src/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,28 +51,8 @@ function Editor() {
const map = useSelector((state: RootState) => state.editor.map)

useEffect(() => {
let region: Region = 'USA'
switch (selectedMapVisualization?.geography_type) {
case 2:
region = 'World'
break
case 3:
region = 'GriddedWorld'
break
default:
break
}
let file = '/usa.json'
switch (region) {
case 'World':
file = '/world.json'
break
case 'GriddedWorld':
file = '/gridded-world.json'
break
default:
break
}
const region: Region = selectedMapVisualization?.geography_type === 2 ? 'World' : 'USA'
const file = region === 'USA' ? '/usa.json' : '/world.json'
json<TopoJson>(file).then((topoJson) => {
if (topoJson) {
dispatch(setMap({ topoJson, region }))
Expand Down

0 comments on commit 06b5417

Please sign in to comment.