mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 19:49:58 +02:00
[apps/graph/graph] Make the model graph window inherit from curve view
window Change-Id: I21a08f181725800937ec5ee043cc40a0ac301a6a
This commit is contained in:
@@ -51,23 +51,23 @@ float GraphWindow::yGridUnit() {
|
||||
void GraphWindow::setXMin(float xMin) {
|
||||
m_xMin = xMin;
|
||||
computeYaxes();
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
}
|
||||
|
||||
void GraphWindow::setXMax(float xMax) {
|
||||
m_xMax = xMax;
|
||||
computeYaxes();
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
}
|
||||
|
||||
void GraphWindow::setYMin(float yMin) {
|
||||
m_yMin = yMin;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
|
||||
void GraphWindow::setYMax(float yMax) {
|
||||
m_yMax = yMax;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
|
||||
void GraphWindow::setYAuto(bool yAuto) {
|
||||
@@ -104,7 +104,7 @@ bool GraphWindow::computeYaxes() {
|
||||
m_yMax = max + 1;
|
||||
}
|
||||
}
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -123,11 +123,11 @@ void GraphWindow::zoom(float ratio) {
|
||||
float yMax = m_yMax;
|
||||
m_xMin = (xMax+xMin)/2.0f - ratio*fabsf(xMax-xMin);
|
||||
m_xMax = (xMax+xMin)/2.0f + ratio*fabsf(xMax-xMin);
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
m_yAuto = false;
|
||||
m_yMin = (yMax+yMin)/2.0f - ratio*fabsf(yMax-yMin);
|
||||
m_yMax = (yMax+yMin)/2.0f + ratio*fabsf(yMax-yMin);
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
|
||||
void GraphWindow::centerAxisAround(Axis axis, float position) {
|
||||
@@ -136,13 +136,13 @@ void GraphWindow::centerAxisAround(Axis axis, float position) {
|
||||
m_xMin = position - range/2.0f;
|
||||
m_xMax = position + range/2.0f;
|
||||
computeYaxes();
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
} else {
|
||||
m_yAuto = false;
|
||||
float range = m_yMax - m_yMin;
|
||||
m_yMin = position - range/2.0f;
|
||||
m_yMax = position + range/2.0f;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,23 +151,23 @@ void GraphWindow::translateWindow(Direction direction) {
|
||||
if (direction == Direction::Up) {
|
||||
m_yMin = m_yMin + m_yGridUnit;
|
||||
m_yMax = m_yMax + m_yGridUnit;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
if (direction == Direction::Down) {
|
||||
m_yMin = m_yMin - m_yGridUnit;
|
||||
m_yMax = m_yMax - m_yGridUnit;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
if (direction == Direction::Left) {
|
||||
m_xMin = m_xMin - m_xGridUnit;
|
||||
m_xMax = m_xMax - m_xGridUnit;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
computeYaxes();
|
||||
}
|
||||
if (direction == Direction::Right) {
|
||||
m_xMin = m_xMin + m_xGridUnit;
|
||||
m_xMax = m_xMax + m_xGridUnit;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
computeYaxes();
|
||||
}
|
||||
}
|
||||
@@ -175,11 +175,11 @@ void GraphWindow::translateWindow(Direction direction) {
|
||||
void GraphWindow::setTrigonometric() {
|
||||
m_xMin = -10.5f;
|
||||
m_xMax = 10.5f;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
m_yAuto = false;
|
||||
m_yMin = -1.6f;
|
||||
m_yMax = 1.6f;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
|
||||
void GraphWindow::roundAbscissa() {
|
||||
@@ -187,7 +187,7 @@ void GraphWindow::roundAbscissa() {
|
||||
float xMax = m_xMax;
|
||||
m_xMin = roundf((xMin+xMax)/2) - 160.0f;
|
||||
m_xMax = roundf((xMin+xMax)/2) + 159.0f;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
computeYaxes();
|
||||
}
|
||||
|
||||
@@ -198,17 +198,17 @@ void GraphWindow::normalize() {
|
||||
float yMax = m_yMax;
|
||||
m_xMin = (xMin+xMax)/2 - 5.3f;
|
||||
m_xMax = (xMin+xMax)/2 + 5.3f;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
m_yAuto = false;
|
||||
m_yMin = (yMin+yMax)/2 - 3.1f;
|
||||
m_yMax = (yMin+yMax)/2 + 3.1f;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
}
|
||||
|
||||
void GraphWindow::setDefault() {
|
||||
m_xMin = -10.0f;
|
||||
m_xMax = 10.0f;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
setYAuto(true);
|
||||
}
|
||||
|
||||
@@ -219,56 +219,30 @@ bool GraphWindow::panToMakePointVisible(float x, float y, float xMargin, float y
|
||||
if (x < m_xMin + xMargin) {
|
||||
m_xMin = x - xMargin;
|
||||
m_xMax = m_xMin + xRange;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
computeYaxes();
|
||||
windowMoved = true;
|
||||
}
|
||||
if (x > m_xMax - xMargin) {
|
||||
m_xMax = x + xMargin;
|
||||
m_xMin = m_xMax - xRange;
|
||||
computeGridUnit(Axis::X);
|
||||
m_xGridUnit = computeGridUnit(Axis::X);
|
||||
computeYaxes();
|
||||
windowMoved = true;
|
||||
}
|
||||
if (y < m_yMin + yMargin) {
|
||||
m_yMin = y - yMargin;
|
||||
m_yMax = m_yMin + yRange;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
windowMoved = true;
|
||||
}
|
||||
if (y > m_yMax - yMargin) {
|
||||
m_yMax = y + yMargin;
|
||||
m_yMin = m_yMax - yRange;
|
||||
computeGridUnit(Axis::Y);
|
||||
m_yGridUnit = computeGridUnit(Axis::Y);
|
||||
windowMoved = true;
|
||||
}
|
||||
return windowMoved;
|
||||
}
|
||||
|
||||
void GraphWindow::computeGridUnit(Axis axis) {
|
||||
int a = 0;
|
||||
int b = 0;
|
||||
float d = m_xMax - m_xMin;
|
||||
float maxNumberOfUnits = k_maxNumberOfXGridUnits;
|
||||
float minNumberOfUnits = k_minNumberOfXGridUnits;
|
||||
if (axis == Axis::Y) {
|
||||
d = m_yMax - m_yMin;
|
||||
maxNumberOfUnits = k_maxNumberOfYGridUnits;
|
||||
minNumberOfUnits = k_minNumberOfYGridUnits;
|
||||
}
|
||||
float units[3] = {k_oneUnit, k_twoUnit, k_fiveUnit};
|
||||
for (int k = 0; k < 3; k++) {
|
||||
float unit = units[k];
|
||||
if (floorf(log10f(d/(unit*maxNumberOfUnits))) != floorf(log10f(d/(unit*minNumberOfUnits)))) {
|
||||
b = floorf(log10f(d/(unit*minNumberOfUnits)));
|
||||
a = unit;
|
||||
}
|
||||
}
|
||||
if (axis == Axis::X) {
|
||||
m_xGridUnit = a*powf(10,b);
|
||||
} else {
|
||||
m_yGridUnit = a*powf(10,b);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,15 +2,12 @@
|
||||
#define GRAPH_GRAPH_AXIS_INTERVAL_H
|
||||
|
||||
#include "../function_store.h"
|
||||
#include "../../curve_view_window.h"
|
||||
|
||||
namespace Graph {
|
||||
|
||||
class GraphWindow {
|
||||
class GraphWindow : public CurveViewWindow {
|
||||
public:
|
||||
enum class Axis {
|
||||
X,
|
||||
Y
|
||||
};
|
||||
enum class Direction {
|
||||
Up,
|
||||
Left,
|
||||
@@ -18,13 +15,13 @@ public:
|
||||
Right
|
||||
};
|
||||
GraphWindow(FunctionStore * functionStore);
|
||||
float xMin();
|
||||
float xMax();
|
||||
float yMin();
|
||||
float yMax();
|
||||
float xMin() override;
|
||||
float xMax() override;
|
||||
float yMin() override;
|
||||
float yMax() override;
|
||||
bool yAuto();
|
||||
float xGridUnit();
|
||||
float yGridUnit();
|
||||
float xGridUnit() override;
|
||||
float yGridUnit() override;
|
||||
void setXMin(float f);
|
||||
void setXMax(float f);
|
||||
void setYMin(float f);
|
||||
@@ -44,14 +41,6 @@ public:
|
||||
void setDefault();
|
||||
bool panToMakePointVisible(float x, float y, float xMargin, float yMargin);
|
||||
private:
|
||||
constexpr static float k_minNumberOfXGridUnits = 7.0f;
|
||||
constexpr static float k_maxNumberOfXGridUnits = 18.0f;
|
||||
constexpr static float k_minNumberOfYGridUnits = 5.0f;
|
||||
constexpr static float k_maxNumberOfYGridUnits = 13.0f;
|
||||
constexpr static float k_oneUnit = 1.0f;
|
||||
constexpr static float k_twoUnit = 2.0f;
|
||||
constexpr static float k_fiveUnit = 5.0f;
|
||||
void computeGridUnit(Axis axis);
|
||||
float m_xMin;
|
||||
float m_xMax;
|
||||
float m_yMin;
|
||||
|
||||
Reference in New Issue
Block a user