Changeset 1452

Show
Ignore:
Timestamp:
11/04/08 07:51:37 (2 months ago)
Author:
amostafa
Message:
 
Location:
branches/dev-brotecs-refactor/org.javarosa.polish.chatterbox.extensions/src/org/javarosa/formmanager/view/chatterbox/widget/chart
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • branches/dev-brotecs-refactor/org.javarosa.polish.chatterbox.extensions/src/org/javarosa/formmanager/view/chatterbox/widget/chart/CurrentTemplate.java

    r1253 r1452  
    3333         * @see org.javarosa.formmanager.view.chatterbox.widget.chart.IGraphTemplate#getDataPoints() 
    3434         */ 
    35         public Vector getLines(Vector data) { 
     35        public Vector getLines(Vector data,LineChart chart) { 
    3636 
    3737                Vector lines = new Vector(); 
  • branches/dev-brotecs-refactor/org.javarosa.polish.chatterbox.extensions/src/org/javarosa/formmanager/view/chatterbox/widget/chart/IGraphTemplate.java

    r971 r1452  
    55public interface IGraphTemplate { 
    66         
     7 
    78        /** 
    89         * @return The internal ID used to identify the template 
     
    2324         * lines for the template. 
    2425         */ 
    25         Vector getLines(Vector data); 
     26        Vector getLines(Vector data,LineChart chart); 
     27        //public void setIsUseTemplate(boolean isUseTemplate); 
     28        //public boolean getIsUseTemplate(); 
    2629} 
  • branches/dev-brotecs-refactor/org.javarosa.polish.chatterbox.extensions/src/org/javarosa/formmanager/view/chatterbox/widget/chart/LineChart.java

    r1252 r1452  
    5050 
    5151    private boolean isDefaultColor; 
    52  
     52     
     53    private boolean defaulttemplate;//brotecs 
     54    private int templatemarginOne;//brotecs 
     55    private int templatexScaleFactor;//brotecs 
     56     
    5357    public LineChart(String label, Style style) { 
    5458        super(label,style); 
     
    5963            pointsVector.addElement(currentPointVector); 
    6064            yScaleFactor = 100; 
    61             xScaleFactor = 25; 
     65            xScaleFactor = 26; 
    6266            isDrawAxis = true; 
    6367            marginOne = 1; 
     
    7579            shadowColorThree = 100; 
    7680            font = Font.getDefaultFont(); 
     81            defaulttemplate=false;//brotecs 
     82            templatemarginOne=36;//brotecs 
     83            templatexScaleFactor=13;//brotecs 
    7784           // System.out.println("Brotecs::LineChart->LineChart(String label, Style style)"); 
    7885    } 
     
    153160            g1.setColor(0, 0, 0); 
    154161            g1.drawLine(marginOne, this.height - marginFour, marginOne + width, this.height - marginFour); 
     162            //System.out.println("Line 1->X1:"+marginOne+" Y1:"+(this.height - marginFour)+" X2:"+(marginOne+width)+" Y2:"+(this.height - marginFour)); 
    155163            g1.drawLine(marginOne, this.height - marginFour, marginOne, this.height - marginFour - height); 
    156             
     164            //System.out.println("Line 2->X1:"+marginOne+" Y1:"+(this.height - marginFour)+" X2:"+marginOne+" Y2:"+(this.height - marginFour - height)); 
     165             
    157166        } 
    158167    } 
     
    293302            for(int i = 0; i <= height; i += 10) { 
    294303                int j1 = this.height - fontSpaceHeight - i; 
     304                //System.out.println("Brotecs::LineChart->marginOne:"+marginOne+"j1:"+j1+"marginOne-2"+(marginOne-2)); 
    295305                g.drawLine(marginOne, j1, marginOne - 2, j1); //draw Y axis "-"  
    296306                int point = (yScaleFactor * i) / height; 
     
    306316            } 
    307317        } 
     318 
    308319        Enumeration en = pointsVector.elements(); 
    309320        while(en.hasMoreElements()) { 
     
    314325    
    315326   public void drawLine(Graphics g, Vector pointVector) { 
    316  
     327           //System.out.println("Brotecs::LineChart->drawLine:pointVector.size()="+pointVector.size()); 
    317328       pointVector.size(); 
    318329       int count = -1; 
     
    345356            
    346357           int pointY2 = this.height - fontSpaceHeight - (height * b1.yCordPt) / (yScaleFactor); 
    347            //System.out.println("Brotecs::LineChart->drawLine:"+height+" * " +  b1.yCordPt + " / "+yScaleFactor); 
    348            int pointX2 = marginOne + (width * b1.xCordPt) / (xScaleFactor * scaleFactor); 
     358            
     359           //System.out.println("Brotecs::pointY2->this.height:"+this.height +"- fontSpaceHeight:"+fontSpaceHeight+" - (height:"+height+" * b1.yCordPt:" +  b1.yCordPt + ") / yScaleFactor:"+yScaleFactor); 
     360           //int pointX2 = marginOne + (width * b1.xCordPt) / (xScaleFactor * scaleFactor); 
     361           /************Brotecs*************/ 
     362           int pointX2; 
     363           if(defaulttemplate){// 
     364                   pointX2 = marginOne + (width * b1.xCordPt) / (templatexScaleFactor * scaleFactor); 
     365           } 
     366           else 
     367           { 
     368                   pointX2 = marginOne + (width * b1.xCordPt) / (xScaleFactor * scaleFactor); 
     369           } 
     370            
     371          // System.out.println("Brotecs::pointX2->marginOne:"+marginOne+"+(width:"+width+"* b1.xCordPt:"+b1.xCordPt+") / (xScaleFactor:"+xScaleFactor+"* scaleFactor:"+scaleFactor+")"); 
     372           /************Brotecs*************/ 
    349373           //System.out.println("pointX1 ==  " + pointX1 + " pointY1 == " + pointY1 + " pointX2 == " + pointX2 + " pointY2 == " + pointY2); 
    350374            
    351375           if(count > -1) { 
    352376               g.drawLine(pointX1, pointY1, pointX2, pointY2); 
     377               //System.out.println("Brotecs::LineChart->pointX1:"+pointX1+" pointY1:"+pointY1+" pointX2:"+pointX2+" pointY2:"+pointY2); 
    353378           } 
    354379           pointX1 = pointX2; 
    355380           pointY1 = pointY2; 
    356381           if(isMarginTwoTrue) { 
    357                g.setColor(0, 0, 0); 
    358                if((count + 1) % ticker == 0) { 
    359                    //g.drawLine(pointX2, this.height - fontSpaceHeight, pointX2, (this.height - fontSpaceHeight) + 2); 
    360                } 
    361                pointLabelWidth = font.stringWidth(b1.labelX); 
    362                if(isLabelXTrue && (count + 1) % (equalCoordTicker * ticker) == 0) { 
    363                    g.drawString(b1.labelX, pointX2 - pointLabelWidth / 2, (this.height - fontSpaceHeight) + 1, 20); 
    364    
    365                } 
     382                   g.setColor(0, 0, 0); 
     383                   /************Brotecs*************/ 
     384                   if(defaulttemplate){ 
     385                           for(int i=1;i<5;i++){ 
     386                           g.drawLine(marginOne+(templatemarginOne*i), this.height - fontSpaceHeight, marginOne+(templatemarginOne*i), (this.height - fontSpaceHeight) + 3); 
     387                           g.drawString(i+" Year", marginOne+(templatemarginOne*i), (this.height - fontSpaceHeight) + 4, 20); 
     388                           } 
     389                   }/********Brotecs**********/ 
     390                   else{ 
     391                       if((count + 1) % ticker == 0) { 
     392                           //g.drawLine(pointX2, this.height - fontSpaceHeight, pointX2, (this.height - fontSpaceHeight) + 4); 
     393                            
     394                       } 
     395                       pointLabelWidth = font.stringWidth(b1.labelX); 
     396                       if(isLabelXTrue && (count + 1) % (equalCoordTicker * ticker) == 0) { 
     397                           //g.drawString(b1.labelX, pointX2 - pointLabelWidth / 2, (this.height - fontSpaceHeight) + 1, 20); 
     398           
     399                       } 
     400                   } 
    366401           } 
    367402       } while(true); 
     
    461496    } 
    462497     
     498    public void defaulttemplate(boolean defaulttemplate) { 
     499        this.defaulttemplate = defaulttemplate; 
     500    } 
     501    public boolean getdefaulttemplate() 
     502    { 
     503        return defaulttemplate; 
     504    } 
    463505} 
  • branches/dev-brotecs-refactor/org.javarosa.polish.chatterbox.extensions/src/org/javarosa/formmanager/view/chatterbox/widget/chart/WHOWeightTemplate.java

    r1252 r1452  
    11package org.javarosa.formmanager.view.chatterbox.widget.chart; 
    2  
     2import java.util.Calendar; 
     3import java.util.Date; 
    34import java.util.Vector; 
    45 
     
    4546         * @see org.javarosa.formmanager.view.chatterbox.widget.chart.IGraphTemplate#getDataPoints() 
    4647         */ 
    47         public Vector getLines(Vector data) { 
     48        public Vector getLines(Vector data,LineChart chart) { 
    4849                //This function will give a number of days. We can use it to scale record dates  
    49                 //DateUtils.getApproxDaysDifference(earlierDate, laterDate) 
     50                //DateUtils.getApproxDaysDifference(earlierDate, laterDate); 
    5051                 
    5152                //TODO: Scale X axis from 0 to 5 years. Display the data from the website 
    5253                Vector lines = new Vector(); 
    53                 Vector points1 = new Vector(); 
     54                Vector points1 = new Vector();/*Brotecs*/ 
    5455                Vector points2 = new Vector(); 
    5556                Vector points3 = new Vector(); 
    5657                 
    57                 lines.addElement(points1); 
    58                 lines.addElement(points3); 
     58                lines.addElement(points1);/*Brotecs*/ 
     59                lines.addElement(points3);/*Brotecs*/ 
    5960                lines.addElement(points2); 
     61                 
     62 
    6063         
    61         int [] chartX1PointsArray = {12, 20, 30, 40, 50, 60, 70, 80, 90}; 
    62         int [] chartY1PointsArray = {10, 10, 10, 10, 10, 10, 10, 10, 10}; 
     64        Date birthdate=patient.getBirthDate(); 
     65         
     66        Date today=new Date(); 
     67        Calendar calendar = Calendar.getInstance(); 
     68                calendar.setTime(today); 
     69                int thisYear = calendar.get(Calendar.YEAR); 
     70                System.out.println("towhid::::WHOWeightTemplate:thisYear="+thisYear); 
     71                calendar.setTime(birthdate); 
     72                int birthYear = calendar.get(Calendar.YEAR); 
     73                System.out.println("towhid::::WHOWeightTemplate:birthYear="+birthYear); 
    6374                 
    64                 int [] chartX2PointsArray = {15, 20, 30, 35, 45, 55, 68, 79, 90}; 
    65         int [] chartY2PointsArray = {2, 8, 16, 32, 48, 55, 64, 70, 80}; 
    66          
    67         int [] chartX3PointsArray = {10, 10, 10, 10, 10, 10, 10, 10, 10}; 
    68         int [] chartY3PointsArray = {15, 20, 30, 40, 50, 60, 70, 80, 90}; 
    69          
    70         for(int i = 0; i < chartX2PointsArray.length; i++) { 
    71                 points2.addElement(new LinePointsItem("", chartX2PointsArray[i], chartY2PointsArray[i], 0,  255,   255)); 
    72         } 
    73  
    74         for(int i = 0; i < chartX1PointsArray.length; i++) { 
    75                 points1.addElement(new LinePointsItem("", chartX1PointsArray[i], chartY1PointsArray[i], 255,  0,   255)); 
    76         } 
    77  
    78         for(int i = 0; i < chartX3PointsArray.length; i++) { 
    79                 points3.addElement(new LinePointsItem("", chartX3PointsArray[i], chartY3PointsArray[i], 0,  0,   0)); 
    80         } 
     75                int diff_year = thisYear-birthYear; 
     76                System.out.println("towhid::::WHOWeightTemplate:diff_year="+diff_year); 
     77                if(diff_year<5){ 
     78                        if(patient.getGender()==patient.SEX_MALE){ 
     79                                 
     80                                int [] chartY1PointsArray = {5, 6, 8, 12, 13, 15, 17, 19, 23}; 
     81                        int [] chartX1PointsArray = {0, 1, 2, 12, 16, 23, 31, 39, 60}; 
     82                                 
     83                                int [] chartX2PointsArray = {3, 5, 9, 10, 11, 13, 15, 17, 18}; 
     84                        int [] chartY2PointsArray = {0, 2, 10, 14, 18, 28, 40, 52, 56}; 
     85                         
     86                        int [] chartX3PointsArray = {2, 4, 5, 8, 9, 10, 11, 12, 14}; 
     87                        int [] chartY3PointsArray = {0, 2, 4, 11, 20, 26, 34, 42, 58}; 
     88                         
     89                                System.out.println("towhid::::WHOWeightTemplate:Gender=MALE");        
     90                        for(int i = 0; i < chartX2PointsArray.length; i++) { 
     91                                points2.addElement(new LinePointsItem("", chartX2PointsArray[i], chartY2PointsArray[i], 0,  255, 255)); 
     92                        } 
     93                 
     94                        for(int i = 0; i < chartX1PointsArray.length; i++) { 
     95                                points1.addElement(new LinePointsItem("", chartY1PointsArray[i], chartX1PointsArray[i], 255, 0 , 255)); 
     96                        } 
     97                 
     98                        for(int i = 0; i < chartX3PointsArray.length; i++) { 
     99                                points3.addElement(new LinePointsItem("", chartX3PointsArray[i], chartY3PointsArray[i], 255, 0, 255)); 
     100                        } 
     101                        //this.isUseTemplate=true; 
     102                        chart.defaulttemplate(true); 
     103                        chart.setMaxYScaleFactor(30); 
     104                        } 
     105                        else if(patient.getGender()==patient.SEX_FEMALE) 
     106                        { 
     107                                int [] chartY1PointsArray = {4, 6, 9, 12, 13, 14, 19, 22, 25}; 
     108                        int [] chartX1PointsArray = {0, 1, 5, 14, 16, 19, 39, 50, 60}; 
     109                                 
     110                                int [] chartY2PointsArray = {3, 5, 7,  9, 11, 13, 15, 17, 18}; 
     111                        int [] chartX2PointsArray = {0, 2, 5, 12, 20, 31, 42, 55, 59}; 
     112                         
     113                        int [] chartY3PointsArray = {2, 4, 5, 7, 8, 9, 10, 13, 14}; 
     114                        int [] chartX3PointsArray = {0, 2, 4, 12, 17, 24, 30, 53, 59}; 
     115                         
     116                                System.out.println("towhid::::WHOWeightTemplate:Gender=FEMALE"); 
     117                                for(int i = 0; i < chartX3PointsArray.length; i++) { 
     118                                points3.addElement(new LinePointsItem("", chartY3PointsArray[i], chartX3PointsArray[i], 0,  255, 255)); 
     119                        } 
     120                                for(int i = 0; i < chartX1PointsArray.length; i++) { 
     121                                points1.addElement(new LinePointsItem("", chartY1PointsArray[i], chartX1PointsArray[i], 255,  0, 255)); 
     122                        } 
     123                                for(int i = 0; i < chartX2PointsArray.length; i++) { 
     124                                points2.addElement(new LinePointsItem("", chartY2PointsArray[i], chartX2PointsArray[i], 255,  0, 255)); 
     125                            } 
     126                                //this.isUseTemplate=true; 
     127                        chart.defaulttemplate(true); 
     128                        chart.setMaxYScaleFactor(30); 
     129                        }/**************UNKNOWN************* 
     130                        else 
     131                        { 
     132                                int [] chartX1PointsArray = {5, 6, 8, 12, 13, 15, 17, 19, 23}; 
     133                        int [] chartY1PointsArray = {0, 1, 2, 12, 16, 23, 31, 39, 60}; 
     134                                 
     135                                int [] chartX2PointsArray = {3, 5, 9, 10, 11, 13, 15, 17, 18}; 
     136                        int [] chartY2PointsArray = {0, 2, 10, 14, 18, 28, 40, 52, 56}; 
     137                         
     138                        int [] chartX3PointsArray = {2, 4, 5, 8, 9, 10, 11, 12, 14}; 
     139                        int [] chartY3PointsArray = {0, 2, 4, 11, 20, 26, 34, 42, 58}; 
     140                         
     141                                System.out.println("towhid::::WHOWeightTemplate:Gender=UNKNOWN"); 
     142                                for(int i = 0; i < chartX3PointsArray.length; i++) { 
     143                                points3.addElement(new LinePointsItem("", chartX3PointsArray[i], chartY3PointsArray[i], 255,  0,   255)); 
     144                        } 
     145                                for(int i = 0; i < chartX1PointsArray.length; i++) { 
     146                                points1.addElement(new LinePointsItem("", chartX1PointsArray[i], chartY1PointsArray[i], 255,  0,   255)); 
     147                        } 
     148                                for(int i = 0; i < chartX2PointsArray.length; i++) { 
     149                                points2.addElement(new LinePointsItem("", chartX2PointsArray[i], chartY2PointsArray[i], 255,  0,   255)); 
     150                            } 
     151                        }/**************************/ 
     152                         
     153                } 
     154                else 
     155                { 
     156                        this.isUseTemplate=false; 
     157                        chart.defaulttemplate(false); 
     158                chart.setMaxYScaleFactor(100); 
     159                } 
     160                         
    81161                return lines; 
    82162        } 
     
    88168                this.patient = patient; 
    89169        } 
    90         /*************Brotecs:add this**********************/ 
    91         public void setIsUseTemplate(boolean isUseTemplate) 
     170        /*************Brotecs:add this********************** 
     171        public void setIsUseTemplate(boolean isUse) 
    92172        { 
    93                 this.isUseTemplate=isUseTemplate; 
     173                isUseTemplate=isUse; 
    94174        } 
    95175