131 lines
4.2 KiB
C++
131 lines
4.2 KiB
C++
#ifndef MULTICHARTVIEW_H
|
|
#define MULTICHARTVIEW_H
|
|
|
|
#include <QWidget>
|
|
#include <QLineSeries>
|
|
#include <QtCharts>
|
|
#include <nix.hpp>
|
|
|
|
#include "dataqueue.h"
|
|
#include "conversionqueue.h"
|
|
#include "chart.h"
|
|
#include "chartview.h"
|
|
|
|
struct ArrayInfo {
|
|
|
|
ArrayInfo(const nix::DataArray &array) {
|
|
if (!array)
|
|
std::cerr << "shiiii\n";
|
|
arrayid = array.id();
|
|
dataExtent = array.dataExtent();
|
|
xDim = guessBestXdim(array);
|
|
nix::Dimension d = array.getDimension(xDim);
|
|
dimType = d.dimensionType();
|
|
xlabel = "";
|
|
if (dimType == nix::DimensionType::Sample) {
|
|
nix::SampledDimension sd = d.asSampledDimension();
|
|
xoffset = sd.offset() ? *sd.offset() : 0.0;
|
|
sampleinterval = sd.samplingInterval();
|
|
xmax = dataExtent[xDim - 1] * sampleinterval + xoffset;
|
|
xlabel = sd.label() ? *sd.label() : "";
|
|
xlabel += sd.unit() ? " [" + *sd.unit() + "]" : "";
|
|
|
|
} else if (dimType == nix::DimensionType::Range) {
|
|
nix::RangeDimension rd = d.asRangeDimension();
|
|
tics = rd.ticks();
|
|
xoffset = tics.front();
|
|
xmax = tics.back();
|
|
sampleinterval = 0.0;
|
|
xlabel = rd.label() ? *rd.label() : "";
|
|
xlabel += rd.unit() ? " [" + *rd.unit() + "]" : "";
|
|
} else { // SetDimension
|
|
xoffset = 0.0;
|
|
xmax = dataExtent[xDim - 1];
|
|
sampleinterval = 1.0;
|
|
}
|
|
name = array.name();
|
|
ylabel = array.label() ? *array.label() : "";
|
|
ylabel += array.unit() ? " [" + *array.unit() + "]" : "";
|
|
|
|
}
|
|
|
|
std::string arrayid;
|
|
std::string name;
|
|
std::string ylabel;
|
|
std::string xlabel;
|
|
int xDim;
|
|
nix::DimensionType dimType;
|
|
double xoffset, xmax, sampleinterval;
|
|
std::vector<double> tics;
|
|
nix::NDSize dataExtent;
|
|
|
|
int guessBestXdim(const nix::DataArray &array) const {
|
|
if(dataExtent.size() == 0) {
|
|
throw nix::IncompatibleDimensions("Array has dataExtent().size 0.", "guess_best_xdim");
|
|
}
|
|
if(dataExtent.size() > 2) {
|
|
throw nix::IncompatibleDimensions("Array has more than two dimensions.", "guess_best_xdim");
|
|
}
|
|
if(dataExtent.size() == 1) {
|
|
return 1;
|
|
} else {
|
|
nix::DimensionType d_1 = array.getDimension(1).dimensionType();
|
|
nix::DimensionType d_2 = array.getDimension(2).dimensionType();
|
|
|
|
if(d_1 == nix::DimensionType::Sample) {
|
|
return 1;
|
|
} else if (d_2 == nix::DimensionType::Sample) {
|
|
return 2;
|
|
} else {
|
|
if(d_1 == nix::DimensionType::Set && d_2 == nix::DimensionType::Range) {
|
|
return 2;
|
|
} else if (d_1 == nix::DimensionType::Range && d_2 == nix::DimensionType::Set){
|
|
return 1;
|
|
} else {
|
|
std::cerr << "How did you manage to end up in Lineplotter with 2D Set Data? guess_best_xdims() failure?" << std::endl;
|
|
throw nix::IncompatibleDimensions("Array contains 2D set data.", "guess_best_xdim");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
|
|
namespace Ui {
|
|
class MultiChartView;
|
|
}
|
|
|
|
class MultiChartView : public QWidget
|
|
{
|
|
Q_OBJECT
|
|
|
|
public:
|
|
explicit MultiChartView(DataQueue *queue, ConversionQueue *cqueue, QWidget *parent = 0);
|
|
~MultiChartView();
|
|
|
|
void addArray(const nix::DataArray &array);
|
|
void loadData(const ArrayInfo &info);
|
|
|
|
private:
|
|
DataQueue *dataQueue;
|
|
ConversionQueue *conversionQueue;
|
|
Ui::MultiChartView *ui;
|
|
double xRangeMin, xRangeMax;
|
|
std::map<std::string, nix::DataArray> arrayMap;
|
|
std::map<std::string, Chart*> chartMap;
|
|
std::map<std::string, ChartView*> viewMap;
|
|
std::map<std::string, ArrayInfo*> infoMap;
|
|
std::map<std::string, QVector<QPointF>*> data_buffer;
|
|
QFont labelFont, tickLabelFont;
|
|
|
|
Chart* createChart(const ArrayInfo &info);
|
|
ChartView* createChartView(Chart *chart, const ArrayInfo &info);
|
|
|
|
public slots:
|
|
void dataReady(QString requestId);
|
|
void dataConverted(QString entityId, double ymin, double ymax);
|
|
void newDataRequest(const std::string &entity_id, qreal max);
|
|
};
|
|
|
|
#endif // MULTICHARTVIEW_H
|