@@ -1,59 +1,91 | |||||
1 | #include "Visualization/GraphPlottablesFactory.h" |
|
1 | #include "Visualization/GraphPlottablesFactory.h" | |
2 | #include "Visualization/qcustomplot.h" |
|
2 | #include "Visualization/qcustomplot.h" | |
3 |
|
3 | |||
4 | #include <Data/ScalarSeries.h> |
|
4 | #include <Data/ScalarSeries.h> | |
5 |
|
5 | |||
6 | #include <Variable/Variable.h> |
|
6 | #include <Variable/Variable.h> | |
7 |
|
7 | |||
8 | Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory") |
|
8 | Q_LOGGING_CATEGORY(LOG_GraphPlottablesFactory, "GraphPlottablesFactory") | |
9 |
|
9 | |||
10 | namespace { |
|
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 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot) |
|
31 | QCPAbstractPlottable *createScalarSeriesComponent(ScalarSeries &scalarSeries, QCustomPlot &plot) | |
14 | { |
|
32 | { | |
15 | auto component = plot.addGraph(); |
|
33 | auto component = plot.addGraph(); | |
16 |
|
34 | |||
17 | if (component) { |
|
35 | if (component) { | |
18 | // Graph data |
|
36 | // Graph data | |
19 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), |
|
37 | component->setData(scalarSeries.xAxisData()->data(), scalarSeries.valuesData()->data(), | |
20 | true); |
|
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 | // Display all data |
|
54 | // Display all data | |
23 | component->rescaleAxes(); |
|
55 | component->rescaleAxes(); | |
24 |
|
56 | |||
25 | plot.replot(); |
|
57 | plot.replot(); | |
26 | } |
|
58 | } | |
27 | else { |
|
59 | else { | |
28 | qCDebug(LOG_GraphPlottablesFactory()) |
|
60 | qCDebug(LOG_GraphPlottablesFactory()) | |
29 | << QObject::tr("Can't create graph for the scalar series"); |
|
61 | << QObject::tr("Can't create graph for the scalar series"); | |
30 | } |
|
62 | } | |
31 |
|
63 | |||
32 | return component; |
|
64 | return component; | |
33 | } |
|
65 | } | |
34 |
|
66 | |||
35 | } // namespace |
|
67 | } // namespace | |
36 |
|
68 | |||
37 | QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(const Variable *variable, |
|
69 | QVector<QCPAbstractPlottable *> GraphPlottablesFactory::create(const Variable *variable, | |
38 | QCustomPlot &plot) noexcept |
|
70 | QCustomPlot &plot) noexcept | |
39 | { |
|
71 | { | |
40 | auto result = QVector<QCPAbstractPlottable *>{}; |
|
72 | auto result = QVector<QCPAbstractPlottable *>{}; | |
41 |
|
73 | |||
42 | if (variable) { |
|
74 | if (variable) { | |
43 | // Gets the data series of the variable to call the creation of the right components |
|
75 | // Gets the data series of the variable to call the creation of the right components | |
44 | // according to its type |
|
76 | // according to its type | |
45 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { |
|
77 | if (auto scalarSeries = dynamic_cast<ScalarSeries *>(variable->dataSeries())) { | |
46 | result.append(createScalarSeriesComponent(*scalarSeries, plot)); |
|
78 | result.append(createScalarSeriesComponent(*scalarSeries, plot)); | |
47 | } |
|
79 | } | |
48 | else { |
|
80 | else { | |
49 | qCDebug(LOG_GraphPlottablesFactory()) |
|
81 | qCDebug(LOG_GraphPlottablesFactory()) | |
50 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); |
|
82 | << QObject::tr("Can't create graph plottables : unmanaged data series type"); | |
51 | } |
|
83 | } | |
52 | } |
|
84 | } | |
53 | else { |
|
85 | else { | |
54 | qCDebug(LOG_GraphPlottablesFactory()) |
|
86 | qCDebug(LOG_GraphPlottablesFactory()) | |
55 | << QObject::tr("Can't create graph plottables : the variable is null"); |
|
87 | << QObject::tr("Can't create graph plottables : the variable is null"); | |
56 | } |
|
88 | } | |
57 |
|
89 | |||
58 | return result; |
|
90 | return result; | |
59 | } |
|
91 | } |
General Comments 0
You need to be logged in to leave comments.
Login now