Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'active' variable in style for VictoryBar no longer works as expected #2861

Open
2 tasks done
nateguy opened this issue Apr 22, 2024 · 6 comments
Open
2 tasks done

'active' variable in style for VictoryBar no longer works as expected #2861

nateguy opened this issue Apr 22, 2024 · 6 comments
Labels
Type: Bug 🐛 Oh no! A bug or unintentional behavior

Comments

@nateguy
Copy link

nateguy commented Apr 22, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct

  • I agree to follow this project's Code of Conduct

Victory version

37.0.2

Code Sandbox link

No response

Bug report

<VictoryBar
   key={1}
   barRatio={1}
   style={{
      data: {
         fill: ({active}) =>
            active ? '#3A7DC0' : '#CCD2D9',
         },
      }}
   data={chartData.transactionCountData}
   y={(datum) => datum.y}
/>

Steps to reproduce

1. Open screen with VictoryBar chart
2. Click on one of the bars

Expected behavior

The selected bar color should change to #3A7DC0

Actual behavior

The selected bar no longer changes color

Environment

- Device:
- OS:
- Node:
- npm:
@nateguy nateguy added the Type: Bug 🐛 Oh no! A bug or unintentional behavior label Apr 22, 2024
@vinitsood
Copy link

I noticed it too. This worked in 36.9.2

@carbonrobot
Copy link
Contributor

The active property is only available when a component is wrapped in a selection container like VictorySelectionContainer, VictoryBrushContainer, etc. Components by default do not have events attached to them, so for a simple Bar chart you would do something like this.

Here is an example codesandbox of using events to target data elements. Relevant code pasted below.

<VictoryBar
  style={{
    data: {
      fill: (props) => (props.active ? "#3A7DC0" : "#CCD2D9"),
    },
  }}
  events={[
    {
      target: "data",
      eventHandlers: {
        onMouseOver: () => {
          return [{ target: "data", mutation: () => ({ active: true }) }];
        },
        onMouseOut: () => {
          return [{ target: "data", mutation: () => ({ active: false }) }];
        },
      },
    },
  ]}
/>

@nateguy
Copy link
Author

nateguy commented May 20, 2024

@carbonrobot Unfortunately this example doesn't solve the problem for me. Any reason why the active property was working in an earlier release but no longer working now?

@carbonrobot
Copy link
Contributor

I went back and tried all versions back to 36.6.0 and was unable to reproduce the expected behavior. Here is a codesandbox pinned to 36.9.2 if someone wants to try to reproduce the problem.

https://codesandbox.io/p/sandbox/strange-hooks-sj3m22

@nateguy
Copy link
Author

nateguy commented May 21, 2024

@carbonrobot I have downgraded to 36.9.2 and the active events are all working as expected without needing to add a custom events function. Let me describe all the events using active that were working previously

Screenshot 2024-05-21 at 7 22 30 PM

In Image 1, expected behavior is when a custom SVG point (ActiveScatterPoint) is made visible on a VictoryScatter chart when the user finger swipes over the chart. Code is as follows:

const ActiveScatterPoint = useCallback((props) => {
  const {x, y, active, datum} = props;
  if (datum.y > 0 && active) {
    return (
      <G x={x - 8} y={y - 8}>
        <TransactionDotIcon height={16} width={16} />
      </G>
    );
  }, []);

<VictoryScatter
  key={'transactionPriceScatterActive'}
  name={'transactionPriceScatterActive'}
  data={consolidatedTransactionPriceData}
  dataComponent={<ActiveScatterPoint />}
/>
Screenshot 2024-05-21 at 7 13 54 PM

Image 2 is the issue I described above in which the expected behavior is where the corresponding bar gets highlighted when user swipes over that bar and it becomes 'active' .

@carbonrobot
Copy link
Contributor

Thanks, that's more information that is helpful. The tooltip elements add events to the base container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug 🐛 Oh no! A bug or unintentional behavior
Projects
None yet
Development

No branches or pull requests

3 participants