import de.bezier.data.sql.*; // function to demonstrate animations, // Initially without smoothing // or interpolation // Uncommenting the commented code will activate Ben Frys integrator int mCount=0; int MaxScale =0; MySQL msql; int [][] Veg2009 = new int[6][12]; float plotX1, plotY1; float plotX2, plotY2; float labelX, labelY; String [] Veglabel = {"Bean","Carrot","Lemon","Potato","Pumpkin","Tomato"}; String [] Months = {"January","February","March","April","May","June","July","August","September","October","November","December"}; PFont font; int [] SixValues = new int[6]; //Integrator[] SmoothBars; float prevMillis; void setup() { size(900,300); font = loadFont("UniversLTStd-Cn-14.vlw"); // connecting to the database String user = "mat259"; String pass = "V1sual1zat1on"; String database = "spl_all"; String TheQuery =""; String TextToSearch =""; String TheFile = "2009Monthly.txt"; String lines[] = loadStrings(TheFile); msql = new MySQL( this, "tango.mat.ucsb.edu", database, user, pass ); if ( msql.connect() ) { for(int t =0; t<6;t++){ for (int k =0 ; k < 12; k++){ TheQuery="SELECT count(*) FROM transactionsallID WHERE id BETWEEN " + lines[2*k] + " and " + lines[2*k+1] ; TheQuery+= " and (title like '%" + Veglabel[t] + "%')"; msql.query( TheQuery); msql.next(); Veg2009[t][k]= msql.getInt(1); // Saving the Maximum if (Veg2009[t][k] > MaxScale){ MaxScale = Veg2009[t][k]; } println(k + " " + Veglabel[t]+ " " + msql.getInt(1)); } } } else { println(" connection failed "); } plotX1 = 30; plotX2 = width - 30; labelX = 20; plotY1 = 30; plotY2 = height - 60; labelY = height - 20; frameRate(20); //SmoothBars = new Integrator[6]; // //for(int t =0; t<6;t++){ // SmoothBars[t] = new Integrator(Veg2009[t][0],.5,.2); // .5,1.0 .1,1.0 // SmoothBars[t].target(Veg2009[t][1]); //} prevMillis = millis(); mCount=1; } void draw(){ float m = millis(); if (m -prevMillis>=800){ mCount++; // incrementing the month counter mCount%=12; // getting the modulus for(int t=0;t<6;t++){ // SmoothBars[t].target(Veg2009[t][mCount]) ; SixValues[t] = Veg2009[t][mCount]; } prevMillis = m; } // for(int t=0;t<6;t++){ // SmoothBars[t].update(); // SixValues[t] =(int)SmoothBars[t].value; // } drawBar(); } void drawBar(){ float Hside; float Vside; background(230); strokeWeight(1); Hside = (plotX2-plotX1)/6; Vside = (plotY2-plotY1); fill(160); stroke(0); //The total for (int t =0;t<6;t++){ float NewHeigh = map(SixValues[t],0,MaxScale,0,Vside); rect(plotX1+t*Hside, plotY2-NewHeigh,floor(Hside*.95),NewHeigh); } // Labeling textFont(font); fill(128); for (int t =0;t<6;t++){ textAlign(CENTER,CENTER); text(Veglabel[t],plotX1 + Hside*(t+.5),plotY2+20); } for (int k =0;k<12;k++){ textAlign(CENTER,CENTER); if (mCount==k){ fill(50); } else{ fill(160); } text(Months[k],plotX1 + (plotX2-plotX1)/12*(k+.5),plotY2+40); } }