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

tooltip formatter as slot when tooltip.useHTML == true #160

Open
MathieuDerelle opened this issue Sep 4, 2020 · 1 comment
Open

tooltip formatter as slot when tooltip.useHTML == true #160

MathieuDerelle opened this issue Sep 4, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@MathieuDerelle
Copy link

MathieuDerelle commented Sep 4, 2020

would be cool to be able to use slots to construct tooltip when using tooltip.useHTML == true
with the parameters of https://api.highcharts.com/class-reference/Highcharts#.TooltipFormatterCallbackFunction passed like so

<highcharts :options="chartOptions" :callback="someFunction">
  <template v-slot:tooltip="{ instance, tooltip }">
    <table>
                <thead>
                  <tr>
                    <th colspan="3"><b>${instance.x}</b> :</th>
                  </tr>
                </thead>
                <tbody>
                  <tr v-for="data in instance.points">
                    <td>
                      <span style="color:${data.point.color}">●</span>
                      ${data.series.name}
                    </td>
                    <td class="text-end px-2">
                      <b>${data.point.y}</b>
                    </td>
                    <td class="text-end">
                      <b>${data.percentage.toFixed(2)} %</b>
                    </td>
                  </tr>
	       </tbody>
    </table>
  </template>
</highcharts>

and be able to encapsulate it in a component :

<highcharts :options="chartOptions" :callback="someFunction">
	<template v-slot:tooltip="{ instance, tooltip }">
		<HighchartTooltip :instance="instance" :tooltip="tooltip" />
	</template>
</highcharts>

writting html in strings is annoying :

          formatter() {
            const body = this.points
              .concat()
              .reverse()
              .filter((data) => data.series.visible)
              .map(
                (data) => `
                  <tr>
                    <td>
                      <span style="color:${data.point.color}">●</span>
                      ${data.series.name}
                    </td>
                    <td class="text-end px-2">
                      <b>${data.point.y}</b>
                    </td>
                    <td class="text-end">
                      <b>${data.percentage.toFixed(2)} %</b>
                    </td>
                  </tr>
                `
              )
              .join('')
            return `
              <table>
                <thead>
                  <tr>
                    <th colspan="3"><b>${this.x}</b> :</th>
                  </tr>
                </thead>
                <tbody>${body}</tbody>
              </table>
            `
          }
@Denyllon
Copy link
Contributor

Denyllon commented Sep 9, 2020

Hello @MathieuDerelle ,

Thank you for reporting your suggestion! We will consider to add it in the next major release, but I can't tell you the exact date of when it will be done. Meanwhile, added the enhancement label in order to know how much work do we have to do with the new version of the wrapper.

Kind regards!

@Denyllon Denyllon added the enhancement New feature or request label Sep 9, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants