Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

IconLegend.h

Go to the documentation of this file.
00001 
00002 //
00003 // This file is part of the MADELINE 2 program 
00004 // written by Edward H. Trager and Ritu Khanna
00005 // Copyright (c) 2005 by the
00006 // Regents of the University of Michigan.
00007 // All Rights Reserved.
00008 // 
00009 // The latest version of this program is available from:
00010 // 
00011 //   http://eyegene.ophthy.med.umich.edu/madeline/
00012 //   
00013 // Released under the GNU General Public License.
00014 // A copy of the GPL is included in the distribution
00015 // package of this software, or see:
00016 // 
00017 //   http://www.gnu.org/copyleft/
00018 //   
00019 // ... for licensing details.
00020 // 
00022 
00023 #ifndef ICONLEGEND_INCLUDED
00024 #define ICONLEGEND_INCLUDED
00025 
00026 #include "DrawingMetrics.h"
00027 #include "DrawingLabelManager.h"
00028 #include "DrawingCanvas.h"
00029 #include "SVG.h"
00030 #include "Utf8String.h"
00031 #include "UniqueList.h"
00032 #include "Legend.h"
00033 
00034 class IconLegend : public Legend{
00035         
00036 private:
00037         const DataTable * _ppedigreeTable;
00038         
00039 public:
00040         
00041         IconLegend() { _width=_height=0;}
00042         void setPedigreeTable(const DataTable *const pedigreeTable){
00043                 
00044                 _ppedigreeTable = pedigreeTable;
00045                 
00046         }
00047         
00048         void draw(std::ostringstream& os,SVG* psvg,DrawingLabelManager* plm,const double x,const double y){
00049                 
00050                 double lineHeight = DrawingMetrics::getLineHeight();
00051                 double labelMargin = DrawingMetrics::getLabelMargin();
00052                 unsigned sections = _ppedigreeTable->getIconColumnCount();
00053                 double ystt = y;
00054                 double xstt = x - DrawingMetrics::getHorizontalInterval() + labelMargin;
00055                 //_width  = DrawingMetrics::getIconInterval()  + 2*labelMargin;
00056                 
00057                 _width = DrawingMetrics::getIconInterval();
00058                 _height = (sections) * lineHeight + (sections+1)*labelMargin;
00059                 // Wrap icon labels in a group:
00060                 psvg->startGroup(os,"legend");
00061                 for(unsigned i=0;i<sections;i++){
00062                         //
00063                         // Get the data column of the ith icon column:
00064                         //
00065                         DataColumn * pDC = _ppedigreeTable->getColumn( _ppedigreeTable->getIconColumnIndex(i) );
00066                         //
00067                         // Get the UniqueList for this column:
00068                         //
00069                         const UniqueList * pUL = pDC->getUniqueList();
00070                         //std::cout << " pUL has missing " << pUL->getCountMissing() << std::endl;
00071                         //
00072                         // What is the level and label in the UniqueList corresponding to the data value
00073                         // for this individual?
00074                         //
00075                         std::string label = _ppedigreeTable->getColumn( _ppedigreeTable->getIconColumnIndex(i) )->getName();
00076                         psvg->drawText(os,x,ystt, plm->fitStringToLabelWidth( label ) );
00077                         ystt += labelMargin;
00078                         std::vector<std::string> labels = pUL->getLabels();
00079                         unsigned levelsCount = labels.size();
00080                         //
00081                         // Get the color series corresponding to this icon column:
00082                         //
00083                         ColorSeries *pCS;
00084                         if(sections == 1){
00085                                 if(DrawingMetrics::getColor()) pCS = _ppedigreeTable->getColorSeriesFromStack(i);
00086                                 else                       pCS =   _ppedigreeTable->getBlackAndWhiteSeriesFromStack(i);
00087                         }else if(DrawingMetrics::getBlackAndWhite()) pCS=_ppedigreeTable->getBlackAndWhiteSeriesFromStack(i);
00088                         else                                     pCS = _ppedigreeTable->getColorSeriesFromStack(i);
00089                         //
00090                         // Assume reversed for now:
00091                         //
00092                         bool reversed=true;
00093                         std::string textClass;
00094                         // Check if there exists a missing level
00095                         if(pUL->getCountMissing()){
00096                                 levelsCount++;
00097                                 // push the missing label:
00098                                 labels.push_back(".");
00099                         }
00100                         double ytemp;
00101                         for(unsigned j=0;j<levelsCount;j++){
00102                                 if(pCS->reversedSeriesUseBlackInkAtLevel(j)) textClass = "blackInkLetter_1";
00103                                 else textClass="whiteInkLetter_1";
00104                                 std::string style = "fill:" + (reversed?pCS->reversedSeriesGetColorAtLevel(j):pCS->getColorAtLevel(j)) + ";";
00105                                 psvg->drawRectangle(os,xstt,ystt,_width-2*labelMargin,lineHeight,"","",style);
00106                                 ytemp = ystt+lineHeight/2;
00107                                 if(j < levelsCount - 1) ytemp +=  DrawingMetrics::getYMaximum()/2;
00108                                 else if(!pUL->getCountMissing()) ytemp += DrawingMetrics::getYMaximum()/2;
00109                                 psvg->drawText(os,x,ytemp, plm->fitStringToLabelWidth( labels[j] ),textClass );
00110                                 ystt += lineHeight;
00111                                 _height += lineHeight;
00112                         }
00113                         ystt+=lineHeight;
00114                 }
00115                 psvg->endGroup(os);
00116         }
00117 };
00118 
00119 #endif

Generated on Fri Nov 18 16:24:39 2011 for MADELINE by  doxygen 1.4.4