D3
OG
Old school D3 from simpler times
All examples
By author
By category
About
AlainRo
Full window
Github gist
d3js Exercice 2 - scales
d3js Exercice 2 - Scales
<!DOCTYPE html> <head> <meta charset="utf-8"> <script src="https://d3js.org/d3.v4.min.js"></script> </head> <body> <pre> <script> document.writeln('LE BAC A SABLE DES SCALES\n'); const sc = d3.scaleLinear() .domain([0, 20]) .range([0, 1]); document.writeln('sc(0) -> ' + sc(0)); document.writeln('sc(10) -> ' + sc(10)); document.writeln('sc(20) -> ' +sc(20)); document.writeln(); document.writeln('Et au delĂ des intervalles convenus\n'); document.writeln(); let x = 5; // <- Faire varier ici document.writeln('sc(' + x + ') -> ' + sc(x)); document.writeln(); const scc = d3.scaleLinear() .domain([0, 20]) .range([0, 1]) .clamp(true); // Clamp !!! document.writeln(scc(-10)); document.writeln(scc(200)); // Essayer: invert, power, log //Lire la documentation https://github.com/d3/d3-scale // Essayer avec une range de couleur ["red", "white", "green"] </script> </pre> </body>
https://d3js.org/d3.v4.min.js