echarts icon indicating copy to clipboard operation
echarts copied to clipboard

[Bug] Hover emphasis lightens the previous colour after an update with universalTransition

Open robinrydberg-ce opened this issue 2 weeks ago • 1 comments

Version

6.1.0 (the same code order is on master)

Link to Minimal Reproduction

Paste into the examples editor:

const build = (data) => ({
  xAxis: { type: 'category', data: ['a', 'b', 'c'] },
  yAxis: {},
  series: [{ id: 's', type: 'bar', universalTransition: true, itemStyle: { color: '#1f5fd6' }, data }]
});

myChart.setOption(build([3, 5, 7]));

setTimeout(() => {
  myChart.setOption(
    build([3, 5, 7].map((value) => ({ value, itemStyle: { color: '#14a04a' } }))),
    { replaceMerge: ['series'] }
  );
}, 1500);

Steps to Reproduce

  1. Run the code above and wait until the columns have turned green.
  2. Hover any column.

Current Behavior

The hovered column turns light blue (rgba(34,104,235,1), lifted from #1f5fd6): the emphasis colour is lifted from the colour the column had before the update.

Expected Behavior

The hovered column turns light green, lifted from the colour it shows (rgba(22,176,81,1) with universalTransition: false).

With universalTransition: false, or with animation: false, the hover colour is right.

Environment

- OS: macOS
- Browser: Chromium, canvas renderer (also reproduced in jsdom with the SVG renderer)
- Framework: none

Any additional comments?

In renderSeries (src/core/echarts.ts), series:transition runs before updateStates:

  1. The universal transition calls to.animateFrom({ style: from.style }, ...) in transitionBetween. animateFrom writes the old style onto the element straight away and animates towards the new one, so el.style.fill holds the old colour for now.
  2. updateStates then calls savePathStates(el), which stores el.style.fill as normalFill.
  3. createEmphasisDefaultState lifts normalFill, so the emphasis is computed from the old colour. It stays wrong until the next render saves the states again.

Possible fixes: take the normal fill from the animation target rather than the current style when the element has a style animator running (as getFromStateStyle already does for state transitions), or save the path states before series:transition.

robinrydberg-ce avatar Nov 16 '26 14:11 robinrydberg-ce

Hi, I'd like to work on this. I'd change savePathStates so that when a style animation (other than a state transition) is running, it saves the fill/stroke the animation is heading to rather than the current el.style, similar to getFromStateStyle, and add a unit test for the universalTransition case.

schizophrenicmaniac avatar Nov 16 '26 14:11 schizophrenicmaniac