+++ /dev/null
-<% dist_measure = measure(metric)
- if dist_measure && !dist_measure.data.blank?
-%>
-<div id="chart_<%=metric -%>" class="chart" style="display: <%= visible ? "block" : "none" %>">
-<%
- query="ck=distbar&c=777777&v=" + u(dist_measure.data)
- small_size_query=query + '&w=220&h=100&fs=8&bgc=ffffff'
- big_size_query=query + '&w=300&h=150&fs=12&bgc=CAE3F2'
-%><%= chart(small_size_query, :id => 'chart_img_' + metric, :alt => title) -%>
-
- <script type='text/javascript'>
- //<![CDATA[
- new Tip('chart_img_<%=metric-%>', '<div style="width:300px;"><b><%= title -%></b><br>'+
- '<%= chart(big_size_query, :id => 'chart_img_' + metric, :alt => title) -%></div>');
- //]]>
- </script>
-</div>
-<% end %>
\ No newline at end of file
<div class="widget-span widget-span-7">
<%
- function_distribution=measure('function_complexity_distribution')
- class_distribution=measure('class_complexity_distribution')
- file_distribution=measure('file_complexity_distribution')
- distributions=[function_distribution, class_distribution, file_distribution].compact
- selected_distribution=nil
- if distributions.size>0
- selected_distribution=distributions.first
- end
- if selected_distribution
+ function_distribution = measure('function_complexity_distribution')
+ if function_distribution
%>
- <div class="dashbox" id="cmp_charts">
- <script type='text/javascript'>
- //<![CDATA[
- function selectComplexity(metric) {
- $j('#cmp_charts .chart').hide();
- $j('#chart_' + metric).show();
- }
- </script>
- <style>
- #cmp_charts form {
- font-size: 93%; padding-left: 30px;
- }
-
- #cmp_charts form label {
- padding-right: 5px;
- }
- </style>
- <% distributions.each do |distribution_measure| %>
- <%= render :partial => 'project/widgets/complexity_chart', :locals => {:metric => distribution_measure.metric.key, :title => distribution_measure.metric.description, :visible => (selected_distribution==distribution_measure)} %>
- <% end %>
-
- <form>
- <%
- count_dist=0
- if function_distribution
- count_dist+=1
- %>
- <input type="radio" name="cmp_dist" value="function_complexity_distribution" id="cmp_dist_function_complexity_distribution" onClick="selectComplexity('function_complexity_distribution');" <%= 'checked' if function_distribution==selected_distribution -%>/>
- <label for="cmp_dist_function_complexity_distribution"><%= message('metric.functions.name') -%></label>
- <%
- end
- if class_distribution
- count_dist+=1
- %>
- <input type="radio" name="cmp_dist" value="class_complexity_distribution" id="cmp_dist_class_complexity_distribution" onClick="selectComplexity('class_complexity_distribution');" <%= 'checked' if class_distribution==selected_distribution -%>/>
- <label for="cmp_dist_class_complexity_distribution"><%= message('metric.classes.name') -%></label><%= '<br/>' if count_dist==2 %>
- <%
- end
- if file_distribution
- count_dist+=1
- %>
- <input type="radio" name="cmp_dist" value="file_complexity_distribution" id="cmp_dist_file_complexity_distribution" onClick="selectComplexity('file_complexity_distribution');" <%= 'checked' if file_distribution==selected_distribution -%>/>
- <label for="cmp_dist_file_complexity_distribution"><%= message('metric.files.name') -%></label>
- <% end %>
-
- </form>
-
- </div>
+ <div id="complexity-widget-<%= widget.id.to_s -%>-function-distribution"></div>
+ <script>
+ (function () {
+ window.ComplexityDistribution({
+ el: '#complexity-widget-<%= widget.id.to_s -%>-function-distribution',
+ value: '<%= function_distribution.data -%>',
+ of: 'function'
+ });
+ })();
+ </script>
+ <% end %>
+ <%
+ file_distribution = measure('file_complexity_distribution')
+ if file_distribution
+ %>
+ <div id="complexity-widget-<%= widget.id.to_s -%>-file-distribution"></div>
+ <script>
+ (function () {
+ window.ComplexityDistribution({
+ el: '#complexity-widget-<%= widget.id.to_s -%>-file-distribution',
+ value: '<%= file_distribution.data -%>',
+ of: 'file'
+ });
+ })();
+ </script>
<% end %>
</div>
</div>
--- /dev/null
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact 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 { render } from 'react-dom';
+import { translate } from '../../helpers/l10n';
+import { ComplexityDistribution } from '../../apps/overview/components/complexity-distribution';
+
+const Widget = ({ value, of }) => {
+ return (
+ <div>
+ <span className="widget-label">
+ {translate(`metric.${of}_complexity_distribution.name`)}
+ </span>
+ <ComplexityDistribution distribution={value} of={of}/>
+ </div>
+ );
+};
+
+function start ({ el, ...other }) {
+ window.sonarqube.appStarted.then(() => {
+ const element = document.querySelector(el);
+ render(<Widget {...other}/>, element);
+ });
+}
+
+export default function (options) {
+ if (options.value) {
+ document.addEventListener('DOMContentLoaded', () => start(options), false);
+ }
+}
import './old/widget';
import IssueFilterWidget from './issue-filter/widget';
+import ComplexityDistribution from './complexity';
+
window.IssueFilterWidget = IssueFilterWidget;
+window.ComplexityDistribution = ComplexityDistribution;
+++ /dev/null
-<% dist_measure = measure(metric)
- if dist_measure && !dist_measure.data.blank?
- query="w=220&h=100&fs=10&bgc=ffffff&ck=distbar&c=777777&v=" + u(dist_measure.data)
-%>
- <div id="chart_<%= metric -%>" class="chart" style="display: <%= visible ? "block" : "none" %>">
- <%= chart(query, :id => 'chart_img_' + metric, :alt => title) -%>
- </div>
-<% end %>
\ No newline at end of file