Format plot values according to requested formatting.

This commit is contained in:
Bartosz Taudul 2019-11-05 18:08:42 +01:00
parent 661c4a417b
commit cfce429fca
2 changed files with 25 additions and 25 deletions

View File

@ -4744,18 +4744,18 @@ int View::DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover,
return offset; return offset;
} }
static const char* FormatPlotValue( double val, PlotType type ) static const char* FormatPlotValue( double val, PlotValueFormatting format )
{ {
static char buf[64]; static char buf[64];
switch( type ) switch( format )
{ {
case PlotType::User: case PlotValueFormatting::Number:
return RealToString( val, true ); return RealToString( val, true );
break; break;
case PlotType::Memory: case PlotValueFormatting::Memory:
return MemSizeToString( val ); return MemSizeToString( val );
break; break;
case PlotType::SysTime: case PlotValueFormatting::Percentage:
sprintf( buf, "%.2f%%", val ); sprintf( buf, "%.2f%%", val );
break; break;
default: default:
@ -4828,9 +4828,9 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl
ImGui::TextDisabled( "(%.2f%%)", activity / double( traceLen ) * 100 ); ImGui::TextDisabled( "(%.2f%%)", activity / double( traceLen ) * 100 );
ImGui::Separator(); ImGui::Separator();
TextFocused( "Data points:", RealToString( v->data.size(), true ) ); TextFocused( "Data points:", RealToString( v->data.size(), true ) );
TextFocused( "Data range:", FormatPlotValue( v->max - v->min, v->type ) ); TextFocused( "Data range:", FormatPlotValue( v->max - v->min, v->format ) );
TextFocused( "Min value:", FormatPlotValue( v->min, v->type ) ); TextFocused( "Min value:", FormatPlotValue( v->min, v->format ) );
TextFocused( "Max value:", FormatPlotValue( v->max, v->type ) ); TextFocused( "Max value:", FormatPlotValue( v->max, v->format ) );
TextFocused( "Data/second:", RealToString( double( v->data.size() ) / activity * 1000000000ll, true ) ); TextFocused( "Data/second:", RealToString( double( v->data.size() ) / activity * 1000000000ll, true ) );
const auto it = std::lower_bound( v->data.begin(), v->data.end(), last - 1000000000ll * 10, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } ); const auto it = std::lower_bound( v->data.begin(), v->data.end(), last - 1000000000ll * 10, [] ( const auto& l, const auto& r ) { return l.time.Val() < r; } );
@ -4962,7 +4962,7 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl
{ {
const auto x = ( it->time.Val() - m_vd.zvStart ) * pxns; const auto x = ( it->time.Val() - m_vd.zvStart ) * pxns;
const auto y = PlotHeight - ( it->val - min ) * revrange * PlotHeight; const auto y = PlotHeight - ( it->val - min ) * revrange * PlotHeight;
DrawPlotPoint( wpos, x, y, offset, 0xFF44DDDD, hover, false, it, 0, false, v->type, PlotHeight ); DrawPlotPoint( wpos, x, y, offset, 0xFF44DDDD, hover, false, it, 0, false, v->type, v->format, PlotHeight );
} }
auto prevx = it; auto prevx = it;
@ -4985,7 +4985,7 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl
const auto rsz = std::distance( it, range ); const auto rsz = std::distance( it, range );
if( rsz == 1 ) if( rsz == 1 )
{ {
DrawPlotPoint( wpos, x1, y1, offset, 0xFF44DDDD, hover, true, it, prevy->val, false, v->type, PlotHeight ); DrawPlotPoint( wpos, x1, y1, offset, 0xFF44DDDD, hover, true, it, prevy->val, false, v->type, v->format, PlotHeight );
prevx = it; prevx = it;
prevy = it; prevy = it;
++it; ++it;
@ -5019,9 +5019,9 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl
TextFocused( "Number of values:", RealToString( rsz, true ) ); TextFocused( "Number of values:", RealToString( rsz, true ) );
TextDisabledUnformatted( "Estimated range:" ); TextDisabledUnformatted( "Estimated range:" );
ImGui::SameLine(); ImGui::SameLine();
ImGui::Text( "%s - %s", FormatPlotValue( tmpvec[0], v->type ), FormatPlotValue( dst[-1], v->type ) ); ImGui::Text( "%s - %s", FormatPlotValue( tmpvec[0], v->format ), FormatPlotValue( dst[-1], v->format ) );
ImGui::SameLine(); ImGui::SameLine();
ImGui::TextDisabled( "(%s)", FormatPlotValue( dst[-1] - tmpvec[0], v->type ) ); ImGui::TextDisabled( "(%s)", FormatPlotValue( dst[-1] - tmpvec[0], v->format ) );
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
} }
@ -5036,11 +5036,11 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl
assert( vrange > vit ); assert( vrange > vit );
if( std::distance( vit, vrange ) == 1 ) if( std::distance( vit, vrange ) == 1 )
{ {
DrawPlotPoint( wpos, x1, PlotHeight - ( *vit - min ) * revrange * PlotHeight, offset, 0xFF44DDDD, hover, false, *vit, 0, false, v->type, PlotHeight ); DrawPlotPoint( wpos, x1, PlotHeight - ( *vit - min ) * revrange * PlotHeight, offset, 0xFF44DDDD, hover, false, *vit, 0, false, v->format, PlotHeight );
} }
else else
{ {
DrawPlotPoint( wpos, x1, PlotHeight - ( *vit - min ) * revrange * PlotHeight, offset, 0xFF44DDDD, hover, false, *vit, 0, true, v->type, PlotHeight ); DrawPlotPoint( wpos, x1, PlotHeight - ( *vit - min ) * revrange * PlotHeight, offset, 0xFF44DDDD, hover, false, *vit, 0, true, v->format, PlotHeight );
} }
vit = vrange; vit = vrange;
} }
@ -5053,13 +5053,13 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl
char tmp[64]; char tmp[64];
if( yPos + ty >= yMin && yPos <= yMax ) if( yPos + ty >= yMin && yPos <= yMax )
{ {
sprintf( tmp, "(y-range: %s, visible data points: %s)", FormatPlotValue( max - min, v->type ), RealToString( num, true ) ); sprintf( tmp, "(y-range: %s, visible data points: %s)", FormatPlotValue( max - min, v->format ), RealToString( num, true ) );
draw->AddText( wpos + ImVec2( ty * 1.5f + txtx, offset - ty ), 0x8844DDDD, tmp ); draw->AddText( wpos + ImVec2( ty * 1.5f + txtx, offset - ty ), 0x8844DDDD, tmp );
} }
sprintf( tmp, "%s", FormatPlotValue( max, v->type ) ); sprintf( tmp, "%s", FormatPlotValue( max, v->format ) );
DrawTextContrast( draw, wpos + ImVec2( 0, offset ), 0x8844DDDD, tmp ); DrawTextContrast( draw, wpos + ImVec2( 0, offset ), 0x8844DDDD, tmp );
offset += PlotHeight - ty; offset += PlotHeight - ty;
sprintf( tmp, "%s", FormatPlotValue( min, v->type ) ); sprintf( tmp, "%s", FormatPlotValue( min, v->format ) );
DrawTextContrast( draw, wpos + ImVec2( 0, offset ), 0x8844DDDD, tmp ); DrawTextContrast( draw, wpos + ImVec2( 0, offset ), 0x8844DDDD, tmp );
draw->AddLine( wpos + ImVec2( 0, offset + ty - 1 ), wpos + ImVec2( w, offset + ty - 1 ), 0x8844DDDD ); draw->AddLine( wpos + ImVec2( 0, offset + ty - 1 ), wpos + ImVec2( w, offset + ty - 1 ), 0x8844DDDD );
@ -5078,7 +5078,7 @@ int View::DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, fl
return offset; return offset;
} }
void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, double val, double prev, bool merged, PlotType type, float PlotHeight ) void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, double val, double prev, bool merged, PlotValueFormatting format, float PlotHeight )
{ {
auto draw = ImGui::GetWindowDrawList(); auto draw = ImGui::GetWindowDrawList();
if( merged ) if( merged )
@ -5093,16 +5093,16 @@ void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint
if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( x - 2, offset ), wpos + ImVec2( x + 2, offset + PlotHeight ) ) ) if( hover && ImGui::IsMouseHoveringRect( wpos + ImVec2( x - 2, offset ), wpos + ImVec2( x + 2, offset + PlotHeight ) ) )
{ {
ImGui::BeginTooltip(); ImGui::BeginTooltip();
TextFocused( "Value:", FormatPlotValue( val, type ) ); TextFocused( "Value:", FormatPlotValue( val, format ) );
if( hasPrev ) if( hasPrev )
{ {
TextFocused( "Change:", FormatPlotValue( val - prev, type ) ); TextFocused( "Change:", FormatPlotValue( val - prev, format ) );
} }
ImGui::EndTooltip(); ImGui::EndTooltip();
} }
} }
void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, const PlotItem* item, double prev, bool merged, PlotType type, float PlotHeight ) void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, const PlotItem* item, double prev, bool merged, PlotType type, PlotValueFormatting format, float PlotHeight )
{ {
auto draw = ImGui::GetWindowDrawList(); auto draw = ImGui::GetWindowDrawList();
if( merged ) if( merged )
@ -5134,12 +5134,12 @@ void View::DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint
} }
else else
{ {
TextFocused( "Value:", FormatPlotValue( item->val, type ) ); TextFocused( "Value:", FormatPlotValue( item->val, format ) );
} }
if( hasPrev ) if( hasPrev )
{ {
const auto change = item->val - prev; const auto change = item->val - prev;
TextFocused( "Change:", FormatPlotValue( change, type ) ); TextFocused( "Change:", FormatPlotValue( change, format ) );
if( type == PlotType::Memory ) if( type == PlotType::Memory )
{ {

View File

@ -128,8 +128,8 @@ private:
void DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLocation& srcloc, bool hover, ImDrawList* draw, const ImVec2& wpos, float w, float ty, float offset, uint8_t tid ); void DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLocation& srcloc, bool hover, ImDrawList* draw, const ImVec2& wpos, float w, float ty, float offset, uint8_t tid );
int DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int offset, LockHighlight& highlight, float yMin, float yMax ); int DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int offset, LockHighlight& highlight, float yMin, float yMax );
int DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax ); int DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax );
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, const PlotItem* item, double prev, bool merged, PlotType type, float PlotHeight ); void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, const PlotItem* item, double prev, bool merged, PlotType type, PlotValueFormatting format, float PlotHeight );
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, double val, double prev, bool merged, PlotType type, float PlotHeight ); void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, double val, double prev, bool merged, PlotValueFormatting format, float PlotHeight );
int DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax ); int DrawCpuData( int offset, double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax );
void DrawOptions(); void DrawOptions();
void DrawMessages(); void DrawMessages();