diff --git a/js/components/LunchStats.js b/js/components/LunchStats.js index 7e5e2dd..503e337 100644 --- a/js/components/LunchStats.js +++ b/js/components/LunchStats.js @@ -6,6 +6,7 @@ var DropdownButton = ReactBootstrap.DropdownButton; var MenuItem = ReactBootstrap.MenuItem; var BarChart = require('../components/BarChart'); +var RatioBarChart = require('../components/RatioBarChart'); module.exports = React.createClass({ displayName: "LunchStats", @@ -15,7 +16,12 @@ module.exports = React.createClass({ }; }, selectReport: function(reportId) { - this.props.fetchReport(reportId); + if (reportId == "suggestion-veto-ratio") { + this.props.fetchReport("suggestions"); + this.props.fetchReport("vetoed-suggestions"); + } else { + this.props.fetchReport(reportId); + } this.setState({ selectedReportId: reportId }); @@ -27,7 +33,14 @@ module.exports = React.createClass({ var report = this.props.reports[this.state.selectedReportId]; var data = report.Data; data.sort(function(a, b){return b.Value - a.Value;}); - var chart=(); + chart=(); + } else if (this.state.selectedReportId == "suggestion-veto-ratio" && + this.props.reports.hasOwnProperty("suggestions") && + this.props.reports.hasOwnProperty("vetoed-suggestions")) { + chart=(); } return ( @@ -40,6 +53,7 @@ module.exports = React.createClass({ Suggestion Frequency Non-Vetoed Suggestions Vetoed Suggestions + Veto Ratio Attendee Frequency diff --git a/js/components/RatioBarChart.js b/js/components/RatioBarChart.js new file mode 100644 index 0000000..d2d7147 --- /dev/null +++ b/js/components/RatioBarChart.js @@ -0,0 +1,38 @@ +var React = require('react'); + +var BarChart = require('../components/BarChart') + +module.exports = React.createClass({ + displayName: "RatioBarChart", + render: function() { + /* Expects 'this.props.numerator' and '.denominator' to be in the form: + * [ + * {'Label': 'foo', 'Value': 1.4}, + * {'Label': 'bar', 'Value': 8} + * ] + */ + if (this.props.denominator.length < 1) + return (
); + + 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 ( + + ); + } +});