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