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

Introduce formatter -options for tooltips and tick labels #6037

Closed
wants to merge 4 commits into from

Conversation

kurkle
Copy link
Member

@kurkle kurkle commented Jan 31, 2019

Couple of things going on here:

  • Fix scatter sample to use callback instead of legacy userCallback
  • Alias helpers.callback for minimization
  • Propose a _configure step to scale for resolving options
  • Propose a fallback path for formatter options in _configure
  • Propose _formatTick and _formatTooltip method names
  • Format tick labels if a callback is provided
  • Format value/label in TooltipItem
  • Add a test for multiline labels (I broke it and nothing failed)

Todo if merging is plausible:

  • Tests for formatter's
  • Docs

For testing: CodePen

src/core/core.scale.js Outdated Show resolved Hide resolved
@@ -217,8 +217,8 @@ function createTooltipItem(element) {
return {
xLabel: xScale ? xScale.getLabelForIndex(index, datasetIndex) : '',
yLabel: yScale ? yScale.getLabelForIndex(index, datasetIndex) : '',
label: indexScale ? indexScale.getLabelForIndex(index, datasetIndex) : '',
value: valueScale ? valueScale.getLabelForIndex(index, datasetIndex) : '',
label: indexScale ? indexScale._formatTooltip(index, datasetIndex) : '',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about a private function here

/**
* @private
*/
_configure: function() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is an interesting concept for supporting these options

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only things that should need an update to change can be resolved here though.

@benmccann
Copy link
Contributor

Docs would have to be added as well

src/core/core.scale.js Outdated Show resolved Hide resolved
@benmccann
Copy link
Contributor

I'm wondering what the tick is when it's passed to the user-supplied formatter function. Is it a number or an object {tick: number, major: boolean}. I think we have both in different places. The latter would be useful to allow users to more easily do more advanced formatting on their own

@kurkle kurkle force-pushed the formatter branch 4 times, most recently from 64795ee to c832c17 Compare February 2, 2019 09:42
@kurkle
Copy link
Member Author

kurkle commented Feb 2, 2019

how hard can it be to rebase 😄

changes

core.scale:

  • alias globalDefaults globally
  • pass tick object to formatter

scale.time:

  • pass tick object to tickFormatFunction
  • use already figured tick.major in tickFormatFunction
  • call _formatTick in tickFormatFunction

src/scales/scale.time.js Outdated Show resolved Hide resolved
- alias globalDefaults globally
- pass tick object to formatter
time scale:
- pass tick object to tickFormatFunction
- use already figured `tick.major` in tickFormatFunction
- use _formatTick in tickFormatFunction
@@ -73,6 +73,22 @@ describe('Core.scale', function() {

expect(lastTick(chart).label).toBeUndefined();
});

it('should display multiline-labels correctly', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: "multiline labels" or "multi-line labels" would both be fine. current hyphen location is unexpected

});

expect(lastTick(chart).label).toEqual(['September', '2018']);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd probably remove this blank line

@benmccann
Copy link
Contributor

This looks pretty good to me. I'm wondering if there are any other tests we need? Maybe one for the new _formatTooltip method?

var labels = [];
var i, ilen, tick;

if (helpers.isArray(ticks) && ticks.length) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be nicer to make whether the ticks are being passed in and whether it's the new format be independent. Can we check if the tick is an object instead?

@nishantprajapti
Copy link

@benmccann just want to know why have you referenced #2442 at the bottom here. Any reasons ??

@benmccann
Copy link
Contributor

benmccann commented Apr 10, 2019

Ah, I guess this only handles textual formatting and not styling

@kurkle kurkle deleted the formatter branch June 12, 2020 05:32
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

Successfully merging this pull request may close these issues.

None yet

4 participants