| 1 |
Rickshaw.namespace('Rickshaw.Graph.Behavior.Series.Order'); |
| 2 |
|
| 3 |
Rickshaw.Graph.Behavior.Series.Order = function(args) { |
| 4 |
|
| 5 |
this.graph = args.graph; |
| 6 |
this.legend = args.legend; |
| 7 |
|
| 8 |
var self = this; |
| 9 |
|
| 10 |
if (typeof window.jQuery == 'undefined') { |
| 11 |
throw "couldn't find jQuery at window.jQuery"; |
| 12 |
} |
| 13 |
|
| 14 |
if (typeof window.jQuery.ui == 'undefined') { |
| 15 |
throw "couldn't find jQuery UI at window.jQuery.ui"; |
| 16 |
} |
| 17 |
|
| 18 |
jQuery(function() { |
| 19 |
jQuery(self.legend.list).sortable( { |
| 20 |
containment: 'parent', |
| 21 |
tolerance: 'pointer', |
| 22 |
update: function( event, ui ) { |
| 23 |
var series = []; |
| 24 |
jQuery(self.legend.list).find('li').each( function(index, item) { |
| 25 |
if (!item.series) return; |
| 26 |
series.push(item.series); |
| 27 |
} ); |
| 28 |
|
| 29 |
for (var i = self.graph.series.length - 1; i >= 0; i--) { |
| 30 |
self.graph.series[i] = series.shift(); |
| 31 |
} |
| 32 |
|
| 33 |
self.graph.update(); |
| 34 |
} |
| 35 |
} ); |
| 36 |
jQuery(self.legend.list).disableSelection(); |
| 37 |
}); |
| 38 |
|
| 39 |
//hack to make jquery-ui sortable behave |
| 40 |
this.graph.onUpdate( function() { |
| 41 |
var h = window.getComputedStyle(self.legend.element).height; |
| 42 |
self.legend.element.style.height = h; |
| 43 |
} ); |
| 44 |
}; |