mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[graph] Force same grid unit on orthonormal graphs
Change-Id: I2abca9eb1c4a14057323ee97e1044715f89620ff
This commit is contained in:
committed by
Émilie Feral
parent
7322751453
commit
26754a3230
@@ -27,9 +27,10 @@ public:
|
||||
}
|
||||
constexpr static float k_maxNumberOfXGridUnits = 18.0f;
|
||||
constexpr static float k_maxNumberOfYGridUnits = 13.0f;
|
||||
private:
|
||||
protected:
|
||||
constexpr static float k_minNumberOfXGridUnits = 7.0f;
|
||||
constexpr static float k_minNumberOfYGridUnits = 5.0f;
|
||||
private:
|
||||
/* The grid units is constrained to be a number of type: k*10^n with k = 1,2 or 5
|
||||
* and n a relative integer. The choice of x and y grid units depend on the
|
||||
* grid range.*/
|
||||
|
||||
@@ -33,6 +33,22 @@ void InteractiveCurveViewRange::setYMax(float yMax) {
|
||||
MemoizedCurveViewRange::protectedSetYMax(yMax, k_lowerMaxFloat, k_upperMaxFloat);
|
||||
}
|
||||
|
||||
float InteractiveCurveViewRange::yGridUnit() const {
|
||||
float res = MemoizedCurveViewRange::yGridUnit();
|
||||
if (m_zoomNormalize) {
|
||||
/* When m_zoomNormalize is active, both xGridUnit and yGridUnit will be the
|
||||
* same. To declutter the X axis, we try a unit twice as large. We check
|
||||
* that it allows enough graduations on the Y axis, but if the standard
|
||||
* unit would lead to too many graduations on the X axis, we force the
|
||||
* larger unit anyways. */
|
||||
float numberOfUnits = (yMax() - yMin()) / res;
|
||||
if (numberOfUnits > k_maxNumberOfXGridUnits || numberOfUnits / 2.f > k_minNumberOfYGridUnits) {
|
||||
return 2 * res;
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
void InteractiveCurveViewRange::zoom(float ratio, float x, float y) {
|
||||
float xMi = xMin();
|
||||
float xMa = xMax();
|
||||
|
||||
@@ -26,6 +26,10 @@ public:
|
||||
bool zoomNormalize() const { return m_zoomNormalize; }
|
||||
void setZoomNormalize(bool v) { m_zoomNormalize = v; }
|
||||
|
||||
// MemoizedCurveViewRange
|
||||
float xGridUnit() const override { return m_zoomNormalize ? yGridUnit() : MemoizedCurveViewRange::xGridUnit(); }
|
||||
float yGridUnit() const override;
|
||||
|
||||
// CurveViewWindow
|
||||
void setXMin(float f) override;
|
||||
void setXMax(float f) override;
|
||||
|
||||
Reference in New Issue
Block a user