Skip to content

Commit cc5b435

Browse files
authored
Merge pull request #311 from konstantin24121/issue310
add animation events #310
2 parents 7a19c5a + ee72d56 commit cc5b435

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

demo/component/BarChart.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,14 @@ export default React.createClass({
213213
console.log(`Pv Bar (${index}) Click: `, data);
214214
},
215215

216+
handleBarAnimationStart() {
217+
console.log('Animation start');
218+
},
219+
220+
handleBarAnimationEnd() {
221+
console.log('Animation end');
222+
},
223+
216224
render() {
217225
const { data, data01, data02 } = this.state;
218226

@@ -236,7 +244,7 @@ export default React.createClass({
236244
<Legend />
237245
<Tooltip />
238246
<CartesianGrid vertical={false}/>
239-
<Bar yAxisId="a" dataKey="uv" label={<RenderLabel />}>
247+
<Bar yAxisId="a" dataKey="uv" label={<RenderLabel />} onAnimationStart={this.handleBarAnimationStart} onAnimationEnd={this.handleBarAnimationEnd} >
240248
{
241249
data.map((entry, index) => (
242250
<Cell key={`cell-${index}`} fill={colors[index % 20]}/>

src/cartesian/Area.js

+8
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class Area extends Component {
6060
onMouseEnter: PropTypes.func,
6161
onMouseLeave: PropTypes.func,
6262
onClick: PropTypes.func,
63+
onAnimationStart: PropTypes.func,
64+
onAnimationEnd: PropTypes.func,
6365

6466
animationId: PropTypes.number,
6567
isAnimationActive: PropTypes.bool,
@@ -84,10 +86,14 @@ class Area extends Component {
8486
curve: true,
8587
activeDot: true,
8688

89+
8790
isAnimationActive: true,
8891
animationBegin: 0,
8992
animationDuration: 1500,
9093
animationEasing: 'ease',
94+
95+
onAnimationStart: () => {},
96+
onAnimationEnd: () => {},
9197
};
9298

9399
constructor(props, ctx) {
@@ -101,10 +107,12 @@ class Area extends Component {
101107

102108
handleAnimationEnd = () => {
103109
this.setState({ isAnimationFinished: true });
110+
this.props.onAnimationEnd();
104111
};
105112

106113
handleAnimationStart = () => {
107114
this.setState({ isAnimationFinished: false });
115+
this.props.onAnimationStart();
108116
};
109117

110118
renderCurve() {

src/cartesian/Bar.js

+7
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ class Bar extends Component {
5050
onMouseEnter: PropTypes.func,
5151
onMouseLeave: PropTypes.func,
5252
onClick: PropTypes.func,
53+
onAnimationStart: PropTypes.func,
54+
onAnimationEnd: PropTypes.func,
5355

5456
animationId: PropTypes.number,
5557
isAnimationActive: PropTypes.bool,
@@ -71,6 +73,9 @@ class Bar extends Component {
7173
animationBegin: 0,
7274
animationDuration: 1500,
7375
animationEasing: 'ease',
76+
77+
onAnimationStart: () => {},
78+
onAnimationEnd: () => {},
7479
};
7580

7681
state = {
@@ -79,10 +84,12 @@ class Bar extends Component {
7984

8085
handleAnimationEnd = () => {
8186
this.setState({ isAnimationFinished: true });
87+
this.props.onAnimationEnd();
8288
};
8389

8490
handleAnimationStart = () => {
8591
this.setState({ isAnimationFinished: false });
92+
this.props.onAnimationStart();
8693
};
8794

8895
renderRectangle(option, props) {

src/cartesian/Line.js

+8
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ class Line extends Component {
5858
onMouseEnter: PropTypes.func,
5959
onMouseLeave: PropTypes.func,
6060
onClick: PropTypes.func,
61+
onAnimationStart: PropTypes.func,
62+
onAnimationEnd: PropTypes.func,
63+
6164
isAnimationActive: PropTypes.bool,
6265
animationBegin: PropTypes.number,
6366
animationDuration: PropTypes.number,
@@ -86,6 +89,9 @@ class Line extends Component {
8689
animationBegin: 0,
8790
animationDuration: 1500,
8891
animationEasing: 'ease',
92+
93+
onAnimationStart: () => {},
94+
onAnimationEnd: () => {},
8995
};
9096

9197
constructor(props, ctx) {
@@ -166,10 +172,12 @@ class Line extends Component {
166172

167173
handleAnimationEnd = () => {
168174
this.setState({ isAnimationFinished: true });
175+
this.props.onAnimationEnd();
169176
};
170177

171178
handleAnimationStart = () => {
172179
this.setState({ isAnimationFinished: false });
180+
this.props.onAnimationStart();
173181
};
174182

175183
renderLabelItem(option, props, value) {

0 commit comments

Comments
 (0)