summaryrefslogtreecommitdiffstats
path: root/utils/test/reporting/js/trend.js
diff options
context:
space:
mode:
authorMorgan Richomme <morgan.richomme@orange.com>2016-09-29 15:23:01 +0000
committerGerrit Code Review <gerrit@172.30.200.206>2016-09-29 15:23:01 +0000
commit6a082c66d6f14ba8801e0a02fe5bd193c2a32f68 (patch)
treeaab4b2a46b5d3779eff91c6e4f61a80a3a5e82d7 /utils/test/reporting/js/trend.js
parente30a45c0a8d598a4765dbd14c266271065719a70 (diff)
parentb24f036bc4817ec3f8ee29593c93721f826a6264 (diff)
Merge "Add a trend line to Functest reporting And use d3js lib rather than static images"
Diffstat (limited to 'utils/test/reporting/js/trend.js')
-rw-r--r--utils/test/reporting/js/trend.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/utils/test/reporting/js/trend.js b/utils/test/reporting/js/trend.js
new file mode 100644
index 000000000..ec48e75ef
--- /dev/null
+++ b/utils/test/reporting/js/trend.js
@@ -0,0 +1,68 @@
+// ******************************************
+// Trend line for reporting
+// based on scenario_history.txt
+// where data looks like
+// date,scenario,installer,detail,score
+// 2016-09-22 13:12,os-nosdn-fdio-noha,apex,4/12,33.0
+// 2016-09-22 13:13,os-odl_l2-fdio-noha,apex,12/15,80.0
+// 2016-09-22 13:13,os-odl_l2-sfc-noha,apex,18/24,75.0
+// .....
+// ******************************************
+// Set the dimensions of the canvas / graph
+var trend_margin = {top: 20, right: 30, bottom: 50, left: 40},
+ trend_width = 300 - trend_margin.left - trend_margin.right,
+ trend_height = 130 - trend_margin.top - trend_margin.bottom;
+
+// Parse the date / time
+var parseDate = d3.time.format("%Y-%m-%d %H:%M").parse;
+
+// Set the ranges
+var trend_x = d3.time.scale().range([0, trend_width]);
+var trend_y = d3.scale.linear().range([trend_height, 0]);
+
+// Define the axes
+var trend_xAxis = d3.svg.axis().scale(trend_x)
+ .orient("bottom").ticks(2).tickFormat(d3.time.format("%m-%d"));
+
+var trend_yAxis = d3.svg.axis().scale(trend_y)
+ .orient("left").ticks(2);
+
+// Define the line
+var valueline = d3.svg.line()
+ .x(function(d) { return trend_x(d.date); })
+ .y(function(d) { return trend_y(d.score); });
+
+var trend = function(container, trend_data) {
+
+ var trend_svg = d3.select(container)
+ .append("svg")
+ .attr("width", trend_width + trend_margin.left + trend_margin.right)
+ .attr("height", trend_height + trend_margin.top + trend_margin.bottom)
+ .append("g")
+ .attr("transform",
+ "translate(" + trend_margin.left + "," + trend_margin.top + ")");
+
+ // Scale the range of the data
+ trend_x.domain(d3.extent(trend_data, function(d) { return d.date; }));
+ trend_y.domain([0, d3.max(trend_data, function(d) { return d.score; })]);
+
+ // Add the X Axis
+ trend_svg.append("g")
+ .attr("class", "x axis")
+ .attr("transform", "translate(0," + trend_height + ")")
+ .call(trend_xAxis);
+
+ // Add the Y Axis
+ trend_svg.append("g")
+ .attr("class", "y axis")
+ .call(trend_yAxis);
+
+ // Add the valueline path.
+ trend_svg.append("path")
+ .attr("class", "line")
+ .attr("d", valueline(trend_data))
+ .attr("stroke", "steelblue")
+ .attr("fill", "none");
+
+ return trend;
+}