Skip to content

[Feature] Add ability to disable emphasis/highlight functionality of tooltip axis trigger #18495

@juliepagano

Description

@juliepagano

What problem does this feature solve?

It would be really helpful to be able to render the tooltip axis trigger (e.g. a line or a cross) while disabling the highlight/emphasis functionality it triggers on the underlying series. This would probably be a configuration option for tooltip or tooltip.axisPointer.

I created a very simple example where you can see the behavior based on one of the line chart examples.
https://codesandbox.io/s/line-chart-tooltip-highlight-issue-ob1ob0?file=/index.js

When you have a line chart with multiple series, the axis trigger tends to highlight all the series, which is often unhelpful and can be really confusing to users.
image

If you focus very specifically on a line in this use case, you get a single focus. This behavior is fine.
image

If you set tooltip.trigger to none, you get more helpful highlight behavior where nothing is highlighted when you're outside a series, but you lose the visual assistance of the axis pointer tracking line to orient yourself within the chart.
image

A single series is highlighted when you are hovered over it, so that behavior is the same.
image

I tried a few different combinations of series, tooltip, and axis pointer configuration options to see if I could generate what I wanted with the current functionality, but I could not find a way. It seems like it's currently possible to disable highlight behavior entirely and disable the tooltip axis pointer. I'm hoping for the ability to have only series-level highlight functionality while rendering an axis pointer.

What does the proposed API look like?

This would probably be a configuration option for tooltip and/or tooltip.axisPointer. I do not have strong feelings about the name of the option to trigger this behavior. I see a silent option on some other parts of the API, so maybe having tooltip.axisPointer.silent: true could trigger "render but do not highlight" behavior, but I'm not sure if that would break other tooltip functionality (e.g. showing the tooltip on hover). Maybe a more specific emphasisTrigger or something like that would be more helpful. I'm open to whatever API approach folks with more experience with the internals of the library feel is best.

It looks like the implementation change would probably go hereabouts in the code.

function dispatchHighDownActually(
axesInfo: Dictionary<CollectedAxisInfo>,
dispatchAction: ExtensionAPI['dispatchAction'],
api: ExtensionAPI
) {
// FIXME
// highlight status modification should be a stage of main process?
// (Consider confilct (e.g., legend and axisPointer) and setOption)
const zr = api.getZr();
const highDownKey = 'axisPointerLastHighlights' as const;
const lastHighlights = inner(zr)[highDownKey] || {};
const newHighlights: Dictionary<BatchItem> = inner(zr)[highDownKey] = {};
// Update highlight/downplay status according to axisPointer model.
// Build hash map and remove duplicate incidentally.
each(axesInfo, function (axisInfo, key) {
const option = axisInfo.axisPointerModel.option;
option.status === 'show' && each(option.seriesDataIndices, function (batchItem) {
const key = batchItem.seriesIndex + ' | ' + batchItem.dataIndex;
newHighlights[key] = batchItem;
});
});
// Diff.
const toHighlight: BatchItem[] = [];
const toDownplay: BatchItem[] = [];
each(lastHighlights, function (batchItem, key) {
!newHighlights[key] && toDownplay.push(batchItem);
});
each(newHighlights, function (batchItem, key) {
!lastHighlights[key] && toHighlight.push(batchItem);
});
toDownplay.length && api.dispatchAction({
type: 'downplay',
escapeConnect: true,
// Not blur others when highlight in axisPointer.
notBlur: true,
batch: toDownplay
} as DownplayPayload);
toHighlight.length && api.dispatchAction({
type: 'highlight',
escapeConnect: true,
// Not blur others when highlight in axisPointer.
notBlur: true,
batch: toHighlight
} as HighlightPayload);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    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