##// END OF EJS Templates
Handles axes properties
Alexandre Leroux -
r170:aee0cf3098de
parent child
Show More
@@ -1,59 +1,91
1 1 #include "Visualization/GraphPlottablesFactory.h"
2 2 #include "Visualization/qcustomplot.h"
3 3
4 4 #include <Data/ScalarSeries.h>
5 5
6 6 #include <Variable/Variable.h>
7 7
8 8 Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory")
9 9
10 10 namespace {
11 11
12 /// Format for datetimes on a axis
13 const auto DATETIME_TICKER_FORMAT = QStringLiteral("yyyy/MM/dd \nhh:mm:ss");
14
15 /// Generates the appropriate ticker for an axis, depending on whether the axis displays time or
16 /// non-time data
17 QSharedPointer<QCPAxisTicker> axisTicker(bool isTimeAxis)
18 {
19 if (isTimeAxis) {
20 auto dateTicker = QSharedPointer<QCPAxisTickerDateTime>::create();
21 dateTicker->setDateTimeFormat(DATETIME_TICKER_FORMAT);
22
23 return dateTicker;
24 }
25 else {
26 // default ticker
27 return QSharedPointer<QCPAxisTicker>::create();
28 }
29 }
12 30
13 31 QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot)
14 32 {
15 33 auto component = plot.addGraph();
16 34
17 35 if (component) {
18 36 // Graph data
19 37 component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(),
20 38 true);
21 39
40 // Axes properties
41 /// @todo : for the moment, no control is performed on the axes: the units and the tickers
42 /// are fixed for the default x-axis and y-axis of the plot, and according to the new graph
43
44 auto setAxisProperties = [](auto axis, const auto &unit) {
45 // label (unit name)
46 axis->setLabel(unit.m_Name);
47
48 // ticker (depending on the type of unit)
49 axis->setTicker(axisTicker(unit.m_TimeUnit));
50 };
51 setAxisProperties(plot.xAxis, scalarSeries.xAxisUnit());
52 setAxisProperties(plot.yAxis, scalarSeries.valuesUnit());
53
22 54 // Display all data
23 55 component->rescaleAxes();
24 56
25 57 plot.replot();
26 58 }
27 59 else {
28 60 qCDebug(LOG_GraphPlottablesFactory())
29 61 << QObject::tr("Can't create graph for the scalar series");
30 62 }
31 63
32 64 return component;
33 65 }
34 66
35 67 } // namespace
36 68
37 69 QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(const Variable *variable,
38 70 QCustomPlot &plot) noexcept
39 71 {
40 72 auto result = QVector<QCPAbstractPlottable *>{};
41 73
42 74 if (variable) {
43 75 // Gets the data series of the variable to call the creation of the right components
44 76 // according to its type
45 77 if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) {
46 78 result.append(createScalarSeriesComponent(*scalarSeries, plot));
47 79 }
48 80 else {
49 81 qCDebug(LOG_GraphPlottablesFactory())
50 82 << QObject::tr("Can't create graph plottables : unmanaged data series type");
51 83 }
52 84 }
53 85 else {
54 86 qCDebug(LOG_GraphPlottablesFactory())
55 87 << QObject::tr("Can't create graph plottables : the variable is null");
56 88 }
57 89
58 90 return result;
59 91 }
General Comments 0
You need to be logged in to leave comments. Login now