-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
549 additions
and
101 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"schemaType": "NERDPACK", | ||
"id": "6ed5a801-c5ce-45b2-89f1-6adef1c5bee0", | ||
"id": "69229974-8558-4fe9-bb2b-055fd1f88376", | ||
"displayName": "Location Geo Map Viz", | ||
"description": "Location Geo Map Viz" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,102 @@ | ||
import React from "react"; | ||
import React, {useEffect, useContext, useState} from "react"; | ||
import Region from "./Region"; | ||
import allGeoRegions from "../geo/all-geo-regions"; | ||
// import allUKRegions from "../geo/uk-regions/all-uk-regions"; | ||
import countries from "../geo/countries.geojson.json" | ||
import {PlatformStateContext, NerdGraphQuery} from "nr1"; | ||
import { nerdGraphMarkerQuery } from "../queries"; | ||
import { FETCH_INTERVAL_DEFAULT } from "../constants"; | ||
import {deriveStatus, formatValues} from "../utils/dataFormatting"; | ||
import { useProps } from "../context/VizPropsProvider"; | ||
import { generateTooltipConfig} from "../utils/map"; | ||
|
||
|
||
const Regions = () => { | ||
return allGeoRegions.map((region, index) => ( | ||
<Region key={index} region={region} /> | ||
)); | ||
|
||
const { | ||
accountId, | ||
regionsQuery, | ||
fetchInterval, | ||
ignorePicker, | ||
defaultSince | ||
} = useProps(); | ||
|
||
const [regions, setRegions] = useState([]); | ||
|
||
const defSinceString = | ||
defaultSince === undefined || defaultSince === null | ||
? "" | ||
: " " + defaultSince; | ||
if (regionsQuery === null || regionsQuery === undefined) { | ||
return null; | ||
} | ||
|
||
|
||
const { timeRange } = useContext(PlatformStateContext); | ||
|
||
useEffect(() => { | ||
const fetchData = async () => { | ||
const query = nerdGraphMarkerQuery( | ||
regionsQuery, | ||
timeRange, | ||
defSinceString, | ||
ignorePicker | ||
); | ||
const variables = { id: parseInt(accountId) }; | ||
|
||
try { | ||
const response = await NerdGraphQuery.query({ query, variables }); | ||
const results = response?.data?.actor?.account?.markers?.results; | ||
if (results && Array.isArray(results)) { | ||
results.forEach((location) => { | ||
deriveStatus(location); | ||
formatValues(location); | ||
}); | ||
} | ||
setRegions(response?.data?.actor?.account?.markers?.results); | ||
} catch (error) { | ||
console.error("Error fetching data:", error); | ||
// Handle error appropriately | ||
} | ||
}; | ||
|
||
// Perform the immediate fetch to populate the initial data | ||
fetchData(); | ||
|
||
// Then set an interval to continue fetching | ||
const fetchIntervalms = (fetchInterval || FETCH_INTERVAL_DEFAULT) * 1000; | ||
const intervalId = setInterval(fetchData, fetchIntervalms); | ||
// Clear the interval when the component unmounts | ||
return () => clearInterval(intervalId); | ||
}, [timeRange, fetchInterval]); | ||
|
||
if(!regions || regions.length == 0) { | ||
return null; //no regions to display | ||
} else { | ||
const tooltipConfig=generateTooltipConfig(regions) | ||
|
||
let geoFeatureLocations = regions.map((location,index)=>{ | ||
|
||
let feature; | ||
if(location.iso_a3 && location.isa_a3!="") { | ||
feature=countries.features.find((f)=>{ return f.properties.ISO_A3 == location.iso_a3;}); | ||
} else { | ||
if(location.iso_a2 && location.isa_a2!="") { | ||
feature=countries.features.find((f)=>{return f.properties.ISO_A2 == location.iso_a2;}) | ||
} | ||
} | ||
if(feature) { | ||
return <Region key={index} region={feature} location={location} tooltipConfig={tooltipConfig}/>; | ||
} else { | ||
console.log("Region could not be found in geo region map",location) | ||
return null; | ||
} | ||
}) | ||
|
||
return geoFeatureLocations; | ||
} | ||
|
||
|
||
|
||
}; | ||
|
||
export default Regions; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
261 changes: 261 additions & 0 deletions
261
visualizations/store-map-viz/geo/countries.geojson.json
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
Get GEO Data (GEOJSON) from here if needed | ||
https://cartographyvectors.com/geo/united-kingdom | ||
https://cartographyvectors.com/geo/united-kingdom | ||
https://github.com/datasets/geo-countries |
31 changes: 31 additions & 0 deletions
31
visualizations/store-map-viz/geo/uk-regions/all-uk-regions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { northEastUK } from "./northeast"; | ||
import { northWestUK } from "./northwest"; | ||
import { yorkshireAndTheHumber } from "./yorkshireandthehumber"; | ||
import { eastMidlands } from "./eastmidlands"; | ||
import { westMidlands } from "./westmidlands"; | ||
import { eastOfEngland } from "./eastofengland"; | ||
import { london } from "./london"; | ||
import { southEastUK } from "./southeast"; | ||
import { southWestUK } from "./southwest"; | ||
import { wales } from "./wales"; | ||
import { scotland } from "./scotland"; | ||
import { northernIreland } from "./northernireland"; | ||
import { ireland } from "./ireland"; | ||
|
||
const allUKRegions = [ | ||
northEastUK, | ||
northWestUK, | ||
yorkshireAndTheHumber, | ||
eastMidlands, | ||
westMidlands, | ||
eastOfEngland, | ||
london, | ||
southEastUK, | ||
southWestUK, | ||
wales, | ||
scotland, | ||
northernIreland, | ||
ireland, | ||
]; | ||
|
||
export default allUKRegions; |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.