Skip to content

Commit

Permalink
- Added the code to get the unique color for each curve.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8255 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Mar 16, 2011
1 parent a007934 commit 292b23f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
15 changes: 14 additions & 1 deletion OMPlot/OMPlotGUI/PlotCurve.cpp
Expand Up @@ -38,7 +38,7 @@ using namespace OMPlot;

PlotCurve::PlotCurve(Plot *pParent)
{

mpParentPlot = pParent;
}

PlotCurve::~PlotCurve()
Expand Down Expand Up @@ -89,3 +89,16 @@ void PlotCurve::updateLegend(QwtLegend *legend) const

QwtPlotItem::updateLegend(legend);
}

QColor PlotCurve::getUniqueColor(QColor color)
{
foreach (PlotCurve *pPlotCurve, mpParentPlot->getPlotCurvesList())
{
if (pPlotCurve->pen().color() == color)
{
color = getUniqueColor(QColor(rand()%255, rand()%255, rand()%255));
break;
}
}
return color;
}
2 changes: 2 additions & 0 deletions OMPlot/OMPlotGUI/PlotCurve.h
Expand Up @@ -43,6 +43,7 @@ class PlotCurve : public QwtPlotCurve
private:
QVector<double> mXAxisVector;
QVector<double> mYAxisVector;
Plot *mpParentPlot;
public:
PlotCurve(Plot *pParent);
~PlotCurve();
Expand All @@ -53,6 +54,7 @@ class PlotCurve : public QwtPlotCurve
void setYAxisVector(QVector<double> vector);
void addYAxisValue(double value);
QVector<double> getYAxisVector();
QColor getUniqueColor(QColor color = QColor(255, 0, 0));

virtual void updateLegend(QwtLegend *legend) const;
};
Expand Down
8 changes: 3 additions & 5 deletions OMPlot/OMPlotGUI/PlotWindow.cpp
Expand Up @@ -561,14 +561,12 @@ void PlotWindow::plotGraph(QList<PlotCurve*> plotCurvesList)
{
for(int i = 0; i < plotCurvesList.length(); i++)
{
int colorValue = 7 + i;
if(colorValue > 19 )
colorValue = 1 + i % 12;
QPen pen(QColor(Qt::GlobalColor(colorValue + 1)));
pen.setWidth(2);
plotCurvesList[i]->setData(plotCurvesList[i]->getXAxisVector(), plotCurvesList[i]->getYAxisVector());
QPen pen(plotCurvesList[i]->getUniqueColor());
pen.setWidth(2);
plotCurvesList[i]->setPen(pen);
plotCurvesList[i]->attach(mpPlot);
mpPlot->addPlotCurve(plotCurvesList[i]);
}
}

Expand Down

0 comments on commit 292b23f

Please sign in to comment.