Skip to content

Commit 83a205f

Browse files
committed
rotate labels if domain is too short
1 parent 8bdaaf2 commit 83a205f

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

public/javascripts/usage_bar_chart.js

+20-18
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
let formatFixed = d3.format(",.0f");
117117
let formatTime = d3.time.format.utc("%H:%M:%S");
118118
let height = 200
119-
var margin = { top: 10, right: 20, bottom: 20, left: 20 };
119+
var margin = { top: 10, right: 20, bottom: 30, left: 20 };
120120

121121
let chartWidth = document.getElementById("myTabContent").offsetWidth*0.95
122122
if(displayMode == "citations"){
@@ -147,7 +147,7 @@
147147
.data([data])
148148
.attr("width", margin.left + setup.width + margin.right)
149149
.attr("height", margin.top + height + margin.bottom)
150-
.attr("style","position:relative")
150+
.attr("style","position:relative;")
151151
.attr("class", "chart barchart")
152152
.append("svg:g")
153153
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
@@ -198,20 +198,22 @@
198198
last_tick = chart.selectAll("rect").pop().pop().x.animVal.value
199199
}
200200

201-
202-
201+
var rotate = "0"
202+
if(setup.length < 4){
203+
rotate = "-65"
204+
}
203205

204206
chart.append("text")
205207
.attr("class", "label")
206208
.attr("text-anchor", "middle")
207-
.attr("transform", "translate(11," + (height + 18) + ")")
209+
.attr("transform", "translate(11," + (height + 18) + "), rotate("+rotate+")")
208210
.text(setup.firstLabel)
209211
.style("font-size", "13px");
210212

211213
chart.append("text")
212214
.attr("class", "label")
213215
.attr("text-anchor", "middle")
214-
.attr("transform", "translate(" + (last_tick - 11) + "," + (height + 18) + ")")
216+
.attr("transform", "translate(" + (last_tick - 11) + "," + (height + 18) + "), rotate("+rotate+")")
215217
.text(setup.lastLabel)
216218
.style("font-size", "13px");
217219

@@ -353,20 +355,20 @@ $(document).ready(function(e) {
353355
// {id: "2019-08", title: "April 2018", sum: 337},
354356
// ]
355357

356-
// yop="1980"
358+
// yop="2000"
357359

358360
// citations = [
359-
// {id: "2009", title: "April 2018", sum: 337},
360-
// {id: "2010", title: "April 2018", sum: 337},
361-
// {id: "2011", title: "April 2018", sum: 337},
362-
// {id: "2012", title: "April 2018", sum: 12},
363-
// {id: "2013", title: "April 2018", sum: 337},
364-
// {id: "2014", title: "April 2018", sum: 337},
365-
// {id: "2015", title: "April 2018", sum: 1000},
366-
// {id: "2016", title: "April 2018", sum: 337},
367-
// {id: "2017", title: "April 2018", sum: 23},
368-
// {id: "2018", title: "April 2018", sum: 337},
369-
// {id: "2019", title: "April 2018", sum: 337}
361+
// // {id: "2009", title: "April 2018", sum: 337},
362+
// // {id: "2010", title: "April 2018", sum: 337},
363+
// // {id: "2011", title: "April 2018", sum: 337},
364+
// // {id: "2012", title: "April 2018", sum: 12},
365+
// // {id: "2013", title: "April 2018", sum: 337},
366+
// // {id: "2014", title: "April 2018", sum: 337},
367+
// // {id: "2015", title: "April 2018", sum: 1000},
368+
// // {id: "2016", title: "April 2018", sum: 337},
369+
// // {id: "2017", title: "April 2018", sum: 23},
370+
// // {id: "2018", title: "April 2018", sum: 337},
371+
// // {id: "2019", title: "April 2018", sum: 337}
370372
// ]
371373

372374
if(views){bar2Viz(views,"#views-chart","sum","months","full",yop); }

0 commit comments

Comments
 (0)