BarChart: Round floating-point numbers to 2 digits by default
This commit is contained in:
		| @@ -11,6 +11,9 @@ module.exports = React.createClass({ | ||||
| 		 * 	{'Label': 'bar', 'Value': 8} | ||||
| 		 * ]; | ||||
| 		 */ | ||||
| 		var roundTo = 2; | ||||
| 		if (this.props.roundTo) | ||||
| 			roundTo = this.props.roundTo; | ||||
|  | ||||
| 		var rows = []; | ||||
| 		if (this.props.data.length >= 1) { | ||||
| @@ -26,15 +29,16 @@ module.exports = React.createClass({ | ||||
|  | ||||
| 			for (var i = 0; i < this.props.data.length; i++) { | ||||
| 				var rowData = this.props.data[i]; | ||||
| 				var value = parseFloat((rowData.Value).toFixed(roundTo)) | ||||
| 				if ((max - min) == 0.0) | ||||
| 					var percent = 100; | ||||
| 				else if (min < 0) | ||||
| 					var percent = 100*(parseFloat(rowData.Value)-min)/(max-min); | ||||
| 					var percent = 100*(value-min)/(max-min); | ||||
| 				else | ||||
| 					var percent = 100*parseFloat(rowData.Value)/max; | ||||
| 					var percent = 100*value/max; | ||||
| 				rows.push(( | ||||
| 					<tr key={i}> | ||||
| 						<td style={{'width': '20%'}}>{rowData.Label + " (" + rowData.Value + ")"}</td> | ||||
| 						<td style={{'width': '20%'}}>{rowData.Label + " (" + value + ")"}</td> | ||||
| 						<td style={{'width': '80%'}}><div style={{'width': percent + "%", 'backgroundColor': 'steelblue'}}> </div></td> | ||||
| 					</tr> | ||||
| 				)); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user