return peaks;
}
-RulerDrawData SignalController::getRulerDrawData(const double from, const double to, Axis axis)
+RulerDrawData SignalController::getRulerDrawData(const double from, const double to, Axis axis, const int pixelLength, const int minPixelStep, const int maxPixelStep)
{
double diffAbs, diffRel;
double fromAbs, toAbs;
double step, relStep;
double firstTickAbs, firstTickRel;
+ double pixelStep;
+ double numSteps;
+
+ /* Don't bother doing anything for an invisible chart */
+ if (pixelLength < 1)
+ return RulerDrawData();
diffRel = to - from;
/* Calculate step */
diffAbs = toAbs - fromAbs;
step = 1 / pow(10, floor(log10(1 / (diffAbs))) + 1); // Magic - you want to love it but you better not touch!
+ numSteps = diffAbs / step;
+ pixelStep = pixelLength / numSteps + 1;
+ Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString("pixelStep %1, step %2, pixelLength %3, numSteps %4").arg(pixelStep).arg(step).arg(pixelLength).arg(numSteps));
+ if (pixelStep < minPixelStep) {
+ const double upscaleFactor = ceil(minPixelStep / pixelStep);
+ step *= upscaleFactor;
+ Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString("Corrected step %1, upscaleFactor %2").arg(step).arg(upscaleFactor));
+ } else if (pixelStep > maxPixelStep) {
+ const double downscaleFactor = ceil(pixelStep / maxPixelStep);
+ step /= downscaleFactor;
+ Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString("Corrected step %1, downscaleFactor %2").arg(step).arg(downscaleFactor));
+ }
relStep = (diffRel * step) / (diffAbs);
//Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString(" rD %1 aD %2").arg(diffRel).arg(diffAbs));
//Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString(" fA %1 tA %2 fR %3 tR %4").arg(fromAbs).arg(toAbs).arg(from).arg(to));
};
struct RulerDrawData {
- RulerDrawData() : firstTickAbs(0), firstTickRel(0), step(0), relStep(0) {}
- RulerDrawData(const double fta, const double ftr, const double s, const double rs) : firstTickAbs(fta), firstTickRel(ftr), step(s), relStep(rs)
+ RulerDrawData() : firstTickAbs(0), firstTickRel(0), step(0), relStep(0), valid(false) {}
+ RulerDrawData(const double fta, const double ftr, const double s, const double rs) : firstTickAbs(fta), firstTickRel(ftr), step(s), relStep(rs), valid(true)
{}
const double firstTickAbs;
const double firstTickRel;
const double step;
const double relStep;
+ const bool valid;
};
class SignalController : public QObject, public JSONSerializable
Signal::TimeValuePair getXYValues(const double x);
std::shared_ptr<GraphDrawData> getGraphDrawData(const double fromX, const double toX);
std::vector<PeakDrawData> getPeaksDrawData(const double fromX, const double fromY, const double toX, const double toY);
- RulerDrawData getRulerDrawData(const double from, const double to, SignalController::Axis axis);
+ RulerDrawData getRulerDrawData(const double from, const double to, SignalController::Axis axis, const int pixelLength, const int minPixelStep, const int maxPixelStep);
GUIViewport guiViewport() const { return m_guiViewport; }
double fromXAbs() const { return m_signal->timeAt(0); }
double toXAbs() const { return m_signal->timeAt(m_signal->count()-1); }
const QString SignalDrawer::ME_SENDER_STR("SignalDrawer");
const int SignalDrawer::AXIS_LABEL_BORDER_OFFSET(2);
const int SignalDrawer::AXIS_LABEL_SCALE_OFFSET(3);
+const int SignalDrawer::MAXIMAL_AXIS_BIGTICK_STEP(75);
+const int SignalDrawer::MINIMAL_AXIS_BIGTICK_STEP(25);
const int SignalDrawer::SCALE_MARGIN_TIME(16);
const int SignalDrawer::SCALE_MARGIN_VALUE(12);
const double subAbsStep = subStep(rd.step);
double subRel = rd.firstTickRel;
double subAbs = rd.firstTickAbs;
- int ctr = 0;
while (subRel >= relMin) {
- drawFunc(subRel, subAbs, (ctr++ == 5) ? TickType::TICK : TickType::SUBTICK);
+ drawFunc(subRel, subAbs, TickType::SUBTICK);
subRel -= subRelStep;
subAbs -= subAbsStep;
}
double subRel = fromSubRel;
double absVal = fromAbsVal;
- int ctr = 10 - floor(((toSubRel - fromSubRel) / subRelStep) + 0.5);
- //Logger::log(Logger::Level::DEBUG, ME_SENDER_STR, __QFUNC__ + QString("ctr %1, tsr %2, fsr %3 srs %4").arg(ctr).arg(fromSubRel).arg(toSubRel).arg(subRelStep));
-
while (subRel < toSubRel) {
- drawFunc(subRel, absVal, (ctr++ == 5) ? TickType::TICK : TickType::SUBTICK);
+ drawFunc(subRel, absVal, TickType::SUBTICK);
subRel += subRelStep;
absVal += subAbsStep;
}
textDrawFunc = std::bind(&SignalDrawer::renderTimeScaleText, this, p, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
tickDrawFunc = std::bind(&SignalDrawer::renderTimeScaleTick, this, p, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
- RulerDrawData rd = m_controller->getRulerDrawData(m_relXMin, m_relXMax, SignalController::Axis::TIME);
+ RulerDrawData rd = m_controller->getRulerDrawData(m_relXMin, m_relXMax, SignalController::Axis::TIME, m_gWidth, MINIMAL_AXIS_BIGTICK_STEP, MAXIMAL_AXIS_BIGTICK_STEP);
+ if (!rd.valid)
+ return;
/* Draw text first - we need to know how wide is the largest numeric cue */
drawScaleByTicks(rd, textDrawFunc, m_relXMax, false);
textDrawFunc = std::bind(&SignalDrawer::renderValueScaleText, this, p, std::ref(maxCueWidth), std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
tickDrawFunc = std::bind(&SignalDrawer::renderValueScaleTick, this, p, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
- RulerDrawData rd = m_controller->getRulerDrawData(m_relYMin, m_relYMax, SignalController::Axis::VALUE);
+ RulerDrawData rd = m_controller->getRulerDrawData(m_relYMin, m_relYMax, SignalController::Axis::VALUE, m_gHeight, MINIMAL_AXIS_BIGTICK_STEP, MAXIMAL_AXIS_BIGTICK_STEP);
+ if (!rd.valid)
+ return;
/* Draw text first - we need to know how wide is the largest numeric cue */
drawScaleByTicks(rd, textDrawFunc, m_relYMax, false);
case TickType::BIGTICK:
p->drawLine(xPix, m_gHeight + 2, xPix, m_gHeight + 8);
break;
- case TickType::TICK:
- p->drawLine(xPix, m_gHeight + 2, xPix, m_gHeight + 6);
- break;
case TickType::SUBTICK:
p->drawLine(xPix, m_gHeight + 2, xPix , m_gHeight + 4);
break;
case TickType::BIGTICK:
p->drawLine(m_leftGraphOffset - 8, yPix, m_leftGraphOffset - 1, yPix);
break;
- case TickType::TICK:
- p->drawLine(m_leftGraphOffset - 6, yPix, m_leftGraphOffset - 1, yPix);
- break;
case TickType::SUBTICK:
p->drawLine(m_leftGraphOffset - 4, yPix, m_leftGraphOffset - 1, yPix);
break;
double SignalDrawer::subStep(const double step)
{
- return step / 10;
+ return step / 5;
}
SignalDrawer::~SignalDrawer()