option to link RHS ticks to LHS ticks on XY-plots

This commit is contained in:
Jan Käberich 2024-06-29 12:44:10 +02:00
parent 8b021cf5d1
commit 4dea10552c
6 changed files with 48 additions and 14 deletions

View file

@ -97,6 +97,7 @@ static void createLogarithmicTicks(vector<double>& ticks, double start, double s
YAxis::YAxis()
{
type = Type::Magnitude;
tickMaster = nullptr;
}
double YAxis::sampleToCoordinate(Trace::Data data, Trace *t, unsigned int sample)
@ -391,6 +392,17 @@ std::complex<double> YAxis::reconstructValueFromYAxisType(std::map<YAxis::Type,
return ret;
}
void YAxis::updateTicks()
{
Axis::updateTicks();
if((autorange || autoDivs) && tickMaster && Preferences::getInstance().Graphs.enableMasterTicksForYAxis) {
ticks.clear();
for(auto masterTick : tickMaster->getTicks()) {
ticks.push_back(Util::Scale(masterTick, tickMaster->rangeMin, tickMaster->rangeMax, rangeMin, rangeMax));
}
}
}
bool XAxis::isSupported(XAxis::Type type, TraceModel::DataSource source)
{
if(source == TraceModel::DataSource::VNA) {

View file

@ -22,7 +22,7 @@ public:
const std::vector<double> &getTicks() const;
protected:
void updateTicks();
virtual void updateTicks();
bool log;
bool autorange;
double rangeMin;
@ -99,14 +99,22 @@ public:
QString Unit(TraceModel::DataSource source = TraceModel::DataSource::VNA);
QString Prefixes(TraceModel::DataSource source = TraceModel::DataSource::VNA);
void setTickMaster(YAxis &master) {
tickMaster = &master;
}
Type getType() const;
bool isSupported(XAxis::Type type, TraceModel::DataSource source);
static std::set<YAxis::Type> getSupported(XAxis::Type type, TraceModel::DataSource source);
static std::complex<double> reconstructValueFromYAxisType(std::map<Type, double> yaxistypes);
protected:
virtual void updateTicks() override;
private:
Type type;
YAxis *tickMaster; // if set, the tick positions will be set to match if this option is enabled in the preferences and ticks are set to auto
};
#endif // TRACEAXIS_H

View file

@ -24,6 +24,8 @@ TraceXYPlot::TraceXYPlot(TraceModel &model, QWidget *parent)
{
xAxisMode = XAxisMode::UseSpan;
yAxis[1].setTickMaster(yAxis[0]);
// Setup default axis
setYAxis(0, YAxis::Type::Magnitude, false, false, -120, 20, 14, true);
setYAxis(1, YAxis::Type::Phase, false, false, -180, 180, 12, true);

View file

@ -286,6 +286,7 @@ void PreferencesDialog::setInitialGUIState()
ui->GraphsSweepLine->setChecked(p->Graphs.SweepIndicator.line);
ui->GraphsSweepHide->setChecked(p->Graphs.SweepIndicator.hide);
ui->GraphsSweepHidePercent->setValue(p->Graphs.SweepIndicator.hidePercent);
ui->graphsEnableMasterTicksForYAxis->setChecked(p->Graphs.enableMasterTicksForYAxis);
ui->MarkerShowMarkerData->setChecked(p->Marker.defaultBehavior.showDataOnGraphs);
@ -398,6 +399,7 @@ void PreferencesDialog::updateFromGUI()
p->Graphs.SweepIndicator.line = ui->GraphsSweepLine->isChecked();
p->Graphs.SweepIndicator.hide = ui->GraphsSweepHide->isChecked();
p->Graphs.SweepIndicator.hidePercent = ui->GraphsSweepHidePercent->value();
p->Graphs.enableMasterTicksForYAxis = ui->graphsEnableMasterTicksForYAxis->isChecked();
p->Marker.defaultBehavior.showDataOnGraphs = ui->MarkerShowMarkerData->isChecked();
p->Marker.defaultBehavior.showdB = ui->MarkerShowdB->isChecked();

View file

@ -136,6 +136,8 @@ public:
bool enablePanAndZoom;
double zoomFactor;
bool enableMasterTicksForYAxis;
struct {
bool triangle;
int triangleSize;
@ -258,6 +260,7 @@ private:
{&Graphs.fontSizeTraceNames, "Graphs.fontSizeTraceNames", 12},
{&Graphs.enablePanAndZoom, "Graphs.enablePanAndZoom", true},
{&Graphs.zoomFactor, "Graphs.zoomFactor", 0.9},
{&Graphs.enableMasterTicksForYAxis, "Graphs.enableMasterTicksForYAxis", false},
{&Graphs.SweepIndicator.triangle, "Graphs.SweepIndicator.triangle", true},
{&Graphs.SweepIndicator.triangleSize, "Graphs.SweepIndicator.triangleSize", 5},
{&Graphs.SweepIndicator.line, "Graphs.SweepIndicator.line", false},

View file

@ -98,7 +98,7 @@
</size>
</property>
<property name="currentIndex">
<number>5</number>
<number>2</number>
</property>
<widget class="QWidget" name="Startup">
<layout class="QHBoxLayout" name="horizontalLayout_4">
@ -112,8 +112,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>522</width>
<height>914</height>
<width>424</width>
<height>852</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_13">
@ -703,8 +703,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>565</width>
<height>477</height>
<width>450</width>
<height>416</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_21">
@ -944,8 +944,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>553</width>
<height>1075</height>
<width>679</width>
<height>964</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_22">
@ -1029,6 +1029,13 @@
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="graphsEnableMasterTicksForYAxis">
<property name="text">
<string>Use left Y-axis ticks for right Y-axis ticks in auto mode</string>
</property>
</widget>
</item>
<item>
<widget class="QGroupBox" name="groupBox_16">
<property name="title">
@ -1438,8 +1445,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>683</width>
<height>605</height>
<width>696</width>
<height>564</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout_7">
@ -1784,8 +1791,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>697</width>
<height>563</height>
<width>696</width>
<height>564</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_12">
@ -2067,8 +2074,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>697</width>
<height>563</height>
<width>194</width>
<height>146</height>
</rect>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_19">