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

Easy way to add arbitrary text (e.g. units) to tooltip or text marks #8658

Open
stenzengel opened this issue Jan 20, 2023 · 1 comment
Open

Comments

@stenzengel
Copy link
Contributor

stenzengel commented Jan 20, 2023

Could you please implement an easy way to add arbitrary text (e.g. units) to tooltips or text marks, because the existing possibilities (proposed in #5122 (comment)) have several disadvantages:

Possible enhancement alternatives come to my mind:

  • New built-in formatType numberAndText:
    With this formatType the d3-number format is specified in braces and all other text is just copied:
    Usage:
"tooltip": [{
    "field": "Mean of energy",
    "format": "{.2f} kWh",
    "formatType": "numberAndText"
}]

Implementation:

vega.expressionFunction("numberAndText", function (datum, params) {
	return params.replace(/{(.*?)}/g, (_, p1) => d3.formatLocale(numberLocale).format(p1)(datum));
});
  • Extension of the existing formatType number to use the same implementation as in the previous alternative, when the format specification contains braces:
    Since { and } do not occur as tokens in the d3-number specification (see https://github.com/d3/d3-format), this should not cause problems with d3-number specifications and has the advantage that "formatType": "number" can be emitted, if it is inferred by vega-lite (which should normally be the case).
    Usage:
"tooltip": [{
    "field": "Mean of energy",
    "format": "{.2f} kWh",
}]
@jeanfabrice
Copy link

Being able to add a custom text to express units (like Watt, Watt hour, Meter, Ampere, Liter, etc) to text marks, tooltips and axis labels would be a great addition!

I +1 this enhancement request. Thank you for raising this

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