Commit 0a7a53693dbf7f052f17f79d0787a5efa824bd62
1 parent
f0706d95
Exists in
master
and in
4 other branches
Set legend position by chart width
Showing
1 changed file
with
5 additions
and
4 deletions
Show diff stats
app/main/static/js/charges.js
1 | -const margin = {top: 60, right: 270, bottom: 100, left: 90}, | |
2 | - width = 1200 - margin.left - margin.right, | |
1 | +const margin = {top: 60, right: 350, bottom: 100, left: 90}, | |
2 | + width = 1300 - margin.left - margin.right, | |
3 | 3 | height = 500 - margin.top - margin.bottom; |
4 | 4 | |
5 | 5 | const tooltip_offset = {dx: 0, dy: 100} |
6 | 6 | |
7 | 7 | const color_scale = d3.scaleOrdinal(d3.schemeCategory10); |
8 | 8 | |
9 | -const legend_cell_size = 15; | |
9 | +const legend_cell_size = 15; // colored scare size | |
10 | +const legend_x = width+20; // begin legend a bit after the end of the chart | |
10 | 11 | |
11 | 12 | // TODO: set main scales attr here then domain later |
12 | 13 | // const x = d3.scaleBand() |
... | ... | @@ -70,7 +71,7 @@ function build_chart(div_selector, data_url, project_name, category) { |
70 | 71 | let reverse_keys = color_scale.domain().reverse(); |
71 | 72 | |
72 | 73 | let legend = svg.append('g') |
73 | - .attr('transform', 'translate(850, -30)'); | |
74 | + .attr('transform', 'translate('+legend_x+', -30)'); | |
74 | 75 | |
75 | 76 | legend.selectAll() |
76 | 77 | .data(reverse_keys) | ... | ... |