80 lines
2.5 KiB
C++
80 lines
2.5 KiB
C++
#pragma once
|
|
#include "Abs_Axis_p.h"
|
|
#include "Axis_p.h"
|
|
#include "Frequent_Axis.h"
|
|
namespace YSG {
|
|
struct Frequent_Axis_Input_Data : Axis_Input_Data {};
|
|
struct Frequent_Axis_Render_State : Axis_Render_State {};
|
|
struct Frequent_Axis_Private : Typed_Render_Data_Base<Axis_Private, Frequent_Axis, Frequent_Axis_Render_State, Frequent_Axis_Input_Data> {
|
|
friend class Frequent_Axis;
|
|
enum XUnitType {
|
|
UnKnow = -1,
|
|
Hz = 0,
|
|
KHz = 3,
|
|
MHz = 6,
|
|
GHz = 9
|
|
} xUnitType = UnKnow;
|
|
static QString getXUnitTypeString(XUnitType unitType) {
|
|
switch (unitType) {
|
|
case Hz:
|
|
return "Hz";
|
|
case KHz:
|
|
return "KHz";
|
|
case MHz:
|
|
return "MHz";
|
|
case GHz:
|
|
return "GHz";
|
|
default:
|
|
return "Unknown";
|
|
}
|
|
}
|
|
QVector<QString> create_label_vector(const QVector<double>& ticks, SRC src) override {
|
|
if (!ticks.empty()) {
|
|
double range = ticks.last() - ticks.first();
|
|
XUnitType beforeUnitType = xUnitType;
|
|
if (range >= 1e9) {
|
|
xUnitType = GHz;
|
|
}
|
|
else if (range >= 1e6) {
|
|
xUnitType = MHz;
|
|
}
|
|
else if (range >= 1e3) {
|
|
xUnitType = KHz;
|
|
}
|
|
else {
|
|
xUnitType = Hz;
|
|
}
|
|
if (beforeUnitType != xUnitType) {
|
|
render_state()->unit_text = "频率/" + getXUnitTypeString(xUnitType);
|
|
}
|
|
}
|
|
QVector<QString> result;
|
|
result.reserve(ticks.size());
|
|
for (const double& tickCoord : ticks) {
|
|
result.append(getTrueValue(get_tick_label(tickCoord, src)));
|
|
}
|
|
return result;
|
|
}
|
|
QString getTrueValue(QString value) {
|
|
value.replace(",", "");
|
|
int moveNum = xUnitType;
|
|
Abs_Axis_Render_State* s = render_state();
|
|
int precision = s->number_precision;
|
|
int dotIndex = value.indexOf('.');
|
|
if (dotIndex == -1) {
|
|
dotIndex = value.size();
|
|
}
|
|
QString number = value.left(dotIndex) + value.mid(dotIndex + 1);
|
|
int afterDotIndex = dotIndex - moveNum;
|
|
if (afterDotIndex < 1) {
|
|
for (int i = 0; i < 1 - afterDotIndex; ++i) {
|
|
number.prepend('0');
|
|
}
|
|
afterDotIndex = 1;
|
|
}
|
|
number.insert(afterDotIndex, '.');
|
|
return QString::number(number.toDouble(), 'd', precision);
|
|
}
|
|
};
|
|
} // namespace YSG
|