var SVGNS = "http://www.w3.org/2000/svg", Router = ReactRouter; var BarChart = React.createClass({ barHeight: 40, barMargin: 5, getInitialState: function() { return {points: [], max: 1}; }, componentDidMount: function() { $.get(this.props.api, function(res){ res = res.slice(0, 15); var max = 1; res.map(function(el) { if (el.commits > max) { max = el.commits } }); this.setState({points: res, max: max}); }.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 ( {this.state.points.map(this.renderBar)} ); }, renderBar: function(point, i) { return ( ); } }); 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, label = p.item + ': ' + p.commits, labelm = 10, // Margin labelw = label.length*9 + 2*labelm, // Width textx = labelm; if (labelw + 2*labelm > w) { textx = w + textx; } return ( {label} ); } });