I tried to produce a bar chart that visualizes the most-starred projects on GitHub. I added 'label'
and 'xlink'
inside tooltips, however, 'label'
contents are not very well fit in for some items, also, some links are not shown up in certain projects' tooltip. See below,
Below is the Python code using Pygal module, run it and see the .svg file yourself.
import requests, pygal
url = 'https://api.github.com/search/repositories?q=language:python&sort=star'
r = requests.get(url)
repo_list = r.json()['items']
names, stars = [], []
for k in repo_list:
names.append(k['name'])
temp = {
'value': k['stargazers_count'],
'label': k['description'],
'xlink': k['html_url'],
}
stars.append(temp)
my_config = pygal.Config()
my_config.x_label_rotation = 45
chart = pygal.Bar(my_config)
chart.title = 'GitHub, Python Most Starred Projects'
chart.x_labels = names
chart.add('', stars)
chart.render_to_file('MyFile.svg', force_uri_protocol = 'http')
How do I solve this problem, either by adjusting font size of tooltip or tooltip window size?
I don't think there's a clean way to do this; I think you'd need to modify the .svg file directly. There's an open issue on the Pygal project asking this question. Someone seems to have found a solution using \n
and the force_uri_protocol='http'
, but that doesn't work for me. On my machine \n
just gets converted to a single space.
The best I could come up with is truncating the description to a certain number of characters, something like this:
temp = {
'value': k['stargazers_count'],
'label': k['description'][:80] + "..." ,
'xlink': k['html_url'],
}
If you like this solution you can add some logic so short labels don't have the ellipsis at the end. I think this is the solution I'll use next time I run into this issue.