00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00056
00057 _width = DrawingMetrics::getIconInterval();
00058 _height = (sections) * lineHeight + (sections+1)*labelMargin;
00059
00060 psvg->startGroup(os,"legend");
00061 for(unsigned i=0;i<sections;i++){
00062
00063
00064
00065 DataColumn * pDC = _ppedigreeTable->getColumn( _ppedigreeTable->getIconColumnIndex(i) );
00066
00067
00068
00069 const UniqueList * pUL = pDC->getUniqueList();
00070
00071
00072
00073
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
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
00091
00092 bool reversed=true;
00093 std::string textClass;
00094
00095 if(pUL->getCountMissing()){
00096 levelsCount++;
00097
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