38 lines
973 B
JavaScript
38 lines
973 B
JavaScript
var React = require('react');
|
|
|
|
var BarChart = require('../components/BarChart')
|
|
|
|
module.exports = React.createClass({
|
|
displayName: "RatioBarChart",
|
|
render: function() {
|
|
/* Expects 'this.props.numerator' and 'this.props.denominator' to be in
|
|
* the form:
|
|
* [
|
|
* {'Label': 'foo', 'Value': 1.4},
|
|
* {'Label': 'bar', 'Value': 8}
|
|
* ]
|
|
*/
|
|
|
|
var numeratorMap = {};
|
|
for (var i = 0; i < this.props.numerator.length; i++) {
|
|
var val = this.props.numerator[i];
|
|
numeratorMap[val.Label] = val.Value;
|
|
}
|
|
|
|
var data = []
|
|
for (var i = 0; i < this.props.denominator.length; i++) {
|
|
var val = this.props.denominator[i];
|
|
if (numeratorMap.hasOwnProperty(val.Label)) {
|
|
data.push({'Label': val.Label, 'Value': 1.0*numeratorMap[val.Label]/val.Value});
|
|
} else {
|
|
data.push({'Label': val.Label, 'Value': 0});
|
|
}
|
|
}
|
|
data.sort(function(a, b){return b.Value - a.Value;});
|
|
|
|
return (
|
|
<BarChart title={this.props.title} data={data} />
|
|
);
|
|
}
|
|
});
|