You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.6 KiB
Plaintext

<%= javascript_tag do %>
// Create the tooltip DOM element.
var toolTip = document.createElement("div"),
leftOffset = -(~~$("html").css("padding-left").replace("px", "") + ~~$("body").css("margin-left").replace("px", "")),
topOffset = -32;
toolTip.className = "graphic-tooltip";
document.body.appendChild(toolTip);
// Chart data.
var data = {
// Horizontal set of values (ordinal), vertical values (linear).
"xScale": "ordinal",
"yScale": "linear",
"yMin": 0,
"main": [
<%- serieIndex = 0
series.each do |serie| -%>
{
// Pending effort serie.
"className": ".effort-<%= serieIndex %>",
"data": [
<%- serie[:data].each_with_index do |value, i| -%>
<%- unless value[:effort].nil? -%>
{
"x": <%= i %>,
"y": <%= value[:effort] %>,
"tooltip": "<%= value[:tooltip] %>"
},
<%- end -%>
<%- end -%>
]
},
<%- serieIndex += 1 -%>
<%- end -%>
]
};
// X axis labels.
var x_axis_labels = [
<%- x_axis_labels.each do |label| -%>
'<%= label %>',
<%- end -%>
];
// Chart options.
var options = {
// Use data label as horizontal axis labels.
"tickFormatX": function(x) { return x_axis_labels[x]; },
// Render a tooltip when mouse goes over the values.
"mouseover": function(d, i) {
var pos = $(this).offset();
$(toolTip).text(d.tooltip)
.css({top: topOffset + pos.top, left: pos.left + leftOffset})
.show();
},
// Hide the tooltip when mouse exists the values.
"mouseout": function(x) {
$(toolTip).hide();
}
};
// Generate the chart.
new xChart("line-dotted", data, "#burndown-chart", options);
<% end %>