From 287916796fb794a798f02b5ad1ae4c34befe9325 Mon Sep 17 00:00:00 2001 From: "HuYingzhuo(hugo/hyzboy)" Date: Tue, 11 Jul 2023 20:41:34 +0800 Subject: [PATCH] updated. slite count_bitmap data source --- DistributionChart2D.cpp | 50 ++++++++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 18 deletions(-) diff --git a/DistributionChart2D.cpp b/DistributionChart2D.cpp index 1701610..734e6d1 100644 --- a/DistributionChart2D.cpp +++ b/DistributionChart2D.cpp @@ -166,6 +166,9 @@ constexpr const Vector4u8 stop_color[]= constexpr const uint STOP_COUNT=sizeof(stop_color)/sizeof(Vector4u8); +uint stop_count[STOP_COUNT]; +uint top_count=0; + HGL_GRADIENT_DEFINE(GradientColor3u8,uint,Vector3u8) { result.r=start.r+float(end.r-start.r)*pos; @@ -404,16 +407,19 @@ public: } }; -Chart *ToChart32(const PositionStat *ps) +Chart *CreateChart() { const uint width=BackgroundBitmap->GetWidth(); const uint height=BackgroundBitmap->GetHeight(); std::cout<<"width: "<x-ps->minp.x; y=p->y-ps->minp.y; - cp32=chart->count_bitmap.GetData(x,y); + cp32=count_bitmap.GetData(x,y); ++(*cp32); - if(*cp32>max_count)max_count=*cp32; + if(*cp32>top_count)top_count=*cp32; ++p; } } +} + +void ChartStat(Chart *chart,const uint data_count) +{ + const uint width=chart->width; + const uint height=chart->height; //统计占比 { uint32 *cp32=chart->count_bitmap.GetData(); - hgl_zero(step_count); + hgl_zero(stop_count); for(uint y=0;y0) for(uint i=0;imax_count*(STOP_COUNT-1-i)/STOP_COUNT) + if(*cp32>top_count*(STOP_COUNT-1-i)/STOP_COUNT) { - step_count[i]+=*cp32; + stop_count[i]+=*cp32; break; } @@ -525,7 +537,7 @@ Chart *ToChart32(const PositionStat *ps) } if(CHAR_BITMAP_HEIGHT==0) - return chart; + return; //写入数值 { @@ -535,7 +547,7 @@ Chart *ToChart32(const PositionStat *ps) AnsiString str; AnsiString num_str; - const AnsiString str_total=AnsiString::numberOf(ps->count); + const AnsiString str_total=AnsiString::numberOf(data_count); AnsiString step_str[STOP_COUNT]; const uint dradient_bar_height=CHAR_BITMAP_HEIGHT*STOP_COUNT; @@ -546,7 +558,7 @@ Chart *ToChart32(const PositionStat *ps) for(uint i=0;i0) + if(stop_count[i]>0) { - num_str=AnsiString::floatOf(float(step_count[i])*100.0f/float(ps->count),4); + num_str=AnsiString::floatOf(float(stop_count[i])*100.0f/float(data_count),4); str.Strcat(space,3+(8-num_str.Length())); str+=num_str; @@ -606,8 +618,6 @@ Chart *ToChart32(const PositionStat *ps) blend(&(chart->chart_bitmap),BackgroundBitmap,1.0); } - - return chart; } int os_main(int argc,os_char **argv) @@ -650,7 +660,11 @@ int os_main(int argc,os_char **argv) AutoDelete ps=ToVector2i(sl); - AutoDelete chart=ToChart32(ps); + AutoDelete chart=CreateChart(); + + StatCount(chart->count_bitmap,ps); + + ChartStat(chart,ps->count); OSString tga_filename; {