forked from AlainRo's block: d3js Exercice 2 - scales
Last active
October 11, 2017 08:01
-
-
Save clesauln/232f82183f0f08702108661516f8a4de to your computer and use it in GitHub Desktop.
d3js Exercice 2 - scales
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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; | |
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)); | |
let colors = ["red", "green", "blue"]; | |
const colorRange = d3.scaleLinear() | |
.domain([-100, 0, +100]) | |
.range(colors) | |
.clamp(true) | |
document.writeln(colorRange(100)); | |
// 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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment