getLanguageName (langKey) {
if (this.state && this.state.languages) {
- let lang = _.findWhere(this.state.languages, { key: langKey });
+ const lang = _.findWhere(this.state.languages, { key: langKey });
return lang ? lang.name : translate('unknown');
} else {
return langKey;
renderBarChart () {
let data = this.props.distribution.split(';').map((point, index) => {
- let tokens = point.split('=');
+ const tokens = point.split('=');
return { x: parseInt(tokens[1], 10), y: index, value: tokens[0] };
});
data = _.sortBy(data, d => -d.x);
- let yTicks = data.map(point => this.getLanguageName(point.value)).map(this.cutLanguageName);
-
- let yValues = data.map(point => formatMeasure(point.x / this.props.lines * 100, 'PERCENT'));
+ const yTicks = data.map(point => this.getLanguageName(point.value)).map(this.cutLanguageName);
+ const yValues = data.map(point => {
+ const percent = point.x / this.props.lines * 100;
+ return percent >= 0.1 ? formatMeasure(percent, 'PERCENT') : '<0.1%';
+ });
return <Histogram data={data}
yTicks={yTicks}
it('should pass right yValues', function () {
expect(props.yValues).to.deep.equal(['19.4%', '2.1%', '1.7%']);
});
+
+ it('should correctly render very small values', function () {
+ const DISTRIBUTION_SMALL = 'java=194342;js=999';
+
+ let renderer = TestUtils.createRenderer();
+ renderer.render(<LanguageDistribution distribution={DISTRIBUTION_SMALL} lines={LINES}/>);
+ let output = renderer.getRenderOutput();
+ let child = React.Children.only(output.props.children);
+
+ expect(child.props.yValues).to.deep.equal(['19.4%', '<0.1%']);
+ });
});