Merge branch 'maint/7.0'
[ninja.git] / modules / reports / views / histogram / js / histogram.js
blob3c5bab176739f8af4f0b62fe55c128521a82c0e5
1 $(document).ready(function() {
2         var previousPoint = null;
3         $("#histogram_graph").bind("plothover", function (event, pos, item) {
4                 $("#x").text(pos.x.toFixed(2));
5                 $("#y").text(pos.y.toFixed(2));
7                 if (item) {
8                         if (previousPoint != item.datapoint) {
9                                 previousPoint = item.datapoint;
11                                 $("#tooltip").remove();
12                                 var x = item.datapoint[0].toFixed(0),
13                                 y = item.datapoint[1].toFixed(0);
15                                 showTooltip(item.pageX, item.pageY,
16                                 item.series.label + ": " + y + " (" + get_label(x) + ")");
17                                 //item.series.label + " of " + get_label(x) + " = " + y);
18                         }
19                 } else {
20                         $("#tooltip").remove();
21                         previousPoint = null;
22                 }
23         });
25         $('#show_all_objects').click(function() {
26                 $('#all_objects').toggle('slow');
27         });
29         var choiceContainer = $('#choices');
30         $.each(datasets, function(key, val) {
31                 choiceContainer.append('<br/><input type="checkbox" name="' + key +
32                 '" checked="checked" id="id' + key + '">' +
33                 '<label for="id' + key + '">'
34                 + val.label + '</label>');
35         });
36         choiceContainer.find("input").click(plotAccordingToChoices);
38         function plotAccordingToChoices() {
39                 var data = [];
41                 choiceContainer.find("input:checked").each(function () {
42                         var key = $(this).attr("name");
43                         if (key && datasets[key])
44                                 data.push(datasets[key]);
45                 });
47                 if (data.length > 0)
48                         $.plot($('#histogram_graph'), data, graph_options);
49         }
51         plotAccordingToChoices();
52 });
54 function get_label(x)
56         return graph_xlables[x];
59 function showTooltip(x, y, contents) {
60         $('<div id="tooltip">' + contents + '</div>').css( {
61                 position: 'absolute',
62                 display: 'none',
63                 top: y + 5,
64                 left: x + 5,
65                 border: '1px solid #fdd',
66                 padding: '2px',
67                 'background-color': '#fee',
68                 opacity: 0.80
69         }).appendTo("body").fadeIn(200);