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

How to make the header axis name on 2 lines #84

Open
ilanl opened this issue Jun 8, 2020 · 1 comment
Open

How to make the header axis name on 2 lines #84

ilanl opened this issue Jun 8, 2020 · 1 comment

Comments

@ilanl
Copy link

ilanl commented Jun 8, 2020

My axis dimensions have long names,
Is there a way to make them appear on 2 lines nicely ?

@berci-i
Copy link

berci-i commented Apr 13, 2021

My approach was creating a function which returns a text on 2 lines and than replace the html of the title. (something like:

const getSplittedString = (word, wordsPerLine) => {
  const split = word.split(" ");
  let i = 1;
  let html = `<tspan  x="0" dy="1.2em">${split[ 0 ]}`;
  if (!wordsPerLine) wordsPerLine = Math.ceil(split.length / 2);
  split.slice(1).map((s, index) => {
    i++;
    html = html + (
      index === split.length - 2 ?
        ` ${s}</tspan>`
        :
        (i % wordsPerLine == 0 ? ` ${s}</tspan><tspan  x="0" dy="1.2em">` : ` ${s}`))
  })

  return html;
}

)
I am calling this function for each title element and than replace the html, also update the transform property.

Is kind of a weird approach but it does the job.

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

2 participants