Skip to content

Instantly share code, notes, and snippets.

@aaizemberg
Last active September 15, 2016 17:54
Show Gist options
  • Save aaizemberg/28bbbc53623c8014933e6e6b5a3723a4 to your computer and use it in GitHub Desktop.
Save aaizemberg/28bbbc53623c8014933e6e6b5a3723a4 to your computer and use it in GitHub Desktop.
probando parte del d3-jetpack de Gregor Aisch
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>probando parte del d3-jetpack de Gregor Aisch</title>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/4.2.3/d3.min.js"></script>
</head>
<body>
<h1>Probando parte del <a href="https://github.com/gka/d3-jetpack">d3-jetpack</a></h1>
<script>
// tomado de: https://github.com/gka/d3-jetpack
//
// Gregor Aisch
// https://github.com/gka
// https://twitter.com/driven_by_data
// http://driven-by-data.net/
//
// combines data().enter().append()
d3.selection.prototype.appendMany = function(data, name){
return this.selectAll(name).data(data).enter().append(name);
};
d3.round = d3.round || function(n, p) { d = Math.pow(10, p); return Math.round(n * d) / d; };
d3.wordwrap = function(line, maxCharactersPerLine) {
var w = line.split(' '),
lines = [],
words = [],
maxChars = maxCharactersPerLine || 40,
l = 0;
w.forEach(function(d) {
if (l+d.length > maxChars) {
lines.push(words.join(' '));
words.length = 0;
l = 0;
}
l += d.length;
words.push(d);
});
if (words.length) {
lines.push(words.join(' '));
}
return lines;
};
//
// tomado de: https://github.com/gka/d3-jetpack
var texto_word_wrapeado = d3.wordwrap("Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum",50);
d3.select("body").appendMany(texto_word_wrapeado,'div').text(function(d){return d;})
var numeros_a_redondear = [3.1111,2.222222,1.33333,0.44444444444];
d3.select("body").appendMany(numeros_a_redondear,'h2').text(function(d){return d3.round(d,1);})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment