Published
Edited
Sep 26, 2022
2 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
switch_with_your_key = "zLQyfmaclId2Zub8LTHrXFOjSknWfsUfzzHp0Wgx"
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function addDays(date, days) {
var result = new Date(date);
result.setDate(result.getDate() + days);
return result;
}
Insert cell
Insert cell
Insert cell
date = new Date()
Insert cell
Insert cell
Insert cell
newDate = addDays(date,dateChanger)
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
url = 'https://api.nasa.gov/neo/rest/v1/feed?start_date='+startDate+'&end_date='+endDate+'&detailed=true&api_key='
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
unflattened_asteroids = response.data.near_earth_objects
Insert cell
Insert cell
Insert cell
function takeMultipleDaysAndMerge(asteroid_by_days){
let asteroids_array = []
let keys = Object.keys(asteroid_by_days);
for (let i = 0; i < keys.length; i++){
asteroids_array.push(asteroid_by_days[keys[i]])
}
var merged = [].concat.apply([], asteroids_array);
return merged
}
Insert cell
Insert cell
Insert cell
Insert cell
all_asteroids = takeMultipleDaysAndMerge(unflattened_asteroids)
Insert cell
Insert cell
function refactorObj_1(objectRocks){
let new_astroids_array = []
for (let each = 0; each < objectRocks.length; each++){
let newRow = {}
newRow.name = objectRocks[each].name
newRow.size = objectRocks[each]['estimated_diameter']['kilometers']['estimated_diameter_max']
newRow.x = objectRocks[each]['close_approach_data'][0]['relative_velocity']['kilometers_per_second']
newRow.y = objectRocks[each]['close_approach_data'][0]['miss_distance']['lunar']
new_astroids_array.push(newRow)
}
return new_astroids_array
}
Insert cell
Insert cell
Insert cell
Insert cell
function addLabels(data_withoutLabels,x_and_y){
let data = data_withoutLabels
data.x = x_and_y[0]
data.y = x_and_y[1]
return data
}
Insert cell
Insert cell
data = addLabels(data_withoutLabels,["kilometers per second","distance from Earth at closet path in multiples of Earth to Moon distance"])
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
y = d3.scaleLinear()
.domain(d3.extent(data, d => d.y)).nice()
.domain([0,250])
.range([height - margin.bottom, margin.top])
// y = d3.scaleLinear()
// .domain(d3.extent(data, d => d.y))
// .range([height - margin.bottom, margin.top])
Insert cell
Insert cell
Insert cell
d3 = require("d3@5")
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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