Skip to content
This repository has been archived by the owner on Feb 19, 2022. It is now read-only.

External events #324

Merged
merged 12 commits into from
Jan 2, 2018
Merged

External events #324

merged 12 commits into from
Jan 2, 2018

Conversation

boygirl
Copy link
Contributor

@boygirl boygirl commented Jan 1, 2018

This PR adds support for triggering external events via a prop called externalEventMutations on VictorySharedEvents and components enhanced with the add-events HOC i.e. VictoryBar, VictoryPie etc.

note This feature will require minimal updates to victory-chart and victory-pie repos (adding props). No changes for victory-native will be necessary.

Example Usage:
victory-event-mutations

mutation handlers

removeMutation() {
    this.setState({
      externalMutation: null
    });
  }

  handleClick() {
    const callback = this.removeMutation.bind(this);
    this.setState({
      externalMutation: [{
        childName: "bar",
        target: ["data", "labels"],
        eventKey: "all",
        mutation: (props) => {
          const fill = props.style && props.style.fill;
          return fill === "blue" ?
            { style: Object.assign({}, props.style, { fill: "red" }) } :
            { style: Object.assign({}, props.style, { fill: "blue" }) };
        },
        callback
      }]
    });
  }

clearStyle() {
    this.setState({
      externalMutation: [
        {
          childName: "bar",
          target: "all",
          eventKey: "all",
          mutation: () => ({ style: undefined })
        }
      ]
    });
  }

...
Victory Components

<div>
 <button onClick={this.handleClick.bind(this)}>External Mutation</button>
 <button onClick={this.clearStyle.bind(this)}>Clear Style</button>

 <VictoryChart
  externalEventMutations={this.state.externalMutation}
  events={[
    {
      childName: "bar",
      target: "data",
      eventHandlers: {
        onClick: () => {
          return [
            {
              mutation: () => {
                return { style: { fill: "orange" } };
              }
            }, {
              target: "labels",
              mutation: (props) => {
                return props.text === "clicked" ? { text: "unclicked" } : { text: "clicked" };
              }
            }
          ];
        }
      }
    }
  ]}
>
  <VictoryBar name="bar" style={{ data: { fill: "cyan" } }}/>
</VictoryChart>

</div>

@boygirl boygirl changed the title [WIP] External events External events Jan 2, 2018
@boygirl boygirl merged commit 2562c72 into master Jan 2, 2018
@boygirl boygirl deleted the experiment/external-events branch January 2, 2018 20:54
@mbilokonsky
Copy link

Thanks! Sorry, @boygirl, I didn't get to take a look at it before you merged, I moved across state lines this weekend and won't have reliable internet until thursday.

@boygirl
Copy link
Contributor Author

boygirl commented Jan 2, 2018

@mbilokonsky good luck on your move! I'm going to complete the release process for this, since It won't be a breaking change anyway. I'll hold off on updating the docs until after the weekend. It would be great if you could kick the tires before then. I'd love to get any changes in before I document this feature.

@mbilokonsky
Copy link

mbilokonsky commented Jan 2, 2018 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants