- Use margins properly.

pull/27/head
Rune Broberg 2019-10-01 13:00:59 +02:00
rodzic bf28eb6846
commit b9f9cd07ad
1 zmienionych plików z 111 dodań i 74 usunięć

Wyświetl plik

@ -184,7 +184,7 @@ class FrequencyChart(Chart):
leftMargin = 30
rightMargin = 20
lowerMargin = 20
bottomMargin = 20
topMargin = 30
def __init__(self, name):
@ -343,7 +343,7 @@ class FrequencyChart(Chart):
def resizeEvent(self, a0: QtGui.QResizeEvent) -> None:
self.chartWidth = a0.size().width()-self.rightMargin-self.leftMargin
self.chartHeight = a0.size().height()-self.lowerMargin-self.topMargin
self.chartHeight = a0.size().height() - self.bottomMargin - self.topMargin
self.update()
def paintEvent(self, a0: QtGui.QPaintEvent) -> None:
@ -463,7 +463,7 @@ class PhaseChart(FrequencyChart):
self.minDisplayValue = -180
self.maxDisplayValue = 180
self.setMinimumSize(self.chartWidth + self.rightMargin + self.leftMargin, self.chartHeight + self.topMargin + self.lowerMargin)
self.setMinimumSize(self.chartWidth + self.rightMargin + self.leftMargin, self.chartHeight + self.topMargin + self.bottomMargin)
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
pal = QtGui.QPalette()
pal.setColor(QtGui.QPalette.Background, self.backgroundColor)
@ -561,8 +561,10 @@ class VSWRChart(FrequencyChart):
self.maxDisplayValue = 25
self.minDisplayValue = 1
self.setMinimumSize(self.chartWidth + 20 + self.leftMargin, self.chartHeight + 40)
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
self.setMinimumSize(self.chartWidth + self.rightMargin + self.leftMargin,
self.chartHeight + self.topMargin + self.bottomMargin)
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
QtWidgets.QSizePolicy.MinimumExpanding))
pal = QtGui.QPalette()
pal.setColor(QtGui.QPalette.Background, self.backgroundColor)
self.setPalette(pal)
@ -572,8 +574,10 @@ class VSWRChart(FrequencyChart):
qp.setPen(QtGui.QPen(self.textColor))
qp.drawText(3, 15, self.name)
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
qp.drawLine(self.leftMargin, self.topMargin - 5,
self.leftMargin, self.topMargin + self.chartHeight + 5)
qp.drawLine(self.leftMargin-5, self.topMargin + self.chartHeight,
self.leftMargin+self.chartWidth, self.topMargin + self.chartHeight)
def drawValues(self, qp: QtGui.QPainter):
from NanoVNASaver.NanoVNASaver import NanoVNASaver
@ -630,26 +634,26 @@ class VSWRChart(FrequencyChart):
ticksize = 2
for i in range(minVSWR, maxVSWR, ticksize):
y = 30 + round((maxVSWR-i)/span*(self.chartHeight-10))
y = self.topMargin + round((maxVSWR-i)/span*self.chartHeight)
if i != minVSWR and i != maxVSWR:
qp.setPen(self.textColor)
qp.drawText(3, y+3, str(i))
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
qp.drawLine(self.leftMargin - 5, 30, self.leftMargin + self.chartWidth, 30)
qp.drawLine(self.leftMargin - 5, self.topMargin, self.leftMargin + self.chartWidth, self.topMargin)
qp.setPen(self.textColor)
qp.drawText(3, 35, str(maxVSWR))
qp.drawText(3, self.chartHeight+20, str(minVSWR))
qp.drawText(3, self.chartHeight + self.topMargin, str(minVSWR))
# At least 100 px between ticks
qp.drawText(self.leftMargin-20, 20 + self.chartHeight + 15, Chart.shortenFrequency(fstart))
qp.drawText(self.leftMargin-20, self.topMargin + self.chartHeight + 15, Chart.shortenFrequency(fstart))
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
for i in range(ticks):
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
qp.drawLine(x, self.topMargin, x, self.topMargin + self.chartHeight + 5)
qp.setPen(self.textColor)
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
qp.drawText(x-20, self.topMargin + self.chartHeight + 15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
self.drawData(qp, self.data, self.sweepColor)
self.drawData(qp, self.reference, self.referenceColor)
@ -658,7 +662,7 @@ class VSWRChart(FrequencyChart):
def getYPosition(self, d: Datapoint) -> int:
from NanoVNASaver.NanoVNASaver import NanoVNASaver
_, _, vswr = NanoVNASaver.vswr(d)
return 30 + round((self.maxVSWR - vswr) / self.span * (self.chartHeight - 10))
return self.topMargin + round((self.maxVSWR - vswr) / self.span * self.chartHeight)
def resetDisplayLimits(self):
self.maxDisplayValue = 25
@ -944,7 +948,7 @@ class LogMagChart(FrequencyChart):
self.minDisplayValue = -80
self.maxDisplayValue = 10
self.setMinimumSize(self.chartWidth + self.rightMargin + self.leftMargin, self.chartHeight + self.topMargin + self.lowerMargin)
self.setMinimumSize(self.chartWidth + self.rightMargin + self.leftMargin, self.chartHeight + self.topMargin + self.bottomMargin)
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
pal = QtGui.QPalette()
pal.setColor(QtGui.QPalette.Background, self.backgroundColor)
@ -1076,8 +1080,10 @@ class QualityFactorChart(FrequencyChart):
self.minDisplayValue = 0
self.maxDisplayValue = 100
self.setMinimumSize(self.chartWidth + 20 + self.leftMargin, self.chartHeight + 40)
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
self.setMinimumSize(self.chartWidth + self.rightMargin + self.leftMargin,
self.chartHeight + self.topMargin + self.bottomMargin)
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding,
QtWidgets.QSizePolicy.MinimumExpanding))
pal = QtGui.QPalette()
pal.setColor(QtGui.QPalette.Background, self.backgroundColor)
self.setPalette(pal)
@ -1088,8 +1094,9 @@ class QualityFactorChart(FrequencyChart):
qp.setPen(QtGui.QPen(self.textColor))
qp.drawText(3, 15, self.name)
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth, 20 + self.chartHeight)
qp.drawLine(self.leftMargin, self.topMargin - 5, self.leftMargin, self.topMargin + self.chartHeight + 5)
qp.drawLine(self.leftMargin-5, self.topMargin + self.chartHeight,
self.leftMargin+self.chartWidth, self.topMargin + self.chartHeight)
maxQ = 0
# Make up some sensible scaling here
@ -1115,12 +1122,12 @@ class QualityFactorChart(FrequencyChart):
if self.span == 0:
return # No data to draw the graph from
for i in range(self.minQ, self.maxQ, step):
y = 30 + round((self.maxQ - i) / self.span * (self.chartHeight-10))
y = self.topMargin + round((self.maxQ - i) / self.span * self.chartHeight)
qp.setPen(QtGui.QPen(self.textColor))
qp.drawText(3, y+3, str(i))
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(self.leftMargin-5, y, self.leftMargin+self.chartWidth, y)
qp.drawLine(self.leftMargin - 5, 30, self.leftMargin + self.chartWidth, 30)
qp.drawLine(self.leftMargin-5, y, self.leftMargin + self.chartWidth, y)
qp.drawLine(self.leftMargin - 5, self.topMargin, self.leftMargin + self.chartWidth, self.topMargin)
qp.setPen(self.textColor)
qp.drawText(3, 35, str(self.maxQ))
@ -1155,14 +1162,15 @@ class QualityFactorChart(FrequencyChart):
self.drawBands(qp, fstart, fstop)
qp.setPen(self.textColor)
qp.drawText(self.leftMargin-20, 20 + self.chartHeight + 15, Chart.shortenFrequency(fstart))
qp.drawText(self.leftMargin-20, self.topMargin + self.chartHeight + 15, Chart.shortenFrequency(fstart))
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
for i in range(ticks):
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
qp.drawLine(x, self.topMargin - 5, x, self.topMargin + self.chartHeight + 5)
qp.setPen(self.textColor)
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
qp.drawText(x - 20, self.topMargin + self.chartHeight + 15,
Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
self.drawData(qp, self.data, self.sweepColor)
self.drawData(qp, self.reference, self.referenceColor)
@ -1171,7 +1179,7 @@ class QualityFactorChart(FrequencyChart):
def getYPosition(self, d: Datapoint) -> int:
from NanoVNASaver.NanoVNASaver import NanoVNASaver
Q = NanoVNASaver.qualifyFactor(d)
return 30 + round((self.maxQ - Q) / self.span * (self.chartHeight - 10))
return self.topMargin + round((self.maxQ - Q) / self.span * self.chartHeight)
class TDRChart(Chart):
@ -1180,7 +1188,7 @@ class TDRChart(Chart):
self.tdrWindow = None
self.leftMargin = 20
self.rightMargin = 20
self.lowerMargin = 35
self.bottomMargin = 35
self.setMinimumSize(250, 250)
self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.MinimumExpanding))
pal = QtGui.QPalette()
@ -1194,12 +1202,12 @@ class TDRChart(Chart):
qp.drawText(3, 15, self.name)
width = self.width() - self.leftMargin - self.rightMargin
height = self.height() - self.lowerMargin
height = self.height() - self.bottomMargin
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(self.leftMargin - 5, self.height() - self.lowerMargin, self.width() - self.rightMargin,
self.height() - self.lowerMargin)
qp.drawLine(self.leftMargin, 20, self.leftMargin, self.height() - self.lowerMargin + 5)
qp.drawLine(self.leftMargin - 5, self.height() - self.bottomMargin, self.width() - self.rightMargin,
self.height() - self.bottomMargin)
qp.drawLine(self.leftMargin, 20, self.leftMargin, self.height() - self.bottomMargin + 5)
ticks = math.floor((self.width() - self.leftMargin)/100) # Number of ticks does not include the origin
@ -1302,8 +1310,9 @@ class RealImaginaryChart(FrequencyChart):
qp.drawText(10, 15, "R")
qp.drawText(self.leftMargin + self.chartWidth + 10, 15, "X")
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(self.leftMargin, 20, self.leftMargin, 20+self.chartHeight+5)
qp.drawLine(self.leftMargin-5, 20+self.chartHeight, self.leftMargin+self.chartWidth+5, 20 + self.chartHeight)
qp.drawLine(self.leftMargin, self.topMargin - 5, self.leftMargin, self.topMargin + self.chartHeight + 5)
qp.drawLine(self.leftMargin-5, self.topMargin + self.chartHeight,
self.leftMargin + self.chartWidth + 5, self.topMargin + self.chartHeight)
def drawValues(self, qp: QtGui.QPainter):
from NanoVNASaver.NanoVNASaver import NanoVNASaver
@ -1411,7 +1420,7 @@ class RealImaginaryChart(FrequencyChart):
horizontal_ticks = math.floor(self.chartHeight/50)
for i in range(horizontal_ticks):
y = 30 + round(i * (self.chartHeight-10) / horizontal_ticks)
y = self.topMargin + round(i * self.chartHeight / horizontal_ticks)
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(self.leftMargin - 5, y, self.leftMargin + self.chartWidth + 5, y)
qp.setPen(QtGui.QPen(self.textColor))
@ -1420,17 +1429,17 @@ class RealImaginaryChart(FrequencyChart):
qp.drawText(3, y + 4, str(round(re, 1)))
qp.drawText(self.leftMargin + self.chartWidth + 8, y + 4, str(round(im, 1)))
qp.drawText(3, self.chartHeight + 20, str(round(min_real, 1)))
qp.drawText(self.leftMargin + self.chartWidth + 8, self.chartHeight + 20, str(round(min_imag, 1)))
qp.drawText(3, self.chartHeight + self.topMargin, str(round(min_real, 1)))
qp.drawText(self.leftMargin + self.chartWidth + 8, self.chartHeight + self.topMargin, str(round(min_imag, 1)))
qp.drawText(self.leftMargin-20, 20 + self.chartHeight + 15, Chart.shortenFrequency(fstart))
qp.drawText(self.leftMargin-20, self.topMargin + self.chartHeight + 15, Chart.shortenFrequency(fstart))
ticks = math.floor(self.chartWidth/100) # Number of ticks does not include the origin
for i in range(ticks):
x = self.leftMargin + round((i+1)*self.chartWidth/ticks)
qp.setPen(QtGui.QPen(self.foregroundColor))
qp.drawLine(x, 20, x, 20+self.chartHeight+5)
qp.drawLine(x, self.topMargin - 5, x, self.topMargin + self.chartHeight + 5)
qp.setPen(self.textColor)
qp.drawText(x-20, 20+self.chartHeight+15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
qp.drawText(x-20, self.topMargin + self.chartHeight + 15, Chart.shortenFrequency(round(fspan/ticks*(i+1) + fstart)))
primary_pen = pen
secondary_pen = QtGui.QPen(self.secondarySweepColor)
@ -1449,29 +1458,43 @@ class RealImaginaryChart(FrequencyChart):
qp.drawLine(self.leftMargin + self.chartWidth, 9, self.leftMargin + self.chartWidth + 5, 9)
for i in range(len(self.data)):
re, im = NanoVNASaver.normalize50(self.data[i])
x = self.getXPosition(self.data[i])
y_re = 30 + round((max_real - re) / span_real * (self.chartHeight - 10))
y_im = 30 + round((max_imag - im) / span_imag * (self.chartHeight - 10))
y_re = self.getReYPosition(self.data[i])
y_im = self.getImYPosition(self.data[i])
qp.setPen(primary_pen)
if re > 0:
qp.drawPoint(int(x), int(y_re))
if self.isPlotable(x, y_re):
qp.drawPoint(x, y_re)
qp.setPen(secondary_pen)
qp.drawPoint(int(x), int(y_im))
if self.isPlotable(x, y_im):
qp.drawPoint(x, y_im)
if self.drawLines and i > 0:
new_re, new_im = NanoVNASaver.normalize50(self.data[i-1])
prev_x = self.getXPosition(self.data[i-1])
prev_y_re = 30 + round((max_real - new_re) / span_real * (self.chartHeight - 10))
prev_y_im = 30 + round((max_imag - new_im) / span_imag * (self.chartHeight - 10))
prev_x = self.getXPosition(self.data[i - 1])
prev_y_re = self.getReYPosition(self.data[i-1])
prev_y_im = self.getImYPosition(self.data[i-1])
if re > 0 and new_re > 0:
# Real part first
if self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
line_pen.setColor(self.sweepColor)
qp.setPen(line_pen)
qp.drawLine(x, y_re, prev_x, prev_y_re)
elif self.isPlotable(x, y_re) and not self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(x, y_re, prev_x, prev_y_re)
qp.drawLine(x, y_re, new_x, new_y)
elif not self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
line_pen.setColor(self.secondarySweepColor)
qp.setPen(line_pen)
qp.drawLine(x, y_im, prev_x, prev_y_im)
# Imag part first
if self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
line_pen.setColor(self.secondarySweepColor)
qp.setPen(line_pen)
qp.drawLine(x, y_im, prev_x, prev_y_im)
elif self.isPlotable(x, y_im) and not self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(x, y_im, prev_x, prev_y_im)
qp.drawLine(x, y_im, new_x, new_y)
elif not self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
primary_pen.setColor(self.referenceColor)
line_pen.setColor(self.referenceColor)
@ -1489,38 +1512,52 @@ class RealImaginaryChart(FrequencyChart):
for i in range(len(self.reference)):
if self.reference[i].freq < fstart or self.reference[i].freq > fstop:
continue
re, im = NanoVNASaver.normalize50(self.reference[i])
x = self.getXPosition(self.reference[i])
y_re = 30 + round((max_real - re) / span_real * (self.chartHeight - 10))
y_im = 30 + round((max_imag - im) / span_imag * (self.chartHeight - 10))
y_re = self.getReYPosition(self.reference[i])
y_im = self.getImYPosition(self.reference[i])
qp.setPen(primary_pen)
if re > 0:
qp.drawPoint(int(x), int(y_re))
if self.isPlotable(x, y_re):
qp.drawPoint(x, y_re)
qp.setPen(secondary_pen)
qp.drawPoint(int(x), int(y_im))
if self.isPlotable(x, y_im):
qp.drawPoint(x, y_im)
if self.drawLines and i > 0:
new_re, new_im = NanoVNASaver.normalize50(self.reference[i-1])
prev_x = self.getXPosition(self.reference[i-1])
prev_y_re = 30 + round((max_real - new_re) / span_real * (self.chartHeight - 10))
prev_y_im = 30 + round((max_imag - new_im) / span_imag * (self.chartHeight - 10))
prev_x = self.getXPosition(self.reference[i - 1])
prev_y_re = self.getReYPosition(self.reference[i-1])
prev_y_im = self.getImYPosition(self.reference[i-1])
if re > 0 and new_re > 0:
line_pen.setColor(self.referenceColor)
# Real part first
if self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
line_pen.setColor(self.sweepColor)
qp.setPen(line_pen)
qp.drawLine(x, y_re, prev_x, prev_y_re)
elif self.isPlotable(x, y_re) and not self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(x, y_re, prev_x, prev_y_re)
qp.drawLine(x, y_re, new_x, new_y)
elif not self.isPlotable(x, y_re) and self.isPlotable(prev_x, prev_y_re):
new_x, new_y = self.getPlotable(prev_x, prev_y_re, x, y_re)
qp.drawLine(prev_x, prev_y_re, new_x, new_y)
qp.drawLine(x, y_im, prev_x, prev_y_im)
# Imag part first
if self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
line_pen.setColor(self.secondarySweepColor)
qp.setPen(line_pen)
qp.drawLine(x, y_im, prev_x, prev_y_im)
elif self.isPlotable(x, y_im) and not self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(x, y_im, prev_x, prev_y_im)
qp.drawLine(x, y_im, new_x, new_y)
elif not self.isPlotable(x, y_im) and self.isPlotable(prev_x, prev_y_im):
new_x, new_y = self.getPlotable(prev_x, prev_y_im, x, y_im)
qp.drawLine(prev_x, prev_y_im, new_x, new_y)
# Now draw the markers
for m in self.markers:
if m.location != -1:
highlighter.setColor(m.color)
qp.setPen(highlighter)
re, im = NanoVNASaver.normalize50(self.data[m.location])
x = self.getXPosition(self.data[m.location])
y_re = 30 + round((max_real - re) / span_real * (self.chartHeight - 10))
y_im = 30 + round((max_imag - im) / span_imag * (self.chartHeight - 10))
y_re = self.getReYPosition(self.data[m.location])
y_im = self.getImYPosition(self.data[m.location])
qp.drawLine(int(x), int(y_re) + 3, int(x) - 3, int(y_re) - 3)
qp.drawLine(int(x), int(y_re) + 3, int(x) + 3, int(y_re) - 3)
@ -1532,13 +1569,13 @@ class RealImaginaryChart(FrequencyChart):
def getImYPosition(self, d: Datapoint) -> int:
from NanoVNASaver.NanoVNASaver import NanoVNASaver
re, im = NanoVNASaver.normalize50(d)
return 30 + round((self.max_imag - im) / self.span_imag * (self.chartHeight - 10))
_, im = NanoVNASaver.normalize50(d)
return self.topMargin + round((self.max_imag - im) / self.span_imag * self.chartHeight)
def getReYPosition(self, d: Datapoint) -> int:
from NanoVNASaver.NanoVNASaver import NanoVNASaver
re, im = NanoVNASaver.normalize50(d)
return 30 + round((self.max_real - re) / self.span_real * (self.chartHeight - 10))
re, _ = NanoVNASaver.normalize50(d)
return self.topMargin + round((self.max_real - re) / self.span_real * self.chartHeight)
def getNearestMarker(self, x, y) -> Marker:
if len(self.data) == 0: