Published
Edited
Jul 5, 2022
2 stars
Insert cell
Insert cell
barPipes(randomData)
Insert cell
Insert cell
function barPipes(data, {
width = 800,
padding = 20
} = {}) {
const sel = d3.create('div')
.attr('class', 'bar-pipe');
sel.append('ul')
.style('min-width', width + 'px')
.selectAll('li')
.data(data)
.join('li')
.attr('class', 'block pb1')
.attr('color', 'pipeColor')
.html(d => {
const pipes = repeatStringNumTimes('|', d.value)
return `${d.label} : <span class='pipe'>${pipes}</span> ${d.value}`
});

function repeatStringNumTimes (string, times) {
return times > 0 ? string.repeat(times) : '';
};

return sel.node();
}
Insert cell
Insert cell
randomNumber = (min, max) => {
return Math.floor((max - min + 1) * Math.random() + min)
}
Insert cell
<link href="https://unpkg.com/basscss@8.0.2/css/basscss.min.css" rel="stylesheet">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Mono&display=swap" rel="stylesheet">

<style>
.bar-pipe {
font-size: 14px;
font-family: 'Space Mono', monospace;
font-weight: 400;
color: #454545;
padding-bottom: 20px
}
.pipe {
color: tomato;
font-weight: bold;
letter-spacing: -5px;
font-size: 18px;
}
</style>
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more