Skip to content

Commit 30df8e4

Browse files
Tables now save as CSV correctly
I changed the function to pWriter.write() because pWriter.print() automatically creates a new line. Changing pWriter.print() so it doesn't do this would cause many other bugs since everything is written using the print() function.
1 parent a5d3fcf commit 30df8e4

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/io/files.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,7 +1050,8 @@ p5.PrintWriter = function (filename, extension) {
10501050
var self = this;
10511051
this.name = filename;
10521052
this.content = '';
1053-
this.print = function (data) {
1053+
//Changed to write because it was being overloaded by function below.
1054+
this.write = function (data) {
10541055
this.content += data;
10551056
};
10561057
this.print = function (data) {
@@ -1384,25 +1385,27 @@ p5.prototype.saveTable = function (table, filename, options) {
13841385
if (header[0] !== '0') {
13851386
for (var h = 0; h < header.length; h++) {
13861387
if (h < header.length - 1) {
1387-
pWriter.print(header[h] + sep);
1388+
pWriter.write(header[h] + sep);
13881389
} else {
1389-
pWriter.print(header[h]);
1390+
pWriter.write(header[h]);
13901391
}
13911392
}
1393+
pWriter.write("\n");
13921394
}
13931395

13941396
// make rows
13951397
for (var i = 0; i < table.rows.length; i++) {
13961398
var j;
13971399
for (j = 0; j < table.rows[i].arr.length; j++) {
13981400
if (j < table.rows[i].arr.length - 1) {
1399-
pWriter.print(table.rows[i].arr[j] + sep);
1401+
pWriter.write(table.rows[i].arr[j] + sep);
14001402
} else if (i < table.rows.length - 1) {
1401-
pWriter.print(table.rows[i].arr[j]);
1403+
pWriter.write(table.rows[i].arr[j]);
14021404
} else {
1403-
pWriter.print(table.rows[i].arr[j]); // no line break
1405+
pWriter.write(table.rows[i].arr[j]);
14041406
}
14051407
}
1408+
pWriter.write("\n");
14061409
}
14071410
}
14081411

0 commit comments

Comments
 (0)