##// END OF EJS Templates
Uses SciQlop color scale in graphs
Alexandre Leroux -
r1050:761051f0c06c
parent child
Show More
@@ -10,8 +10,8 Q_DECLARE_LOGGING_CATEGORY(LOG_AxisRenderingUtils)
10
10
11 class IDataSeries;
11 class IDataSeries;
12 class QCPAxis;
12 class QCPAxis;
13 class QCPColorScale;
14 class QCustomPlot;
13 class QCustomPlot;
14 class SqpColorScale;
15
15
16 /// Formats a data value according to the axis on which it is present
16 /// Formats a data value according to the axis on which it is present
17 QString formatValue(double value, const QCPAxis &axis);
17 QString formatValue(double value, const QCPAxis &axis);
@@ -26,7 +26,7 struct IAxisHelper {
26 /// parameters
26 /// parameters
27 /// @param plot the plot for which to set axe properties
27 /// @param plot the plot for which to set axe properties
28 /// @param colorScale the color scale for which to set properties
28 /// @param colorScale the color scale for which to set properties
29 virtual void setProperties(QCustomPlot &plot, QCPColorScale &colorScale) = 0;
29 virtual void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) = 0;
30 };
30 };
31
31
32 struct IAxisHelperFactory {
32 struct IAxisHelperFactory {
@@ -4,6 +4,7
4 #include <Data/SpectrogramSeries.h>
4 #include <Data/SpectrogramSeries.h>
5 #include <Data/VectorSeries.h>
5 #include <Data/VectorSeries.h>
6
6
7 #include <Visualization/SqpColorScale.h>
7 #include <Visualization/qcustomplot.h>
8 #include <Visualization/qcustomplot.h>
8
9
9 Q_LOGGING_CATEGORY(LOG_AxisRenderingUtils, "AxisRenderingUtils")
10 Q_LOGGING_CATEGORY(LOG_AxisRenderingUtils, "AxisRenderingUtils")
@@ -64,7 +65,7 void setAxisProperties(QCPAxis &axis, const Unit &unit,
64 */
65 */
65 template <typename T, typename Enabled = void>
66 template <typename T, typename Enabled = void>
66 struct AxisSetter {
67 struct AxisSetter {
67 static void setProperties(T &, QCustomPlot &, QCPColorScale &)
68 static void setProperties(T &, QCustomPlot &, SqpColorScale &)
68 {
69 {
69 // Default implementation does nothing
70 // Default implementation does nothing
70 qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis properties: unmanaged type of data";
71 qCCritical(LOG_AxisRenderingUtils()) << "Can't set axis properties: unmanaged type of data";
@@ -79,7 +80,7 struct AxisSetter {
79 template <typename T>
80 template <typename T>
80 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
81 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>::value
81 or std::is_base_of<VectorSeries, T>::value> > {
82 or std::is_base_of<VectorSeries, T>::value> > {
82 static void setProperties(T &dataSeries, QCustomPlot &plot, QCPColorScale &)
83 static void setProperties(T &dataSeries, QCustomPlot &plot, SqpColorScale &)
83 {
84 {
84 dataSeries.lockRead();
85 dataSeries.lockRead();
85 auto xAxisUnit = dataSeries.xAxisUnit();
86 auto xAxisUnit = dataSeries.xAxisUnit();
@@ -97,7 +98,7 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<ScalarSeries, T>:
97 */
98 */
98 template <typename T>
99 template <typename T>
99 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
100 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries, T>::value> > {
100 static void setProperties(T &dataSeries, QCustomPlot &plot, QCPColorScale &colorScale)
101 static void setProperties(T &dataSeries, QCustomPlot &plot, SqpColorScale &colorScale)
101 {
102 {
102 dataSeries.lockRead();
103 dataSeries.lockRead();
103 auto xAxisUnit = dataSeries.xAxisUnit();
104 auto xAxisUnit = dataSeries.xAxisUnit();
@@ -110,20 +111,18 struct AxisSetter<T, typename std::enable_if_t<std::is_base_of<SpectrogramSeries
110
111
111 // Displays color scale in plot
112 // Displays color scale in plot
112 plot.plotLayout()->insertRow(0);
113 plot.plotLayout()->insertRow(0);
113 plot.plotLayout()->addElement(0, 0, &colorScale);
114 plot.plotLayout()->addElement(0, 0, colorScale.m_Scale);
114 colorScale.setType(QCPAxis::atTop);
115 colorScale.m_Scale->setType(QCPAxis::atTop);
115 colorScale.setMinimumMargins(QMargins{0, 0, 0, 0});
116 colorScale.m_Scale->setMinimumMargins(QMargins{0, 0, 0, 0});
116
117
117 // Aligns color scale with axes
118 // Aligns color scale with axes
118 auto marginGroups = plot.axisRect()->marginGroups();
119 auto marginGroups = plot.axisRect()->marginGroups();
119 for (auto it = marginGroups.begin(), end = marginGroups.end(); it != end; ++it) {
120 for (auto it = marginGroups.begin(), end = marginGroups.end(); it != end; ++it) {
120 colorScale.setMarginGroup(it.key(), it.value());
121 colorScale.m_Scale->setMarginGroup(it.key(), it.value());
121 }
122 }
122
123
123 // Set color scale properties
124 // Set color scale properties
124 setAxisProperties(*colorScale.axis(), valuesUnit, QCPAxis::stLogarithmic);
125 setAxisProperties(*colorScale.m_Scale->axis(), valuesUnit, QCPAxis::stLogarithmic);
125 /// @todo ALX: temp data range, remove it when widget to set data range is implemented
126 colorScale.setDataRange(QCPRange{8.32e2, 1.77e7});
127 }
126 }
128 };
127 };
129
128
@@ -135,7 +134,7 template <typename T>
135 struct AxisHelper : public IAxisHelper {
134 struct AxisHelper : public IAxisHelper {
136 explicit AxisHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
135 explicit AxisHelper(T &dataSeries) : m_DataSeries{dataSeries} {}
137
136
138 void setProperties(QCustomPlot &plot, QCPColorScale &colorScale) override
137 void setProperties(QCustomPlot &plot, SqpColorScale &colorScale) override
139 {
138 {
140 AxisSetter<T>::setProperties(m_DataSeries, plot, colorScale);
139 AxisSetter<T>::setProperties(m_DataSeries, plot, colorScale);
141 }
140 }
@@ -12,9 +12,6 Q_LOGGING_CATEGORY(LOG_PlottablesRenderingUtils, "PlottablesRenderingUtils")
12
12
13 namespace {
13 namespace {
14
14
15 /// Default gradient used for colormap
16 const auto DEFAULT_COLORMAP_GRADIENT = QCPColorGradient::gpJet;
17
18 /**
15 /**
19 * Delegate used to set plottables properties
16 * Delegate used to set plottables properties
20 */
17 */
@@ -81,8 +78,6 struct PlottablesSetter<T,
81 }
78 }
82 }
79 }
83
80
84 // Sets gradient used for color scale
85 colormap->setGradient(DEFAULT_COLORMAP_GRADIENT);
86 colormap->rescaleDataRange();
81 colormap->rescaleDataRange();
87 }
82 }
88 else {
83 else {
@@ -2,6 +2,7
2 #include "Visualization/AxisRenderingUtils.h"
2 #include "Visualization/AxisRenderingUtils.h"
3 #include "Visualization/ColorScaleEditor.h"
3 #include "Visualization/ColorScaleEditor.h"
4 #include "Visualization/PlottablesRenderingUtils.h"
4 #include "Visualization/PlottablesRenderingUtils.h"
5 #include "Visualization/SqpColorScale.h"
5 #include "Visualization/VisualizationGraphWidget.h"
6 #include "Visualization/VisualizationGraphWidget.h"
6 #include "Visualization/qcustomplot.h"
7 #include "Visualization/qcustomplot.h"
7
8
@@ -103,7 +104,7 struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegateP
103 m_XAxisPixmap{new QCPItemPixmap{&m_Plot}},
104 m_XAxisPixmap{new QCPItemPixmap{&m_Plot}},
104 m_ShowXAxis{true},
105 m_ShowXAxis{true},
105 m_XAxisLabel{},
106 m_XAxisLabel{},
106 m_ColorScale{new QCPColorScale{&m_Plot}}
107 m_ColorScale{SqpColorScale{m_Plot}}
107 {
108 {
108 initPointTracerStyle(*m_PointTracer);
109 initPointTracerStyle(*m_PointTracer);
109
110
@@ -164,7 +165,7 struct VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegateP
164 QCPItemPixmap *m_XAxisPixmap;
165 QCPItemPixmap *m_XAxisPixmap;
165 bool m_ShowXAxis; /// X-axis properties are shown or hidden
166 bool m_ShowXAxis; /// X-axis properties are shown or hidden
166 QString m_XAxisLabel;
167 QString m_XAxisLabel;
167 QCPColorScale *m_ColorScale; /// Color scale used for some types of graphs (as spectrograms)
168 SqpColorScale m_ColorScale; /// Color scale used for some types of graphs (as spectrograms)
168 };
169 };
169
170
170 VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate(
171 VisualizationGraphRenderingDelegate::VisualizationGraphRenderingDelegate(
@@ -232,7 +233,7 void VisualizationGraphRenderingDelegate::setAxesProperties(
232 impl->m_XAxisLabel = dataSeries->xAxisUnit().m_Name;
233 impl->m_XAxisLabel = dataSeries->xAxisUnit().m_Name;
233
234
234 auto axisHelper = IAxisHelperFactory::create(dataSeries);
235 auto axisHelper = IAxisHelperFactory::create(dataSeries);
235 axisHelper->setProperties(impl->m_Plot, *impl->m_ColorScale);
236 axisHelper->setProperties(impl->m_Plot, impl->m_ColorScale);
236
237
237 // Updates x-axis state
238 // Updates x-axis state
238 impl->updateXAxisState();
239 impl->updateXAxisState();
General Comments 0
You need to be logged in to leave comments. Login now