Public
Edited
May 3, 2023
Fork of Marimekko
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
currentFires = {
const data = await getCurrentIncidentLocations(query4)

return data.features
.map(d => {
const {IncidentName, DailyAcres, FireDiscoveryDateTime, PercentContained, POOState, ...restOfAttrs } = d.properties
return {name: IncidentName, acres: DailyAcres, date: FireDiscoveryDateTime, pctContained: PercentContained, state: POOState.split('-')[1], ...restOfAttrs}
})
.sort((a,b) => b.acres - a.acres )

}
Insert cell
Insert cell
Insert cell
Insert cell
perimeterResponse = await fetch("https://services9.arcgis.com/RHVPKKiFTONKtxq3/ArcGIS/rest/services/USA_Wildfires_v1/FeatureServer/1/query?" + new URLSearchParams({
where: "GISAcres >= 1000 AND IncidentName LIKE 'Great Lakes'",
geometryPrecision: 3,
maxAllowableOffset: 1,
resultRecordCount: 100,
outFields: "IncidentName",
f: "json",
}) ).then(response => response.json())
Insert cell
{
const height = 100
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("font-family", "Helvetica");

const xScale = d3.scaleLinear().domain([0, 1]).range([0, width / 2])

const popOutside = demoData.pop_mile - demoData.total_pop
const housingOutside = demoData.hh_mile - demoData.total_hh

const labelPositions = [width / 2 - xScale(demoData.total_hh / demoData.hh_mile), width / 2 + xScale(demoData.total_pop / demoData.pop_mile),20, width ]
const labelNumbers = [housingOutside, demoData.total_hh, demoData.total_pop, popOutside ]


svg.append('line')
.attr('x1', width / 2 )
.attr('x2', width / 2 )
.attr('y1', 0)
.attr('y2', height )
.attr('stroke', 'lightgrey')
.attr('stroke-dasharray', '2 2')

svg.append('circle')
.attr('cx', width/ 2)
.attr('cy', height / 2)
.attr('r', 20)
.attr('fill', red)
.attr('fill-opacity', .5)

svg.append('line')
.attr('x1', 20 )
.attr('x2', width )
.attr('y1', height / 2 )
.attr('y2', height / 2 )
.attr('stroke', 'grey')

svg.append('rect')
.attr('x', width / 2)
.attr('y', height / 2 - 4)
.attr('height', 8)
.attr('width', d => xScale(demoData.total_pop / demoData.pop_mile ) )
.attr('rx', 5)
.attr('fill', red)

svg.append('rect')
.attr('x', d => width / 2 - xScale(demoData.total_hh / demoData.hh_mile))
.attr('y', height / 2 - 4)
.attr('height', 8)
.attr('width', d => xScale(demoData.total_hh / demoData.hh_mile) )
.attr('rx', 5)
.attr('fill', red)

svg.append('circle')
.attr('cx', width/ 2)
.attr('cy', height / 2)
.attr('r', 8)
.attr('fill', red)

const numbers = svg.append('g')
.attr('transform', `translate(0,${height / 2 + 20})`)
.attr('font-size', '14px')

numbers
.selectAll('text')
.data(labelPositions)
.enter()
.append('text')
.attr('x', d => d)
.text((d, i) => Object.values(demoData)[i].toLocaleString('en'))
.attr('fill', (d, i) => ['total_pop', 'total_hh'].includes(Object.keys(demoData)[i]) ? red : 'black' )
.attr('font-weight', (d, i) => ['total_pop', 'total_hh'].includes(Object.keys(demoData)[i]) ? 600 : 400 )
.attr('text-anchor', (d, i) => ['pop_mile', 'total_pop'].includes(Object.keys(demoData)[i]) ? 'end' : 'start' )

const labels = svg.append('g')
.attr('transform', `translate(0,${height / 2 - 15})`)
.attr('font-size', '16px')
labels.append('text')
.attr('x', labelPositions[1])
.attr('text-anchor', 'end')
.attr('fill', red)
.text('Inside Boundary')

labels.append('text')
.attr('x', width)
.attr('text-anchor', 'end')
.text('Within 2 mi')

labels.append('text')
.attr('x', width / 2 - 5)
.attr('text-anchor', 'end')
.text('← Housing')

labels.append('text')
.attr('x', width / 2 + 5)
.text('Population →')

return svg.node()
}
Insert cell
Insert cell
Insert cell
245 / 10
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
perimeter = {
return {...perimeterResponse.features[0].geometry, spatialReference: {
"wkid": 4326
}}
}
Insert cell
Insert cell
Insert cell
function getDemographics(queryParams) {

const url = new URL("https://services.arcgis.com/P3ePLMYs2RVChkJx/ArcGIS/rest/services/ACS_Highlights_Population_Housing_Basics_Boundaries/FeatureServer/2/query");
Object.keys(queryParams).forEach(key => url.searchParams.append(key, queryParams[key]));
return fetch(url)
.then(response => response.json())
.catch(error => console.error(error));
}
Insert cell
demographics = await getDemographics(query3)
Insert cell
demographicsMile = await getDemographics({...query3, distance: 1609 * 2})
Insert cell
demoData = {
const summarize = (data) => {
return data.features.map(d => {
const {B25002_001E, B01001_001E} = d.properties
return {hh:B25002_001E, pop: B01001_001E }
})
}
const data = summarize(demographics)
const bufferData = summarize(demographicsMile)

return {total_hh: d3.sum(data, d => d.hh),
total_pop: d3.sum(data, d => d.pop),
hh_mile: d3.sum(bufferData, d => d.hh),
pop_mile: d3.sum(bufferData, d => d.pop)
}
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
height = 600
Insert cell
getPctBefore = (i, data) => d3.sum(data.slice(0, i), d => d.pct)
Insert cell
d3 = require("d3@6")
Insert cell
ESRI = require("esri/geometry/Polygon")
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more