Skip to content

Commit 430a886

Browse files
committed
Fix for chart not rendering when new script version adds extra columns to data
Now the original number of columns from the first json file is used. If later files have more columns, they are ignored.
1 parent b0c1360 commit 430a886

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

get_beer_data.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949

5050
// aggregate all json data for the beer
5151
$renderedRow = false;
52+
$cols = "";
5253
echo "{\"rows\":[";
5354
foreach ( $fileNames as $fileName ) {
5455
$contents = file_get_contents(dirname(__FILE__) . '/' . $fileName);
@@ -59,10 +60,9 @@
5960
echo get_list_between($contents, '"rows":' , ']}]');
6061
$renderedRow = true;
6162

62-
$colsThisFile = get_list_between($contents, '"cols":' , ']');
63-
if(strlen($colsThisFile) > strlen($cols)){
63+
if($cols == ""){
6464
// use largest column list
65-
$cols = $colsThisFile;
65+
$cols = get_list_between($contents, '"cols":' , ']');
6666
}
6767
}
6868
}

js/beer-chart.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function toDygraphArray(jsonData) {
161161

162162
for (i = 0; i < rows.length; i++){
163163
row = [];
164-
for (j = 0; j < rows[i].c.length; j++) {
164+
for (j = 0; j < Math.min(rows[i].c.length, handlers.length); j++) {
165165
handlers[j](j, rows[i].c[j]);
166166
}
167167
dataArray.push(row);

0 commit comments

Comments
 (0)