pygal icon indicating copy to clipboard operation
pygal copied to clipboard

x_labels line breaks

Open johnwilson opened this issue 8 years ago • 1 comments

First I'd like to thank you for creating such a wonderful library/tool! However I was wondering if it's possible to have line breaks in the x_labels. Currently adding \n adds an actual line break in the SVG file which isn't rendered. I noticed this issue has been addressed with the tooltips but doesn't appear to be working for x_labels.

Thanks

johnwilson avatar Feb 28 '17 14:02 johnwilson

Have you tried to set the css for the element to have white-space: pre-line. E.G.

config = pygal.Config()

# make plot title larger and add linebreaks
config.css.append('''inline:
  g.titles text.plot_title {
    font-size: 18px !important;
    white-space: pre-line;
  }''')

chart = pygal.Pie(config,
                  width=300,
                  height=300,
                  )

chart.title = "Created by Users \n(%s)"%tracker

in case somebody else is looking here for a solution. Note you will need to change the css selector to target the element you want to use. See: https://svgwg.org/svg-next/text.html#TextLayoutPre.

I would go so far as to suggest changing the css/graph.css file to add white-space: pre-line to:

{{ id }}.title {
  text-anchor: middle;
}

so all titles can be split into multiple lines using an embedded \n. \n is unlikely to be added by accident. I am not sure where the multiple line element will end up aligned to the rest of the chart. It could be centered on the location of the original single line. The top line of the wrapped element could be aligned at the same point as the single line. Could even be bottom aligned....

rouilj avatar Jun 03 '21 17:06 rouilj