-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathbar.js
More file actions
16 lines (10 loc) · 726 Bytes
/
bar.js
File metadata and controls
16 lines (10 loc) · 726 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
function barh(selector, data, options) {
const width = options && options.width ? options.width : 400;
const bar_height = 26;
const x = d3.scaleLinear().domain([0, d3.max(data, d => d.value)]).range([0, width]);
const chart = d3.select(selector).attr('width', width).attr('height', bar_height * data.length);
const bar = chart.selectAll('g').data(data).enter().append('g').attr('transform', (d, i) => 'translate(0,' + i * bar_height + ')');
bar.append('rect').attr('width', d => x(d.value)).attr('height', bar_height - 4);
bar.append('text').attr('x', 3).attr('y', bar_height / 2).attr('dy', bar_height / 16).text(d => d.name);
}
(typeof exports !== 'undefined' ? exports : this).barh = barh;