[Bug] Hover emphasis lightens the previous colour after an update with universalTransition
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
- Run the code above and wait until the columns have turned green.
- 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:
- The universal transition calls
to.animateFrom({ style: from.style }, ...)intransitionBetween.animateFromwrites the old style onto the element straight away and animates towards the new one, soel.style.fillholds the old colour for now. updateStatesthen callssavePathStates(el), which storesel.style.fillasnormalFill.createEmphasisDefaultStateliftsnormalFill, 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.
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.