chart = (text = "What hath God wrought", options = {}) => {
options = Object.assign({}, defaults, options);
const svg = d3.create("svg")
.attr("class", "morse-code")
.attr("width", options.width);
const words = getWords(text);
const spaceBetweenWords = options.dotWidth * 7;
let dx = 0;
let dy = 0;
for (let i = 0; i < words.length; i++) {
const lowerCasedWord = words[i].toLowerCase();
const wordContainer = createWordContainer(lowerCasedWord, options);
if ((dx + wordContainer.width) > width) {
dx = 0;
dy += options.lineHeight;
}
wordContainer.attr("transform", `translate(${dx},${dy})`);
svg.append(() => wordContainer.node());
dx += wordContainer.width;
if (i < (words.length - 1)) {
dx += spaceBetweenWords;
}
}
svg.attr("height", dy + options.signalHeight);
return svg.node();
}