Skip to content

[Lens] Improve tick formatting #97100

@flash1293

Description

@flash1293

Right now the chart decides where to place tick labels on an axis, then the formatter of the current dimension is applied to the value. This has some edge cases leading to misleading charts

Screenshot 2021-04-14 at 11 34 10

Using the default format, it's showing correctly:
Screenshot 2021-04-14 at 11 34 53

I think the issue here is the following: The chart wants to place a tick at 3.5 - based on the formatter, this gets shown as 4, but at the position of 3.5 (which is highly confusing), It would place another tick at 4, which would be formatted correctly, but as elastic-charts is filtering out duplicate ticks, it's omitting this tick, resulting in the situation that got reported by the customer.

For a workaround, the user can make sure the formatting supports digits after the decimal point. It should work fine by default), maybe they changed the space wide advanced setting format:number:defaultPattern? They can also change it within Lens
Screenshot 2021-04-14 at 11 37 50

Also, see #92152

There are some ways we could tackle this ( via @markov00 ):

  • we internally have a property for each axis to only show integer numbers integerOnly. This truncate all the digits correctly
  • we can make the chart aware of the formatting type (you will just pass in a formatting string depending on the type) instead of a formatting function. In this way, the chart is aware of the "context" and knows how to deal with it. It is anyway a bit more complicated due to the fact that we need to align and define a set of interchangeable formatting patterns between Kibana and charts.
  • Lens could fix that, if instead of using rounding everything like 0.5.toFixed(0) it can truncate the number to the number of digits specified. Using floor for example when the number of digits is 0

It gets even worse because Lens doesn't own formatting either in most cases (it's globally configured in advanced settings and in the index pattern).

Because of this I think it would make sense to explore option 2 here and pass some information about the formatting to the chart so it can influence tick placement.

One possible API would be to extend the field formatter API with something like this:

getValueHint(): undefined | 'integer' | 'binary' | 'double'

Some (but not all) formatters are able to provide this information - Lens could pass it on to the chart which uses it to place ticks accordingly.

What do you think @markov00

Metadata

Metadata

Assignees

Labels

Feature:LensTeam:VisualizationsTeam label for Lens, elastic-charts, Graph, legacy editors (TSVB, Visualize, Timelion) t//enhancementNew value added to drive a business resultimpact:needs-assessmentProduct and/or Engineering needs to evaluate the impact of the change.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions