diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp index fc461b3..6a6a515 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/traceplot.cpp @@ -562,6 +562,10 @@ Marker *TracePlot::markerAtPosition(QPoint p, bool onlyMovable) // invalid, skip continue; } + if(!positionWithinGraphArea(markerPoint) && !Preferences::getInstance().Marker.clipToYAxis) { + // this marker is currently not visible on the graph, do not accept it as a valid choice + continue; + } auto diff = markerPoint - p; unsigned int distance = diff.x() * diff.x() + diff.y() * diff.y(); if(distance < closestDistance) { diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp index 5f6269c..298f2a6 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracepolar.cpp @@ -130,7 +130,7 @@ bool TracePolar::positionWithinGraphArea(const QPoint &p) QPoint TracePolar::dataToPixel(std::complex d) { - return transform.map(QPoint(d.real() * polarCoordMax * (1.0 / edgeReflection), -d.imag() * polarCoordMax * (1.0 / edgeReflection))); + return transform.map(QPoint(round(d.real() * polarCoordMax * (1.0 / edgeReflection)), round(-d.imag() * polarCoordMax * (1.0 / edgeReflection)))); } QPoint TracePolar:: dataToPixel(Trace::Data d) @@ -165,13 +165,22 @@ std::complex TracePolar::pixelToData(QPoint p) QPoint TracePolar::markerToPixel(Marker *m) { QPoint ret = QPoint(); -// if(!m->isTimeDomain()) { - if(m->getPosition() >= sweep_fmin && m->getPosition() <= sweep_fmax) { - auto d = m->getData(); - d = dataAddOffset(d); - ret = dataToPixel(d); + if(m->getPosition() >= sweep_fmin && m->getPosition() <= sweep_fmax) { + auto d = m->getData(); + d = dataAddOffset(d); + if(abs(d) > edgeReflection && limitToEdge) { + // marker position is outside of the graph + auto &pref = Preferences::getInstance(); + if(pref.Marker.clipToYAxis) { + // we still want to show the marker but at the edge of the graph + d /= (abs(d) / edgeReflection); + } else { + // we do not show the marker + return ret; + } } -// } + ret = dataToPixel(d); + } return ret; } @@ -188,6 +197,10 @@ double TracePolar::nearestTracePoint(Trace *t, QPoint pixel, double *distance) continue; } data = dataAddOffset(data); + if(limitToEdge && abs(data.y) > edgeReflection) { + // this trace point is outside of the visible range, clip to circle + data.y /= (abs(data.y) / edgeReflection); + } auto plotPoint = dataToPixel(data); if (plotPoint.isNull()) { // destination point outside of currently displayed range diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp index 9bf81c7..e2d5b83 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracesmithchart.cpp @@ -367,14 +367,16 @@ void TraceSmithChart::draw(QPainter &p) { // marker not in trace range continue; } - auto coords = m->getData(); - coords = dataAddOffset(coords); - - if (limitToEdge && abs(coords) > edgeReflection) { - // outside of visible area + auto point = markerToPixel(m); + if(point.isNull()) { + // marker point is invalid continue; } - auto point = dataToPixel(coords); + + // if (limitToEdge && abs(pixelToData(point)) > edgeReflection) { + // // outside of visible area + // continue; + // } auto symbol = m->getSymbol(); p.drawPixmap(point.x() - symbol.width()/2, point.y() - symbol.height(), symbol); } diff --git a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp index 3071c38..bd0fc30 100644 --- a/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Traces/tracexyplot.cpp @@ -452,8 +452,8 @@ void TraceXYPlot::draw(QPainter &p) plotAreaWidth -= yAxisDisabledSpace; } - auto plotRect = QRect(plotAreaLeft, plotAreaTop, plotAreaWidth + 1, plotAreaBottom-plotAreaTop); - p.drawRect(plotRect); + auto plotRect = QRect(plotAreaLeft, plotAreaTop, plotAreaWidth + 1, plotAreaBottom-plotAreaTop + 1); + p.drawRect(QRect(plotAreaLeft, plotAreaTop, plotAreaWidth, plotAreaBottom-plotAreaTop)); // draw axis types auto font = p.font(); @@ -490,7 +490,7 @@ void TraceXYPlot::draw(QPainter &p) int lastTickLabelEnd = std::numeric_limits::max(); for(unsigned int j = 0; j < yAxis[i].getTicks().size(); j++) { - auto yCoord = yAxis[i].transform(yAxis[i].getTicks()[j], w.height() - xAxisSpace, plotAreaTop); + auto yCoord = yAxis[i].transform(yAxis[i].getTicks()[j], plotAreaBottom, plotAreaTop); p.setPen(QPen(pref.Graphs.Color.axis, 1)); // draw tickmark on axis auto tickStart = i == 0 ? plotAreaLeft : plotAreaLeft + plotAreaWidth; @@ -630,15 +630,6 @@ void TraceXYPlot::draw(QPainter &p) p.drawLine(p1, p2); } - if(pref.Marker.clipToYAxis) { - // clip Y coordinate of markers to visible area (always show markers, even when out of range) - if(point.y() < plotRect.top()) { - point.ry() = plotRect.top(); - } else if(point.y() > plotRect.bottom()) { - point.ry() = plotRect.bottom(); - } - } - if(!plotRect.contains(point)) { // out of screen continue; @@ -1116,8 +1107,8 @@ QPointF TraceXYPlot::traceToCoordinate(Trace *t, unsigned int sample, YAxis &yax QPoint TraceXYPlot::plotValueToPixel(QPointF plotValue, int Yaxis) { QPoint p; - p.setX(xAxis.transform(plotValue.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth)); - p.setY(yAxis[Yaxis].transform(plotValue.y(), plotAreaBottom, plotAreaTop)); + p.setX(round(xAxis.transform(plotValue.x(), plotAreaLeft, plotAreaLeft + plotAreaWidth))); + p.setY(round(yAxis[Yaxis].transform(plotValue.y(), plotAreaBottom, plotAreaTop))); return p; } @@ -1156,6 +1147,14 @@ QPoint TraceXYPlot::markerToPixel(Marker *m) } else { markerPoint = traceToCoordinate(t, t->index(xPosition), yAxis[0]); } + auto &pref = Preferences::getInstance(); + if(pref.Marker.clipToYAxis) { + if(markerPoint.y() > yAxis[0].getRangeMax()) { + markerPoint.setY(yAxis[0].getRangeMax()); + } else if(markerPoint.y() < yAxis[0].getRangeMin()) { + markerPoint.setY(yAxis[0].getRangeMin()); + } + } return plotValueToPixel(markerPoint, 0); } @@ -1175,6 +1174,8 @@ double TraceXYPlot::nearestTracePoint(Trace *t, QPoint pixel, double *distance) continue; } auto plotPoint = plotValueToPixel(point, 0); + // constrain to the visible Y axis range + Util::constrain(plotPoint.ry(), plotAreaTop, plotAreaBottom); QPointF diff = plotPoint - pixel; auto distance = diff.x() * diff.x() + diff.y() * diff.y(); if(distance < closestDistance) {