Skip to content

Commit

Permalink
add option to provide an option for color fill in some graphs #820
Browse files Browse the repository at this point in the history
  • Loading branch information
ElderOrb committed Jun 16, 2024
1 parent 686f0de commit 9ef4354
Show file tree
Hide file tree
Showing 3 changed files with 104 additions and 5 deletions.
1 change: 1 addition & 0 deletions Source/Core/Core.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct per_item
const activefilter Filter;
const char* color;
const int thickness;
const char* fillInfo { nullptr };
};

struct stream_info
Expand Down
10 changes: 5 additions & 5 deletions Source/Core/VideoCore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ struct per_group VideoPerGroup [Group_VideoMax]=
const struct per_item VideoPerItem [Item_VideoMax]=
{
//Y
{ Group_Y, Group_VideoMax, "Y MIN", "lavfi.signalstats.YMIN", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, "gray", 1 },
{ Group_Y, Group_VideoMax, "Y LOW", "lavfi.signalstats.YLOW", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, "green", 2 },
{ Group_Y, Group_VideoMax, "Y AVG", "lavfi.signalstats.YAVG", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, "yellow", 3 },
{ Group_Y, Group_VideoMax, "Y HIGH", "lavfi.signalstats.YHIGH", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, nullptr, -1 },
{ Group_Y, Group_VideoMax, "Y MAX", "lavfi.signalstats.YMAX", 0, true, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, nullptr, -1 },
{ Group_Y, Group_VideoMax, "Y MIN", "lavfi.signalstats.YMIN", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, "gray", 1, }, // "Y LOW;green;0.5" },
{ Group_Y, Group_VideoMax, "Y LOW", "lavfi.signalstats.YLOW", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, "green", 2, }, // "Y LOW;transparent;0.5" },
{ Group_Y, Group_VideoMax, "Y AVG", "lavfi.signalstats.YAVG", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, "yellow", 3, }, // "Y LOW;red;0.5" },
{ Group_Y, Group_VideoMax, "Y HIGH", "lavfi.signalstats.YHIGH", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, nullptr, -1, "Y AVG;yellow;0.8" },
{ Group_Y, Group_VideoMax, "Y MAX", "lavfi.signalstats.YMAX", 0, true, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, nullptr, -1, "Y HIGH;green;0.5" },
//U
{ Group_U, Group_VideoMax, "U MIN", "lavfi.signalstats.UMIN", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, nullptr, -1 },
{ Group_U, Group_VideoMax, "U LOW", "lavfi.signalstats.ULOW", 0, false, DBL_MAX, DBL_MAX, ActiveFilter_Video_signalstats, nullptr, -1 },
Expand Down
98 changes: 98 additions & 0 deletions Source/GUI/Plot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <qwt_point_mapper.h>
#include <qwt_painter.h>
#include <qwt_symbol.h>
#include <qwt_clipper.h>

#include "Core/FileInformation.h"
#include <cassert>
Expand Down Expand Up @@ -250,7 +251,80 @@ class PlotCurve : public QwtPlotCurve {
m_count = count;
}

void setClipCurve(QwtPlotCurve* curve) {
m_clipCurve = curve;
}

void setFillBrush(QBrush brush) {
m_fillBrush = brush;
}

protected:
virtual void drawCurve( QPainter* painter , int style, const QwtScaleMap& xMap, const QwtScaleMap& yMap, const QRectF& canvasRect, int from, int to ) const {
QwtPlotCurve::drawCurve(painter, style, xMap, yMap, canvasRect, from, to);

if(m_clipCurve && !symbol())
{
auto brush = m_fillBrush;

if ( brush.style() == Qt::NoBrush )
return;

const bool doFit = ( testCurveAttribute( Fitted ) && curveFitter() );
const bool doAlign = !doFit && QwtPainter::roundingAlignment( painter );

QwtPointMapper mapper;

if ( doAlign )
{
mapper.setFlag( QwtPointMapper::RoundPoints, true );
mapper.setFlag( QwtPointMapper::WeedOutIntermediatePoints,
testPaintAttribute( FilterPointsAggressive ) );
}

mapper.setFlag( QwtPointMapper::WeedOutPoints,
testPaintAttribute( FilterPoints ) ||
testPaintAttribute( FilterPointsAggressive ) );

mapper.setBoundingRect( canvasRect );
QPolygonF polygon = mapper.toPolygonF( xMap, yMap, data(), from, to);
QPolygonF baselinePolygon = mapper.toPolygonF( xMap, yMap, m_clipCurve->data(), from, to);

for(auto it = baselinePolygon.rbegin(); it != baselinePolygon.rend(); ++it) {
polygon += *it;
}

if ( polygon.count() <= 2 ) // a line can't be filled
return;

if ( !brush.color().isValid() )
brush.setColor( this->pen().color() );

if ( testPaintAttribute(ClipPolygons) )
{
const QRectF clipRect = qwtIntersectedClipRect( canvasRect, painter );
QwtClipper::clipPolygonF( clipRect, polygon, true );
}

painter->save();

painter->setPen( Qt::NoPen );
painter->setBrush( brush );

QwtPainter::drawPolygon( painter, polygon );

painter->restore();
}
}

virtual void fillCurve( QPainter *painter, const QwtScaleMap& xMap, const QwtScaleMap& yMap, const QRectF& canvasRect, QPolygonF& polygon) const {
QwtPlotCurve::fillCurve(painter, xMap, yMap, canvasRect, polygon);
}

virtual void drawLines(QPainter* p, const QwtScaleMap& xMap, const QwtScaleMap& yMap, const QRectF& canvasRect, int from, int to) const {
QwtPlotCurve::drawLines(p, xMap, yMap, canvasRect, from, to);
}

void drawSymbols(QPainter *p, const QwtSymbol &s, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRectF &canvasRect, int from, int to) const {

QwtPointMapper mapper;
Expand Down Expand Up @@ -287,6 +361,8 @@ class PlotCurve : public QwtPlotCurve {
private:
int m_index;
int m_count;
QBrush m_fillBrush;
QwtPlotCurve* m_clipCurve { nullptr };
};

//***************************************************************************
Expand Down Expand Up @@ -506,6 +582,7 @@ Plot::Plot( size_t streamPos, size_t Type, size_t Group, const FileInformation*

// curves
m_curves.reserve(PerStreamType[m_type].PerGroup[m_group].Count);
QMap<QString, PlotCurve*> curvesByName;

for( unsigned j = 0; j < PerStreamType[m_type].PerGroup[m_group].Count; ++j )
{
Expand Down Expand Up @@ -536,6 +613,27 @@ Plot::Plot( size_t streamPos, size_t Type, size_t Group, const FileInformation*
curve->attach( this );

m_curves += curve;

curvesByName[item.Name] = curve;
}

for( unsigned j = 0; j < PerStreamType[m_type].PerGroup[m_group].Count; ++j )
{
auto item = PerStreamType[m_type].PerItem[PerStreamType[m_type].PerGroup[m_group].Start + j];
if(item.fillInfo) {
auto splitted = QString(item.fillInfo).split(";");
auto curveName = splitted[0];
auto color = QColor(splitted[1]);
auto alpha = QString(splitted[2]).toFloat();

color.setAlphaF(alpha);
auto curve = curvesByName[item.Name];
curve->setFillBrush(QBrush(color));

auto fillCurve = curvesByName[curveName];

curve->setClipCurve(fillCurve);
}
}

PlotPicker* picker = new PlotPicker( this, &PerStreamType[m_type], m_group, &m_curves, fileInformation );
Expand Down

0 comments on commit 9ef4354

Please sign in to comment.