@@ -164,37 +164,41 @@ public static void Write<T0, T1, T2, T3>(float x, float y, string format, T0 arg
164164 instance . _Write ( x , y , format , new ArgList4 < T0 , T1 , T2 , T3 > ( arg0 , arg1 , arg2 , arg3 ) ) ;
165165 }
166166
167- // Draw a stacked histogram from numSets of data. Data must contain numSets of interleaved, non-negative datapoints.
168- public static void DrawHist ( float x , float y , float w , float h , float [ ] data , int startSample , Color [ ] color , int numSets , float maxRange = - 1.0f )
167+ // Draw a histogram of one set of data. Data must contain non-negative datapoints.
168+ public static void DrawHist ( float x , float y , float w , float h , float [ ] data , int startSample , Color color , float maxRange = - 1.0f )
169169 {
170170 if ( instance == null )
171171 return ;
172- instance . _DrawHist ( x , y , w , h , data , startSample , color , numSets , maxRange ) ;
172+ s_TempData [ 0 ] = data ;
173+ s_TempColors [ 0 ] = color ;
174+ instance . _DrawHist ( x , y , w , h , s_TempData , startSample , s_TempColors , maxRange ) ;
175+ s_TempData [ 0 ] = null ;
173176 }
177+ static float [ ] [ ] s_TempData = new float [ 1 ] [ ] ;
178+ static Color [ ] s_TempColors = new Color [ 1 ] ;
174179
175- static Color [ ] m_Colors = new Color [ 1 ] ;
176- public static void DrawHist ( float x , float y , float w , float h , float [ ] data , int startSample , Color color , float maxRange = - 1.0f )
180+ // Draw a stacked histogram multiple sets of data. Data must contain non-negative datapoints.
181+ public static void DrawHist ( float x , float y , float w , float h , float [ ] [ ] data , int startSample , Color [ ] color , float maxRange = - 1.0f )
177182 {
178183 if ( instance == null )
179184 return ;
180- m_Colors [ 0 ] = color ;
181- instance . _DrawHist ( x , y , w , h , data , startSample , m_Colors , 1 , maxRange ) ;
185+ instance . _DrawHist ( x , y , w , h , data , startSample , color , maxRange ) ;
182186 }
183187
184- public static void DrawGraph ( float x , float y , float w , float h , float [ ] data , int startSample , Color [ ] color , int numSets , float maxRange = - 1.0f )
188+ public static void DrawGraph ( float x , float y , float w , float h , float [ ] data , int startSample , Color color , float maxRange = - 1.0f )
185189 {
186190 if ( instance == null )
187191 return ;
188- instance . _DrawGraph ( x , y , w , h , data , startSample , color , numSets , maxRange ) ;
192+ s_TempData [ 0 ] = data ;
193+ s_TempColors [ 0 ] = color ;
194+ instance . _DrawGraph ( x , y , w , h , s_TempData , startSample , s_TempColors , maxRange ) ;
189195 }
190196
191-
192- public static void DrawGraph ( float x , float y , float w , float h , float [ ] data , int startSample , Color color , float maxRange = - 1.0f )
197+ public static void DrawGraph ( float x , float y , float w , float h , float [ ] [ ] data , int startSample , Color [ ] color , float maxRange = - 1.0f )
193198 {
194199 if ( instance == null )
195200 return ;
196- m_Colors [ 0 ] = color ;
197- instance . _DrawGraph ( x , y , w , h , data , startSample , m_Colors , 1 , maxRange ) ;
201+ instance . _DrawGraph ( x , y , w , h , data , startSample , color , maxRange ) ;
198202 }
199203
200204 public static void DrawRect ( float x , float y , float w , float h , Color col )
@@ -234,22 +238,32 @@ void _DrawText(float x, float y, ref char[] text, int length)
234238 }
235239 }
236240
237- void _DrawGraph ( float x , float y , float w , float h , float [ ] data , int startSample , Color [ ] color , int numSets , float maxRange = - 1.0f )
241+ void _DrawGraph ( float x , float y , float w , float h , float [ ] [ ] data , int startSample , Color [ ] color , float maxRange = - 1.0f )
238242 {
239- if ( data . Length % numSets != 0 )
240- throw new System . ArgumentException ( "Length of data must be a multiple of numSets" ) ;
241- if ( color . Length != numSets )
242- throw new System . ArgumentException ( "Length of colors must be numSets" ) ;
243+ if ( data == null || data . Length == 0 || data [ 0 ] == null )
244+ throw new System . ArgumentException ( "Invalid data argument (data must contain at least one non null array" ) ;
243245
244- var dataLength = data . Length ;
245- var numSamples = dataLength / numSets ;
246+ var numSamples = data [ 0 ] . Length ;
247+ /*
248+ for(int i = 1; i < data.Length; ++i)
249+ {
250+ if(data[i] == null || data[i].Length != numSamples)
251+ throw new System.ArgumentException("Length of data of all arrays must be the same");
252+ }
253+ */
254+
255+ if ( color . Length != data . Length )
256+ throw new System . ArgumentException ( "Length of colors must match number of datasets" ) ;
246257
247258 float maxData = float . MinValue ;
248259
249- for ( var i = 0 ; i < dataLength ; i ++ )
260+ foreach ( var dataset in data )
250261 {
251- if ( data [ i ] > maxData )
252- maxData = data [ i ] ;
262+ for ( var i = 0 ; i < numSamples ; i ++ )
263+ {
264+ if ( dataset [ i ] > maxData )
265+ maxData = dataset [ i ] ;
266+ }
253267 }
254268
255269 if ( maxData > maxRange )
@@ -258,14 +272,14 @@ void _DrawGraph(float x, float y, float w, float h, float[] data, int startSampl
258272 float dx = w / numSamples ;
259273 float scale = maxRange > 0 ? h / maxRange : 1.0f ;
260274
261- for ( var j = 0 ; j < numSets ; j ++ )
275+ for ( var j = 0 ; j < data . Length ; j ++ )
262276 {
263277 float old_pos_x = 0 ;
264278 float old_pos_y = 0 ;
265279 Vector4 col = color [ j ] ;
266280 for ( var i = 0 ; i < numSamples ; i ++ )
267281 {
268- float d = data [ ( ( i + startSample ) % numSamples ) * numSets + j ] ;
282+ float d = data [ j ] [ ( i + startSample ) % numSamples ] ;
269283 var pos_x = m_OriginX + x + dx * i ;
270284 var pos_y = m_OriginY + y + h - d * scale ;
271285 if ( i > 0 )
@@ -274,19 +288,29 @@ void _DrawGraph(float x, float y, float w, float h, float[] data, int startSampl
274288 old_pos_y = pos_y ;
275289 }
276290 }
291+
277292 AddLine ( x , y + h , x + w , y + h , color [ 0 ] ) ;
278293 AddLine ( x , y , x , y + h , color [ 0 ] ) ;
279294 }
280295
281- void _DrawHist ( float x , float y , float w , float h , float [ ] data , int startSample , Color [ ] color , int numSets , float maxRange = - 1.0f )
296+ void _DrawHist ( float x , float y , float w , float h , float [ ] [ ] data , int startSample , Color [ ] color , float maxRange = - 1.0f )
282297 {
283- if ( data . Length % numSets != 0 )
284- throw new System . ArgumentException ( "Length of data must be a multiple of numSets" ) ;
285- if ( color . Length != numSets )
286- throw new System . ArgumentException ( "Length of colors must be numSets" ) ;
298+ if ( data == null || data . Length == 0 || data [ 0 ] == null )
299+ throw new System . ArgumentException ( "Invalid data argument (data must contain at least one non null array" ) ;
300+
301+ var numSamples = data [ 0 ] . Length ;
302+ /*
303+ for (int i = 1; i < data.Length; ++i)
304+ {
305+ if (data[i] == null || data[i].Length != numSamples)
306+ throw new System.ArgumentException("Length of data of all arrays must be the same");
307+ }
308+ */
309+
310+ if ( color . Length != data . Length )
311+ throw new System . ArgumentException ( "Length of colors must match number of datasets" ) ;
287312
288313 var dataLength = data . Length ;
289- var numSamples = dataLength / numSets ;
290314
291315 float maxData = float . MinValue ;
292316
@@ -295,8 +319,8 @@ void _DrawHist(float x, float y, float w, float h, float[] data, int startSample
295319 {
296320 float sum = 0 ;
297321
298- for ( var j = 0 ; j < numSets ; j ++ )
299- sum += data [ i * numSets + j ] ;
322+ foreach ( var dataset in data )
323+ sum += dataset [ i ] ;
300324
301325 if ( sum > maxData )
302326 maxData = sum ;
@@ -312,10 +336,10 @@ void _DrawHist(float x, float y, float w, float h, float[] data, int startSample
312336 for ( var i = 0 ; i < numSamples ; i ++ )
313337 {
314338 stackOffset = 0 ;
315- for ( var j = 0 ; j < numSets ; j ++ )
339+ for ( var j = 0 ; j < data . Length ; j ++ )
316340 {
317341 var c = color [ j ] ;
318- float d = data [ ( ( i + startSample ) % numSamples ) * numSets + j ] ;
342+ float d = data [ j ] [ ( i + startSample ) % numSamples ] ;
319343 float barHeight = d * scale ; // now in [0, h]
320344 var pos_x = m_OriginX + x + dx * i ;
321345 var pos_y = m_OriginY + y + h - barHeight - stackOffset ;
0 commit comments