From 261ec7dbda461dee5f84604bbc9a448aa4d36cb2 Mon Sep 17 00:00:00 2001 From: Daniel Shiffman Date: Fri, 31 May 2013 14:57:17 -0400 Subject: [PATCH] small fixes to data examples --- .../LoadSaveTable/LoadSaveTable.pde | 26 ++++++++++--------- .../Advanced Data/LoadSaveXML/LoadSaveXML.pde | 6 ++--- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/java/examples/Topics/Advanced Data/LoadSaveTable/LoadSaveTable.pde b/java/examples/Topics/Advanced Data/LoadSaveTable/LoadSaveTable.pde index e8fcc64ae..8f9efd440 100644 --- a/java/examples/Topics/Advanced Data/LoadSaveTable/LoadSaveTable.pde +++ b/java/examples/Topics/Advanced Data/LoadSaveTable/LoadSaveTable.pde @@ -8,13 +8,13 @@ * * Here is what the CSV looks like: * - x,y,diameter,name - 160,103,43.19838,Happy - 372,137,52.42526,Sad - 273,235,61.14072,Joyous - 121,179,44.758068,Melancholy + x,y,diameter,name + 160,103,43.19838,Happy + 372,137,52.42526,Sad + 273,235,61.14072,Joyous + 121,179,44.758068,Melancholy */ - + // An Array of Bubble objects Bubble[] bubbles; // A Table object @@ -41,7 +41,10 @@ void draw() { void loadData() { // Load CSV file into a Table object // "header" option indicates the file has a header row - table = loadTable("data.csv","header"); + table = loadTable("data.csv", "header"); + + TableRow r = table.getRow(2); + int val1 = r.getInt("y"); // The size of the array of Bubble objects is determined by the total number of rows in the CSV bubbles = new Bubble[table.getRowCount()]; @@ -57,8 +60,7 @@ void loadData() { // Make a Bubble object out of the data read bubbles[rowCount] = new Bubble(x, y, d, n); rowCount++; - } - + } } void mousePressed() { @@ -69,15 +71,15 @@ void mousePressed() { row.setFloat("y", mouseY); row.setFloat("diameter", random(40, 80)); row.setString("name", "Blah"); - + // If the table has more than 10 rows if (table.getRowCount() > 10) { // Delete the oldest row - table.removeRow(0); + table.removeRow(0); } // Writing the CSV back to the same file - saveTable(table,"data/data.csv"); + saveTable(table, "data/data.csv"); // And reloading it loadData(); } diff --git a/java/examples/Topics/Advanced Data/LoadSaveXML/LoadSaveXML.pde b/java/examples/Topics/Advanced Data/LoadSaveXML/LoadSaveXML.pde index 27ef12fdd..4a5b07b82 100644 --- a/java/examples/Topics/Advanced Data/LoadSaveXML/LoadSaveXML.pde +++ b/java/examples/Topics/Advanced Data/LoadSaveXML/LoadSaveXML.pde @@ -59,14 +59,14 @@ void loadData() { // The position element has two attributes: x and y XML positionElement = children[i].getChild("position"); - // Note how with attributes we can get an integer or float directly + // Note how with attributes we can get an integer or float via getInt() and getFloat() float x = positionElement.getInt("x"); float y = positionElement.getInt("y"); // The diameter is the content of the child named "diamater" XML diameterElement = children[i].getChild("diameter"); - // Note how with the content of an XML node, we retrieve as a String and then convert - float diameter = float(diameterElement.getContent()); + // Note how with the content of an XML node, we retrieve via getIntContent() and getFloatContent() + float diameter = diameterElement.getFloatContent(); // The label is the content of the child named "label" XML labelElement = children[i].getChild("label");