Fixed simulation plot legend
This commit is contained in:
parent
0261a0e59c
commit
781a12222c
|
@ -68,6 +68,7 @@ void SIM_PLOT_PANEL::AddTrace( const wxString& aName, int aPoints,
|
||||||
TRACE trace;
|
TRACE trace;
|
||||||
|
|
||||||
trace.name = aName;
|
trace.name = aName;
|
||||||
|
trace.style = wxString( '-' ) + m_painter.GenerateColor( SIM_PLOT_PAINTER::DARK );
|
||||||
trace.x.Set( aT, aPoints );
|
trace.x.Set( aT, aPoints );
|
||||||
trace.y.Set( aY, aPoints );
|
trace.y.Set( aY, aPoints );
|
||||||
m_traces.push_back( trace );
|
m_traces.push_back( trace );
|
||||||
|
@ -141,12 +142,54 @@ int SIM_PLOT_PAINTER::Draw( mglGraph* aGraph )
|
||||||
// Draw traces
|
// Draw traces
|
||||||
for( auto t : traces )
|
for( auto t : traces )
|
||||||
{
|
{
|
||||||
aGraph->AddLegend( (const char*) t.name.c_str(), "" );
|
aGraph->AddLegend( (const char*) t.name.c_str(), t.style );
|
||||||
aGraph->Plot( t.y, "-" );
|
aGraph->Plot( t.y, t.style );
|
||||||
}
|
}
|
||||||
|
|
||||||
if( traces.size() )
|
if( traces.size() )
|
||||||
aGraph->Legend( 1, "-#" );
|
aGraph->Legend( 1, "-#" ); // legend entries horizontally + draw a box around legend
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
wxString SIM_PLOT_PAINTER::GenerateColor( COLOR_TYPE aType )
|
||||||
|
{
|
||||||
|
const char colors[] = "rgbcmylenupq";
|
||||||
|
const unsigned int colorsNumber = sizeof( colors ) - 1;
|
||||||
|
|
||||||
|
// Safe defaults
|
||||||
|
char color = 'k'; // black
|
||||||
|
int shade = 5;
|
||||||
|
|
||||||
|
switch( aType )
|
||||||
|
{
|
||||||
|
case LIGHT:
|
||||||
|
color = colors[m_lightColorIdx % colorsNumber];
|
||||||
|
shade = 5 + m_lightColorIdx / colorsNumber;
|
||||||
|
++m_lightColorIdx;
|
||||||
|
|
||||||
|
if( shade == 10 )
|
||||||
|
{
|
||||||
|
// Reached the color limit
|
||||||
|
shade = 5;
|
||||||
|
m_lightColorIdx = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case DARK:
|
||||||
|
color = toupper( colors[m_darkColorIdx % colorsNumber] );
|
||||||
|
shade = 5 - m_darkColorIdx / colorsNumber;
|
||||||
|
++m_darkColorIdx;
|
||||||
|
|
||||||
|
if( shade == 0 )
|
||||||
|
{
|
||||||
|
// Reached the color limit
|
||||||
|
shade = 5;
|
||||||
|
m_darkColorIdx = 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return wxString::Format( "{%c%d}", color, shade );
|
||||||
|
}
|
||||||
|
|
|
@ -33,7 +33,7 @@ class SIM_PLOT_PAINTER : public mglDraw
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SIM_PLOT_PAINTER( const SIM_PLOT_PANEL* aParent )
|
SIM_PLOT_PAINTER( const SIM_PLOT_PANEL* aParent )
|
||||||
: m_parent( aParent )
|
: m_parent( aParent ), m_lightColorIdx( 0 ), m_darkColorIdx( 0 )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,8 +45,14 @@ public:
|
||||||
|
|
||||||
int Draw( mglGraph* aGraph ) override;
|
int Draw( mglGraph* aGraph ) override;
|
||||||
|
|
||||||
|
enum COLOR_TYPE { LIGHT, DARK };
|
||||||
|
|
||||||
|
///> Generates a new, unique color for plotting curves
|
||||||
|
wxString GenerateColor( COLOR_TYPE aType );
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const SIM_PLOT_PANEL* m_parent;
|
const SIM_PLOT_PANEL* m_parent;
|
||||||
|
int m_lightColorIdx, m_darkColorIdx;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -59,7 +65,7 @@ public:
|
||||||
~SIM_PLOT_PANEL();
|
~SIM_PLOT_PANEL();
|
||||||
|
|
||||||
struct TRACE {
|
struct TRACE {
|
||||||
wxString name;
|
wxString name, style;
|
||||||
mglData x, y;
|
mglData x, y;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue