1
+ var chartingLib = {
2
+ createOpts : function ( title , labelsDiv , yLabel , commits ) {
3
+ return {
4
+ "title" : title ,
5
+ "colors" : [ "#00BFB3" , "#FED10A" , "#0078A0" , "#DF4998" , "#93C90E" , "#00A9E5" , "#222" , "#AAA" , "#777" ] ,
6
+ "axisLabelColor" : "#555" ,
7
+ "axisLineColor" : "#555" ,
8
+ "labelsUTC" : false ,
9
+ "includeZero" : true ,
10
+ "xlabel" : "Timestamp (UTC)" ,
11
+ "ylabel" : yLabel ,
12
+ "connectSeparatedPoints" : true ,
13
+ "hideOverlayOnMouseOut" : false ,
14
+ "labelsDiv" : labelsDiv ,
15
+ "labelsSeparateLines" : true ,
16
+ "legend" : "always" ,
17
+ "drawPoints" : true ,
18
+ "pointSize" : 3 ,
19
+ "gridLineColor" : "#BBB" ,
20
+ pointClickCallback : function ( e , p ) {
21
+ var commitInfo = commits [ p . xval ] ;
22
+ if ( commitInfo ) {
23
+ var url = "https://github.com/elastic/elasticsearch/compare/" + commitInfo . prev_commit + "..." + commitInfo . this_commit ;
24
+ window . open ( url ) ;
25
+ }
26
+ }
27
+ //"strokePattern": [5, 10]
28
+ }
29
+ } ,
30
+
31
+ renderChart : function ( elementId , title , yLabel , annotationSource ) {
32
+ var commits = { } ;
33
+ var g = new Dygraph (
34
+ document . getElementById ( "chart_" + elementId ) ,
35
+ elementId + ".csv" ,
36
+ this . createOpts ( "<a href='#" + elementId + "'>" + title + "</a>" , "chart_" + elementId + "_labels" , yLabel , commits )
37
+ ) ;
38
+ g . ready ( function ( ) {
39
+ var annotationSource = elementId + '_annotations.json'
40
+ $ . getJSON ( annotationSource , function ( json ) {
41
+ g . setAnnotations ( json ) ;
42
+ } ) ;
43
+ $ . ajax ( {
44
+ type : 'GET' ,
45
+ url : 'source_revision.csv' ,
46
+ dataType : 'text' ,
47
+ success : function ( allText ) {
48
+ var allTextLines = allText . split ( / \r \n | \n / ) ;
49
+
50
+ var previousCommit = null ;
51
+ for ( var i = 1 ; i < allTextLines . length ; i ++ ) {
52
+ var data = allTextLines [ i ] . split ( ',' ) ;
53
+ var date = new Date ( data [ 0 ] ) ;
54
+ commits [ date . getTime ( ) ] = {
55
+ this_commit : data [ 1 ] ,
56
+ prev_commit : previousCommit
57
+ } ;
58
+ previousCommit = data [ 1 ] ;
59
+ }
60
+ }
61
+ } ) ;
62
+ } ) ;
63
+ return g ;
64
+ } ,
65
+
66
+ // Multiple column bar chart
67
+ multiColumnBarPlotter : function ( e ) {
68
+ // We need to handle all the series simultaneously.
69
+ if ( e . seriesIndex !== 0 ) return ;
70
+
71
+ var g = e . dygraph ;
72
+ var ctx = e . drawingContext ;
73
+ var sets = e . allSeriesPoints ;
74
+ var y_bottom = e . dygraph . toDomYCoord ( 0 ) ;
75
+ var bar_width = 5.0
76
+
77
+ if ( sets . length > 1 ) {
78
+ // Find the minimum separation between x-values.
79
+ // This determines the bar width.
80
+ var min_sep = Infinity ;
81
+ for ( var j = 0 ; j < sets . length ; j ++ ) {
82
+ var points = sets [ j ] ;
83
+ for ( var i = 1 ; i < points . length ; i ++ ) {
84
+ var sep = points [ i ] . canvasx - points [ i - 1 ] . canvasx ;
85
+ if ( sep < min_sep ) min_sep = sep ;
86
+ }
87
+ }
88
+ bar_width = Math . max ( Math . floor ( 2.0 / 3 * min_sep ) , bar_width ) ;
89
+ } else {
90
+ bar_width = bar_width = 50.0
91
+ }
92
+
93
+ var fillColors = [ ] ;
94
+ var strokeColors = g . getColors ( ) ;
95
+ for ( var i = 0 ; i < strokeColors . length ; i ++ ) {
96
+ var color = Dygraph . toRGB_ ( strokeColors [ i ] ) ;
97
+ color . r = Math . floor ( ( 255 + color . r ) / 2 ) ;
98
+ color . g = Math . floor ( ( 255 + color . g ) / 2 ) ;
99
+ color . b = Math . floor ( ( 255 + color . b ) / 2 ) ;
100
+ darkened = 'rgb(' + color . r + ',' + color . g + ',' + color . b + ')' ;
101
+ fillColors . push ( darkened ) ;
102
+ }
103
+
104
+ for ( var j = 0 ; j < sets . length ; j ++ ) {
105
+ ctx . fillStyle = fillColors [ j ] ;
106
+ ctx . strokeStyle = strokeColors [ j ] ;
107
+ for ( var i = 0 ; i < sets [ j ] . length ; i ++ ) {
108
+ var p = sets [ j ] [ i ] ;
109
+ var center_x = p . canvasx ;
110
+ var x_left = center_x - ( bar_width / 2 ) * ( 1 - j / Math . max ( sets . length - 1 , 1 ) ) ;
111
+
112
+ ctx . fillRect ( x_left , p . canvasy ,
113
+ bar_width / sets . length , y_bottom - p . canvasy ) ;
114
+
115
+ ctx . strokeRect ( x_left , p . canvasy ,
116
+ bar_width / sets . length , y_bottom - p . canvasy ) ;
117
+ }
118
+ }
119
+ } ,
120
+
121
+ comparisonParser : function ( versions ) {
122
+ return function ( str ) {
123
+ return $ . inArray ( str , versions ) + 1 ;
124
+ }
125
+ } ,
126
+
127
+
128
+ createBarOpts : function ( title , labelsDiv , yLabel , versions ) {
129
+ return {
130
+ "title" : title ,
131
+ "colors" : [ "#00BFB3" , "#FED10A" , "#0078A0" , "#DF4998" , "#93C90E" , "#00A9E5" , "#222" , "#AAA" , "#777" ] ,
132
+ "axisLabelColor" : "#555" ,
133
+ "axisLineColor" : "#555" ,
134
+ "labelsUTC" : false ,
135
+ "includeZero" : true ,
136
+ "xlabel" : "Candidate" ,
137
+ "ylabel" : yLabel ,
138
+ "hideOverlayOnMouseOut" : false ,
139
+ "labelsDiv" : labelsDiv ,
140
+ "labelsSeparateLines" : true ,
141
+ "legend" : "always" ,
142
+ "drawPoints" : false ,
143
+ "pointSize" : 0 ,
144
+ "gridLineColor" : "#BBB" ,
145
+ "plotter" : this . multiColumnBarPlotter ,
146
+ // use a gap of 1 on each side to ensure we show all bars
147
+ "dateWindow" : [ 0 , versions . length + 1 ] ,
148
+ "xValueParser" : this . comparisonParser ( versions ) ,
149
+ "axes" : {
150
+ "x" : {
151
+ "axisLabelFormatter" : function ( x ) {
152
+ var v = versions [ x - 1 ] ;
153
+ if ( v === undefined ) {
154
+ return ""
155
+ } else {
156
+ return v
157
+ }
158
+ }
159
+ } ,
160
+ "y" : {
161
+ "valueFormatter" : function ( y ) {
162
+ return + ( Math . round ( y + "e+2" ) + "e-2" ) ;
163
+ }
164
+ }
165
+ } ,
166
+ "legend" : "always" ,
167
+ "valueFormatter" : function ( x , opts , seriesName , dygraph , row , col ) {
168
+ var v = versions [ x - 1 ] ;
169
+ if ( v === undefined ) {
170
+ return ""
171
+ } else {
172
+ return v
173
+ }
174
+ }
175
+ }
176
+ } ,
177
+
178
+
179
+ renderBarChart : function ( elementId , title , yLabel , versions ) {
180
+ var g = new Dygraph (
181
+ document . getElementById ( "chart_" + elementId ) ,
182
+ elementId + "_comparison.csv" ,
183
+ this . createBarOpts ( "<a href='#" + elementId + "'>" + title + "</a>" , "chart_" + elementId + "_labels" , yLabel , versions )
184
+ ) ;
185
+ return g ;
186
+ } ,
187
+
188
+ synchronize : function ( graphs ) {
189
+ var sync = Dygraph . synchronize ( graphs , {
190
+ selection : false ,
191
+ zoom : true ,
192
+ // synchronize x-axis only
193
+ range : false
194
+ } ) ;
195
+ }
196
+ } ;
0 commit comments