Published
Edited
Jun 21, 2021
Insert cell
md`# Carte Sun Tunnels, 5 photos, test couleurs + légende`
Insert cell
Insert cell
legendaire = {
//source couleurs: https://observablehq.com/@mbostock/mortality-due-to-alcohol-use-disorder
const width = 600;
const title = "Réutilisation des photographies"
const svg = d3.create("svg")
.attr("width", width)
const legend = svg.append("g")
.attr("transform", `translate(0,20)`)
.call(d3.axisBottom(color.copy().rangeRound(d3.quantize(d3.interpolate(0, width),color.domain().length))).tickSize(13).ticks(5))
.call(g => g.selectAll(".tick line").attr("stroke", "#fff"))
.call(g => g.select(".domain").remove());

legend.insert("image", "*")
.attr("width", width)
.attr("height", 13)
.attr("preserveAspectRatio", "none")
.attr("xlink:href", ramp(color).toDataURL());
legend.append("text")
.attr("class", "caption")
.attr("y", -6)
.attr("fill", "#000")
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(title);
return svg.node()
}
Insert cell
format = d3.format(".1f")
Insert cell
function ramp(color, n = 256) {
const context = DOM.context2d(n, 1, 1);
const x = d3.scaleLinear()
.domain(d3.quantize(d3.interpolate(0, n - 1), color.domain().length))
.range(color.domain());
for (let i = 0; i < n; ++i) {
context.fillStyle = color(x(i));
context.fillRect(i, 0, 1, 1);
}
return context.canvas;
}
Insert cell
Insert cell
color = d3.scaleLog().base(2).domain([1, 60]).range(["#B7ECF5","#18304E"])
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
showToolTip = (text, coords) => {
d3.select(".tooltip")
.text(text)
.style("top", coords[1] + "px")
.style("left", coords[0] + "px")
.style("visibility", "visible");
}
Insert cell
md `## Données`
Insert cell
countries.features[0].properties.data.length
Insert cell
entities = d3.group(donnees, d => d.COUNTRY)
Insert cell
data = donnees.map(({PHOTO, URL, COUNTRY}) => ({photo: PHOTO, url: URL, country: COUNTRY}))
Insert cell
donnees = d3.csv("https://gist.githubusercontent.com/artetsite/5b3f9862628ef44b4d4dab6f34ffff1d/raw/2003ea5c79ee6ac7511f49cc42bd8a78d709c30b/gistfile1.txt")
Insert cell
countries = {
// attach data to each country in properties
const countries = topojson.feature(world, world.objects.countries);
countries.features.forEach(country => {
if (!entities.get(country.properties.name))
country.properties.data = ""
else
country.properties.data = entities.get(country.properties.name);
})
return countries
}
Insert cell
countriesTest = topojson.feature(world, world.objects.countries);
Insert cell
outline = ({ type: "Sphere" })
Insert cell
projection = d3.geoNaturalEarth1()
Insert cell
path = d3.geoPath(projection)
Insert cell
world = await FileAttachment("countries-110m.json").json()

Insert cell
topojson = require("topojson-client@3")
Insert cell
import { legend } from "@d3/color-legend"
Insert cell
d3 = require("d3@6")

Insert cell
styles = html`
<style>

.tooltip {
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
background: rgba(69,77,93,.9);
border-radius: .1rem;
color: #fff;
display: block;
font-size: 11px;
max-width: 320px;
padding: .2rem .4rem;
position: absolute;
text-overflow: ellipsis;
white-space: pre;
z-index: 300;
visibility: hidden;
}


</style>`
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