Fix bugs with displaying of axis ticks
This commit is contained in:
parent
fe78ccdeeb
commit
e1dfc48906
@ -234,11 +234,18 @@ 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, labelX);
|
p.drawText(QRect(0, w.height()-AxisLabelSize*1.5, w.width(), AxisLabelSize*1.5), Qt::AlignHCenter, labelX);
|
||||||
|
if(XAxis.ticks.size() >= 1) {
|
||||||
// draw X ticks
|
// draw X ticks
|
||||||
// this only works for evenly distributed ticks:
|
// this only works for evenly distributed ticks:
|
||||||
auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
auto max = qMax(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
||||||
auto minLabel = qMin(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
auto minLabel = qMin(abs(XAxis.ticks.front()), abs(XAxis.ticks.back()));
|
||||||
auto step = abs(XAxis.ticks[0] - XAxis.ticks[1]);
|
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) {
|
if(minLabel > 0 && minLabel < step) {
|
||||||
step = minLabel;
|
step = minLabel;
|
||||||
}
|
}
|
||||||
@ -288,6 +295,7 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
p.drawLine(xCoord, 0, xCoord, plotAreaBottom);
|
p.drawLine(xCoord, 0, 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) {
|
||||||
@ -311,10 +319,16 @@ void TraceXYPlot::draw(QPainter &p)
|
|||||||
p.drawText(QRect(0, 0, w.height()-xAxisSpace, AxisLabelSize*1.5), Qt::AlignHCenter, labelY);
|
p.drawText(QRect(0, 0, w.height()-xAxisSpace, AxisLabelSize*1.5), Qt::AlignHCenter, labelY);
|
||||||
p.restore();
|
p.restore();
|
||||||
// draw ticks
|
// draw ticks
|
||||||
if(YAxis[0].type != YAxisType::Disabled) {
|
if(YAxis[i].type != YAxisType::Disabled && YAxis[i].ticks.size() > 0) {
|
||||||
// this only works for evenly distributed ticks:
|
// this only works for evenly distributed ticks:
|
||||||
auto max = qMax(abs(YAxis[i].ticks.front()), abs(YAxis[i].ticks.back()));
|
auto max = qMax(abs(YAxis[i].ticks.front()), abs(YAxis[i].ticks.back()));
|
||||||
auto step = abs(YAxis[i].ticks[0] - YAxis[i].ticks[1]);
|
double step;
|
||||||
|
if(YAxis[i].ticks.size() >= 2) {
|
||||||
|
step = abs(YAxis[i].ticks[0] - YAxis[i].ticks[1]);
|
||||||
|
} else {
|
||||||
|
// only one tick, set arbitrary number of digits
|
||||||
|
step = max / 1000;
|
||||||
|
}
|
||||||
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
int significantDigits = floor(log10(max)) - floor(log10(step)) + 1;
|
||||||
for(auto t : YAxis[i].ticks) {
|
for(auto t : YAxis[i].ticks) {
|
||||||
auto yCoord = Util::Scale<double>(t, YAxis[i].rangeMax, YAxis[i].rangeMin, 0, w.height() - xAxisSpace);
|
auto yCoord = Util::Scale<double>(t, YAxis[i].rangeMax, YAxis[i].rangeMin, 0, w.height() - xAxisSpace);
|
||||||
|
Loading…
Reference in New Issue
Block a user