forked from HTTPArchive/legacy.httparchive.org
-
Notifications
You must be signed in to change notification settings - Fork 1
/
charts.inc
569 lines (477 loc) · 18.9 KB
/
charts.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
<?php
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
require_once("utils.inc");
require_once("dbapi.inc");
// Normally charts have an href to the page they're currently in (interesting.php or viewsite.php).
// But if we're on index.php we need to point somewhere else.
$gPhpFile = ( "/index.php" == $_SERVER['PHP_SELF'] ? "interesting.php" : "" );
// eg: average total amount of JS downloaded per page
function bytesContentTypeChart($hStats) {
$aVarValues = array();
$aVarNames = array();
$kb = formatSize($hStats['bytesImg']);
if ( $kb ) {
$aVarValues[] = $kb;
$aVarNames[] = "Images - $kb kB";
}
$kb = formatSize($hStats['bytesHtml']);
if ( $kb ) {
$aVarValues[] = $kb;
$aVarNames[] = "HTML - $kb kB";
}
$kb = formatSize($hStats['bytesCSS']);
if ( $kb ) {
$aVarValues[] = $kb;
$aVarNames[] = "Stylesheets - $kb kB";
}
$kb = formatSize($hStats['bytesJS']);
if ( $kb ) {
$aVarValues[] = $kb;
$aVarNames[] = "Scripts - $kb kB";
}
$kb = formatSize($hStats['bytesFont']);
if ( $kb ) {
$aVarValues[] = $kb;
$aVarNames[] = "Fonts - $kb kB";
}
$kb = formatSize($hStats['bytesVideo']);
if ( $kb ) {
$aVarValues[] = $kb;
$aVarNames[] = "Video - $kb kB";
}
$kb = formatSize($hStats['bytesOther']);
if ( $kb ) {
$aVarValues[] = $kb;
$aVarNames[] = "Other - $kb kB";
}
return pieChart("Average Bytes per Page by Content Type", "bytesperpage", $aVarNames, $aVarValues, "007099",
"total " . formatSize($hStats['bytesTotal']) . " kB");
}
function responseSizes($hStats) {
$aVarValues = array();
$aVarNames = array();
if ( 0 != $hStats['reqGif'] ) {
$aVarValues[] = formatSize( $hStats['bytesGif'] / $hStats['reqGif'] );
$aVarNames[] = "GIF";
}
if ( 0 != $hStats['reqJpg'] ) {
$aVarValues[] = formatSize( $hStats['bytesJpg'] / $hStats['reqJpg'] );
$aVarNames[] = "JPG";
}
if ( 0 != $hStats['reqPng'] ) {
$aVarValues[] = formatSize( $hStats['bytesPng'] / $hStats['reqPng'] );
$aVarNames[] = "PNG";
}
if ( 0 != $hStats['reqWebp'] ) {
$aVarValues[] = formatSize( $hStats['bytesWebp'] / $hStats['reqWebp'] );
$aVarNames[] = "WebP";
}
if ( 0 != $hStats['reqSvg'] ) {
$aVarValues[] = formatSize( $hStats['bytesSvg'] / $hStats['reqSvg'] );
$aVarNames[] = "SVG";
}
if ( 0 != $hStats['reqHtml'] ) {
$aVarValues[] = formatSize( $hStats['bytesHtml'] / $hStats['reqHtml'] );
$aVarNames[] = "HTML";
}
if ( 0 != $hStats['reqJS'] ) {
$aVarValues[] = formatSize( $hStats['bytesJS'] / $hStats['reqJS'] );
$aVarNames[] = "JS";
}
if ( 0 != $hStats['reqCSS'] ) {
$aVarValues[] = formatSize( $hStats['bytesCSS'] / $hStats['reqCSS'] );
$aVarNames[] = "CSS";
}
if ( 0 != $hStats['reqVideo'] ) {
$aVarValues[] = formatSize( $hStats['bytesVideo'] / $hStats['reqVideo'] );
$aVarNames[] = "Video";
}
if ( ! count($aVarValues) ) {
return;
}
return horizontalBarChart("Average Individual Response Size", "responsesizes", $aVarNames, $aVarValues, "3B356A", 0, max($aVarValues)+10,
"average response size (kB)", false, "+kB");
}
function percentGoogleLibrariesAPI($hStats) {
$yes = $hStats['perGlibs'];
$no = 100-$yes;
$aVarNames = array("no $no%", "yes $yes%");
$aVarValues = array($no, $yes);
return pieChart("Pages Using Google Libraries API", "googlelibs", $aVarNames, $aVarValues);
}
function percentFlash($hStats) {
$yes = $hStats['perFlash'];
$no = 100-$yes;
$aVarNames = array("No Flash $no%", "Flash $yes%");
$aVarValues = array($no, $yes);
return pieChart("Pages Using Flash", "flash", $aVarNames, $aVarValues);
}
function percentFonts($hStats) {
$yes = $hStats['perFonts'];
$no = 100-$yes;
$aVarNames = array("No Fonts $no%", "Fonts $yes%");
$aVarValues = array($no, $yes);
return pieChart("Pages Using Custom Fonts", "fonts", $aVarNames, $aVarValues);
}
function popularImageFormats($hStats) {
$total = $hStats['reqImg'];
if ( ! $total ) {
return;
}
$gif = round(100*$hStats['reqGif'] / $total);
$jpg = round(100*$hStats['reqJpg'] / $total);
$png = round(100*$hStats['reqPng'] / $total);
$webp = round(100*$hStats['reqWebp'] / $total);
$svg = round(100*$hStats['reqSvg'] / $total);
$other = 100 - ($gif+$jpg+$png+$webp+$svg);
$aVarNames = array("GIF $gif%", "JPG $jpg%", "PNG $png%", "WebP $webp%", "SVG $svg%", "Other $other%");
$aVarValues = array($gif, $jpg, $png, $webp, $svg, $other);
return pieChart("Image Requests by Format", "imageformats", $aVarNames, $aVarValues);
}
function maxage($hStats) {
$aNames = array("t = 0", "0 < t <= 1", "1 < t <= 30", "30 < t <= 365", "t > 365");
$aValues = array($hStats['maxage0'],
$hStats['maxage1'],
$hStats['maxage30'],
$hStats['maxage365'],
$hStats['maxageMore']
);
return percentageColumnChart("Cache Lifetime (days)", "caching", $aNames, $aValues);
}
function percentByProtocol($hStats) {
$https = $hStats['perHttps'];
$http = 100-$https;
$aVarNames = array("HTTP $http%", "HTTPS $https%");
$aVarValues = array($http, $https);
return pieChart("HTTPS Requests", "protocol", $aVarNames, $aVarValues);
}
function requestErrors($hStats) {
$yes = $hStats['perErrors'];
$no = 100-$yes;
$aVarNames = array("No Errors $no%", "Errors $yes%");
$aVarValues = array($no, $yes);
return pieChart("Pages with Errors (4xx, 5xx)", "errors", $aVarNames, $aVarValues);
}
// $var1 is "onLoad" or "renderStart" or "SpeedIndex"
function correlationChart($hStats, $var1) {
global $ghColumnTitles;
$aNames = array();
$aValues = array();
for ( $i = 1; $i <= 5; $i++ ) {
$field = $hStats["{$var1}ccf$i"];
if ( ! $field ) {
// bail - no data
return "";
}
$aNames[] = ( array_key_exists($field, $ghColumnTitles) ? $ghColumnTitles[$field] : $field );
$aValues[] = $hStats["{$var1}ccv$i"];
}
$title = "Highest Correlation to " . ( "onLoad" == $var1 ? "Load Time" : ( "renderStart" == $var1 ? "Render Time" : $var1 ) );
$color = fieldColor($var1);
return correlationColumnChart($title, $var1, $aNames, $aValues, $color);
}
function pieChart($title, $id, $aNames, $aValues, $color="", $legend = "") {
global $gPhpFile;
$color = ( $color ? $color : pickColor($title) );
return "<a href='$gPhpFile#$id'><img width=400 height=225 id=$id class=chart src='//chart.googleapis.com/chart?chs=400x225&cht=p&chco=$color&chd=t:" .
implode(",", $aValues) .
chdsMinmax($aValues, true) .
( $legend ? "&chdlp=b&chdl=$legend" : "" ) .
"&chl=" .
urlencode(implode("|", $aNames)) .
"&chma=|5&chtt=" . urlencode($title) . "' style='vertical-align: top;'></a><a href='about.php#$id' class=info title='info'>i</a>";
}
// The chd (data) param in text ("t:") format only allows values from 0-100.
// You have to use the chds param if you have values outside that range.
function chdsMinmax($aValues, $bZero = false) {
$chds = "";
if ( count($aValues) ) {
$min = ( $bZero ? 0 : min($aValues) );
$max = max($aValues);
if ( $min < 0 || $max > 100 ) {
$chds = "&chds=$min,$max";
}
}
return $chds;
}
// $minPercent is the value at which we only show one bin then stop
function histogram($hStats, $column, $title, $id, $binMultiple=1, $minPercent=1, $color="") {
if (!isset($hStats["cdf_$column"])) {
return "<!-- $column data not available for this crawl -->";
}
$aVals = explode(",", $hStats["cdf_$column"]);
if ( !isset($aVals[98]) || 0 == $aVals[98] ) {
return "<!-- $column data not available for this crawl -->";
}
$hHist = array();
foreach($aVals as $val) {
if ( $binMultiple ) {
$val = ceil($val / $binMultiple);
}
$val = "" . $val; // trick it in treating this as a key rather than an array index
if ( ! array_key_exists($val, $hHist) ) {
$hHist[$val] = 0;
}
$hHist[$val] = $hHist[$val] + 1;
}
$bFirst = true;
$aNames = array();
$aValues = array();
foreach( array_keys($hHist) as $xval ) {
$percent = $hHist[$xval];
if ( 0 == $percent ) {
continue;
}
if ( $binMultiple > 1 && 0 < $xval ) {
if ( 0 === ($binMultiple % (1024*1024)) ) {
$xval = ($xval-1) . "-" . $xval . "M";
}
else if ( 0 === ($binMultiple % 1024) ) {
$multiplier = $binMultiple / 1024;
$xval = (($xval-1)*$multiplier+1) . "-" . $xval*$multiplier . "K";
}
else if ( 0 === ($binMultiple % 1000000) ) {
$xval = ($xval-1) . "-" . $xval . "M";
}
else if ( 0 === ($binMultiple % 1000) ) {
$xval = ($xval-1) . "-" . $xval . "K";
}
else {
$xval = (($binMultiple*($xval - 1))+1) . "-" . ($binMultiple*$xval);
}
}
array_push($aNames, $xval);
array_push($aValues, $percent);
if ( $percent <= $minPercent ) {
if ( ! $bFirst ) {
break;
}
}
else {
$bFirst = false;
}
}
return percentageColumnChart($title, $id, $aNames, $aValues, $color);
}
function percentageColumnChart($title, $id, $aNames, $aValues, $color="") {
global $gPhpFile;
$n = count($aNames);
$width = ( $n < 7 ? 500 : ( $n < 9 ? 550 : 600 ) );
$colw = round(0.75*($width-60) / $n);
$colsp = round(0.25*($width-60) / $n);
$color = ( $color ? $color : pickColor($title) );
return "<a href='$gPhpFile#$id'><img width=$width height=225 id=$id class=chart src='//chart.googleapis.com/chart" .
"?chxl=0:|20%25|40%25|60%25|80%25|100%25|1:|" . urlencode(implode("|", $aNames)) . // axis labels
"&chm=N**%,676767,0,,12,,::4" .
"&chxp=0,20,40,60,80,100" .
"&chxs=0,$color,11.5,0,lt,$color|1,676767,11.5,0,lt,67676700" .
"&chxtc=0,4|1,4&chxt=y,x&chbh=$colw,30,$colsp" .
"&chs={$width}x225&cht=bvg&chco=$color&chd=t:" .
implode(",", $aValues) .
"&chtt=" . urlencode($title) . "' style='vertical-align: top;'></a><a href='about.php#$id' class=info title='info'>i</a>";
}
function correlationColumnChart($title, $id, $aNames, $aValues, $color="80C65A") {
global $gPhpFile;
return "<a href='$gPhpFile#$id'><img width=500 height=225 id=$id class=chart src='//chart.googleapis.com/chart?chxl=1:|" .
str_replace("Requests", "Reqs", str_replace("Transfer", "Xfer", urlencode(implode("|", $aNames)))) .
"&chxr=0,0,1&chxs=1,676767,11.5,0,lt,67676700&chxtc=1,5&chxt=y,x&chbh=60,30,30&chs=500x225&cht=bvg&chco=$color&chds=0,1&chd=t:" .
implode(",", $aValues) .
"&chm=N,676767,0,,12,,::4&chtt=" . urlencode($title) . "' style='vertical-align: top;'></a><a href='about.php#$id' class=info title='info'>i</a>";
}
function horizontalBarChart($title, $id, $aNames, $aValues, $color="80C65A", $min, $max, $xtitle = "", $bPercentage = false, $markSuffix = "") {
global $gPhpFile;
$height = ( count($aValues) > 9 ? 370 : ( count($aValues) > 7 ? 310 : ( count($aValues) > 5 ? 260 : 220 ) ) );
return "<a href='$gPhpFile#$id'><img width=640 height=$height id=$id class=chart src='//chart.googleapis.com/chart?" .
( $bPercentage ? "chxp=0,20,40,60,80,100&chxl=0:|20%|40%|60%|80%|100%|1:|" : "chxl=1:|" ) .
urlencode(implode("|", array_reverse($aNames))) .
( $xtitle ? "&chdlp=b&chdl=$xtitle" : "" ) .
"&chxtc=0,6&chxs=0,676767,11.5,0,l|1,676767,11.5,1,lt,67676700&chxr=1,0,160|0,$min,$max&chxt=x,y&chbh=22&chs=640x$height" .
"&cht=bhg&chco=$color&chds=$min,$max&chd=t:" .
implode(",", $aValues) .
"&chm=N**$markSuffix,676767,0,,12,,:4:&chma=|0,5&chtt=" . urlencode($title) . "' style='vertical-align: top;'></a>"; // lame - no "info" link on this chart because it's too wide <a href='about.php#$field' class=info title='info'>i</a>
}
function cdf($hStats, $column, $title, $id, $binMultiple=1, $minPercent=1, $color="") {
$sHist = $hStats["cdf_$column"];
$aVals = explode(",", $sHist);
$min = $aVals[0];
$max = $aVals[96]; // skip the 100th value
$range = $max - $min;
$aXLabels = array(0); // values in the units of the column
$aLineLabels = array(0); // percentages
$curPercent = 0;
for ( $i = 1; $i <= 100; $i++ ) {
$x = round($i*$range/100);
while ( $aVals[$curPercent] < $x && $curPercent < 100 ) {
$curPercent++;
}
array_push($aXLabels, ( 0 === ($i % 10) ? number_format($x/$binMultiple, 1) : "+" ));
array_push($aLineLabels, $curPercent);
}
$color = pickColor($title);
$url = "//chart.googleapis.com/chart" .
"?chxt=x,y" . // visible axes
"&chs=600x300" . // size
"&cht=lxy" . // chart type
"&chco=$color" . // series color
"&chxs=0,676767,11.5,0,lt,676767" . // axis label styles
"&chxtc=0,8" . // axis tick mark style
//"&chm=N,$color,0,::$skip,12,,h::8" . // text and data value markers
"&chds=0,100,0,100&chts=$color,24&chtt=" . urlencode($title) . "&chls=2&chma=5,5,5,25&chxr=1,0,100,10" .
"&chd=t:-1|" . implode(",", $aLineLabels) .
"&chxl=0:|" . implode("%7C", $aXLabels);
return "<div id='$id' style='margin: 40px 0 60px 0;'><a class=image-link href='#$id'><img src=$url width=600 height=300 style='vertical-align: top;'></a><a href='about.php#$id' class=info title='info'>i</a></div>\n";
}
////////////////////////////////////////////////////////////////////////////////
//
// TRENDS
//
////////////////////////////////////////////////////////////////////////////////
function format2LineChart($field, $field2, $hTrends, $aRunNames, $labels, $sUnits2="", $percentile="", $bSame = false, $footnote = "", $sUnits1="") {
$color = fieldColor($field);
$suffix = fieldUnits($field);
$color2 = fieldColor($field2);
$suffix2 = fieldUnits($field2);
$fieldVals = fieldValues($field, $hTrends, $aRunNames, $min, $max, false, $percentile);
$max = intval(intval($max)*1.5); // this is a hack specific to the bytes & requests charts
$fieldVals2 = fieldValues($field2, $hTrends, $aRunNames, $min2, $max2, false, $percentile);
if ( $bSame ) {
// make both scales the same
$max = $max2 = max($max, $max2);
$min = $min2 = min($min, $min2);
}
$step = ( $max > 10000 ? 2000 : ( $max > 1500 ? 500 : ( $max > 200 ? 100 : ( $max > 100 ? 20 : 10 ) ) ) );
$step2 = ( $max2 > 10000 ? 2000 : ( $max2 > 1500 ? 500 : ( $max2 > 200 ? 100 : ( $max2 > 100 ? 20 : 10 ) ) ) );
$skip = getSkip(count($aRunNames));
$url = "//chart.googleapis.com/chart" .
"?chd=t:-1|$fieldVals|-1|$fieldVals2" .
"&chxl=0:|$labels" .
"&chxt=x,y,r" .
"&chs=600x300" .
"&cht=lxy" .
"&chco=$color,$color2" .
"&chm=N" . ( $suffix ? "**+$suffix" : "" ) . ",$color,0,$skip,12,,h::8" . "|N" . ( $suffix2 ? "**$suffix2" : "" ) . ",$color2,1,$skip,12,,h::8" .
"&chds=9,99,$min,$max,9,99,$min2,$max2" .
"&chts=$color2,24" .
"&chtt=" . urlencode(fieldTitle($field2)) . "+%26+" . urlencode(fieldTitle($field)) .
"&chma=5,5,5,25" .
"&chls=1,6,3|1" .
"&chxr=1,$min2,$max2,$step2|2,$min,$max,$step" .
"&chxs=1,$color2,11.5,-0.5,lt,$color2,$color2|2,$color,11.5,-0.5,lt,$color,$color" .
"&chxtc=0,4|1,4" .
"&chxp=0&chdl=" . urlencode(fieldTitle($field)) . ( $sUnits1 ? "+$sUnits1" : "" ) . "|" . urlencode(fieldTitle($field2)) . ( $sUnits2 ? "+$sUnits2" : "" ) . "&chdlp=bv|r" .
"";
return "<div id='$field2&$field' style='margin: 40px 0 60px 0;'><a class=image-link href='#$field2&$field'><img src=$url width=600 height=300 style='vertical-align:top;'></a><a href='about.php#$field2' class=info title='info'>i</a>" .
( $footnote ? "<div>$footnote<div>" : "" ) . "</div>\n";
}
function formatChart($field, $hTrends, $aRunNames, $labels, $percentile="", $bJson=false) {
$color = fieldColor($field);
$suffix = fieldUnits($field);
$skip = getSkip(count($aRunNames));
$fieldVals = fieldValues($field, $hTrends, $aRunNames, $min, $max, true, $percentile);
if ( strpos("x|perFlash|perFonts|perGlibs|maxage0|perErrors|perRedirects|perHttps|perCompressed|perCdn|", "|$field|") ) {
$max = 100;
}
if ( $bJson ) {
$hSeries = array();
$hSeries["name"] = fieldTitle($field);
$hSeries["labels"] = explode("|", urldecode($labels));
$hSeries["data"] = explode(",", $fieldVals); // wasteful - we implode then explode
$hSeries["suffix"] = $suffix;
$hSeries["minY"] = $min;
$hSeries["maxY"] = $max;
$hSeries["color"] = "#$color";
return $hSeries;
}
else {
$url = "//chart.googleapis.com/chart" .
"?chd=t:-1|$fieldVals" .
"&chxl=0:|$labels&chxt=x&chs=600x300&cht=lxy&chco=$color" .
"&chxs=0,676767,11.5,0,lt,676767&chxtc=0,8&chm=N" . ( $suffix ? "**+$suffix" : "" ) .
",$color,0,$skip,12,,h::8&chds=0,100,$min,$max&chts=$color,24&chtt=" . urlencode(fieldTitle($field)) . "&chls=2&chma=5,5,5,25";
return "<div id='$field' style='margin: 40px 0 60px 0;'><a class=image-link href='#$field'><img src=$url width=600 height=300 style='vertical-align: top;'></a><a href='about.php#$field' class=info title='info'>i</a></div>\n";
}
}
function getSkip($num, $bNum = false) {
$skip = ( $num < 22 ? 1 : ( $num < 32 ? 2 : ( $num < 42 ? 3 : ( $num < 52 ? 4 : ( $num < 104 ? 5 : 12 ) ) ) ) );
if ( $bNum ) {
return $skip;
}
else {
// always show the LAST value
return ( 0 === ($num % 2) ? "1::$skip" : "::$skip" );
}
}
function getLabels($aLabels, $bSkip = true) {
$skip = abs(getSkip(count($aLabels), true));
$len = count($aLabels);
if ( ! $len ) {
return;
}
$aNewLabels = array_fill(0, $len, " "); // have to create all array elements to set in reverse order? php weirdness?
$iLabel = 0;
for ( $i = $len-1; $i >= 0; $i-- ) {
$aNewLabels[$i] = ( 0 === ($iLabel % $skip) || ! $bSkip ? $aLabels[$i] : " " );
$iLabel++;
}
return urlencode(implode("|", $aNewLabels));
}
function fieldValues($field, $hTrends, $aRunNames, &$min, &$max, $bZero = true, $percentile="") {
$aValues = array();
foreach($aRunNames as $run) {
// Here's the rub: We have A LOT of code that relies on the field name being preserved.
// For example, colors and chart titles associated with "reqTotal".
// So we want to preserve the field name throughout the code, and append the
// $percentile at the last minute when we actually access the data.
$aValues[] = ( array_key_exists($run, $hTrends) ? $hTrends[$run][$field . $percentile] : "_" );
}
if ( "maxageNull" === $field || "maxage0" === $field ) {
// take the inverse
$len = count($aValues);
for ( $i = 0; $i < $len; $i++ ) {
$aValues[$i] = 100 - $aValues[$i];
}
}
findScale($aValues, $min, $max, $bZero);
return implode(",", $aValues);
}
function findScale($aValues, &$min, &$max, $bZero = true) {
if ( ! count($aValues) ) {
return;
}
$minValue = min($aValues);
$maxValue = max($aValues);
if ( "_" === $minValue || "_" === $maxValue ) {
$minValue = $maxValue = null;
for ( $i = 0; $i < count($aValues); $i++ ) {
$val = $aValues[$i];
if ( "_" === $val ) {
continue;
}
$minValue = ( isset($minValue) && $minValue < $val ? $minValue : $val );
$maxValue = ( isset($maxValue) && $maxValue > $val ? $maxValue : $val );
}
}
// Power of 10 less than the min - eg 4719 ==> 3000
$min = 0;
if ( ! $bZero && 20 < $minValue ) {
$base = pow(10, floor(log10($minValue)));
$min = $base * ( floor($minValue/$base) > 1 ? floor($minValue/$base) - 1 : 1 );
}
// Multiple of power of 10 less than max value - eg 4719 ==> 5000
$max = 10;
if ( $maxValue > 10 ) {
$base = pow(10, floor(log10($maxValue)));
$max = $base * ceil($maxValue/$base);
}
}
?>