diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-07-27 17:21:25 +0200 |
---|---|---|
committer | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2017-08-14 11:44:44 +0200 |
commit | d7b669175e4e40341f6f1553ebe8ed84a9980ce2 (patch) | |
tree | c631f0dac9d40e88042d4d2ca8f4643b9f780134 /server/sonar-web/src/main/js/components/shared/ComplexityDistribution.js | |
parent | a0ea568244db7b77b165c7ecf7dca83620f8edbd (diff) | |
download | sonarqube-d7b669175e4e40341f6f1553ebe8ed84a9980ce2.tar.gz sonarqube-d7b669175e4e40341f6f1553ebe8ed84a9980ce2.zip |
SONAR-9608 SONAR-9634 Create the measure list view
Diffstat (limited to 'server/sonar-web/src/main/js/components/shared/ComplexityDistribution.js')
-rw-r--r-- | server/sonar-web/src/main/js/components/shared/ComplexityDistribution.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/components/shared/ComplexityDistribution.js b/server/sonar-web/src/main/js/components/shared/ComplexityDistribution.js new file mode 100644 index 00000000000..0dd2ccc4514 --- /dev/null +++ b/server/sonar-web/src/main/js/components/shared/ComplexityDistribution.js @@ -0,0 +1,70 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import React from 'react'; +import PropTypes from 'prop-types'; +import { BarChart } from '../charts/bar-chart'; +import { formatMeasure } from '../../helpers/measures'; +import { translateWithParameters } from '../../helpers/l10n'; + +const HEIGHT = 80; + +export default class ComplexityDistribution extends React.PureComponent { + static propTypes = { + distribution: PropTypes.string.isRequired, + of: PropTypes.string.isRequired + }; + + renderBarChart = () => { + const data = this.props.distribution.split(';').map((point, index) => { + const tokens = point.split('='); + const y = parseInt(tokens[1], 10); + const value = parseInt(tokens[0], 10); + return { + x: index, + y, + value, + tooltip: translateWithParameters(`overview.complexity_tooltip.${this.props.of}`, y, value) + }; + }); + + const xTicks = data.map(point => point.value); + + const xValues = data.map(point => formatMeasure(point.y, 'INT')); + + return ( + <BarChart + data={data} + xTicks={xTicks} + xValues={xValues} + height={HEIGHT} + barsWidth={20} + padding={[25, 10, 25, 10]} + /> + ); + }; + + render() { + return ( + <div className="overview-bar-chart" style={{ height: HEIGHT }}> + {this.renderBarChart()} + </div> + ); + } +} |