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

[BUG] Newline in tooltips gets converted to a space #4087

Closed
thany opened this issue Mar 29, 2017 · 1 comment · Fixed by #5521
Closed

[BUG] Newline in tooltips gets converted to a space #4087

thany opened this issue Mar 29, 2017 · 1 comment · Fixed by #5521

Comments

@thany
Copy link

thany commented Mar 29, 2017

Expected Behavior

When you return a newline character in the tooltip text in the callback for its title, that newline should be rendered as such.

Current Behavior

Newlines (\n) are converted to spaces. And <br> is rendered literally.

Possible Solution

I'm not sure, but there might be a mechanism in place that arbitrarily converts unsupported characters to spaces before rendering. If this would not convert newlines, and pass them to the renderer, perhaps that'll fix it.

Steps to Reproduce (for bugs)

  1. Any chart will do.
  2. Make a simple tooltips callback like this:
//...
tooltips: {
  callbacks: {
    title: (items, data) => {
      return "Hello\nworld";
    }
  }
}
//...

Context

I'm trying to give each tooltip a title that is the date and time, which a newline in between to keep the tooltip not too wide. I'm aiming for a tooltip title like this:

Tu 28 March 2107
2:59 PM

Environment

  • Chart.js version: 2.5.0 (using through Angular-chart.js 1.1.1 with Angular 1.6.2)
  • Browser name and version: Firefox 52.0.1
@etimberg
Copy link
Member

@thany the behaviour with <br/> is as designed since the text renders on the canvas. At the moment, we only support multiple lines of text by returning an array of strings. You can use this as a word around for your case.

tooltips: {
  callbacks: {
    title: (items, data) => {
      return "Hello\nworld".split('\n');
    }
  }
}

To anyone wanting to implement this functionality, changes would need to be made in a few places:

  1. https://github.com/chartjs/Chart.js/blob/master/src/core/core.tooltip.js#L105
  2. https://github.com/chartjs/Chart.js/blob/master/src/core/core.tooltip.js#L404
  3. https://github.com/chartjs/Chart.js/blob/master/src/core/core.tooltip.js#L432

I'm happy to look at a PR that adds this. Please include tests with the changes.

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

Successfully merging a pull request may close this issue.

3 participants