Barcharts are working perfectly
This commit is contained in:
		
							parent
							
								
									dcbc4efe55
								
							
						
					
					
						commit
						a9a74f511c
					
				@ -80,7 +80,8 @@ var TeamStats = React.createClass({
 | 
			
		||||
    render: function(){
 | 
			
		||||
        return (
 | 
			
		||||
            <section className="content">
 | 
			
		||||
                <BarChart api="/api/stat/teams/top" params={this.getParams()} items={["repo", "user"]} />
 | 
			
		||||
                <BarChart key={this.getParams().team} api="/api/stat/teams/top"
 | 
			
		||||
                params={this.getParams()} items={["repo", "user"]} />
 | 
			
		||||
            </section>
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
@ -102,7 +103,7 @@ var RepoStats = React.createClass({
 | 
			
		||||
    render: function(){
 | 
			
		||||
        return (
 | 
			
		||||
            <section className="content">
 | 
			
		||||
                <BarChart api="/api/stat/repos/top" params={this.getParams()} items={["team", "user"]} />
 | 
			
		||||
                <BarChart api="/api/stat/repos/top" params={this.getParams()} items={["user", "team"]} />
 | 
			
		||||
            </section>
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -21,7 +21,7 @@ var BarChart = React.createClass({
 | 
			
		||||
        this.fetchData();
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    onFilter: function(thing, i) {
 | 
			
		||||
    handleFilter: function(thing, i) {
 | 
			
		||||
        if (thing === 'item' && this.props.items[i] !== this.state.item) {
 | 
			
		||||
            this.setState({
 | 
			
		||||
                item: this.props.items[i]
 | 
			
		||||
@ -33,6 +33,12 @@ var BarChart = React.createClass({
 | 
			
		||||
        }
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    handleClick: function(point) {
 | 
			
		||||
        var params = {org: this.getParams().org};
 | 
			
		||||
        params[this.state.item] = point.item;
 | 
			
		||||
        this.transitionTo(this.state.item, params);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    fetchData: function() {
 | 
			
		||||
        $.get(this.props.api, this.apiParams(), function(res){
 | 
			
		||||
            this.setState({
 | 
			
		||||
@ -95,11 +101,11 @@ var BarChart = React.createClass({
 | 
			
		||||
                    <Selector thing="item"
 | 
			
		||||
                        items={this.props.items}
 | 
			
		||||
                        value={this.state.item}
 | 
			
		||||
                        onChange={this.onFilter.bind(this, 'item')} />
 | 
			
		||||
                        onChange={this.handleFilter.bind(this, 'item')} />
 | 
			
		||||
                    <Selector thing="sort"
 | 
			
		||||
                        items={['commits', 'delta']}
 | 
			
		||||
                        value={this.state.sort}
 | 
			
		||||
                        onChange={this.onFilter.bind(this, 'sort')} />
 | 
			
		||||
                        onChange={this.handleFilter.bind(this, 'sort')} />
 | 
			
		||||
                </div>
 | 
			
		||||
                <svg className="barchart" width="100%" height={this.height()}>
 | 
			
		||||
                    {this.state.points.map(this.renderBar)}
 | 
			
		||||
@ -119,13 +125,12 @@ var BarChart = React.createClass({
 | 
			
		||||
            offset = -min/max2*maxWidth,
 | 
			
		||||
            x = (min >= 0 ? 0 : offset - (val >= 0 ? 0 : width)),
 | 
			
		||||
            y = this.y(i);
 | 
			
		||||
            // console.log(point.item, {val: val, max: max, x: x, y: y, width: width})
 | 
			
		||||
 | 
			
		||||
        return (
 | 
			
		||||
            <Bar key={point.item} point={point} i={i}
 | 
			
		||||
                metric={this.state.sort}
 | 
			
		||||
            <Bar key={point.item} item={point.item} value={val}
 | 
			
		||||
                color={Colors2[i]}
 | 
			
		||||
                x={x} y={y} offset={offset} width={width} height={height}
 | 
			
		||||
                link={this.props.link} />
 | 
			
		||||
                onClick={this.handleClick.bind(this, point)} />
 | 
			
		||||
        );
 | 
			
		||||
    }
 | 
			
		||||
});
 | 
			
		||||
@ -133,13 +138,9 @@ var BarChart = React.createClass({
 | 
			
		||||
var Bar = React.createClass({
 | 
			
		||||
    mixins: [Router.Navigation],
 | 
			
		||||
 | 
			
		||||
    handleClick: function(e) {
 | 
			
		||||
        this.transitionTo(this.props.link + this.props.point.item);
 | 
			
		||||
    },
 | 
			
		||||
 | 
			
		||||
    render: function() {
 | 
			
		||||
        var val = this.props.point[this.props.metric],
 | 
			
		||||
            item = this.props.point.item,
 | 
			
		||||
        var val = this.props.value,
 | 
			
		||||
            item = this.props.item,
 | 
			
		||||
            offset = this.props.offset,
 | 
			
		||||
            width = this.props.width,
 | 
			
		||||
            label = item + ': ' + val,
 | 
			
		||||
@ -168,8 +169,8 @@ var Bar = React.createClass({
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return (
 | 
			
		||||
            <g onClick={this.handleClick}>
 | 
			
		||||
                <rect className="bar" fill={Colors2[this.props.i]}
 | 
			
		||||
            <g onClick={this.props.onClick}>
 | 
			
		||||
                <rect className="bar" fill={this.props.color}
 | 
			
		||||
                    width={width} height={this.props.height}
 | 
			
		||||
                    x={this.props.x} y={this.props.y} rx="2" ry="2" />
 | 
			
		||||
                <rect className="label_underlay"
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								db/stat.go
									
									
									
									
									
								
							
							
						
						
									
										14
									
								
								db/stat.go
									
									
									
									
									
								
							@ -128,7 +128,7 @@ order by week, commits desc`
 | 
			
		||||
 | 
			
		||||
const repoTopQuery = `
 | 
			
		||||
select
 | 
			
		||||
    c.author as item,
 | 
			
		||||
    %s as item,
 | 
			
		||||
    sum(c.commits) as commits,
 | 
			
		||||
    sum(c.additions) - sum(c.deletions) as delta
 | 
			
		||||
from contribs c
 | 
			
		||||
@ -191,26 +191,26 @@ func StatTeamActivity(p map[string]interface{}) (res []StatPoint) {
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func StatUserTop(p interface{}) (res []StatItem) {
 | 
			
		||||
func StatUserTop(p map[string]interface{}) (res []StatItem) {
 | 
			
		||||
	defer measure("StatUserTop", time.Now())
 | 
			
		||||
	mustSelectN(&res, userTopQuery, p)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func StatUserActivity(p interface{}) (res []StatPoint) {
 | 
			
		||||
func StatUserActivity(p map[string]interface{}) (res []StatPoint) {
 | 
			
		||||
	defer measure("StatUserActivity", time.Now())
 | 
			
		||||
	mustSelectN(&res, userActivityQuery, p)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func StatRepoTop(p interface{}) (res []StatItem) {
 | 
			
		||||
func StatRepoTop(p map[string]interface{}) (res []StatItem) {
 | 
			
		||||
	defer measure("StatRepoTop", time.Now())
 | 
			
		||||
	mustSelectN(&res, repoTopQuery, p)
 | 
			
		||||
	mustSelectN(&res, fmt.Sprintf(repoTopQuery, p["item"]), p)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func StatRepoActivity(p interface{}) (res []StatPoint) {
 | 
			
		||||
func StatRepoActivity(p map[string]interface{}) (res []StatPoint) {
 | 
			
		||||
	defer measure("StatRepoActivity", time.Now())
 | 
			
		||||
	mustSelectN(&res, repoActivityQuery, p)
 | 
			
		||||
	mustSelectN(&res, fmt.Sprintf(repoTopQuery, p["item"]), p)
 | 
			
		||||
	return
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user