2015-03-08 10:02:14 +00:00
|
|
|
var Router = ReactRouter;
|
|
|
|
|
2015-03-07 17:22:32 +00:00
|
|
|
var BarChart = React.createClass({
|
|
|
|
barHeight: 40,
|
|
|
|
barMargin: 5,
|
|
|
|
|
|
|
|
getInitialState: function() {
|
2015-03-08 10:02:14 +00:00
|
|
|
return {points: [], max: 1};
|
2015-03-07 17:22:32 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function() {
|
2015-03-08 10:02:14 +00:00
|
|
|
$.get(this.props.api, function(res){
|
2015-03-08 11:17:56 +00:00
|
|
|
res = res.slice(0, 15);
|
2015-03-08 10:02:14 +00:00
|
|
|
var max = 1;
|
|
|
|
res.map(function(el) {
|
2015-03-08 11:17:56 +00:00
|
|
|
if (el.commits > max) {
|
|
|
|
max = el.commits
|
2015-03-08 10:02:14 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
this.setState({points: res, max: max});
|
2015-03-07 17:22:32 +00:00
|
|
|
}.bind(this))
|
|
|
|
},
|
|
|
|
|
|
|
|
height: function() {
|
|
|
|
if (this.state.points.length === 0) {
|
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return this.y(this.state.points.length) - this.barMargin;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
y: function(i) {
|
|
|
|
return i*(this.barHeight + this.barMargin);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
return (
|
2015-03-08 10:02:14 +00:00
|
|
|
<svg className="barchart" width="100%" height={this.height()}>
|
|
|
|
{this.state.points.map(this.renderBar)}
|
2015-03-07 17:22:32 +00:00
|
|
|
</svg>
|
|
|
|
);
|
2015-03-08 10:02:14 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
renderBar: function(point, i) {
|
|
|
|
return (
|
|
|
|
<Bar key={point.item} point={point} i={i} link={this.props.link}
|
|
|
|
y={this.y(i)}
|
2015-03-08 11:17:56 +00:00
|
|
|
width={point.commits/this.state.max}
|
2015-03-08 10:02:14 +00:00
|
|
|
height={this.barHeight} />
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
var Bar = React.createClass({
|
|
|
|
mixins: [Router.Navigation],
|
|
|
|
handleClick: function(e) {
|
|
|
|
this.transitionTo(this.props.link + this.props.point.item);
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var p = this.props.point
|
|
|
|
w = this.props.width*500,
|
2015-03-08 11:17:56 +00:00
|
|
|
label = p.item + ": " + p.commits,
|
|
|
|
lw = label.length*10 + 5,
|
2015-03-08 10:02:14 +00:00
|
|
|
tx = 10;
|
2015-03-08 11:17:56 +00:00
|
|
|
if (lw > w) {
|
2015-03-08 10:02:14 +00:00
|
|
|
tx = w + tx;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<g onClick={this.handleClick}>
|
|
|
|
<rect className="bar" fill={Colors2[this.props.i]}
|
|
|
|
width={this.props.width*500}
|
|
|
|
height={this.props.height}
|
|
|
|
x="0" y={this.props.y} rx="2" ry="2" />
|
2015-03-08 11:17:56 +00:00
|
|
|
<rect className="label_underlay" x={tx-6} y={this.props.y+10} height={20} width={lw} rx="3" ry="3" />
|
2015-03-08 10:02:14 +00:00
|
|
|
<text className="label" x={tx} y={this.props.y + 26}>{label}</text>
|
|
|
|
</g>
|
|
|
|
);
|
2015-03-07 17:22:32 +00:00
|
|
|
}
|
|
|
|
});
|