diff --git a/doc/images/JKQTPVectorFieldGraph.png b/doc/images/JKQTPVectorFieldGraph.png index a2c5381627f..b7047fe7c62 100644 Binary files a/doc/images/JKQTPVectorFieldGraph.png and b/doc/images/JKQTPVectorFieldGraph.png differ diff --git a/doc/images/JKQTPVectorFieldGraphAnchorBottom.png b/doc/images/JKQTPVectorFieldGraphAnchorBottom.png index a22256a9e6a..e03ea025740 100644 Binary files a/doc/images/JKQTPVectorFieldGraphAnchorBottom.png and b/doc/images/JKQTPVectorFieldGraphAnchorBottom.png differ diff --git a/doc/images/JKQTPVectorFieldGraphAnchorMid.png b/doc/images/JKQTPVectorFieldGraphAnchorMid.png index e78cf6f293a..02f0cbacfe8 100644 Binary files a/doc/images/JKQTPVectorFieldGraphAnchorMid.png and b/doc/images/JKQTPVectorFieldGraphAnchorMid.png differ diff --git a/doc/images/JKQTPVectorFieldGraphAnchorTip.png b/doc/images/JKQTPVectorFieldGraphAnchorTip.png index 84ef5902934..9b548ca8659 100644 Binary files a/doc/images/JKQTPVectorFieldGraphAnchorTip.png and b/doc/images/JKQTPVectorFieldGraphAnchorTip.png differ diff --git a/lib/jkqtplotter/graphs/jkqtpvectorfield.cpp b/lib/jkqtplotter/graphs/jkqtpvectorfield.cpp index d95409c9965..88e0cd35546 100644 --- a/lib/jkqtplotter/graphs/jkqtpvectorfield.cpp +++ b/lib/jkqtplotter/graphs/jkqtpvectorfield.cpp @@ -34,6 +34,7 @@ JKQTPVectorFieldGraph::JKQTPVectorFieldGraph(JKQTBasePlotter *parent): JKQTPXYAndVectorGraph(parent), m_autoscaleLength(true), + m_autoscaleLengthFactor(0.9), m_lengthScaleFactor(1), m_anchorPoint(AnchorBottom) { @@ -97,7 +98,7 @@ void JKQTPVectorFieldGraph::draw(JKQTPEnhancedPainter &painter) avgVecLength/=NDatapoints; const double plotsize=qMax(fabs(xmax-xmin),fabs(ymax-ymin)); const double aproxNPerSide=sqrt(NDatapoints); - scale=plotsize/aproxNPerSide/avgVecLength; + scale=plotsize/aproxNPerSide/avgVecLength*m_autoscaleLengthFactor; } else { scale=m_lengthScaleFactor; } @@ -153,6 +154,16 @@ void JKQTPVectorFieldGraph::setAutoscaleLength(bool newAutoscaleLength) m_autoscaleLength = newAutoscaleLength; } +double JKQTPVectorFieldGraph::getAutoscaleLengthFactor() const +{ + return m_autoscaleLengthFactor; +} + +void JKQTPVectorFieldGraph::setAutoscaleLengthFactor(double newAutoscaleLengthFactor) +{ + m_autoscaleLengthFactor=newAutoscaleLengthFactor; +} + double JKQTPVectorFieldGraph::getLengthScaleFactor() const { return m_lengthScaleFactor; diff --git a/lib/jkqtplotter/graphs/jkqtpvectorfield.h b/lib/jkqtplotter/graphs/jkqtpvectorfield.h index 949bf718431..8a5837135fb 100644 --- a/lib/jkqtplotter/graphs/jkqtpvectorfield.h +++ b/lib/jkqtplotter/graphs/jkqtpvectorfield.h @@ -39,9 +39,11 @@ class JKQTPDatastore; /*! \brief This graph plots a vector field, i.e. a set of vectors (dx,dy) or (angle,length) at positions (x,y). - This type of plot is sometimes also refered to as quicver plot (e.g. in Matlab or matplotlib) + This class immplements the most basic form of vector plot, i.e. the vector are drawn with a length + corresponding to their magnitude. \ingroup jkqtplotter_vectorfieldgraphs + \note This type of plot is sometimes also refered to as quiver plot (e.g. in Matlab or matplotlib) \image html JKQTPVectorFieldGraph.png @@ -98,6 +100,11 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPVectorFieldGraph: public JKQTPXYAndVectorGraph /** \copydoc m_autoscaleLength */ void setAutoscaleLength(bool newAutoscaleLength); + /** \copydoc m_autoscaleLengthFactor */ + double getAutoscaleLengthFactor() const; + /** \copydoc m_autoscaleLengthFactor */ + void setAutoscaleLengthFactor(double newAutoscaleLengthFactor); + /** \copydoc m_lengthScaleFactor */ double getLengthScaleFactor() const; /** \copydoc m_lengthScaleFactor */ @@ -110,19 +117,36 @@ class JKQTPLOTTER_LIB_EXPORT JKQTPVectorFieldGraph: public JKQTPXYAndVectorGraph void setAnchorPoint(VectorAnchorPoint newAnchorPoint); Q_PROPERTY(bool autoscaleLength READ getAutoscaleLength WRITE setAutoscaleLength ) + Q_PROPERTY(bool autoscaleLengthFactor READ getAutoscaleLengthFactor WRITE setAutoscaleLengthFactor ) Q_PROPERTY(double lengthScaleFactor READ getLengthScaleFactor WRITE setLengthScaleFactor ) Q_PROPERTY(VectorAnchorPoint anchorPoint READ getAnchorPoint WRITE setAnchorPoint ) protected: private: /** \brief enables or disables the autoscaling of vector lengths * - * If disabled (\c false ) the vector is drawn from (x,y) to (x+dx*m_lengthScaleFactor,y+dy*m_lengthScaleFactor), - * otherweise to (x+dx*autoscale,y+dy*autoscale) + * If disabled (\c false ) the vector is drawn from \c (x,y) to \c (x+dx,y+dy)*m_lengthScaleFactor , + * otherweise to \c (x+dx,y+dy)*autoscale*m_autoscaleLengthFactor . + * The autoscaled length is calculated by a siple algorithm that uses the average vector length in the data: + * \c autoscale=plotwidth/VectorPerWidth/avgVectorLength . + * + * \see m_autoscaleFactor, m_autoscaleLengthFactor, setAutoscaleLength(), getAutoscaleLength() */ bool m_autoscaleLength; - /** \brief if m_autoscaleLength \c ==false, this is the scale-factor used to calculate the vector length */ + /** \brief a scaling factor that can be used to modify the result of the autoscaling algorithm (m_autoscaleLength \c ==true) + * + * The vector length is further scaled by this value. + * \see m_autoscaleLength, setAutoscaleFactor(), getAutoscaleFactor() + */ + double m_autoscaleLengthFactor; + /** \brief if m_autoscaleLength \c ==false, this is the scale-factor used to calculate the vector length + * + * \see setLengthScaleFactor(), getLengthScaleFactor(), m_autoscaleLength + */ double m_lengthScaleFactor; - /** \brief defines where the vector is anchored */ + /** \brief defines where the vector is anchored + * + * \see VectorAnchorPoint + */ VectorAnchorPoint m_anchorPoint; }; diff --git a/screenshots/vectorfield.png b/screenshots/vectorfield.png index b59db42500e..9b46c60d0b5 100644 Binary files a/screenshots/vectorfield.png and b/screenshots/vectorfield.png differ diff --git a/screenshots/vectorfield_small.png b/screenshots/vectorfield_small.png index 64208b4d773..93758700813 100644 Binary files a/screenshots/vectorfield_small.png and b/screenshots/vectorfield_small.png differ