Published
Edited
Aug 18, 2019
1 fork
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
listOfNumbers = createRandomArray(1000)
Insert cell
Insert cell
md`${sparkUniverse(listOfNumbers)}`
Insert cell
sparkUniverse(listOfNumbers)
Insert cell
function sparkUniverse(listOfNumbers) {
const sparkLines = []
listOfNumbers.forEach(function(d) {
const data = conjecture(d)
const sparkLine = sparkline(data, 150, 75)
sparkLines.push(sparkLine)
})
return sparkLines;
}
Insert cell
function sparkline(values, width = 64, height = 17) {
const x = d3.scaleLinear()
.domain([0, values.length - 1])
.range([5, width - 5]);
const y = d3.scaleLinear().domain(d3.extent(values)).range([height - 5, 5]);
const context = DOM.context2d(width, height);
const line = (d) => {
context.beginPath();
var lineDrawer = d3.line().x((d, i) => x(i)).y(y).context(context);
lineDrawer(d);
context.strokeStyle = 'black';
context.stroke();
context.closePath();
}
line(values)
context.fillText(values[0], width - (width * .2), 10)
return context.canvas;
}
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more