From 0df7d25fad23f50f5ef969360d7040ce90f3e630 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 8 May 2017 16:44:10 +0200 Subject: [PATCH] SONAR-9045 Add a color legend to projects bubble charts --- .../src/main/js/apps/projects/styles.css | 25 +++++++++++ .../projects/visualizations/RatingsLegend.js | 43 +++++++++++++++++++ .../js/apps/projects/visualizations/Risk.js | 4 +- .../visualizations/SimpleBubbleChart.js | 4 +- 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/projects/visualizations/RatingsLegend.js diff --git a/server/sonar-web/src/main/js/apps/projects/styles.css b/server/sonar-web/src/main/js/apps/projects/styles.css index 99e3232f7d0..4d113484e13 100644 --- a/server/sonar-web/src/main/js/apps/projects/styles.css +++ b/server/sonar-web/src/main/js/apps/projects/styles.css @@ -202,6 +202,31 @@ font-style: italic; } +.projects-visualizations-ratings { + display: flex; + justify-content: center; + margin-top: 16px; +} + +.projects-visualizations-ratings > *:not(:first-child) { + margin-left: 24px; +} + +.projects-visualizations-ratings-rect { + display: inline-block; + vertical-align: top; + margin-top: 1px; + margin-right: 4px; + border: 1px solid; +} + +.projects-visualizations-ratings-rect-inner { + display: block; + width: 8px; + height: 8px; + opacity: 0.2; +} + .measure-details-bubble-chart-axis { position: absolute; color: #777; diff --git a/server/sonar-web/src/main/js/apps/projects/visualizations/RatingsLegend.js b/server/sonar-web/src/main/js/apps/projects/visualizations/RatingsLegend.js new file mode 100644 index 00000000000..246ce40c685 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/projects/visualizations/RatingsLegend.js @@ -0,0 +1,43 @@ +/* + * 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. + */ +// @flow +import React from 'react'; +import { formatMeasure } from '../../../helpers/measures'; +import { RATING_COLORS } from '../../../helpers/constants'; + +export default function RatingsLegend() { + return ( +
+ {[1, 2, 3, 4, 5].map(rating => ( +
+ + + + {formatMeasure(rating, 'RATING')} +
+ ))} +
+ ); +} diff --git a/server/sonar-web/src/main/js/apps/projects/visualizations/Risk.js b/server/sonar-web/src/main/js/apps/projects/visualizations/Risk.js index 0a1eafdc472..5a4f0cac15d 100644 --- a/server/sonar-web/src/main/js/apps/projects/visualizations/Risk.js +++ b/server/sonar-web/src/main/js/apps/projects/visualizations/Risk.js @@ -19,6 +19,7 @@ */ // @flow import React from 'react'; +import RatingsLegend from './RatingsLegend'; import BubbleChart from '../../../components/charts/BubbleChart'; import { formatMeasure } from '../../../helpers/measures'; import { translate, translateWithParameters } from '../../../helpers/l10n'; @@ -110,7 +111,7 @@ export default class Risk extends React.PureComponent { formatYTick={formatYTick} height={600} items={items} - padding={[40, 20, 60, 100]} + padding={[80, 20, 60, 100]} yDomain={[100, 0]} />
@@ -130,6 +131,7 @@ export default class Risk extends React.PureComponent { 'component_measures.legend.size_x', translate('metric', SIZE_METRIC, 'name') )} +
); diff --git a/server/sonar-web/src/main/js/apps/projects/visualizations/SimpleBubbleChart.js b/server/sonar-web/src/main/js/apps/projects/visualizations/SimpleBubbleChart.js index 5e0ce2c9b23..abf13ea589c 100644 --- a/server/sonar-web/src/main/js/apps/projects/visualizations/SimpleBubbleChart.js +++ b/server/sonar-web/src/main/js/apps/projects/visualizations/SimpleBubbleChart.js @@ -19,6 +19,7 @@ */ // @flow import React from 'react'; +import RatingsLegend from './RatingsLegend'; import BubbleChart from '../../../components/charts/BubbleChart'; import { formatMeasure } from '../../../helpers/measures'; import { translate, translateWithParameters } from '../../../helpers/l10n'; @@ -108,7 +109,7 @@ export default class SimpleBubbleChart extends React.PureComponent { formatYTick={formatYTick} height={600} items={items} - padding={[40, 20, 60, 100]} + padding={[colorMetric ? 80 : 40, 20, 60, 100]} yDomain={this.props.yDomain} />
@@ -129,6 +130,7 @@ export default class SimpleBubbleChart extends React.PureComponent { 'component_measures.legend.size_x', translate('metric', sizeMetric.key, 'name') )} + {colorMetric != null && }
); -- 2.39.5