Published
Edited
Mar 11, 2021
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
xaxis = svg`
<svg width=600 height=40>
<g id="x-axis" transform="translate(-40,20)" font-size="10" font-family="fantasy" text-anchor="right">
<text fill="grey" text-anchor="end" x="419" y="-3">
Income per inhabitant (dollars at purchasing power parity, logarithmic scale)
</text>
<path fill="none" stroke="black" d="M60.5,6V0.5H419V6"></path>
<g class="tick" transform="translate(60.5,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">10</text>
</g>
<g class="tick" transform="translate(114,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">20</text>
</g>
<g class="tick" transform="translate(146,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">30</text>
</g>
<g class="tick" transform="translate(168,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">40</text>
</g>
<g class="tick" transform="translate(185,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">50</text>
</g>
<g class="tick" transform="translate(200,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(212,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(222,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(231,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(240,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">100</text>
</g>
<g class="tick" transform="translate(294,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">200</text>
</g>
<g class="tick" transform="translate(325,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">300</text>
</g>
<g class="tick" transform="translate(348,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(365,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(379,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(391,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(402,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(411,0)">
<line stroke="black" y2="6"></line>
</g>
<g class="tick" transform="translate(419,0)">
<line stroke="black" y2="6"></line>
<text y="16" x="-3">1 000</text>
</g>
</g>
</svg>

`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
const svg = d3.create("svg")
const a = 179.5 // ad-hoc values for scaling
const b = -119 // ad-hoc values for scaling
const domain = [10, 1000] // values for the income
const range = [10, 550] // x-positions
svg
.attr("width", 600)
.attr("height",40)
const g = svg.append("g") // create an alias so that I can refer to it
.attr("transform", "translate(-40,20)")
.attr("font-size", 10)
.attr("font-family", "sans-serif")
.attr("text-anchor", "right")
g.append("path")
.attr("fill", "none")
.attr("stroke", "black")
.attr("d", "M60.5,6V0.5H419V6") // could be computed from "range"
for(let i = 1; i<4; i++){
for(let j = 1; j<10; j++){ // the limits could be computed from "domain"
let number = j*10**i
// add the ticks here
let translation = "translate(" + (a * Math.log10(number) + b) + ",0)"
// The translation could be computed from "domain" and "range"
// and we could get rid of "a" and "b".
let tick = g.append("g").attr("transform", translation)
tick.append("line")
.attr("stroke", "black")
.attr("y2", 6)
if(j <= 3){
tick.append("text")
.attr("y", 16)
.attr("x", -3)
.text(number)
}
if(number >= domain[1]) break
}
}
return svg.node()
}

Insert cell
Insert cell
Insert cell
{
const students = ['Guillaume','Sophie','Adele']
students.push("Ines : c'est son anniversaire")
return students[3]
}
Insert cell
{
const student = {
"firstname" : "Paul",
"lastname" : "Dupont",
"age":22,
"diploma":['bac','master']
}
student.gender="male"
student.age=23
return student.age
}
Insert cell
countries
Insert cell
Insert cell
countries[4]
Insert cell
countries[4].income
Insert cell
Insert cell
countries.map(country => country.life_expectancy)
Insert cell
Insert cell
lifeExpectArrayOldSchool = {
const array = []
for(let i=0; i<countries.length;i++){
array.push(countries[i].life_expectancy)
}
return array
}
Insert cell
richCountries= {
return countries.filter(country => country.income>6000).map(country => country.name)
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
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