##// END OF EJS Templates
Small GUI fix, show full names in repository tree view...
Small GUI fix, show full names in repository tree view Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>

File last commit:

r1432:db5304cf6c8c
r1461:021e7c505ad4
Show More
AxisRenderingUtils.cpp
217 lines | 6.8 KiB | text/x-c | CppLexer
/ gui / src / Visualization / AxisRenderingUtils.cpp
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 #include "Visualization/AxisRenderingUtils.h"
Switched to new TS impl but quite broken!...
r1420 #include <Data/ScalarTimeSerie.h>
#include <Data/SpectrogramTimeSerie.h>
#include <Data/VectorTimeSerie.h>
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915
Switched to new TS impl but quite broken!...
r1420 #include <Variable/Variable2.h>
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281
Alexandre Leroux
Uses SciQlop color scale in graphs
r1009 #include <Visualization/SqpColorScale.h>
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 #include <Visualization/qcustomplot.h>
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r928 Q_LOGGING_CATEGORY(LOG_AxisRenderingUtils, "AxisRenderingUtils")
Switched to new TS impl but quite broken!...
r1420 namespace
{
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 /// Format for datetimes on a axis
const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
Alexandre Leroux
Tooltip for spectrograms (4)...
r1027 const auto NUMBER_FORMAT = 'g';
const auto NUMBER_PRECISION = 9;
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
/// non-time data
Alexandre Leroux
Handles log scales for y-axis and color scale
r929 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis, QCPAxis::ScaleType scaleType)
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 {
Switched to new TS impl but quite broken!...
r1420 if (isTimeAxis)
{
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
dateTicker->setDateTimeSpec(Qt::UTC);
return dateTicker;
}
Switched to new TS impl but quite broken!...
r1420 else if (scaleType == QCPAxis::stLogarithmic)
{
Alexandre Leroux
Handles log scales for y-axis and color scale
r929 return QSharedPointer<QCPAxisTickerLog>::create();
}
Switched to new TS impl but quite broken!...
r1420 else
{
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 // default ticker
return QSharedPointer<QCPAxisTicker>::create();
}
}
/**
* Sets properties of the axis passed as parameter
* @param axis the axis to set
* @param unit the unit to set for the axis
* @param scaleType the scale type to set for the axis
*/
Switched to new TS impl but quite broken!...
r1420 void setAxisProperties(QCPAxis& axis, const std::string& unit, bool isTime,
QCPAxis::ScaleType scaleType = QCPAxis::stLinear)
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 {
// label (unit name)
Switched to new TS impl but quite broken!...
r1420 axis.setLabel(QString::fromStdString(unit));
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916
// scale type
axis.setScaleType(scaleType);
Switched to new TS impl but quite broken!...
r1420 if (scaleType == QCPAxis::stLogarithmic)
{
Alexandre Leroux
Handles log scales for y-axis and color scale
r929 // Scientific notation
axis.setNumberPrecision(0);
axis.setNumberFormat("eb");
}
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916
// ticker (depending on the type of unit)
Switched to new TS impl but quite broken!...
r1420 axis.setTicker(axisTicker(isTime, scaleType));
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 }
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 /**
* Delegate used to set axes properties
*/
template <typename T, typename Enabled = void>
Switched to new TS impl but quite broken!...
r1420 struct AxisSetter
{
static void setProperties(QCustomPlot&, SqpColorScale&)
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
// Default implementation does nothing
Alexandre Leroux
Adds logs to axe and plottable rendering utils
r928 qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis properties: unmanaged type of data";
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281
Switched to new TS impl but quite broken!...
r1420 static void setUnits(T&, QCustomPlot&, SqpColorScale&)
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 {
// Default implementation does nothing
qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis units: unmanaged type of data";
}
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 };
/**
* Specialization of AxisSetter for scalars and vectors
* @sa ScalarSeries
* @sa VectorSeries
*/
template <typename T>
Switched to new TS impl but quite broken!...
r1420 struct AxisSetter<T,
typename std::enable_if_t<std::is_base_of<ScalarTimeSerie, T>::value
MultiComponent TS almost complete...
r1432 or std::is_base_of<VectorTimeSerie, T>::value
or std::is_base_of<MultiComponentTimeSerie, T>::value>>
Switched to new TS impl but quite broken!...
r1420 {
static void setProperties(QCustomPlot&, SqpColorScale&)
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 {
// Nothing to do
}
Switched to new TS impl but quite broken!...
r1420 static void setUnits(T& dataSeries, QCustomPlot& plot, SqpColorScale&)
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
Switched to new TS impl but quite broken!...
r1420 auto serie = dynamic_cast<TimeSeries::ITimeSerie*>(&dataSeries);
setAxisProperties(*plot.xAxis, "s", true);
setAxisProperties(*plot.yAxis, serie->unit(1), false);
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
};
Alexandre Leroux
Handles axes properties for spectrograms...
r920 /**
* Specialization of AxisSetter for spectrograms
* @sa SpectrogramSeries
*/
template <typename T>
Switched to new TS impl but quite broken!...
r1420 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramTimeSerie, T>::value>>
{
static void setProperties(QCustomPlot& plot, SqpColorScale& colorScale)
Alexandre Leroux
Handles axes properties for spectrograms...
r920 {
// Displays color scale in plot
plot.plotLayout()->insertRow(0);
Alexandre Leroux
Uses SciQlop color scale in graphs
r1009 plot.plotLayout()->addElement(0, 0, colorScale.m_Scale);
colorScale.m_Scale->setType(QCPAxis::atTop);
Switched to new TS impl but quite broken!...
r1420 colorScale.m_Scale->setMinimumMargins(QMargins { 0, 0, 0, 0 });
Alexandre Leroux
Handles axes properties for spectrograms...
r920
// Aligns color scale with axes
auto marginGroups = plot.axisRect()->marginGroups();
Switched to new TS impl but quite broken!...
r1420 for (auto it = marginGroups.begin(), end = marginGroups.end(); it != end; ++it)
{
Alexandre Leroux
Uses SciQlop color scale in graphs
r1009 colorScale.m_Scale->setMarginGroup(it.key(), it.value());
Alexandre Leroux
Handles axes properties for spectrograms...
r920 }
// Set color scale properties
Alexandre Leroux
Minor fix...
r1110 colorScale.m_AutomaticThreshold = true;
Alexandre Leroux
Handles axes properties for spectrograms...
r920 }
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281
Switched to new TS impl but quite broken!...
r1420 static void setUnits(T& dataSeries, QCustomPlot& plot, SqpColorScale& colorScale)
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 {
Switched to new TS impl but quite broken!...
r1420 auto serie = dynamic_cast<TimeSeries::ITimeSerie*>(&dataSeries);
setAxisProperties(*plot.xAxis, "s", true);
setAxisProperties(*plot.yAxis, serie->unit(1), false, QCPAxis::stLogarithmic);
setAxisProperties(
*colorScale.m_Scale->axis(), serie->unit(2), false, QCPAxis::stLogarithmic);
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 }
Alexandre Leroux
Handles axes properties for spectrograms...
r920 };
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 /**
* Default implementation of IAxisHelper, which takes data series to set axes properties
* @tparam T the data series' type
*/
template <typename T>
Switched to new TS impl but quite broken!...
r1420 struct AxisHelper : public IAxisHelper
{
News TS impl seems to pass all tests \o/...
r1421 explicit AxisHelper(std::shared_ptr<T> dataSeries) : m_DataSeries { dataSeries } {}
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915
Switched to new TS impl but quite broken!...
r1420 void setProperties(QCustomPlot& plot, SqpColorScale& colorScale) override
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 AxisSetter<T>::setProperties(plot, colorScale);
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
Switched to new TS impl but quite broken!...
r1420 void setUnits(QCustomPlot& plot, SqpColorScale& colorScale) override
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 {
Switched to new TS impl but quite broken!...
r1420 if (m_DataSeries)
{
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 AxisSetter<T>::setUnits(*m_DataSeries, plot, colorScale);
}
Switched to new TS impl but quite broken!...
r1420 else
{
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 qCCritical(LOG_AxisRenderingUtils()) << "Can't set units: inconsistency between the "
"type of data series and the type supposed";
}
}
News TS impl seems to pass all tests \o/...
r1421 std::shared_ptr<T> m_DataSeries;
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 };
} // namespace
Switched to new TS impl but quite broken!...
r1420 QString formatValue(double value, const QCPAxis& axis)
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 {
// If the axis is a time axis, formats the value as a date
Switched to new TS impl but quite broken!...
r1420 if (auto axisTicker = qSharedPointerDynamicCast<QCPAxisTickerDateTime>(axis.ticker()))
{
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 return DateUtils::dateTime(value, axisTicker->dateTimeSpec()).toString(DATETIME_FORMAT);
}
Switched to new TS impl but quite broken!...
r1420 else
{
Alexandre Leroux
Tooltip for spectrograms (4)...
r1027 return QString::number(value, NUMBER_FORMAT, NUMBER_PRECISION);
Alexandre Leroux
Refactoring handling of axes properties (2)...
r916 }
}
Switched to new TS impl but quite broken!...
r1420 std::unique_ptr<IAxisHelper> IAxisHelperFactory::create(Variable2& variable) noexcept
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 {
Switched to new TS impl but quite broken!...
r1420 switch (variable.type())
{
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 case DataSeriesType::SCALAR:
Switched to new TS impl but quite broken!...
r1420 return std::make_unique<AxisHelper<ScalarTimeSerie>>(
News TS impl seems to pass all tests \o/...
r1421 std::dynamic_pointer_cast<ScalarTimeSerie>(variable.data()));
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 case DataSeriesType::SPECTROGRAM:
Switched to new TS impl but quite broken!...
r1420 return std::make_unique<AxisHelper<SpectrogramTimeSerie>>(
News TS impl seems to pass all tests \o/...
r1421 std::dynamic_pointer_cast<SpectrogramTimeSerie>(variable.data()));
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 case DataSeriesType::VECTOR:
Switched to new TS impl but quite broken!...
r1420 return std::make_unique<AxisHelper<VectorTimeSerie>>(
News TS impl seems to pass all tests \o/...
r1421 std::dynamic_pointer_cast<VectorTimeSerie>(variable.data()));
MultiComponent TS almost complete...
r1432 case DataSeriesType::MULTICOMPONENT:
return std::make_unique<AxisHelper<MultiComponentTimeSerie>>(
std::dynamic_pointer_cast<MultiComponentTimeSerie>(variable.data()));
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281 default:
// Creates default helper
break;
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }
Alexandre Leroux
Updates AxisRenderingUtils to use variable's type instead of dataseries
r1281
Switched to new TS impl but quite broken!...
r1420 return std::make_unique<AxisHelper<TimeSeries::ITimeSerie>>(nullptr);
Alexandre Leroux
Refactoring handling of axes properties (1)...
r915 }