The vertical scale is now drawn.

This commit is contained in:
David Given
2025-02-05 22:51:03 +01:00
parent a88f783f06
commit 709d5bc643
3 changed files with 95 additions and 42 deletions

View File

@@ -49,7 +49,7 @@ public:
void redraw(QPainter& painter,
nanoseconds_t startPos,
nanoseconds_t endPos,
int track)
int track, double height)
{
auto& t = _trackData[track];
if (!t.fluxmap)
@@ -89,7 +89,7 @@ public:
int c = 255 - density * 255.0;
painter.setPen(QPen(
QColor(0, c, c), granularity * FLUXVIEWER_LINE_WIDTH));
painter.drawLine(QLineF(x, 0, x, 5));
painter.drawLine(QLineF(x, 0, x, height));
count = 0;
}
pixel = thisPixel;

View File

@@ -17,5 +17,5 @@ public:
virtual void redraw(QPainter& painter,
nanoseconds_t startPos,
nanoseconds_t endPos,
int track) = 0;
int track, double height) = 0;
};

View File

@@ -18,9 +18,12 @@ class TrackFlux;
static constexpr double VSCALE_TRACK_SIZE = 10;
static constexpr double VMARGIN_SIZE = 30;
static constexpr double HMARGIN_SIZE = 30;
static constexpr double HMARGIN_SIZE = 40;
static constexpr int MINIMUM_TICK_DISTANCE = 10;
static constexpr QRect CENTRED(
-(INT_MAX / 2), -(INT_MAX / 2), INT_MAX, INT_MAX);
class FluxVisualiserWidgetImpl : public FluxVisualiserWidget
{
private:
@@ -75,6 +78,8 @@ protected:
QRectF world =
painter.worldTransform().inverted().mapRect(QRectF(event->rect()));
double topTrack = world.top() / VSCALE_TRACK_SIZE;
double bottomTrack = world.bottom() / VSCALE_TRACK_SIZE;
nanoseconds_t left = world.left() * FLUXVIEWER_NS_PER_UNIT;
nanoseconds_t right = world.right() * FLUXVIEWER_NS_PER_UNIT;
painter.setPen(palette().color(QPalette::Text));
@@ -84,7 +89,14 @@ protected:
{
painter.save();
painter.translate(0, VSCALE_TRACK_SIZE * i);
_fluxView->redraw(painter, left, right, i);
painter.setPen(palette().color(QPalette::Text));
_fluxView->redraw(painter, left, right, i, VSCALE_TRACK_SIZE);
painter.setPen(palette().color(QPalette::Base));
painter.drawLine(left / FLUXVIEWER_NS_PER_UNIT,
0,
right / FLUXVIEWER_NS_PER_UNIT,
0);
painter.restore();
}
painter.restore();
@@ -99,49 +111,90 @@ protected:
/* Draw the horizontal scale. */
double nanosecondsPerPixel = (right - left) / rect().width();
int yy = VMARGIN_SIZE * 4 / 5;
uint64_t tickStep = 1000;
while ((tickStep / nanosecondsPerPixel) < MINIMUM_TICK_DISTANCE)
tickStep *= 10;
painter.setPen(QPen(palette().color(QPalette::Text), 0));
painter.setBrush(Qt::NoBrush);
nanoseconds_t dataLeft = std::max(left, 0.0);
nanoseconds_t dataRight = std::min(right, _totalDuration);
QFontMetrics fontMetrics(painter.font());
painter.drawLine((dataLeft - left) / nanosecondsPerPixel,
yy,
(dataRight - left) / nanosecondsPerPixel,
yy);
uint64_t tick = std::max(floor(dataLeft / tickStep) * tickStep, 0.0);
while (tick < dataRight)
{
int xx = (tick - left) / nanosecondsPerPixel;
int ts = VMARGIN_SIZE / 5;
if ((tick % (10 * tickStep)) == 0)
ts = VMARGIN_SIZE / 4;
if ((tick % (100 * tickStep)) == 0)
ts = VMARGIN_SIZE / 3;
double nanosecondsPerPixel = (right - left) / rect().width();
if ((tick % (10 * tickStep)) == 0)
int yy = VMARGIN_SIZE * 4 / 5;
uint64_t tickStep = 1000;
while ((tickStep / nanosecondsPerPixel) < MINIMUM_TICK_DISTANCE)
tickStep *= 10;
painter.setPen(QPen(palette().color(QPalette::Text), 0));
painter.setBrush(Qt::NoBrush);
nanoseconds_t dataLeft = std::max(left, 0.0);
nanoseconds_t dataRight = std::min(right, _totalDuration);
painter.drawLine((dataLeft - left) / nanosecondsPerPixel,
yy,
(dataRight - left) / nanosecondsPerPixel,
yy);
uint64_t tick =
std::max(floor(dataLeft / tickStep) * tickStep, 0.0);
while (tick < dataRight)
{
painter.drawText(xx - 512,
0,
1024,
VMARGIN_SIZE / 2,
Qt::AlignCenter,
QString::fromStdString(
fmt::format("{:.3f}ms", tick / 1e6)));
int xx = (tick - left) / nanosecondsPerPixel;
int ts = VMARGIN_SIZE / 5;
if ((tick % (10 * tickStep)) == 0)
ts = VMARGIN_SIZE / 4;
if ((tick % (100 * tickStep)) == 0)
ts = VMARGIN_SIZE / 3;
if ((tick % (10 * tickStep)) == 0)
{
painter.drawText(xx - 512,
0,
1024,
VMARGIN_SIZE / 2,
Qt::AlignCenter,
QString::fromStdString(
fmt::format("{:.3f}ms", tick / 1e6)));
}
painter.drawLine(xx, yy, xx, yy - ts);
tick += tickStep;
}
}
painter.drawLine(xx, yy, xx, yy - ts);
/* Draw the vertical scale. */
tick += tickStep;
{
painter.save();
painter.setPen(QPen(palette().color(QPalette::Text), 0));
painter.setBrush(Qt::NoBrush);
double xx = HMARGIN_SIZE * 4 / 5;
double ys = rect().height() / (bottomTrack - topTrack);
int t = std::max(0.0, floor(topTrack));
int bottom = std::min(82.0, ceil(bottomTrack));
double w = std::clamp(xx * 4 / 3 - ys / 2, xx / 2, xx);
QFont font;
font.setPixelSize(std::clamp(ys * 2 / 3, 2.0, HMARGIN_SIZE/3));
painter.setFont(font);
while (t < bottom)
{
double yy = (t - topTrack) * ys;
double yt = yy + ys * 0.5 / VSCALE_TRACK_SIZE;
double yb = yy + ys * 9.5 / VSCALE_TRACK_SIZE;
painter.drawLine(xx, yt, w, yt);
painter.drawLine(xx, yb, w, yb);
painter.drawLine(xx, yt, xx, yb);
painter.save();
painter.setTransform(
QTransform().translate(xx / 2, yy + ys * .5));
painter.drawText(CENTRED,
Qt::AlignCenter,
QString::fromStdString(fmt::format("{}.{}", 0, t)));
painter.restore();
t++;
}
painter.restore();
}
}