Skip to content

Commit

Permalink
Update Node.js usage example.
Browse files Browse the repository at this point in the history
Fixes #153.
  • Loading branch information
jasondavies committed Jul 15, 2022
1 parent 4fc1a94 commit a6d90ab
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions examples/node.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
var Canvas = require("canvas");
const { createCanvas } = require("canvas");
const cloud = require("d3-cloud");

var cloud = require("../");

var words = ["Hello", "world", "normally", "you", "want", "more", "words", "than", "this"]
const words = ["Hello", "world", "normally", "you", "want", "more", "words", "than", "this"]
.map(function(d) {
return {text: d, size: 10 + Math.random() * 90};
});

cloud().size([960, 500])
.canvas(function() { return new Canvas(1, 1); })
.canvas(() => createCanvas(1, 1))
.words(words)
.padding(5)
.rotate(function() { return ~~(Math.random() * 2) * 90; })
.rotate(() => Math.floor(Math.random() * 2) * 90)
.font("Impact")
.fontSize(function(d) { return d.size; })
.on("end", end)
.fontSize(d => d.size)
.on("end", words => console.log(JSON.stringify(words)))
.start();

function end(words) { console.log(JSON.stringify(words)); }

0 comments on commit a6d90ab

Please sign in to comment.