aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorFabrice Bellingard <bellingard@gmail.com>2011-08-19 15:57:22 +0200
committerFabrice Bellingard <bellingard@gmail.com>2011-08-19 18:27:44 +0200
commit12ebcddbcec1e865f271c1fc258ba52fd1c99ae9 (patch)
tree11f4d90553c9551ed271a3424d10ca285e58a3c0 /plugins
parentd3d1f85b2f8d5a88c46c71839d45e7cc26a86ff8 (diff)
downloadsonarqube-12ebcddbcec1e865f271c1fc258ba52fd1c99ae9.tar.gz
sonarqube-12ebcddbcec1e865f271c1fc258ba52fd1c99ae9.zip
SONAR-2074 Improve timeline widget
- Improve JS code - Sort the trends directly in the TrendsChart Ruby class - Add optional title for graph - Graph aware of differential view system
Diffstat (limited to 'plugins')
-rw-r--r--plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java11
-rw-r--r--plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb46
2 files changed, 39 insertions, 18 deletions
diff --git a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java
index c7c98054d88..6faba17f939 100644
--- a/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java
+++ b/plugins/sonar-core-plugin/src/main/java/org/sonar/plugins/core/widgets/TimelineWidget.java
@@ -19,10 +19,15 @@
*/
package org.sonar.plugins.core.widgets;
-import org.sonar.api.web.*;
+import org.sonar.api.web.AbstractRubyTemplate;
+import org.sonar.api.web.RubyRailsWidget;
+import org.sonar.api.web.WidgetProperties;
+import org.sonar.api.web.WidgetProperty;
+import org.sonar.api.web.WidgetPropertyType;
@WidgetProperties(
{
+ @WidgetProperty(key = "chartTitle", type = WidgetPropertyType.STRING),
@WidgetProperty(key = "metric1", type = WidgetPropertyType.METRIC),
@WidgetProperty(key = "metric2", type = WidgetPropertyType.METRIC),
@WidgetProperty(key = "metric3", type = WidgetPropertyType.METRIC),
@@ -40,7 +45,7 @@ public class TimelineWidget extends AbstractRubyTemplate implements RubyRailsWid
@Override
protected String getTemplatePath() {
- return "/org/sonar/plugins/core/widgets/timeline.html.erb";
- //return "/Users/fbellingard/Documents/Sonar/repos/sonar/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb";
+ //return "/org/sonar/plugins/core/widgets/timeline.html.erb";
+ return "/Users/fbellingard/Documents/Sonar/repos/sonar/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb";
}
} \ No newline at end of file
diff --git a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb
index d50e8ad9405..1c2f6ffc520 100644
--- a/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb
+++ b/plugins/sonar-core-plugin/src/main/resources/org/sonar/plugins/core/widgets/timeline.html.erb
@@ -1,9 +1,4 @@
<%= javascript_include_tag 'protovis-sonar' %>
-
-<div id="timeline-chart"></div>
-
-<script type="text/javascript+protovis">
-
<%
metric_data_map = {}
(1..3).each do |index|
@@ -13,8 +8,13 @@
end
end
- trends = TrendsChart.time_machine_measures(@resource, metric_data_map.keys, {}).sort { |t1, t2| t1["created_at"] <=> t2["created_at"] }
- trends.each() do |trend_item|
+ options = {}
+ from_date = dashboard_configuration.from_datetime
+ if from_date
+ options[:from] = from_date
+ end
+
+ TrendsChart.time_machine_measures(@resource, metric_data_map.keys, options).each() do |trend_item|
metric_data_map[trend_item["metric_id"].to_i] << {:date => trend_item["created_at"], :value => trend_item["value"]}
end
@@ -23,19 +23,35 @@
js_data += "["
metric_data_map[metric_id].each() do |metric_data|
m_date = Time.parse(metric_data[:date])
- js_data += "{\"x\":new Date("
- js_data += m_date.strftime("%Y,%m,%d")
- js_data += "),\"y\":\""
- js_data += metric_data[:value]
- js_data += "\"},"
+ js_data += "{\"x\":d("
+ js_data += m_date.year.to_s
+ js_data += ","
+ # Need to decrease by 1 the month as the JS Date object start months at 0 (= January)
+ js_data += (m_date.month - 1).to_s
+ js_data += ","
+ js_data += m_date.day.to_s
+ js_data += "),\"y\":"
+ js_data += sprintf( "%0.02f", metric_data[:value])
+ js_data += "},"
end
js_data += "],"
end
js_data += "]"
%>
- var data = <%= js_data -%>;
-
- displayTrendChart('timeline-chart', data);
+
+<% if widget_properties["chartTitle"] %>
+<h3 style="text-align: center; margin-bottom: 10px"><%= h(widget_properties["chartTitle"]) -%></h3>
+<% end %>
+
+
+<div id="timeline-chart-<%= widget.id -%>"></div>
+<script type="text/javascript+protovis">
+ function d(y,m,d) {
+ return new Date(y,m,d);
+ }
+ var data = <%= js_data -%>;
+ var timeline = new SonarWidgets.Timeline('timeline-chart-<%= widget.id -%>').data(data);
+ timeline.render();
</script> \ No newline at end of file