calculate step using same method that in autolimits + "small" refactoring

This commit is contained in:
Sergei Krasilnikov 2024-01-24 01:23:49 +03:00
parent 08e8b28dd1
commit a350ff98f3
5 changed files with 31 additions and 24 deletions

View File

@ -2043,12 +2043,14 @@ bool Diagram::insideDiagramP(Graph::iterator const &p) const {
return insideDiagram(f1, f2);
}
void
Diagram::calcCoordinateP(const double *x, const double *y, const double *z, Graph::iterator &p, Axis const *A) const {
void Diagram::calcCoordinateP(const double *x, const double *y, const double *z, Graph::iterator &p, Axis const *A) const {
float f1, f2;
calcCoordinate(x, y, z, &f1, &f2, A);
p->setScr(f1, f2);
};
//void Diagram::SetLimitsBySelectionRect(QRectF) {}
// vim:ts=8:sw=2:noet

View File

@ -118,6 +118,7 @@ public:
void calcCoordinateP (const double*x, const double*y, const double*z, Graph::iterator& p, Axis const* A) const;
// TODO: Make pointToValue a pure virtual function.
virtual MappedPoint pointToValue(const QPointF&) { return MappedPoint(); };
virtual void setLimitsBySelectionRect(QRectF) {};
virtual void finishMarkerCoordinates(float&, float&) const;
virtual void calcLimits() {};
virtual QString extraMarkerText(Marker const*) const {return "";}

View File

@ -113,11 +113,34 @@ MappedPoint RectDiagram::pointToValue(const QPointF& point)
result.y2 = zAxis.log ? pow(10, value.y()) : value.y();
// qDebug() << "Transform yields: " << value;
// Convert to exponential if needed.
return result;
}
void RectDiagram::setLimitsBySelectionRect(QRectF select) {
int i;
double a, b, c;
// Set the diagram limits.
auto minValue = pointToValue(select.bottomLeft());
auto maxValue = pointToValue(select.topRight());
xAxis.limit_min = minValue.x;
xAxis.limit_max = maxValue.x;
calcAxisScale(&xAxis, a, b, c, xAxis.step, double(x2)); // calculate step X
xAxis.autoScale = false;
yAxis.limit_min = maxValue.y1;
yAxis.limit_max = minValue.y1;
calcAxisScale(&yAxis, a, b, c, yAxis.step, double(y2)); // calculate step Y1
yAxis.autoScale = false;
zAxis.limit_min = maxValue.y2;
zAxis.limit_max = minValue.y2;
calcAxisScale(&zAxis, a, b, c, zAxis.step, double(y2)); // calculate step Y2
zAxis.autoScale = false;
}
// --------------------------------------------------------------
void RectDiagram::finishMarkerCoordinates(float& fCX, float& fCY) const
{

View File

@ -33,6 +33,7 @@ public:
void calcLimits();
void calcCoordinate(const double*, const double*, const double*, float*, float*, Axis const*) const;
MappedPoint pointToValue(const QPointF& point) override;
void setLimitsBySelectionRect(QRectF) override;
void finishMarkerCoordinates(float&, float&) const;
bool insideDiagram(float, float) const;

View File

@ -1893,27 +1893,7 @@ void MouseActions::MReleaseSetLimits(Schematic *Doc, QMouseEvent *Event)
if (select.width() < MIN_SELECT_SIZE || select.height() < MIN_SELECT_SIZE)
break;
// Set the diagram limits.
auto minValue = diagram->pointToValue(select.bottomLeft());
auto maxValue = diagram->pointToValue(select.topRight());
diagram->xAxis.limit_min = minValue.x;
diagram->xAxis.limit_max = maxValue.x;
// TODO: Implement something less arbitrary for the step size.
diagram->xAxis.step = (maxValue.x - minValue.x) / 2;
diagram->xAxis.autoScale = false;
diagram->yAxis.limit_min = maxValue.y1;
diagram->yAxis.limit_max = minValue.y1;
// TODO: Implement something less arbitrary for the step size.
diagram->yAxis.step = (maxValue.y1 - minValue.y1 / 2);
diagram->yAxis.autoScale = false;
diagram->zAxis.limit_min = maxValue.y2;
diagram->zAxis.limit_max = minValue.y2;
// TODO: Implement something less arbitrary for the step size.
diagram->zAxis.step = (maxValue.y2 - minValue.y2 / 2);
diagram->zAxis.autoScale = false;
diagram->setLimitsBySelectionRect(select);
// TODO: Consider refactoring loadGraphData to reload the current dataset if an empty string is passed.
QFileInfo Info(Doc->DocName);