Debian Codegraph @

src/js/Rickshaw.Graph.Behavior.Series.Highlight.js

raw
1 Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Highlight');
2
3 Rickshaw.Graph.Behavior.Series.Highlight = function(args) {
4
5 this.graph = args.graph;
6 this.legend = args.legend;
7
8 var self = this;
9
10 var colorSafe = {};
11 var activeLine = null;
12
13 var disabledColor = args.disabledColor || function(seriesColor) {
14 return d3.interpolateRgb(seriesColor, d3.rgb('#d8d8d8'))(0.8).toString();
15 };
16
17 this.addHighlightEvents = function (l) {
18
19 l.element.addEventListener( 'mouseover', function(e) {
20
21 if (activeLine) return;
22 else activeLine = l;
23
24 self.legend.lines.forEach( function(line) {
25
26 if (l === line) {
27
28 // if we're not in a stacked renderer bring active line to the top
29 if (self.graph.renderer.unstack && (line.series.renderer ? line.series.renderer.unstack : true)) {
30
31 var seriesIndex = self.graph.series.indexOf(line.series);
32 line.originalIndex = seriesIndex;
33
34 var series = self.graph.series.splice(seriesIndex, 1)[0];
35 self.graph.series.push(series);
36 }
37 return;
38 }
39
40 colorSafe[line.series.name] = colorSafe[line.series.name] || line.series.color;
41 line.series.color = disabledColor(line.series.color);
42
43 } );
44
45 self.graph.update();
46
47 }, false );
48
49 l.element.addEventListener( 'mouseout', function(e) {
50
51 if (!activeLine) return;
52 else activeLine = null;
53
54 self.legend.lines.forEach( function(line) {
55
56 // return reordered series to its original place
57 if (l === line && line.hasOwnProperty('originalIndex')) {
58
59 var series = self.graph.series.pop();
60 self.graph.series.splice(line.originalIndex, 0, series);
61 delete line.originalIndex;
62 }
63
64 if (colorSafe[line.series.name]) {
65 line.series.color = colorSafe[line.series.name];
66 }
67 } );
68
69 self.graph.update();
70
71 }, false );
72 };
73
74 if (this.legend) {
75 this.legend.lines.forEach( function(l) {
76 self.addHighlightEvents(l);
77 } );
78 }
79
80 };