Fix x ticks display issue, adjust default values
This commit is contained in:
parent
6ef0d9e87a
commit
a8aebfb216
@ -381,69 +381,6 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
font.setPixelSize(AxisLabelSize);
|
font.setPixelSize(AxisLabelSize);
|
||||||
p.setFont(font);
|
p.setFont(font);
|
||||||
p.drawText(QRect(0, w.height()-AxisLabelSize*1.5, w.width(), AxisLabelSize*1.5), Qt::AlignHCenter, AxisTypeToName(XAxis.type));
|
p.drawText(QRect(0, w.height()-AxisLabelSize*1.5, w.width(), AxisLabelSize*1.5), Qt::AlignHCenter, AxisTypeToName(XAxis.type));
|
||||||
if(XAxis.ticks.size() >= 1) {
|
|
||||||
// draw X ticks
|
|
||||||
// this only works for evenly distributed ticks:
|
|
||||||
auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
|
||||||
auto minLabel = qMin(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
|
||||||
double step;
|
|
||||||
if(XAxis.ticks.size() >= 2) {
|
|
||||||
step = abs(XAxis.ticks[0] - XAxis.ticks[1]);
|
|
||||||
} else {
|
|
||||||
// only one tick, set arbitrary number of digits
|
|
||||||
step = max / 1000;
|
|
||||||
}
|
|
||||||
if(minLabel > 0 && minLabel < step) {
|
|
||||||
step = minLabel;
|
|
||||||
}
|
|
||||||
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
|
||||||
bool displayFullFreq = significantDigits <= 5;
|
|
||||||
constexpr int displayLastDigits = 4;
|
|
||||||
QString prefixes = "fpnum kMG";
|
|
||||||
QString commonPrefix = QString();
|
|
||||||
if(!displayFullFreq) {
|
|
||||||
auto fullFreq = Unit::ToString(XAxis.ticks.front(), "", prefixes, significantDigits);
|
|
||||||
commonPrefix = fullFreq.at(fullFreq.size() - 1);
|
|
||||||
auto front = fullFreq;
|
|
||||||
front.truncate(fullFreq.size() - displayLastDigits);
|
|
||||||
auto back = fullFreq;
|
|
||||||
back.remove(0, front.size());
|
|
||||||
back.append("..");
|
|
||||||
p.setPen(QPen(QColor("orange")));
|
|
||||||
QRect bounding;
|
|
||||||
p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding);
|
|
||||||
p.setPen(pref.Graphs.Color.axis);
|
|
||||||
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back);
|
|
||||||
}
|
|
||||||
|
|
||||||
for(auto t : XAxis.ticks) {
|
|
||||||
auto xCoord = Util::Scale<double>(t, XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth);
|
|
||||||
auto tickValue = Unit::ToString(t, "", prefixes, significantDigits);
|
|
||||||
p.setPen(QPen(pref.Graphs.Color.axis, 1));
|
|
||||||
if(displayFullFreq) {
|
|
||||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue);
|
|
||||||
} else {
|
|
||||||
// check if the same prefix was used as in the fullFreq string
|
|
||||||
if(tickValue.at(tickValue.size() - 1) != commonPrefix) {
|
|
||||||
// prefix changed, we reached the next order of magnitude. Force same prefix as in fullFreq and add extra digit
|
|
||||||
tickValue = Unit::ToString(t, "", commonPrefix, significantDigits + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
tickValue.remove(0, tickValue.size() - displayLastDigits);
|
|
||||||
QRect bounding;
|
|
||||||
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
|
|
||||||
p.setPen(QPen(QColor("orange")));
|
|
||||||
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, "..");
|
|
||||||
p.setPen(QPen(pref.Graphs.Color.axis, 1));
|
|
||||||
}
|
|
||||||
p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2);
|
|
||||||
if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) {
|
|
||||||
p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine));
|
|
||||||
p.drawLine(xCoord, plotAreaTop, xCoord, plotAreaBottom);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for(int i=0;i<2;i++) {
|
for(int i=0;i<2;i++) {
|
||||||
if(YAxis[i].type == YAxisType::Disabled) {
|
if(YAxis[i].type == YAxisType::Disabled) {
|
||||||
continue;
|
continue;
|
||||||
@ -470,7 +407,6 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||||
|
|
||||||
auto yCoordWidth = 0;
|
auto yCoordWidth = 0;
|
||||||
auto yCoordLast = 0;
|
|
||||||
|
|
||||||
for(unsigned int j = 0; j < YAxis[i].ticks.size(); j++) {
|
for(unsigned int j = 0; j < YAxis[i].ticks.size(); j++) {
|
||||||
auto yCoord = Util::Scale<double>(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace);
|
auto yCoord = Util::Scale<double>(YAxis[i].ticks[j], YAxis[i].rangeMax, YAxis[i].rangeMin, plotAreaTop, w.height() - xAxisSpace);
|
||||||
@ -493,19 +429,18 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
}
|
}
|
||||||
if(i == 0) {
|
if(i == 0) {
|
||||||
// only draw tick lines for primary axis
|
// only draw tick lines for primary axis
|
||||||
p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine));
|
|
||||||
p.drawLine(plotAreaLeft, yCoord, plotAreaLeft + plotAreaWidth, yCoord);
|
|
||||||
|
|
||||||
if (pref.Graphs.Color.Ticks.Background.enabled) {
|
if (pref.Graphs.Color.Ticks.Background.enabled) {
|
||||||
yCoordWidth = floor((w.height() - xAxisSpace - plotAreaTop)/(YAxis[i].ticks.size()-1));
|
yCoordWidth = floor((w.height() - xAxisSpace - plotAreaTop)/(YAxis[i].ticks.size()-1));
|
||||||
if (j%2)
|
if (j%2)
|
||||||
{
|
{
|
||||||
p.setBrush(pref.Graphs.Color.Ticks.Background.background);
|
p.setBrush(pref.Graphs.Color.Ticks.Background.background);
|
||||||
auto rect = QRect(plotAreaLeft, yCoord, plotAreaWidth, yCoordWidth);
|
p.setPen(pref.Graphs.Color.Ticks.Background.background);
|
||||||
|
auto rect = QRect(plotAreaLeft+1, yCoord+1, plotAreaWidth-2, yCoordWidth-2);
|
||||||
p.drawRect(rect);
|
p.drawRect(rect);
|
||||||
}
|
}
|
||||||
yCoordLast = yCoord;
|
|
||||||
}
|
}
|
||||||
|
p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine));
|
||||||
|
p.drawLine(plotAreaLeft, yCoord, plotAreaLeft + plotAreaWidth, yCoord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -572,6 +507,69 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
p.setClipping(false);
|
p.setClipping(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(XAxis.ticks.size() >= 1) {
|
||||||
|
// draw X ticks
|
||||||
|
// this only works for evenly distributed ticks:
|
||||||
|
auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
||||||
|
auto minLabel = qMin(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
||||||
|
double step;
|
||||||
|
if(XAxis.ticks.size() >= 2) {
|
||||||
|
step = abs(XAxis.ticks[0] - XAxis.ticks[1]);
|
||||||
|
} else {
|
||||||
|
// only one tick, set arbitrary number of digits
|
||||||
|
step = max / 1000;
|
||||||
|
}
|
||||||
|
if(minLabel > 0 && minLabel < step) {
|
||||||
|
step = minLabel;
|
||||||
|
}
|
||||||
|
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||||
|
bool displayFullFreq = significantDigits <= 5;
|
||||||
|
constexpr int displayLastDigits = 4;
|
||||||
|
QString prefixes = "fpnum kMG";
|
||||||
|
QString commonPrefix = QString();
|
||||||
|
if(!displayFullFreq) {
|
||||||
|
auto fullFreq = Unit::ToString(XAxis.ticks.front(), "", prefixes, significantDigits);
|
||||||
|
commonPrefix = fullFreq.at(fullFreq.size() - 1);
|
||||||
|
auto front = fullFreq;
|
||||||
|
front.truncate(fullFreq.size() - displayLastDigits);
|
||||||
|
auto back = fullFreq;
|
||||||
|
back.remove(0, front.size());
|
||||||
|
back.append("..");
|
||||||
|
p.setPen(QPen(QColor("orange")));
|
||||||
|
QRect bounding;
|
||||||
|
p.drawText(QRect(2, plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, front, &bounding);
|
||||||
|
p.setPen(pref.Graphs.Color.axis);
|
||||||
|
p.drawText(QRect(bounding.x() + bounding.width(), plotAreaBottom + AxisLabelSize + 5, w.width(), AxisLabelSize), 0, back);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(auto t : XAxis.ticks) {
|
||||||
|
auto xCoord = Util::Scale<double>(t, XAxis.rangeMin, XAxis.rangeMax, plotAreaLeft, plotAreaLeft + plotAreaWidth);
|
||||||
|
auto tickValue = Unit::ToString(t, "", prefixes, significantDigits);
|
||||||
|
p.setPen(QPen(pref.Graphs.Color.axis, 1));
|
||||||
|
if(displayFullFreq) {
|
||||||
|
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue);
|
||||||
|
} else {
|
||||||
|
// check if the same prefix was used as in the fullFreq string
|
||||||
|
if(tickValue.at(tickValue.size() - 1) != commonPrefix) {
|
||||||
|
// prefix changed, we reached the next order of magnitude. Force same prefix as in fullFreq and add extra digit
|
||||||
|
tickValue = Unit::ToString(t, "", commonPrefix, significantDigits + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
tickValue.remove(0, tickValue.size() - displayLastDigits);
|
||||||
|
QRect bounding;
|
||||||
|
p.drawText(QRect(xCoord - 40, plotAreaBottom + 5, 80, AxisLabelSize), Qt::AlignHCenter, tickValue, &bounding);
|
||||||
|
p.setPen(QPen(QColor("orange")));
|
||||||
|
p.drawText(QRect(0, plotAreaBottom + 5, bounding.x() - 1, AxisLabelSize), Qt::AlignRight, "..");
|
||||||
|
p.setPen(QPen(pref.Graphs.Color.axis, 1));
|
||||||
|
}
|
||||||
|
p.drawLine(xCoord, plotAreaBottom, xCoord, plotAreaBottom + 2);
|
||||||
|
if(xCoord != plotAreaLeft && xCoord != plotAreaLeft + plotAreaWidth) {
|
||||||
|
p.setPen(QPen(pref.Graphs.Color.Ticks.divisions, 0.5, Qt::DashLine));
|
||||||
|
p.drawLine(xCoord, plotAreaTop, xCoord, plotAreaBottom);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(dropPending) {
|
if(dropPending) {
|
||||||
p.setOpacity(0.5);
|
p.setOpacity(0.5);
|
||||||
p.setBrush(Qt::white);
|
p.setBrush(Qt::white);
|
||||||
|
@ -130,7 +130,7 @@ private:
|
|||||||
{&Graphs.Color.background, "Graphs.Color.background", QColor(Qt::black)},
|
{&Graphs.Color.background, "Graphs.Color.background", QColor(Qt::black)},
|
||||||
{&Graphs.Color.axis, "Graphs.Color.axis", QColor(Qt::white)},
|
{&Graphs.Color.axis, "Graphs.Color.axis", QColor(Qt::white)},
|
||||||
{&Graphs.Color.Ticks.Background.enabled, "Graphs.Color.Ticks.Background.enabled", true},
|
{&Graphs.Color.Ticks.Background.enabled, "Graphs.Color.Ticks.Background.enabled", true},
|
||||||
{&Graphs.Color.Ticks.Background.background, "Graphs.Color.Ticks.Background.background", QColor(Qt::white)},
|
{&Graphs.Color.Ticks.Background.background, "Graphs.Color.Ticks.Background.background", QColor(20, 20, 20)},
|
||||||
{&Graphs.Color.Ticks.divisions, "Graphs.Color.Ticks.divisions", QColor(Qt::gray)},
|
{&Graphs.Color.Ticks.divisions, "Graphs.Color.Ticks.divisions", QColor(Qt::gray)},
|
||||||
{&Graphs.domainChangeBehavior, "Graphs.domainChangeBehavior", GraphDomainChangeBehavior::AdjustGraphs},
|
{&Graphs.domainChangeBehavior, "Graphs.domainChangeBehavior", GraphDomainChangeBehavior::AdjustGraphs},
|
||||||
{&Graphs.markerBehavior.showDataOnGraphs, "Graphs.markerBehavior.ShowDataOnGraphs", true},
|
{&Graphs.markerBehavior.showDataOnGraphs, "Graphs.markerBehavior.ShowDataOnGraphs", true},
|
||||||
|
@ -715,7 +715,7 @@
|
|||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_17">
|
<widget class="QLabel" name="label_17">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Divisions:</string>
|
<string>Tick lines:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
@ -729,7 +729,7 @@
|
|||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QCheckBox" name="GraphsColorTicksBackgroundEnabled">
|
<widget class="QCheckBox" name="GraphsColorTicksBackgroundEnabled">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Enable background</string>
|
<string>Different background for every 2nd Y tick</string>
|
||||||
</property>
|
</property>
|
||||||
<property name="checked">
|
<property name="checked">
|
||||||
<bool>true</bool>
|
<bool>true</bool>
|
||||||
|
Loading…
Reference in New Issue
Block a user