Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Long legend text truncated #78

Open
cskujbus opened this issue Feb 25, 2023 · 4 comments
Open

Long legend text truncated #78

cskujbus opened this issue Feb 25, 2023 · 4 comments

Comments

@cskujbus
Copy link

Hello,

I'm using Contex version 0.4.0. I try to generate a point plot with a right legend in a Phoenix LiveView application. The legend appears on the right side, but long texts will be truncated. Is it possible to make them appear in full length?

thanks

contex

@mindok
Copy link
Owner

mindok commented Feb 27, 2023

At the moment it is hard-coded as it is very difficult to calculate expected text widths in SVG from within Elixir as it doesn't have an SVG layout engine like you would in a browser.

Where I've hit this in the past, I've separated the chart from the legend and combined them in my page layout. Creating a legend in your page layout could be as easy as using an HTML table with background colour set to the appropriate colour. Each plot module, e.g. Contex.BarChart exposes a function get_legend_scales/1 that returns a list (usually only with one item) of scales that are used to generate the legend. You could them use this to create your HTML table using a pattern similar to that in Contex.Legend.to_svg/1 (or you could modify this to generate an SVG snippet with wider text boxes, and display that instead).

@ghenry
Copy link

ghenry commented Jun 22, 2023

I'm going to try this way too as I'm hitting these. I've tried legend_top and legend_right (but phone numbers are cropped)
Screenshot from 2023-06-22 16-34-39
Screenshot from 2023-06-22 16-34-35

I really don't want to go client side with chartjs either :-(

@mindok
Copy link
Owner

mindok commented Jun 28, 2023

Hi @ghenry - does the workaround suggested (rendering the legend as HTML outside of the Contex chart) work in your situation?

@ghenry
Copy link

ghenry commented Jun 28, 2023

Not quite yet. I've had to use legend_top and reduce my items to 5. I should get more time to look into it as I don't want have to switch to a front end thing like chartjs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants