]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9045 Add a color legend to projects bubble charts
authorStas Vilchik <vilchiks@gmail.com>
Mon, 8 May 2017 14:44:10 +0000 (16:44 +0200)
committerStas Vilchik <stas-vilchik@users.noreply.github.com>
Tue, 9 May 2017 08:02:57 +0000 (10:02 +0200)
server/sonar-web/src/main/js/apps/projects/styles.css
server/sonar-web/src/main/js/apps/projects/visualizations/RatingsLegend.js [new file with mode: 0644]
server/sonar-web/src/main/js/apps/projects/visualizations/Risk.js
server/sonar-web/src/main/js/apps/projects/visualizations/SimpleBubbleChart.js

index 99e3232f7d02fb432aa5d24ee19ba1e7dc0e2291..4d113484e133951df2f6e795fe9b7aa8e9296f43 100644 (file)
   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 (file)
index 0000000..246ce40
--- /dev/null
@@ -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 (
+    <div className="projects-visualizations-ratings">
+      {[1, 2, 3, 4, 5].map(rating => (
+        <div key={rating}>
+          <span
+            className="projects-visualizations-ratings-rect"
+            style={{ borderColor: RATING_COLORS[rating - 1] }}>
+            <span
+              className="projects-visualizations-ratings-rect-inner"
+              style={{ backgroundColor: RATING_COLORS[rating - 1] }}
+            />
+          </span>
+          {formatMeasure(rating, 'RATING')}
+        </div>
+      ))}
+    </div>
+  );
+}
index 0a1eafdc472a4e7c418e760ee00bd5a3b833ffc2..5a4f0cac15dcdde668e466f40f3280e434f430c3 100644 (file)
@@ -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]}
         />
         <div className="measure-details-bubble-chart-axis x">
@@ -130,6 +131,7 @@ export default class Risk extends React.PureComponent {
             'component_measures.legend.size_x',
             translate('metric', SIZE_METRIC, 'name')
           )}
+          <RatingsLegend />
         </div>
       </div>
     );
index 5e0ce2c9b23f2681c3b8fc72a87a5109c4d656a4..abf13ea589cc5e89763ff847944ae3d967e085f0 100644 (file)
@@ -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}
         />
         <div className="measure-details-bubble-chart-axis x">
@@ -129,6 +130,7 @@ export default class SimpleBubbleChart extends React.PureComponent {
             'component_measures.legend.size_x',
             translate('metric', sizeMetric.key, 'name')
           )}
+          {colorMetric != null && <RatingsLegend />}
         </div>
       </div>
     );