/* Matt Martell IAT 800 - Dr. Christopher Shaw Due Dec. 8, 2008 Final Project - Information Sources Dow Jones Indexes - http://www.djindexes.com Yahoo Finance - http://finance.yahoo.com Reuters - http://www.reuters.com/finance/stock Slider created thanks to tutorial from Johnny Rodgers. */ //import controlP5 library import controlP5.*; //initialize controls ControlP5 controller; Slider Slider1, Slider2; controlP5.Button resetButton, clearButton, mainButton, comparisonButton, returnsButton, comparablesButton, geButton, aaButton ; // need to specify that this is the ControlP5 library's button, not the built-in Button class of Processing ControlP5 controlP5; MultiList Rater; //initialize variables (make control variables public or they won't work online) public int pointSize; int pointSizeDefault = 7; public float anotherSliderVal; float zAIntensityDefault = 0; //Define Classes zoneAgreement zA = new zoneAgreement();//For zones of agreement callRaterXY cRXY = new callRaterXY(); //To populate scatter plot callReturns cRet = new callReturns(); gridlines gl = new gridlines(); //Put the frame of the graph in place legend leg = new legend(); // Legend to define colors of dots LabelsPg1 LPg1 = new LabelsPg1(); //Labels for comparision axis's LabelsPg2 LPg2 = new LabelsPg2(); //Labels for returns axis's main main = new main(); //Main Page XYaxis XYaxis = new XYaxis(); //for call boxes in scatter plot Setup Setup = new Setup(); // Setup for pg 3 Comparables Compare Compare = new Compare(); // Information used to populate page 3 Comparables void setup (){ smooth(); size (800,700); //instantiate control object controller = new ControlP5(this); //set parameters for all control objects controller.setColorLabel(0); //add controls to canvas with labels (default label will be name of variable) Slider1 = controller.addSlider("pointSize", 1, 12, pointSizeDefault, 20, 610, 100, 20); Slider1.setLabel("Point Size"); Slider2 = controller.addSlider("zAIntensity", -1.0, 1.0, zAIntensityDefault, 20, 640, 100, 20); Slider2.setLabel("Color Intensity"); resetButton = controller.addButton("reset", 0, 540, 515, 31, 20); clearButton = controller.addButton("clear", 0, 575, 515, 31, 20); mainButton = controller.addButton("Main", 0, 650, 310, 100, 50); comparisonButton = controller.addButton("Comparison", 1, 650, 370, 100, 50); returnsButton = controller.addButton("Returns", 2, 650, 430, 100, 50); comparablesButton = controller.addButton("Comparables", 3, 650, 490, 100, 50); XYaxis.drawMe(); //Draw Call boxes for pg 1 lines = loadStrings( "data.txt" ); // Column Labels 1: 2: 3: 4: 5: 6: 7: 8: 9: 10: n = lines.length; // n = number of lines in text file xArr = new float[n] ; yArr = new float[n] ; colorArr = new float[n] ; lines2 = loadStrings( "index.txt" ); // Column Labels 0:Date 1:DJA label 2:DJA Value 3:Date Code(month) 4:DJA (100) 5: DJA Color (8) // 6:Trans label 7:Trans (100) 8: Trans Color (1) 9:Fin label 10:Fin (100) 11: Fin Color (2) // 12:Ind label 13:Ind (100) 14: Ind Color (3) 15:congd label 16:congd (100) 17: congd Color (4) // 18:util label 19:util (100) 20: util Color (5) 21:comm label 22:comm (100) 23: comm Color (6) // 24:comp label 25:comp (100) 26: comp Color (7) n2 = lines2.length; // n = number of lines in text file mArr = new float[n2] ; nArr = new float[n2] ; n1Arr = new float[n2] ; n2Arr = new float[n2] ; n3Arr = new float[n2] ; n5Arr = new float[n2] ; n6Arr = new float[n2] ; colorArr2 = new float[n2] ; } //________________________________________________________________________________________________________________ void Buttons(){ if (pg==1){ XYaxis.drawMe(); //Draw Call boxes for pg 1 } } //Variables // Define Averages to set bottom 25%, middle 50%, top 25% // Numbers comes from original excel file using rank cut off's float btmAvgX = .45; float btmAvgY = .40; float topAvgX = .65; float topAvgY = .65; // Definintion of variables to turn bottom, middle, top into boundary points float btmX; float btmY; float topX; float topY; // Color definitions color trans = color (255,0,0); // red color fin = color(255,204,0); // yellow color ind = color (0,255,0); // bright green color congd = color (30,144,255); // blue color util = color(205,127,50); // brown color comm = color (0,100,0); // dark green color comp = color (153,50,204); // purple color idx = color (0,0,0); // black // Define Variables for use in calling data from text file int n; // n = number of lines in text file int n2; // n2 = number of lines in index text file float xArr[] ; float yArr[] ; float colorArr[] = new float[n] ; float mArr[] ; float nArr[] ; float n1Arr[]; float n2Arr[]; float n3Arr[]; float n5Arr[]; float n6Arr[]; float colorArr2[] = new float[n2] ; int rX = 3; //Used to define rater from pull down menu for x Axis int rY = 5; //Used to define rater from pull down menu for Y Axis int rC = 1; //Used to define rater from pull down menu for Comparables String labelX; String labelY; String lines[]; String lines2[]; float xAxis; float yAxis; float CI50; // Variable for changing color intensity of labels // Define size of program area int m = 75; // size of margin for text and reference points int wAlt = 500; //width of graph int hAlt = 500; //height of graph int a = hAlt+m; int b = wAlt+m; // Define variables for main screen float pg = 0; //Define variables for pg 3 Comparables float QBtm = (237); float PEBeg = (100); //Begining X-point P/E Bar float DivYBeg = (220); //Begining X-point div Yield Bar float DivGBeg = (380); //Begining X-point div Growth Bar float SalGBeg = (520); //Begining X-point Sales Growth Bar //__________________________________________________________________________________________________________________ void draw (){ background (255,255,255); //Function to turn percentage into boundary points "m" adjusts for margin btmX = btmAvgX*wAlt+m; btmY = btmAvgY*hAlt-m; topX = topAvgX*wAlt+m; topY = topAvgY*hAlt-m; if (pg == 0){ background (255,255,255); main.drawMe(); } if (pg == 1){ background (255,255,255); // zA.drawMe(); //Draw Zones of agreement gl.drawMe(); //Draw gridlines cRXY.drawMe(); //Draw Rater XY points leg.drawMe(); //Draw Legend LPg1.drawMe(); //Draw Labels } if (pg == 2){ background (255,255,255); gl.drawMe(); //Draw gridlines leg.drawMe(); //Draw Legend cRet.drawMe(); //Draw index returns LPg2.drawMe(); //Draw Labels } if (pg == 3){ background (255,255,255); Setup.drawMe(); Compare.drawMe(); } //label the buttons for each window PFont font2; font2 = loadFont("ArialMT.vlw"); textFont(font2); stroke (0); fill(0); text("|------------ Display ------------|", 20, 600); text("|--------------- Comparison ---------------|", 219, 600); text("| Comparables |", 534, 600); } // prints out current value of exampleSliderVal variable void exampleSliderVal() { println("sliderVal set to " + Slider1.value()); } // To bring up the different pages using the buttons void Main(){ println("Main called"); pg = 0; } void Comparison(){ println("comparison called"); pg = 1; } void Returns(){ println("returns called"); pg = 2; } void Comparables(){ println("comparables called"); pg = 3; } //reset sets sliders to their original values void reset() { println("reset called"); Slider1.setValue(pointSizeDefault); Slider2.setValue(zAIntensityDefault); rX = 3; rY = 5; n = lines.length; n2 = lines2.length; pg = 0; } //reset sets sliders to their original values void clear() { println("clear called"); n = 0; n2 = 0; } //Key activation of List Menu void keyPressed() { if(controlP5.controller("level23")!=null) { println("removing multilist button level23."); controlP5.controller("level23").remove(); } } void controlEvent(ControlEvent theEvent) { println(theEvent.controller().name()+" = "+theEvent.value()); if (theEvent.value() == 10) { rX=5; } if (theEvent.value() == 11){ rX=3; } if (theEvent.value() == 12){ rX=4; } if (theEvent.value() == 20) { rY=5; } if (theEvent.value() == 21){ rY=3; } if (theEvent.value() == 22){ rY=4; } if (theEvent.value() == 50){ rC=1; } if (theEvent.value() == 51){ rC=2; } } //_______________________________________________________________________________ class main { void drawMe(){ // Draw gridlines, data labels and legend PFont font; font = loadFont("Graph.vlw"); textFont(font); //background (255,255,255); strokeWeight (1); stroke ( 0, 0, 0,CI50); fill(0); text("Please select a button from the far right", m+25, 250); } } //_______________________________________________________________________________ class LabelsPg1 { void drawMe(){ CI50 = (50 + 50*Slider2.value()); // Draw gridlines, data labels and legend PFont font; font = loadFont("Graph.vlw"); textFont(font); // X-Axis labels and reference points if (rX == 3){ strokeWeight (1); stroke ( 0, 0, 0,CI50); line (wAlt*2/3+m,0,wAlt*2/3+m,hAlt); line (wAlt*1/3+m,0,wAlt*1/3+m,hAlt); fill(0, 102, 153, CI50); text("-33%", wAlt*1/3+m-7, hAlt+25); text("0%", wAlt*2/3+m-7, hAlt+25); labelX = "YoY Returns"; stroke (0,0,0); strokeWeight (2); line (210+m,0,210+m,hAlt); //Mark DJA performance } if (rX == 4){ strokeWeight (1); stroke ( 0, 0, 0,CI50); fill(0, 102, 153, CI50); text("25", m+25, hAlt+25); text("50", m+50, hAlt+25); text("200", m+200, hAlt+25); labelX = "Market Cap ($billion)"; } if (rX == 5){ strokeWeight (1); stroke ( 0, 0, 0,CI50); fill(0, 102, 153, CI50); text("1%", m+50, hAlt+25); text("4%", m+200, hAlt+25); text("7%", m+350, hAlt+25); labelX = "Market Cap as % DJA"; } // Y-Axis labels and reference points if (rY == 3){ strokeWeight (1); stroke ( 0, 0, 0,CI50); line (m,hAlt*1/3,wAlt+m,hAlt*1/3); line (m,hAlt*2/3,wAlt+m,hAlt*2/3); fill(0, 102, 153, CI50); text("-33%", 30, hAlt*2/3+6); text("0%", 30, hAlt*1/3+6); labelY = "YoY Returns"; stroke (0,0,0); strokeWeight (2); line (m,hAlt - 210,wAlt+m,hAlt - 210); //Mark DJA performance } if (rY == 4){ strokeWeight (1); stroke ( 0, 0, 0,CI50); // line (m,hAlt*1/3,wAlt+m,hAlt*1/3); // line (m,hAlt*2/3,wAlt+m,hAlt*2/3); fill(0, 102, 153, CI50); text("25", 30, hAlt-25+6); text("50", 30, hAlt-50+6); text("200", 30, hAlt-200+6); labelY = "Market Cap ($billion)"; } if (rY == 5){ strokeWeight (1); stroke ( 0, 0, 0,CI50); fill(0, 102, 153, CI50); text("1%", 30, hAlt-50); text("4%", 30, hAlt-200); text("7%", 30, hAlt-350); labelY = "Market Cap as % DJA"; } fill(0, 102, 153, 85); text(labelX, wAlt*1/2+m-40, hAlt+45); pushMatrix(); rotate (-PI*1/2); text(labelY, -350, hAlt*1/18); popMatrix(); } } //__________________________________________________________________________ class XYaxis { void drawMe(){ //Choose Variable for x axis Rater = controller.addMultiList("myListX",220,610,75,12); MultiListButton x; x = Rater.add("X Axis",1); x.add("Market Cap 1x",10).setLabel("% Market Cap"); x.add("Returns 2x",11).setLabel("YoY Returns"); x.add("$ Market Cap 3x",12).setLabel("$ Market Cap"); //Choose Variable for y axis Rater = controller.addMultiList("myListY",380,610,75,12); MultiListButton y; y = Rater.add("Y Axis",1); y.add("Market Cap 1y",20).setLabel("Market Cap"); y.add("Returns 2y",21).setLabel("Returns"); y.add("$ Market Cap",22).setLabel("$ Market Cap"); //Companies for comparisons Rater = controller.addMultiList("myListC",540,610,85,12); MultiListButton c; c = Rater.add("Companies",1); c.add("GE",50).setLabel("General Electric"); c.add("AA",51).setLabel("Alcoa"); } } //_______________________________________________________________________________ class LabelsPg2 { void drawMe(){ CI50 = (50 + 50*Slider2.value()); // Draw gridlines, data labels and legend PFont font; font = loadFont("Graph.vlw"); textFont(font); // X-Axis labels and reference points strokeWeight (1); stroke ( 0, 0, 0,CI50); fill(0, 102, 153,CI50 ); text("Sept", m, hAlt+25); text("Dec", 95+m, hAlt+25); line (95+m, 0,95+m,hAlt); text("Mar", 190+m, hAlt+25); line (190+m, 0,190+m,hAlt); text("Jun", 285+m, hAlt+25); line (285+m, 0,285+m,hAlt); text("Sept", 380+m, hAlt+25); line (380+m, 0,380+m,hAlt); labelX = "Month"; strokeWeight (1); line (m,hAlt-400,wAlt+m,hAlt-400); stroke ( 0, 0, 0,CI50); fill(0, 102, 153, CI50); text("100", 30, hAlt-393); labelY = "Returns (Aug 31, 2007 = 100)"; fill(0, 102, 153,85); text(labelX, wAlt*1/2+m-40, hAlt+45); pushMatrix(); rotate (-PI*1/2); text(labelY, -350, hAlt*1/18); popMatrix(); } } //______________________________________________________________________________ class gridlines { void drawMe(){ // Frame for ScatterPlot strokeWeight (2); stroke (0,0,0); line(m,0,m,hAlt); line(m,hAlt,wAlt+m,hAlt); } } //_______________________________________________________________________________ class legend { void drawMe(){ // Draw gridlines, data labels and legend PFont font; font = loadFont("Graph.vlw"); textFont(font); //Legend strokeWeight (1); fill(0); text("Legend", 615, 25); fill(trans); ellipse (605,45, 10,10); text("Transportation", 615, 55); fill(fin); ellipse (605,65, 10,10); text("Financial", 615, 75); fill(ind); ellipse (605,85, 10,10); text("Industrial", 615, 95); fill(congd); ellipse (605,105,10,10); text("Consumer Goods", 615, 115); fill(util); ellipse (605,125, 10,10); text("Utilities", 615, 135); fill(comm); ellipse (605,145, 10,10); text("Communications", 615, 155); fill(comp); ellipse (605,165, 10,10); text("Computers", 615, 175); fill(idx); ellipse (605,185, 10,10); text("Index", 615, 195); } } //__________________________________________________________________________ class zoneAgreement { void drawMe(){ // Draw the boxes for zones of agreement stroke ( 40, 50, 200,5 ); float intB = (53+53*Slider2.value()); color btmZone = color(255,0,0,intB); // lower percentage (red) fill (btmZone); rect (m,hAlt-btmY-m, btmX-m,btmY+m); float intM =(33+33*Slider2.value()); color midZone = color(255,204,0,intM); // middle percentage (yellow) fill (midZone); rect (btmX,hAlt-topY-m,topX-btmX,topY-btmY); float intT =(30+30*Slider2.value()); color topZone = color(0,255,0,intT); // upper percentage (green) fill (topZone); rect(topX,0,wAlt-topY-m,hAlt-topY-m); } } //_______________________________________________________________________________ class callRaterXY{ void drawMe(){ // Call information from text file (only pulling first 3 variables) average and // Code adapted from IAT 355 class example using some help from Allen float xArr[] = new float[n] ; for (int i=0; i < n && i < lines.length ; i++ ) { float[] numbers = float( split( lines[i], "," ) ); for( int j = 0 ; j < numbers.length ; j++ ) { xArr[i] = numbers[rX] ; yArr[i] = numbers[rY] ; if( j == 7 ) { colorArr[i] = numbers[j] ; } } } // Posting elipses to the spreadsheet stroke( 40, 50, 200,75 ); strokeWeight (1); for (int i=0; i