-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbucket.js
84 lines (68 loc) · 1.76 KB
/
bucket.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* @jsx React.DOM
*/
var React = require('react/addons');
var AnimateMixin = ('react-animate');
var d3 = require('d3');
var Arc = d3.svg.arc();
var _ = require('lodash');
module.exports = React.createClass({
getInitialState: function() {
var target = this.props.datum.target;
var scale = this.props.scale;
var allocated = this.props.datum.allocated;
var target = this.props.datum.target;
var targetR = scale(target);
var initAngle = 2*Math.PI*(allocated/target);
var arc = Arc.innerRadius(0).startAngle(0)
return {
targetR: targetR,
allocated: this.props.datum.allocated,
x: this.props.datum.x,
y: this.props.datum.y,
fill: this.props.datum.color,
arcAngle: 0,
initAngle: initAngle,
arc: arc,
translate: "translate("+this.props.datum.x+','+this.props.datum.y+')'
}
},
render: function() {
var arc = this.state.arc
.endAngle(this.state.arcAngle)
.outerRadius(this.state.targetR);
var segmentArc = arc();
return (
<g>
<circle
className="target"
cx={this.state.x}
cy={this.state.y}
r={this.state.targetR}
fill='white'
stroke={this.state.fill} >
</circle>
<path
className='allocated'
transform={this.state.translate}
d={segmentArc}
fill={this.state.fill} >
</path>
</g>
);
},
animate: require('./lib/animate'),
activate: function() {
console.log('activating')
},
animateArc: function() {
this.animate('arcAngle', this.state.initAngle, 700)
},
componentDidMount: function() {
var cmp = this;
var delay = 500;
window.setTimeout(function() {
cmp.animateArc();
}, delay)
}
});