feat/dataset-detail-chart #5
|
|
@ -19,7 +19,6 @@ constexpr int kFillUpsample = 4; // 填充图像每网格格细分 K(
|
||||||
constexpr int kMaxFillDim = 2400; // 填充图像单边像素上限(防极端网格爆内存)
|
constexpr int kMaxFillDim = 2400; // 填充图像单边像素上限(防极端网格爆内存)
|
||||||
constexpr int kLabelFontPx = 10; // 等值线标注字号
|
constexpr int kLabelFontPx = 10; // 等值线标注字号
|
||||||
constexpr double kLabelMinLenPx = 24.0; // 整条线像素长度小于此不标注(极短碎线)
|
constexpr double kLabelMinLenPx = 24.0; // 整条线像素长度小于此不标注(极短碎线)
|
||||||
constexpr double kLabelSpacingPx = 220.0; // 沿线每隔此像素重复一个标注(对齐原版密度)
|
|
||||||
constexpr double kRad2Deg = 57.29577951308232; // 180/π(避免依赖 M_PI)
|
constexpr double kRad2Deg = 57.29577951308232; // 180/π(避免依赖 M_PI)
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
|
@ -195,7 +194,7 @@ void ContourPlotItem::draw(QPainter* painter, const QwtScaleMap& xMap, const Qwt
|
||||||
}
|
}
|
||||||
painter->restore();
|
painter->restore();
|
||||||
|
|
||||||
// 3) 标注:沿线中段画 level 数值(小字黑,随相邻两点方向旋转)。
|
// 3) 标注:每条等值线只标一个(对齐原版),放弧长中点,随该处方向旋转。
|
||||||
if (showLabels_) {
|
if (showLabels_) {
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->setRenderHint(QPainter::Antialiasing, true);
|
painter->setRenderHint(QPainter::Antialiasing, true);
|
||||||
|
|
@ -216,14 +215,13 @@ void ContourPlotItem::draw(QPainter* painter, const QwtScaleMap& xMap, const Qwt
|
||||||
if (total < kLabelMinLenPx) continue; // 极短碎线不标注
|
if (total < kLabelMinLenPx) continue; // 极短碎线不标注
|
||||||
const QString txt = QString::number(ln.level, 'g', 4);
|
const QString txt = QString::number(ln.level, 'g', 4);
|
||||||
const double halfW = fm.horizontalAdvance(txt) * 0.5;
|
const double halfW = fm.horizontalAdvance(txt) * 0.5;
|
||||||
// 沿线每隔 kLabelSpacingPx 放一个标注;首个在半间距处(短线即中点附近)。
|
const double targetAt = total * 0.5; // 弧长中点
|
||||||
double nextAt = std::min(kLabelSpacingPx * 0.5, total * 0.5);
|
|
||||||
double acc = 0.0;
|
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 =
|
const double seg =
|
||||||
std::hypot(px[i].x() - px[i - 1].x(), px[i].y() - px[i - 1].y());
|
std::hypot(px[i].x() - px[i - 1].x(), px[i].y() - px[i - 1].y());
|
||||||
while (nextAt <= acc + seg && nextAt <= total) {
|
if (acc + seg >= targetAt || i == px.size() - 1) {
|
||||||
const double t = seg > 1e-6 ? (nextAt - acc) / seg : 0.0;
|
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,
|
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);
|
px[i - 1].y() + (px[i].y() - px[i - 1].y()) * t);
|
||||||
double ang =
|
double ang =
|
||||||
|
|
@ -236,7 +234,7 @@ void ContourPlotItem::draw(QPainter* painter, const QwtScaleMap& xMap, const Qwt
|
||||||
painter->rotate(ang);
|
painter->rotate(ang);
|
||||||
painter->drawText(QPointF(-halfW, -2), txt);
|
painter->drawText(QPointF(-halfW, -2), txt);
|
||||||
painter->restore();
|
painter->restore();
|
||||||
nextAt += kLabelSpacingPx;
|
break; // 只标一个
|
||||||
}
|
}
|
||||||
acc += seg;
|
acc += seg;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue