Notebooks 2.0 is here.

Public
Edited
Nov 7, 2022
Fork of D3 world map
1 fork
Insert cell
Insert cell
map = htl.html`<svg viewBox="0 0 ${width} ${height}" style="display: block;">
<path d="${path(outline)}" fill="#fff"></path>
<path d="${path(graticule)}" stroke="#ccc" fill="none"></path>
<path d="${path(land)}"></path>
<path d="${path(borders)}" fill="none" stroke="#fff"></path>
<path d="${path(outline)}" fill="none" stroke="#000"></path>
</svg>`
Insert cell
projection = d3.geoEqualEarth().translate( [ width/2, height / 2]).scale([120])
Insert cell
Insert cell
path = d3.geoPath(projection)
Insert cell
// height = {
// const [[x0, y0], [x1, y1]] = d3.geoPath(projection.fitWidth(width, outline)).bounds(outline);
// const dy = Math.ceil(y1 - y0), l = Math.min(Math.ceil(x1 - x0), dy);
// projection.scale(projection.scale() * (l - 1) / l).precision(0.2);
// return dy;
// }

Insert cell
outline = ({type: "Sphere"})
Insert cell
graticule = d3.geoGraticule10()
Insert cell
land = topojson.feature(world, world.objects.land)
Insert cell
borders = topojson.mesh(world, world.objects.countries, (a, b) => a !== b)
Insert cell
world = FileAttachment("countries-50m.json").json()
Insert cell
Insert cell
chart={

const target= html`<svg viewBox= "0 0 ${width} ${height}"/></svg>`;
// const svg= d3.create("svg")
// .attr("viewBox", [0, 0, width, height]);

// svg.append("path")
// .attr("d", "M 10 10 H 90 V 90 H 10 L 10 10");

const svg_sel= d3.select(target);

const grouping= svg_sel.append("g")
.attr("transform", `translate(${margin.left}, ${ margin.top})`);

// AXIS labels
grouping.append("g")
.attr("class", "xAxis")
.attr("transform", `translate(0, ${iheight})`)

grouping.append("g")
.attr("class", "yAxis")
// .attr("transform", `translate(${margin.left}, 0)`)


grouping.select(".xAxis")
.call(d3.axisBottom(x));
grouping.select(".yAxis")
.call(d3.axisLeft(y));
grouping.selectAll("circle")
.data(data_salary)
.join("circle")
.attr("cx", d=> x(d["YearsExperience"]))
.attr("cy", d=> y(d["Salary"]))
.attr("r", 4)
.attr("fill", "red");

return svg_sel.node();

}
Insert cell
x= d3.scaleLinear()
.domain([0, d3.extent(data_salary, d=> d["YearsExperience"])])
.range([0 , iwidth])
Insert cell
y= d3.scaleLinear()
.domain(d3.extent(data_salary, d=> d["Salary"]))
.range([iheight- 0])
Insert cell
Insert cell
margin= ({ left: 20, top: 40, right: 30, bottom: 20})
Insert cell
iwidth= width - margin.left -margin.right
Insert cell
iheight= height - margin.top - margin.bottom
Insert cell
height= 400
Insert cell
Insert cell
data_oco2= FileAttachment("cali_2018_2020.csv").csv()
Insert cell
data_salary= FileAttachment("Salary_Data.csv").csv()
Insert cell
Insert cell
d3= require("d3@6")
Insert cell
import {swatches} from "@d3/color-legend"
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more