JKQTPSingleColumnSymbolsGraph now uses fixed seed-value for random scattering plot

This commit is contained in:
jkriege2 2019-01-26 12:35:57 +01:00
parent 847fcb7a35
commit afaee94f7d
2 changed files with 17 additions and 19 deletions

View File

@ -36,7 +36,7 @@
JKQTPSingleColumnSymbolsGraph::JKQTPSingleColumnSymbolsGraph(JKQTBasePlotter *parent):
JKQTPSingleColumnGraph(parent)
JKQTPSingleColumnGraph(parent), seedValue(123456)
{
color=QColor("red");
style=Qt::SolidLine;
@ -60,25 +60,9 @@ JKQTPSingleColumnSymbolsGraph::JKQTPSingleColumnSymbolsGraph(JKQTBasePlotter *pa
JKQTPSingleColumnSymbolsGraph::JKQTPSingleColumnSymbolsGraph(JKQTPlotter *parent):
JKQTPSingleColumnGraph(parent)
JKQTPSingleColumnSymbolsGraph(parent->getPlotter())
{
color=QColor("red");
style=Qt::SolidLine;
lineWidth=2;
parentPlotStyle=-1;
symbolSize=12;
symbolWidth=1;
symbol=JKQTPNoSymbol;
dataDirection=DataDirection::Y;
position=0;
if (parent) { // get style settings from parent object
parentPlotStyle=parent->getNextStyle();
//std::cout<<"got style settings from parent: "<<parentPlotStyle<<std::endl;
color=parent->getPlotStyle(parentPlotStyle).color();
style=parent->getPlotStyle(parentPlotStyle).style();
}
fillColor=color;
}
@ -146,7 +130,8 @@ void JKQTPSingleColumnSymbolsGraph::draw(JKQTPEnhancedPainter &painter)
if (imax<0) imax=0;
std::random_device rd; // random number generators:
std::mt19937 gen{rd()};
std::minstd_rand gen{rd()};
gen.seed(seedValue);
std::uniform_real_distribution<> dRandomScatter{position-width/2.0, position+width/2.0};
const double symSize=parent->pt2px(painter, symbolSize);

View File

@ -199,6 +199,14 @@ class LIB_EXPORT JKQTPSingleColumnSymbolsGraph: public JKQTPSingleColumnGraph {
{
return this->symbolSize;
}
/** \copydoc seedValue */
inline void setSeedValue(unsigned int val) {
seedValue=val;
}
/** \copydoc seedValue */
inline unsigned int getSeedValue() const {
return seedValue;
}
protected:
/** \brief interpret the data from dataColumn either as X- or Y-data */
DataDirection dataDirection;
@ -216,6 +224,11 @@ class LIB_EXPORT JKQTPSingleColumnSymbolsGraph: public JKQTPSingleColumnGraph {
double symbolSize;
/** \brief width (in pt) of the lines used to plot the symbol for the data points */
double symbolWidth;
/** \brief seed value for the pseudo-random number generator used for drawing.
*
* This seed is used instead of e.g. the system time to ensure that replotting results in the
* same plot every time. ou can set the seed using setSeedvalue() ) */
unsigned int seedValue;
QPen getSymbolPen(JKQTPEnhancedPainter& painter) const;
QBrush getBrush(JKQTPEnhancedPainter &painter) const;