patternfly / patternfly/patternfly-react

getInteractiveLegendEvents onLegendClick not called with ChartBar in ChartStack + ChartAxis

Đang mở
#12,263 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Stale
Ngôn ngữ chính
TypeScript
Star
862
Fork
392
Merge trung bình
4 ngày 8 giờ
Pull request đã merge (30 ngày)
9

Mô tả

Description

getInteractiveLegendEvents's onLegendClick callback is never invoked when ChartBar components are wrapped in ChartStack (or ChartGroup) alongside ChartAxis. The same setup with ChartArea instead of ChartBar works correctly.

Steps to reproduce
  1. Create a Chart with ChartAxis, ChartBar inside a ChartStack, and a ChartLegend
  2. Pass getInteractiveLegendEvents({ chartNames, legendName, onLegendClick }) to Chart's events prop
  3. Click a legend item
  4. onLegendClick is never called
Minimal reproduction
<Chart
    events={getInteractiveLegendEvents({
        chartNames: [['bar-0'], ['bar-1'], ['bar-2']],
        isHidden,
        legendName: 'legend',
        onLegendClick: handleLegendClick,
    })}
    legendComponent={<ChartLegend name="legend" data={legendData} />}
    containerComponent={<ChartContainer />}
>
    <ChartAxis />
    <ChartAxis dependentAxis />
    <ChartStack>
        <ChartBar name="bar-0" data={data[0]} />
        <ChartBar name="bar-1" data={data[1]} />
        <ChartBar name="bar-2" data={data[2]} />
    </ChartStack>
</Chart>

Full repro: https://github.com/sachaudh/pf-legend-click-repro

What works vs what doesn't
Setup onLegendClick fires?
ChartArea + ChartStack + ChartAxis Yes
ChartBar + ChartAxis (no wrapper) Yes
ChartBar + ChartStack (no ChartAxis) Yes
ChartBar + ChartStack + ChartAxis No
ChartBar + ChartGroup + ChartAxis No

All three ingredients are required to trigger the bug: ChartBar, a ChartStack/ChartGroup wrapper, and ChartAxis.

Workaround

Apply click events directly to ChartLegend's events prop instead of relying on Chart-level event dispatch:

const legendClickEvents = [
    { target: 'data', eventHandlers: { onClick: handleClick } },
    { target: 'labels', eventHandlers: { onClick: handleClick } },
];

<ChartLegend name="legend" data={legendData} events={legendClickEvents} />
Affected version

@patternfly/react-charts v8.4.1, Victory v37.3.6


Jira Issue: PF-3666

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với getInteractiveLegendEvents và đường dẫn phân phối sự kiện Chart được ChartBar, ChartStack hoặc ChartGroup và ChartAxis sử dụng. Tái hiện ví dụ tối thiểu, so sánh với các trường hợp ChartArea và ChartBar không được bọc đang hoạt động, sau đó xác minh rằng onLegendClick được kích hoạt cho cả hai loại wrapper khi có ChartAxis.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
react, typescript
Lĩnh vực
frontend
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
55/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.