From 57c14ae8b4bf56461241563c9ebade612e96c1d9 Mon Sep 17 00:00:00 2001 From: gaozheng Date: Thu, 11 Jun 2026 18:36:22 +0800 Subject: [PATCH] =?UTF-8?q?fix(ui):=20=E7=AD=89=E5=80=BC=E7=BA=BF=E6=AF=8F?= =?UTF-8?q?=E6=9D=A1=E5=8F=AA=E6=A0=87=E6=B3=A8=E4=B8=80=E4=B8=AA(?= =?UTF-8?q?=E5=BC=A7=E9=95=BF=E4=B8=AD=E7=82=B9),=E5=AF=B9=E9=BD=90?= =?UTF-8?q?=E5=8E=9F=E7=89=88(=E7=A7=BB=E9=99=A4=E5=91=A8=E6=9C=9F?= =?UTF-8?q?=E9=87=8D=E5=A4=8D=E6=A0=87=E6=B3=A8)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/panels/chart/ContourPlotItem.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/app/panels/chart/ContourPlotItem.cpp b/src/app/panels/chart/ContourPlotItem.cpp index 1ad252e..dcc4091 100644 --- a/src/app/panels/chart/ContourPlotItem.cpp +++ b/src/app/panels/chart/ContourPlotItem.cpp @@ -19,7 +19,6 @@ constexpr int kFillUpsample = 4; // 填充图像每网格格细分 K( constexpr int kMaxFillDim = 2400; // 填充图像单边像素上限(防极端网格爆内存) constexpr int kLabelFontPx = 10; // 等值线标注字号 constexpr double kLabelMinLenPx = 24.0; // 整条线像素长度小于此不标注(极短碎线) -constexpr double kLabelSpacingPx = 220.0; // 沿线每隔此像素重复一个标注(对齐原版密度) constexpr double kRad2Deg = 57.29577951308232; // 180/π(避免依赖 M_PI) } // namespace @@ -195,7 +194,7 @@ void ContourPlotItem::draw(QPainter* painter, const QwtScaleMap& xMap, const Qwt } painter->restore(); - // 3) 标注:沿线中段画 level 数值(小字黑,随相邻两点方向旋转)。 + // 3) 标注:每条等值线只标一个(对齐原版),放弧长中点,随该处方向旋转。 if (showLabels_) { painter->save(); painter->setRenderHint(QPainter::Antialiasing, true); @@ -216,14 +215,13 @@ void ContourPlotItem::draw(QPainter* painter, const QwtScaleMap& xMap, const Qwt if (total < kLabelMinLenPx) continue; // 极短碎线不标注 const QString txt = QString::number(ln.level, 'g', 4); const double halfW = fm.horizontalAdvance(txt) * 0.5; - // 沿线每隔 kLabelSpacingPx 放一个标注;首个在半间距处(短线即中点附近)。 - double nextAt = std::min(kLabelSpacingPx * 0.5, total * 0.5); + const double targetAt = total * 0.5; // 弧长中点 double acc = 0.0; - for (std::size_t i = 1; i < px.size() && nextAt <= total; ++i) { + for (std::size_t i = 1; i < px.size(); ++i) { const double seg = std::hypot(px[i].x() - px[i - 1].x(), px[i].y() - px[i - 1].y()); - while (nextAt <= acc + seg && nextAt <= total) { - const double t = seg > 1e-6 ? (nextAt - acc) / seg : 0.0; + if (acc + seg >= targetAt || i == px.size() - 1) { + const double t = seg > 1e-6 ? (targetAt - acc) / seg : 0.0; const QPointF pos(px[i - 1].x() + (px[i].x() - px[i - 1].x()) * t, px[i - 1].y() + (px[i].y() - px[i - 1].y()) * t); double ang = @@ -236,7 +234,7 @@ void ContourPlotItem::draw(QPainter* painter, const QwtScaleMap& xMap, const Qwt painter->rotate(ang); painter->drawText(QPointF(-halfW, -2), txt); painter->restore(); - nextAt += kLabelSpacingPx; + break; // 只标一个 } acc += seg; }