@@ -23,32 +23,43 @@ class TableRow {
23
23
* @param {String|Number } value The value to be stored
24
24
*
25
25
* @example
26
- * <div class="norender"><code>
27
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
28
- * //
29
- * // id,species,name
30
- * // 0,Capra hircus,Goat
31
- * // 1,Panthera pardus,Leopard
32
- * // 2,Equus zebra,Zebra
33
- *
26
+ * <div>
27
+ * <code>
34
28
* let table;
35
29
*
36
30
* async function setup() {
37
- * // The table is comma separated value "csv"
38
- * // and has a header specifying the columns labels.
39
- * table = await loadTable('assets/mammals.csv', 'csv', 'header' );
31
+ * // Create a 200x200 canvas and set a white background
32
+ * createCanvas(200, 200);
33
+ * background(255 );
40
34
*
41
- * let rows = table.getRows();
35
+ * // Load the CSV file with a header row
36
+ * table = await loadTable('assets/mammals.csv', ',', 'header');
37
+ *
38
+ * // Set every row's "name" to "Unicorn"
39
+ * let rows = table.getRows();
42
40
* for (let r = 0; r < rows.length; r++) {
43
41
* rows[r].set('name', 'Unicorn');
44
42
* }
45
43
*
46
- * //print the results
47
- * print(table.getArray());
44
+ * // Convert the table to an array
45
+ * let tableArray = table.getArray();
46
+ *
47
+ * // Set text properties
48
+ * fill(0); // Set text color to black
49
+ * textSize(12); // Set text size
50
+ *
51
+ * // Display each row of the table on the canvas
52
+ * let y = 20; // Starting y position
53
+ * for (let i = 0; i < tableArray.length; i++) {
54
+ * let rowText = tableArray[i].join(', ');
55
+ * text(rowText, 10, y * 2.5);
56
+ * y += 20; // Increment y position for the next row
57
+ * }
48
58
*
49
59
* describe('no image displayed');
50
60
* }
51
- * </code></div>
61
+ * </code>
62
+ * </div>
52
63
*/
53
64
set ( column , value ) {
54
65
// if typeof column is string, use .obj
@@ -82,31 +93,44 @@ class TableRow {
82
93
* @param {Number|String } value The value to be stored
83
94
* as a Float
84
95
* @example
85
- * <div class="norender"><code>
86
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
87
- * //
88
- * // id,species,name
89
- * // 0,Capra hircus,Goat
90
- * // 1,Panthera pardus,Leopard
91
- * // 2,Equus zebra,Zebra
92
- *
96
+ * <div>
97
+ * <code>
93
98
* let table;
94
99
*
95
100
* async function setup() {
96
- * // The table is comma separated value "csv"
97
- * // and has a header specifying the columns labels.
98
- * table = await loadTable('assets/mammals.csv', 'csv', 'header' );
101
+ * // Create a 200x200 canvas and set a white background
102
+ * createCanvas(200, 200);
103
+ * background(255 );
99
104
*
105
+ * // Load the CSV file with a header row
106
+ * table = await loadTable('assets/mammals.csv', ',', 'header');
107
+ *
108
+ * // Update each row's "id" to (row index + 10)
100
109
* let rows = table.getRows();
101
110
* for (let r = 0; r < rows.length; r++) {
102
111
* rows[r].setNum('id', r + 10);
103
112
* }
104
113
*
105
- * print(table.getArray());
114
+ * // Convert the table to a 2D array for display
115
+ * let tableArray = table.getArray();
116
+ *
117
+ * // Set text properties
118
+ * fill(0); // Text color: black
119
+ * textSize(12); // Adjust text size as needed
120
+ *
121
+ * // Display each row of the table on the canvas
122
+ * let y = 20; // Starting y position
123
+ * for (let i = 0; i < tableArray.length; i++) {
124
+ * // Join each row's values with a comma separator
125
+ * let rowText = tableArray[i].join(', ');
126
+ * text(rowText, 10, y * 2.5);
127
+ * y += 20; // Increment y for the next row
128
+ * }
106
129
*
107
130
* describe('no image displayed');
108
131
* }
109
- * </code></div>
132
+ * </code>
133
+ * </div>
110
134
*/
111
135
setNum ( column , value ) {
112
136
const floatVal = parseFloat ( value ) ;
@@ -123,32 +147,43 @@ class TableRow {
123
147
* @param {String|Number|Boolean|Object } value The value to be stored
124
148
* as a String
125
149
* @example
126
- * <div class="norender"><code>
127
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
128
- * //
129
- * // id,species,name
130
- * // 0,Capra hircus,Goat
131
- * // 1,Panthera pardus,Leopard
132
- * // 2,Equus zebra,Zebra
133
- *
150
+ * <div>
151
+ * <code>
134
152
* let table;
135
153
*
136
154
* async function setup() {
137
- * // The table is comma separated value "csv"
138
- * // and has a header specifying the columns labels.
139
- * table = await loadTable('assets/mammals.csv', 'csv', 'header');
155
+ * // Create a 300x200 canvas and set a white background
156
+ * createCanvas(300, 200);
157
+ * background(255);
158
+ *
159
+ * // Load the CSV file with a header row
160
+ * table = await loadTable('assets/mammals.csv', ',', 'header');
140
161
*
162
+ * // Update each row's "name" field
141
163
* let rows = table.getRows();
142
164
* for (let r = 0; r < rows.length; r++) {
143
165
* let name = rows[r].getString('name');
144
166
* rows[r].setString('name', 'A ' + name + ' named George');
145
167
* }
146
168
*
147
- * print(table.getArray());
169
+ * // Convert the table to a 2D array for display
170
+ * let tableArray = table.getArray();
148
171
*
149
- * describe('no image displayed');
172
+ * // Set text properties
173
+ * fill(0); // Text color: black
174
+ * textSize(12); // Adjust text size as needed
175
+ *
176
+ * // Display each row of the table on the canvas
177
+ * let y = 20; // Starting y position
178
+ * for (let i = 0; i < tableArray.length; i++) {
179
+ * let rowText = tableArray[i].join(', ');
180
+ * text(rowText, 10, y * 2.5);
181
+ * y += 20; // Increment y for the next row
182
+ * }
183
+ *
184
+ * // describe('no image displayed');
150
185
* }
151
- * </code></div>
186
+ * </code>
152
187
*/
153
188
setString ( column , value ) {
154
189
const stringVal = value . toString ( ) ;
@@ -165,32 +200,37 @@ class TableRow {
165
200
* @return {String|Number }
166
201
*
167
202
* @example
168
- * <div class="norender"><code>
169
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
170
- * //
171
- * // id,species,name
172
- * // 0,Capra hircus,Goat
173
- * // 1,Panthera pardus,Leopard
174
- * // 2,Equus zebra,Zebra
175
- *
203
+ * <div>
204
+ * <code>
176
205
* let table;
177
206
*
178
207
* async function setup() {
179
- * // The table is comma separated value "csv"
180
- * // and has a header specifying the columns labels.
181
- * table = await loadTable('assets/mammals.csv', 'csv', 'header' );
208
+ * // Create a 200x100 canvas and set a white background
209
+ * createCanvas(200, 100);
210
+ * background(255 );
182
211
*
212
+ * // Load the CSV file with a header row
213
+ * table = await loadTable('assets/mammals.csv', ',', 'header');
214
+ *
215
+ * // Extract the names from each row and store them in an array
183
216
* let names = [];
184
217
* let rows = table.getRows();
185
218
* for (let r = 0; r < rows.length; r++) {
186
219
* names.push(rows[r].get('name'));
187
220
* }
188
221
*
189
- * print(names);
222
+ * // Set text properties and display the names on the canvas
223
+ * fill(0); // Set text color to black
224
+ * textSize(12); // Set text size
225
+ *
226
+ * // Join names into a single string separated by commas
227
+ * let namesText = names.join(', ');
228
+ * text(namesText, 35, 50);
190
229
*
191
230
* describe('no image displayed');
192
231
* }
193
- * </code></div>
232
+ * </code>
233
+ * </div>
194
234
*/
195
235
get ( column ) {
196
236
if ( typeof column === 'string' ) {
@@ -210,33 +250,39 @@ class TableRow {
210
250
* ID (number)
211
251
* @return {Number } Float Floating point number
212
252
* @example
213
- * <div class="norender"><code>
214
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
215
- * //
216
- * // id,species,name
217
- * // 0,Capra hircus,Goat
218
- * // 1,Panthera pardus,Leopard
219
- * // 2,Equus zebra,Zebra
220
- *
253
+ * <div>
254
+ * <code>
221
255
* let table;
222
256
*
223
257
* async function setup() {
224
- * // The table is comma separated value "csv"
225
- * // and has a header specifying the columns labels.
226
- * table = await loadTable('assets/mammals.csv', 'csv', 'header');
258
+ * // Create a 200x100 canvas and set a white background
259
+ * createCanvas(200, 100);
260
+ * background(255);
261
+ *
262
+ * // Load the CSV file with a header row
263
+ * table = await loadTable('assets/mammals.csv', ',', 'header');
227
264
*
228
265
* let rows = table.getRows();
229
266
* let minId = Infinity;
230
267
* let maxId = -Infinity;
268
+ *
231
269
* for (let r = 0; r < rows.length; r++) {
232
270
* let id = rows[r].getNum('id');
233
271
* minId = min(minId, id);
234
- * maxId = min(maxId, id);
235
- * }
236
- * print('minimum id = ' + minId + ', maximum id = ' + maxId);
272
+ * maxId = max(maxId, id);
273
+ * }
274
+ *
275
+ * let result = 'minimum id = ' + minId + ', maximum id = ' + maxId;
276
+ *
277
+ * // Set text properties and display the result on the canvas
278
+ * fill(0); // Set text color to black
279
+ * textSize(12); // Set text size
280
+ * text(result, 10, 50);
281
+ *
237
282
* describe('no image displayed');
238
283
* }
239
- * </code></div>
284
+ * </code>
285
+ * </div>
240
286
*/
241
287
getNum ( column ) {
242
288
let ret ;
@@ -263,35 +309,38 @@ class TableRow {
263
309
* ID (number)
264
310
* @return {String } String
265
311
* @example
266
- * <div class="norender"><code>
267
- * // Given the CSV file "mammals.csv" in the project's "assets" folder:
268
- * //
269
- * // id,species,name
270
- * // 0,Capra hircus,Goat
271
- * // 1,Panthera pardus,Leopard
272
- * // 2,Equus zebra,Zebra
273
- *
312
+ * <div>
313
+ * <code>
274
314
* let table;
275
315
*
276
316
* async function setup() {
277
- * // The table is comma separated value "csv"
278
- * // and has a header specifying the columns labels.
279
- * table = await loadTable('assets/mammals.csv', 'csv', 'header');
317
+ * // Create a 200x100 canvas and set a white background
318
+ * createCanvas(200, 100);
319
+ * background(255);
320
+ *
321
+ * // Load the CSV file with a header row
322
+ * table = await loadTable('assets/mammals.csv', ',', 'header');
280
323
*
281
324
* let rows = table.getRows();
282
325
* let longest = '';
283
326
* for (let r = 0; r < rows.length; r++) {
284
- * let species = rows[r].getString('species');
285
- * if (longest.length < species.length) {
327
+ * let species = rows[r].getString('species');
328
+ * if (longest.length < species.length) {
286
329
* longest = species;
287
330
* }
288
331
* }
289
332
*
290
- * print('longest: ' + longest);
333
+ * let result = 'longest: ' + longest;
334
+ *
335
+ * // Set text properties and display the result on the canvas
336
+ * fill(0); // Set text color to black
337
+ * textSize(12); // Set text size
338
+ * text(result, 30, 50);
291
339
*
292
340
* describe('no image displayed');
293
341
* }
294
- * </code></div>
342
+ * </code>
343
+ * </div>
295
344
*/
296
345
getString ( column ) {
297
346
if ( typeof column === 'string' ) {
0 commit comments