summaryrefslogtreecommitdiffstats
path: root/plugins/impstats/pygal-tooltips.js
blob: 7b183de12ff9efc836cf2e54e6500991f1b16f3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<html>
<head><title>301 Moved Permanently</title></head>
<body bgcolor="white">
<center><h1>301 Moved Permanently</h1></center>
<hr><center>nginx</center>
</body>
</html>
// Generated by CoffeeScript 1.6.3
(function() {
  var get_translation, init, padding, r_translation, tooltip_timeout;

  padding = 5;

  tooltip_timeout = 0;

  r_translation = /translate\((\d+)[ ,]+(\d+)\)/;

  get_translation = function($elt) {
    return (r_translation.exec($elt.attr('transform')) || []).slice(1);
  };

  init = function(ctx) {
    var tooltip, untooltip;
    $vg('.text-overlay .series', ctx).hide();
    $vg('.reactive', ctx).hover((function() {
      return $vg(this).addClass('active');
    }), (function() {
      return $vg(this).removeClass('active');
    }));
    $vg('.activate-serie', ctx).hover((function() {
      var num;
      num = this.id.replace('activate-serie-', '');
      $vg('.text-overlay .serie-' + num, ctx).show();
      return $vg('.serie-' + num + ' .reactive', ctx).addClass('active');
    }), function() {
      var num;
      num = this.id.replace('activate-serie-', '');
      $vg('.text-overlay .serie-' + num, ctx).hide();
      return $vg('.serie-' + num + ' .reactive', ctx).removeClass('active');
    });
    $vg('.tooltip-trigger', ctx).hover((function() {
      return tooltip($vg(this));
    }), (function() {
      return untooltip();
    }));
    tooltip = function($elt) {
      var $label, $rect, $text, $tooltip, $value, current_x, current_y, h, target, w, x, x_elt, xlink, y, y_elt, _ref;
      clearTimeout(tooltip_timeout);
      $tooltip = $vg('#tooltip', ctx).css({
        opacity: 1
      });
      $text = $tooltip.find('text');
      $label = $tooltip.find('tspan.label');
      $value = $tooltip.find('tspan.value');
      $rect = $tooltip.find('rect');
      if ($elt.siblings('.tooltip').size()) {
        $label.text($elt.siblings('.tooltip').text());
        $value.text('');
      } else {
        $label.text($elt.siblings('.label').text());
        $value.text($elt.siblings('.value').text());
      }
      xlink = $elt.siblings('.xlink').text() || null;
      target = $elt.parent().attr('target');
      if (xlink) {
        $tooltip.find('a').attr('href', xlink).attr('target', target);
      }
      $text.attr('x', padding);
      $text.attr('y', padding + this.config.tooltip_font_size);
      $value.attr('x', padding);
      $value.attr('dy', $label.text() ? this.config.tooltip_font_size + padding : 0);
      w = $text.width() + 2 * padding;
      h = $text.height() + 2 * padding;
      $rect.attr('width', w);
      $rect.attr('height', h);
      x_elt = $elt.siblings('.x');
      y_elt = $elt.siblings('.y');
      x = parseInt(x_elt.text());
      if (x_elt.hasClass('centered')) {
        x -= w / 2;
      } else if (x_elt.hasClass('left')) {
        x -= w;
      }
      y = parseInt(y_elt.text());
      if (y_elt.hasClass('centered')) {
        y -= h / 2;
      } else if (y_elt.hasClass('top')) {
        y -= h;
      }
      _ref = get_translation($tooltip), current_x = _ref[0], current_y = _ref[1];
      if (current_x === x && current_y === y) {
        return;
      }
      return $tooltip.attr('transform', "translate(" + x + " " + y + ")");
    };
    return untooltip = function() {
      return tooltip_timeout = setTimeout((function() {
        return $vg('#tooltip', ctx).css({
          opacity: 0
        });
      }), 1000);
    };
  };

  this.init_svg = function(ctx) {
    return init($vg(ctx));
  };

  $vg(function() {
    var $charts;
    $charts = $vg('.pygal-chart');
    if ($charts.size()) {
      return $charts.each(function() {
        return init_svg(this);
      });
    } else {
      return init();
    }
  });

}).call(this);