Published
Edited
Apr 28, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
tag1 = (...args) => args
Insert cell
nom = 'Alice'
Insert cell
tag1`Salut ${nom}, comment vas-tu?`
Insert cell
tag2 = (partiesTexte, ...variables) => partiesTexte[0] + variables[0].toUpperCase() + partiesTexte[1]
Insert cell
tag2`Salut ${nom}, comment vas-tu?`
Insert cell
Insert cell
md`Markdown`
Insert cell
html`<p>HTML</p>`
Insert cell
svg`
<svg width="100" height="30">
<text x="50" y="20" text-anchor="middle">SVG</text>
</svg>
`
Insert cell
Insert cell
Insert cell
d3 = require('d3')
Insert cell
Insert cell
import {svg as cheery} from "@mbostock/cheery-observable"
Insert cell
Insert cell
cheery
Insert cell
Insert cell
Insert cell
{
const context = DOM.context2d(width, 33)
context.fillText('Je suis un canvas!', 0, 20)
return context.canvas
}
Insert cell
{
const div = DOM.element('div')
const p = document.createElement('p')
p.textContent = 'Un élément <p> à l\'intérieur d\'un élément <div>'
div.appendChild(p)
return div
}
Insert cell
Insert cell
slider = html`<input type="range">`
Insert cell
Insert cell
valeurSlider = Generators.input(slider)
Insert cell
Insert cell
svg`
<svg width="100" height="100">
<circle cx="50" cy="50" r="${valeurSlider / 2}" />
</svg>
`
Insert cell
Insert cell
function* integers() {
// deux valeurs qui peuvent être mutées
let i = 0
let up = true
// tant que oui est oui, donc pour toujours
while (true) {
if (up && i > 50) {
up = false
}
if (!up && i < 0) {
up = true
}
// générer une valeur entre 0 et 50
// si up = true la nouvelle valeur est la valeur précédente incrémentée
// sinon la valeur précédente moins un
yield up ? ++i : --i
}
}
Insert cell
Insert cell
radius = integers()
Insert cell
Insert cell
svg`
<svg width="100" height="100">
<circle cx="50" cy="50" r="${radius}" />
</svg>
`
Insert cell
Insert cell
viewof valeurInput = html`<input />`
Insert cell
html`<p>La valeurInput est: <span style="color:red">${valeurInput}</span></p>`
Insert cell
Insert cell
viewof valeurSlider2 = html`<input type="range" />`
Insert cell
valeurSlider2
Insert cell
Insert cell
viewof a = html`<input type="number" value="1" />`
Insert cell
viewof b = html`<input type="number" value="2" />`
Insert cell
html`
<p>${a} + ${b} = ${a + b}</p>
<p>${a} - ${b} = ${a - b}</p>
<p>${a} * ${b} = ${a * b}</p>
<p>${a} / ${b} = ${a / b}</p>
<br />
`
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