diff --git a/DistributionChart2D.cpp b/DistributionChart2D.cpp index b3be99c..9465569 100644 --- a/DistributionChart2D.cpp +++ b/DistributionChart2D.cpp @@ -7,6 +7,84 @@ using namespace hgl; +constexpr const uint CHAR_BITMAP_WIDTH=3; +constexpr const uint CHAR_BITMAP_HEIGHT=5; +constexpr const uint CHAR_BITMAP_SCALE=4; + +constexpr const uint8 bitmap_font[10][15]= +{ + { + 1,1,1, + 1,0,1, + 1,0,1, + 1,0,1, + 1,1,1 + }, + { + 0,1,0, + 1,1,0, + 0,1,0, + 0,1,0, + 1,1,1 + }, + { + 1,1,1, + 0,0,1, + 1,1,1, + 1,0,0, + 1,1,1 + }, + { + 1,1,1, + 0,0,1, + 1,1,1, + 0,0,1, + 1,1,1 + }, + { + 1,0,1, + 1,0,1, + 1,1,1, + 0,0,1, + 0,0,1 + }, + { + 1,1,1, + 1,0,0, + 1,1,1, + 0,0,1, + 1,1,1 + }, + { + 1,1,1, + 1,0,0, + 1,1,1, + 1,0,1, + 1,1,1 + }, + { + 1,1,1, + 0,0,1, + 0,0,1, + 0,0,1, + 0,0,1 + }, + { + 1,1,1, + 1,0,1, + 1,1,1, + 1,0,1, + 1,1,1 + }, + { + 1,1,1, + 1,0,1, + 1,1,1, + 0,0,1, + 1,1,1 + } +}; + bool ParseLine(Vector2i *result,const UTF8String &str) { if(!result)return(false); @@ -100,16 +178,19 @@ PositionStat *ToVector2i(const UTF8StringList &sl) //std::cout<<"X="<x<<",Y="<y<xminp.x)ps->minp.x=p->x; - if(p->x>ps->maxp.x)ps->maxp.x=p->x; +// if(p->x>ps->maxp.x)ps->maxp.x=p->x; // if(p->yminp.y)ps->minp.y=p->y; - if(p->y>ps->maxp.y)ps->maxp.y=p->y; +// if(p->y>ps->maxp.y)ps->maxp.y=p->y; ++result; ++p; } //std::cout<<"minp: "<minp.x<<","<minp.y<maxp.x<<","<maxp.y<maxp.x<<","<maxp.y<maxp.x=1023; + ps->maxp.y=1023; ps->count=result; @@ -120,9 +201,7 @@ struct Chart { uint width,height; - uint min_count; uint max_count; - uint gap; uint32 *count_data; uint32 *circle_data; @@ -143,9 +222,7 @@ public: hgl_zero(circle_data,width*height); hgl_zero(chart_data,width*height*4); - min_count=0; max_count=0; - gap=0; } ~Chart() @@ -175,6 +252,65 @@ public: } } } + + void DrawBar(const uint x,const uint y,const uint size,const Vector3u8 &color,const uint8 alpha) + { + uint8 *tp=chart_data+(x+y*width)*4; + uint line_bytes=(width-size)*4; + + for(uint row=0;rowcircle_data; for(uint i=0;imin_count)chart->min_count=*cp32; if(*cp32>chart->max_count)chart->max_count=*cp32; ++cp32; } - chart->gap=chart->max_count-chart->min_count; - - std::cout<<"min_count: "<min_count<<",max_count: "<max_count<<",gap: "<gap<max_count<min_count)/float(chart->gap); + result=float(*cp32)/float(chart->max_count); if(result>=0.8f) //0.8 - 1.0 { @@ -307,6 +440,24 @@ Chart *ToChart32(const PositionStat *ps) } } + //写入数值 + { + const Vector3u8 color[6]= + { + {255,0,0}, + {255,255,0}, + {0,255,0}, + {0,255,255}, + {0,0,255}, + {0,0,0}, + }; + + uint num=chart->max_count; + + for(uint i=0;i<6;i++) + chart->DrawNumber(float(num)*(1.0f-float(i)*0.2f),10,10+i*(CHAR_BITMAP_HEIGHT*CHAR_BITMAP_SCALE+1),color[i],255); + } + return chart; } @@ -336,7 +487,6 @@ int os_main(int argc,os_char **argv) AutoDelete chart=ToChart32(ps); - { util::TGAHeader tga_header;