antvis / G2

📊 The concise and progressive visualization grammar.
https://g2.antv.antgroup.com
MIT License
12.08k stars 1.59k forks source link

【v5】图例显隐后 elementHighlightByColor 交互永久失效 #5529

Closed Deathsteps closed 9 months ago

Deathsteps commented 1 year ago

问题描述

首次生效效果

image

关闭图例

image

再打开图例

image

期望结果

图例开关不影响元素高亮效果

如何重现

官方代码修改

/**
 * A recreation of this demo: https://observablehq.com/@d3/grouped-bar-chart
 */
import { Chart } from '@antv/g2';

const chart = new Chart({
  container: 'container',
  autoFit: true,
});

chart.title({
  title: 'Population by age and state',
  subtitle: 'It shows the population of U.S. by age and state.',
});

chart
  .interval()
  .data({
    type: 'fetch',
    value:
      'https://gw.alipayobjects.com/os/bmw-prod/f129b517-158d-41a9-83a3-3294d639b39e.csv',
    format: 'csv',
  })
  .transform({ type: 'sortX', by: 'y', reverse: true, slice: 6 })
  .transform({ type: 'dodgeX' })
  .encode('x', 'state')
  .encode('y', 'population')
  .encode('color', 'age')
  .scale('y', { nice: true })
  .axis('y', { labelFormatter: '~s' });

chart
  .state('inactive', { opacity: 0.5 })
  .interaction('tooltip', { shared: true })
  .interaction('elementHighlightByColor', {
    background: true,
    link: false,
  });

chart.render();

额外信息

pearmini commented 1 year ago

有可能是 elementHighlight 交互没有重新挂载。

Calmio-Y commented 10 months ago

没有修复成功呢,使用上述代码在官网测试,没有通过

Calmio-Y commented 10 months ago

@pearmini