mirror of
https://github.com/Serial-Studio/Serial-Studio.git
synced 2025-01-31 17:42:55 +08:00
Auto-normalize multiplot widgets
This commit is contained in:
parent
5987900c3a
commit
4d2b290975
@ -114,7 +114,8 @@ Generator::OperationMode Generator::operationMode() const
|
||||
/**
|
||||
* Returns @c true if JSON frames shall be generated in a separate thread
|
||||
*/
|
||||
bool Generator::processFramesInSeparateThread() const {
|
||||
bool Generator::processFramesInSeparateThread() const
|
||||
{
|
||||
return m_processInSeparateThread;
|
||||
}
|
||||
|
||||
@ -213,7 +214,8 @@ void Generator::setOperationMode(const JSON::Generator::OperationMode mode)
|
||||
/**
|
||||
* Enables or disables multi-threaded frame processing
|
||||
*/
|
||||
void Generator::setProcessFramesInSeparateThread(const bool threaded) {
|
||||
void Generator::setProcessFramesInSeparateThread(const bool threaded)
|
||||
{
|
||||
m_processInSeparateThread = threaded;
|
||||
emit processFramesInSeparateThreadChanged();
|
||||
}
|
||||
@ -301,9 +303,11 @@ void Generator::readData(const QByteArray &data)
|
||||
m_frameCount++;
|
||||
|
||||
// Create new worker thread to read JSON data
|
||||
if (processFramesInSeparateThread()) {
|
||||
if (processFramesInSeparateThread())
|
||||
{
|
||||
QThread *thread = new QThread;
|
||||
JSONWorker *worker = new JSONWorker(data, m_frameCount, QDateTime::currentDateTime());
|
||||
JSONWorker *worker
|
||||
= new JSONWorker(data, m_frameCount, QDateTime::currentDateTime());
|
||||
worker->moveToThread(thread);
|
||||
connect(thread, SIGNAL(started()), worker, SLOT(process()));
|
||||
connect(worker, SIGNAL(finished()), thread, SLOT(quit()));
|
||||
|
@ -71,6 +71,7 @@ MultiPlot::MultiPlot(const int index)
|
||||
->setAttribute(QwtScaleEngine::Floating, true);
|
||||
|
||||
// Create curves from datasets
|
||||
bool normalize = true;
|
||||
auto group = dash->getMultiplot(m_index);
|
||||
QVector<QString> colors = theme->widgetColors();
|
||||
for (int i = 0; i < group->datasetCount(); ++i)
|
||||
@ -80,21 +81,8 @@ MultiPlot::MultiPlot(const int index)
|
||||
auto dataset = group->getDataset(i);
|
||||
if (dataset)
|
||||
{
|
||||
// Update curve title
|
||||
title = group->getDataset(i)->title();
|
||||
|
||||
// Update graph scale
|
||||
auto max = dataset->max();
|
||||
auto min = dataset->min();
|
||||
if (max > min)
|
||||
{
|
||||
if (m_max < max)
|
||||
m_max = max;
|
||||
if (m_min > min)
|
||||
m_min = min;
|
||||
|
||||
m_plot.setAxisScale(QwtPlot::yLeft, m_min, m_max);
|
||||
}
|
||||
normalize &= dataset->max() > dataset->min();
|
||||
}
|
||||
|
||||
// Create curve
|
||||
@ -121,6 +109,10 @@ MultiPlot::MultiPlot(const int index)
|
||||
m_plot.setAxisTitle(QwtPlot::xBottom, tr("Samples"));
|
||||
m_plot.insertLegend(&m_legend, QwtPlot::BottomLegend);
|
||||
|
||||
// Normalize data curves
|
||||
if (normalize)
|
||||
m_plot.setAxisScale(QwtPlot::yLeft, 0, 1);
|
||||
|
||||
// Show plot
|
||||
updateRange();
|
||||
m_plot.replot();
|
||||
@ -158,7 +150,19 @@ void MultiPlot::updateData()
|
||||
auto data = m_yData[i].data();
|
||||
auto count = m_yData[i].count();
|
||||
memmove(data, data + 1, count * sizeof(double));
|
||||
m_yData[i][count - 1] = dataset->value().toDouble();
|
||||
|
||||
// Normalize dataset value
|
||||
if (dataset->max() > dataset->min())
|
||||
{
|
||||
auto vmin = dataset->min();
|
||||
auto vmax = dataset->max();
|
||||
auto v = dataset->value().toDouble();
|
||||
m_yData[i][count - 1] = (v - vmin) / (vmax - vmin);
|
||||
}
|
||||
|
||||
// Plot dataset value directly
|
||||
else
|
||||
m_yData[i][count - 1] = dataset->value().toDouble();
|
||||
|
||||
// Widget not enabled, do not redraw
|
||||
if (!isEnabled())
|
||||
|
Loading…
x
Reference in New Issue
Block a user