Skip to content

Axis formatter should default to global Axis #676

@nickofthyme

Description

@nickofthyme

When using multiple y-axes and a single global x-axis. Each of the supplied series will use their respective y-axis per groupId and share the x-axis as a fallback.

However, the tick formatter for the x-axis is not associated to the global x-axis, and leaves the tooltip header values unformatted even though the series is using the global x-axis as a default.

Screenshot

Notice the x-axis time has ticks formatted given the tickFormat on the AxisSpec. However, the header value is not formatted.

image

Solution

The code below, chooses the x or y axis based on rotation or uses the explicit tooltipHeaderFormatter

if (!header) {
// if we have a tooltipHeaderFormatter, then don't pass in the xAxis as the user will define a formatter
const xAxisFormatSpec = [0, 180].includes(chartRotation) ? xAxis : yAxis;
const formatterAxis = tooltipHeaderFormatter ? undefined : xAxisFormatSpec;
header = formatTooltip(indexedGeometry, spec, true, false, hasSingleSeries, formatterAxis);
}

However, given this configuration the xAxis will always be undefined as getAxesSpecForSpecId will only associate axis to their groudId.

const { xAxis, yAxis } = getAxesSpecForSpecId(axesSpecs, spec.groupId);

Currently, this is fixed by supplying the tooltipHeaderFormatter to the tooltip but this seems unnecessary.

I think the fix, in this case, is to change getAxesSpecForSpecId to return global spec as a fallback possibly optionally based on an argument.

Note: The global tooltipHeaderFormatter should always override any axis formatter.

Metadata

Metadata

Assignees

No one assigned

    Labels

    :axisAxis related issue:xyBar/Line/Area chart relatedenhancementNew feature or request

    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