Skip to content

Commit b346db3

Browse files
committed
WIP: adding horizontal lines and labels
1 parent 253c67f commit b346db3

File tree

4 files changed

+24
-11
lines changed

4 files changed

+24
-11
lines changed

scout-ui/src/minicharts/d3fns/few.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ module.exports = function(data, g, width, height, options) {
4242
g.selectAll('*').remove();
4343
g.call(tip);
4444

45-
debug('data', _.pluck(data, 'y'));
46-
4745
var bar = g.selectAll('.bar')
4846
.data(data)
4947
.enter().append('g')

scout-ui/src/minicharts/d3fns/many.js

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ module.exports = function(data, g, width, height, options) {
99

1010
options = _.defaults(options || {}, {
1111
bgbars: false,
12-
bglines: false,
13-
legend: true,
12+
legend: false,
1413
labels: false // label options will be set further below
1514
});
1615

@@ -44,14 +43,28 @@ module.exports = function(data, g, width, height, options) {
4443
g.call(tip);
4544

4645
if (options.legend) {
46+
47+
var maxVal = d3.max(y.domain());
48+
var format = d3.format('%.1f');
49+
var legendValues = [format(maxVal), format(maxVal / 2)];
50+
debug(legendValues);
51+
4752
g.append('text')
48-
.attr('x', 0)
49-
.attr('y', -10)
50-
.attr('text-anchor', 'start')
51-
.text(sumY);
52-
}
53+
.attr('class', 'legend')
54+
.attr('x', width)
55+
.attr('y', 0)
56+
.attr('dy', '0.35em')
57+
.attr('text-anchor', 'end')
58+
.text(d3.max(y.domain()) + '%');
59+
60+
g.append('text')
61+
.attr('class', 'legend')
62+
.attr('x', width)
63+
.attr('y', height / 2)
64+
.attr('dy', '0.35em')
65+
.attr('text-anchor', 'end')
66+
.text(d3.max(y.domain()) / 2 + '%');
5367

54-
if (options.bglines) {
5568
g.append('line')
5669
.attr('class', 'bg line')
5770
.attr('x1', 0)
@@ -74,6 +87,7 @@ module.exports = function(data, g, width, height, options) {
7487
.attr('y2', height);
7588
}
7689

90+
7791
var bar = g.selectAll('.bar')
7892
.data(data)
7993
.enter().append('g')

scout-ui/src/minicharts/d3fns/number.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = function(opts) {
5454
.attr('transform', 'translate(' + margin.left + ',' + margin.top + ')');
5555

5656
many(data, g, width, height - 10, {
57-
bglines: true,
57+
legend: true,
5858
bgbars: false,
5959
labels: {
6060
text: function(d, i) {

scout-ui/src/minicharts/d3fns/string.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ module.exports = function(opts) {
4343

4444
var chart = data.length <= 5 ? few : many;
4545
chart(data, g, width, height, {
46+
legend: true,
4647
bglines: true
4748
});
4849
};

0 commit comments

Comments
 (0)