@@ -20,6 +20,7 @@ Backshift.Graph.Rickshaw = Backshift.Class.create( Backshift.Graph, {
20
20
}
21
21
22
22
this . previewDiv = null ;
23
+ this . legendDiv = null ;
23
24
} ,
24
25
25
26
updateSeriesData : function ( dp ) {
@@ -59,10 +60,20 @@ Backshift.Graph.Rickshaw = Backshift.Class.create( Backshift.Graph, {
59
60
}
60
61
} ,
61
62
63
+ getSeriesColor : function ( series , fallback ) {
64
+ if ( series . color !== undefined ) {
65
+ return series . color ;
66
+ } else {
67
+ return fallback ;
68
+ }
69
+ } ,
70
+
62
71
onRender : function ( ) {
63
72
var container = d3 . select ( this . element ) ;
64
73
65
- var chartDiv = container . append ( "div" ) ;
74
+ this . chartDiv = container . append ( "div" ) ;
75
+ this . previewDiv = container . append ( "div" ) ;
76
+ this . legendDiv = container . append ( "div" ) ;
66
77
67
78
var palette = new Rickshaw . Color . Palette ( { scheme : 'classic9' } ) ;
68
79
@@ -73,18 +84,19 @@ Backshift.Graph.Rickshaw = Backshift.Class.create( Backshift.Graph, {
73
84
rickshawSeries . push ( {
74
85
name : series . name ,
75
86
data : this . seriesData [ series . name ] ,
76
- color : palette . color ( ) ,
87
+ color : this . getSeriesColor ( series , palette . color ( ) ) ,
77
88
renderer : series . type
78
89
} ) ;
79
90
}
80
91
81
92
this . graph = new Rickshaw . Graph ( {
82
- element : chartDiv . node ( ) ,
93
+ element : this . chartDiv . node ( ) ,
83
94
renderer : 'multi' ,
84
95
width : this . width ,
85
96
height : this . height ,
86
97
min : 'auto' ,
87
- series : rickshawSeries
98
+ series : rickshawSeries ,
99
+ padding : { top : 0.02 , left : 0.02 , right : 0.02 , bottom : 0.02 }
88
100
} ) ;
89
101
90
102
this . graph . render ( ) ;
@@ -103,12 +115,22 @@ Backshift.Graph.Rickshaw = Backshift.Class.create( Backshift.Graph, {
103
115
104
116
yAxis . render ( ) ;
105
117
106
- new Rickshaw . Graph . HoverDetail ( {
118
+ this . legendDiv . node ( ) . style . paddingTop = '10px' ;
119
+ this . legend = new Backshift . Legend . Rickshaw ( {
120
+ model : this . model ,
121
+ graph : this . graph ,
122
+ element : this . legendDiv . node ( ) ,
123
+ dataProcessor : this . dp
124
+ } ) ;
125
+
126
+ this . legend . render ( ) ;
127
+
128
+ /* var hoverDetail = */ new Rickshaw . Graph . HoverDetail ( {
107
129
graph : this . graph ,
108
130
xFormatter : function ( x ) {
109
131
return new Date ( x * 1000 ) . toString ( ) ;
110
132
}
111
- } ) ;
133
+ } ) ;
112
134
} ,
113
135
114
136
onFetchSuccess : function ( dp ) {
@@ -118,16 +140,17 @@ Backshift.Graph.Rickshaw = Backshift.Class.create( Backshift.Graph, {
118
140
// it fails to load intermittently otherwise
119
141
var container = d3 . select ( this . element ) ;
120
142
121
- if ( this . model . preview && this . previewDiv === null ) {
122
- this . previewDiv = container . append ( "div" ) ;
123
-
143
+ if ( this . model . preview ) {
124
144
var preview = new Rickshaw . Graph . RangeSlider . Preview ( {
125
145
graph : this . graph ,
126
146
element : this . previewDiv . node ( )
127
147
} ) ;
128
148
129
149
preview . render ( ) ;
130
150
}
151
+
152
+ // Update the legend with the latest values
153
+ this . legend . render ( this . dp ) ;
131
154
}
132
155
133
156
} ) ;
0 commit comments