function barPipes(data, {
valueKey = 'value',
indexKey = 'index',
labelKey = 'label',
changeKey = null,
letters = alphabet.map(d => d.letter),
padding = 20,
showLabel = true,
color = 'tomato'
} = {}) {
const sel = d3.create('div')
.attr('class', 'bar-pipe');
sel.append('div')
.selectAll('div')
.data(data)
.join('div')
.style('color', color)
.html(d => {
const pipes = repeatStringNumTimes(`${letters[d[indexKey]]} ` , d[valueKey]);
const change = repeatStringNumTimes(`${letters[d[indexKey]]} ` , d[changeKey]);
console.warn('d', d)
console.warn('change', change)
const labelYes = `${d.label} : <span class='pipe'>${pipes} ------ ${change}</span> ------ :${d[valueKey]}`;
const labelNo = `<span class='pipe'>${pipes}</span>`;
const output = (showLabel) ? labelYes : labelNo;
return output;
});
function repeatStringNumTimes (string, times) {
return times > 0 ? string.repeat(times) : '';
};
return sel.node();
}