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

Inline axis text #798

Closed
davidhund opened this issue Mar 6, 2019 · 5 comments
Closed

Inline axis text #798

davidhund opened this issue Mar 6, 2019 · 5 comments

Comments

@davidhund
Copy link

Description

For a line-chart I'd like to be able to set Y-axis tick text inline on narrow screens:
The tick text would show inside the line-chart as described in this article: "Inset y-axis labels on small viewports"

image

On narrow screens this would free up some horizontal space in the left margin of the chart.
I cannot find any config setting for this.

I could set something like:

chart.config( `axis.y.tick.text.position.x`, 20); // 20 is arbitrary :(

.. but the value (20) depends on the width of the value, and this could be anything...

Q: Is there a way to set the Y-axis text 'inline'?

@netil
Copy link
Member

netil commented Mar 7, 2019

Hi @davidhund, have you ever tried axis.y.inner option?

@netil netil added the question label Mar 7, 2019
@davidhund
Copy link
Author

Hi @netil - Thank you for your quick reply.

I did look at .inner but that gave me really weird results.
It seems as though something goes wrong with the width of the SVG inner <g transform..> - This group is too wide for the SVG when I set .inner to true.

axis_y_inner_g

The SVG width is 307, but the inner group is 356.2...

In the screenshot below, the bottom part is what I currently have. This looks OK (but I'd like the labels inline). If I set y.inner to true I get the top view, where the inner <g> seems too wide...

axis_y_inner

PS: I realize this setting should be used, but it is unusable because of this effect.

@netil
Copy link
Member

netil commented Mar 8, 2019

@davidhund, can you give full generation option to reproduce?

@davidhund
Copy link
Author

@netil - I've added a codepen: https://codepen.io/davidhund/pen/jJmLjJ

The issue is with dynamically setting the inner with chart.config

If you look at the JS pane, line 29 I can set inner to true directly and it works

// ..
axis: {
  y: {
    inner: true // THIS WORKS
  }
}
// ..

However: I am using chart.config after initializing the Chart (see line 68):

if(window.matchMedia(`(max-width: 55em)`).matches) {
  // ...
  chart.config(`axis.y.inner`, true); // THIS DOES NOT WORK
}

Maybe that is because I found I needed to re-draw the Chart with chart.show() after creation to have the config changes be picked up. See lines 73 - 75

// Config changes
// .. chart.config(xyz);

// RE-render (!?)
// https://github.com/naver/billboard.js/issues/500#issuecomment-406487456
chart.show();

@netil
Copy link
Member

netil commented Mar 11, 2019

@davidhund, I fixed axis inner style to be updated via .config() (checkout the screenshot from #802)

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

No branches or pull requests

2 participants