Skip to content

Commit

Permalink
[ISSUE #185] Support creation of the Gantt charts
Browse files Browse the repository at this point in the history
- Introduce the support of the Gantt charts
- Change the plot color set to more contrasting colors
- Change the axis rect name location to the top axis
- Change rules of the plot graph color selection

Signed-off-by: Vladyslav Goncharuk <vladyslav_goncharuk@epam.com>
  • Loading branch information
Vladyslav Goncharuk committed Jul 23, 2024
1 parent 3781716 commit 714cbd5
Show file tree
Hide file tree
Showing 15 changed files with 1,453 additions and 170 deletions.
2 changes: 1 addition & 1 deletion dltmessageanalyzerplugin/src/common/BaseDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Q_DECLARE_METATYPE(tQStringPtrWrapper)
struct QOptionalColor
{
bool isSet = false;
QRgb color_code;
QRgb color_code = RGB_MASK;
bool operator== ( const QOptionalColor& rhs ) const;
};
typedef QVector<QOptionalColor> QOptionalColorVec;
Expand Down
46 changes: 23 additions & 23 deletions dltmessageanalyzerplugin/src/common/Definitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2464,11 +2464,11 @@ tRegexScriptingMetadata::doesContainConsistentPlotViewData(bool fillInStringMsg,
if(true == checkParameters)
{
bool bCheckParameters = checkAllParameters(result.second);
result.first = bMandatoryGanttParametersCheck && bMandatoryNonGanttParametersCheck && bCheckParameters;
result.first = ( bMandatoryGanttParametersCheck && bCheckParameters ) || ( bMandatoryNonGanttParametersCheck && bCheckParameters );
}
else
{
result.first = bMandatoryGanttParametersCheck && bMandatoryNonGanttParametersCheck;
result.first = bMandatoryGanttParametersCheck || bMandatoryNonGanttParametersCheck;
}
}
else if(false == uniqueAvailableAxisTypes.empty())
Expand Down Expand Up @@ -3522,27 +3522,27 @@ QColor getChartColor()
{
static const std::vector<QColor> sColors
{
QColor(230, 25, 75),
QColor(60, 180, 75),
QColor(255, 255, 25),
QColor(67, 99, 216),
QColor(245, 130, 49),
QColor(145, 30, 180),
QColor(70, 240, 240),
QColor(240, 50, 230),
QColor(188, 246, 12),
QColor(250, 190, 190),
QColor(0, 128, 128),
QColor(230, 190, 255),
QColor(154, 99, 36),
QColor(255, 250, 200),
QColor(128, 0, 0),
QColor(170, 255, 195),
QColor(255, 216, 177),
QColor(0, 0, 117),
QColor(128, 128, 128),
QColor(99, 243, 163),
QColor(25, 64, 163),
QColor(255, 0, 0), // Bright Red
QColor(0, 128, 0), // Dark Green
QColor(0, 0, 255), // Bright Blue
QColor(255, 165, 0), // Orange
QColor(128, 0, 128), // Purple
QColor(0, 255, 255), // Cyan
QColor(139, 69, 19), // Saddle Brown
QColor(255, 20, 147), // Deep Pink
QColor(255, 140, 0), // Dark Orange
QColor(75, 0, 130), // Indigo
QColor(0, 206, 209), // Dark Turquoise
QColor(34, 139, 34), // Forest Green
QColor(210, 105, 30), // Chocolate
QColor(148, 0, 211), // Dark Violet
QColor(0, 0, 139), // Dark Blue
QColor(255, 69, 0), // Red-Orange
QColor(0, 255, 127), // Spring Green
QColor(112, 128, 144), // Slate Gray
QColor(0, 191, 255), // Deep Sky Blue
QColor(220, 20, 60), // Crimson
QColor(0, 128, 128), // Teal
};
static const int sColorsSize = sColors.size();
static std::atomic<int> sColorsCounter(0);
Expand Down
51 changes: 50 additions & 1 deletion dltmessageanalyzerplugin/src/common/PlotDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const QString s_PLOT_Y_TIMESTAMP = "PYT";
const QString s_PLOT_GRAPH_NAME = "PGN";
const QString s_PLOT_GRAPH_METADATA = "PGMD";
const QString s_PLOT_GANTT_EVENT = "PGE";
const QString s_PLOT_GANTT_EVENT_ID = "PGEID";
const QString s_PLOT_PARAMETER_DELIMITER = "_";

QString tPlotViewIDItem::getParametersDescription()
Expand Down Expand Up @@ -728,7 +729,7 @@ static tPlotViewIDsMap createPlotIDsMap()
bool bResult = true;
QString lowerValue = value.toLower();
if(lowerValue.compare( "start", Qt::CaseInsensitive ) != 0 &&
lowerValue.compare( "stop", Qt::CaseInsensitive ) != 0)
lowerValue.compare( "end", Qt::CaseInsensitive ) != 0)
{
if(fillInStringMsg)
{
Expand All @@ -755,6 +756,54 @@ static tPlotViewIDsMap createPlotIDsMap()
result.insert(std::make_pair(ePlotViewID::PLOT_GANTT_EVENT, item));
}

auto formGanttEventIdParameters = [](tPlotViewIDItem& item)
{
{
tPlotViewIDParameterPtr pParameter = std::make_shared<tPlotViewIDparameter>();
pParameter->name = "axisRectName";
pParameter->type = ePlotViewParameterType::e_Mandatory;
item.addParameter(pParameter);
}

{
tPlotViewIDParameterPtr pParameter = std::make_shared<tPlotViewIDparameter>();
pParameter->name = "graphId";
pParameter->type = ePlotViewParameterType::e_Mandatory;
pParameter->validationFunction = [](const QString&,
ePlotViewParameterType,
const QString& value,
QString& msg,
bool fillInStringMsg)
{
bool bResult = true;
static_cast<void>(value.toInt(&bResult));
if(false == bResult)
{
if(true == fillInStringMsg)
{
msg.append(QString("Wrong literal '%1' provided. It is not convertible to integer.").arg(value));
}
}
return bResult;
};
item.addParameter(pParameter);
}
};

{
tPlotViewIDItem item;
item.id_type = ePlotViewIDType::e_Optional;
item.id_str = s_PLOT_GANTT_EVENT_ID;
formGanttEventIdParameters(item);
item.description = QString("This parameter specifies an event identifier. "
"If specified, the analysis process will connect each event type's "
"start and end points ONLY if they have the same event identifier. "
"Non-consistent events will be ignored, e.g., with start ID - 5, end ID - 8. %1."
"Optional. If multiple values appear - the 'last win' strategy is applied. "
"Applicable only for Gantt charts.").arg(item.getParametersDescription());
result.insert(std::make_pair(ePlotViewID::PLOT_GANTT_EVENT_ID, item));
}

return result;
}

Expand Down
45 changes: 44 additions & 1 deletion dltmessageanalyzerplugin/src/common/PlotDefinitions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
typedef double tPlotData;
typedef std::vector<tPlotData> tPlotDataVec;

typedef int tEventId;

typedef tQStringPtrWrapper tPlotGraphMetadataKey;
typedef tQStringPtrWrapper tPlotGraphMetadataValue;
typedef std::unordered_map<tPlotGraphMetadataKey, tPlotGraphMetadataValue> tPlotGraphMetadataMap;
Expand All @@ -45,6 +47,7 @@ enum class ePlotViewID
PLOT_X_DATA,
PLOT_Y_TIMESTAMP, // this enum entry should have less value than PLOT_Y_DATA
PLOT_Y_DATA,
PLOT_GANTT_EVENT_ID,
PLOT_GANTT_EVENT
};

Expand Down Expand Up @@ -548,7 +551,7 @@ struct tPlotParametersParser<ePlotViewID::PLOT_X_DATA>
{
assert(splitParameters[2] != nullptr);

result.value.setValue(splitParameters[1]->toDouble(&result.bParsingSuccessful));
result.value.setValue(splitParameters[2]->toDouble(&result.bParsingSuccessful));

if(false == result.bParsingSuccessful)
{
Expand Down Expand Up @@ -898,5 +901,45 @@ struct tPlotParametersParser<ePlotViewID::PLOT_GANTT_EVENT>
}
};

template<>
struct tPlotParametersParser<ePlotViewID::PLOT_GANTT_EVENT_ID>
{
ePlotViewID plotViewId = ePlotViewID::PLOT_GANTT_EVENT_ID;

struct tParsingResult
{
bool bParsingSuccessful = false;
QString errors;
QString axisRectName;
tGraphId graphId;
};

tParsingResult parse(bool fillInStringMsg,
const tQStringPtr& pPlotViewGroupName,
const tQStringPtrVec& splitParameters)
{
tParsingResult result;

if(checkPlotViewParameter(result.errors,
fillInStringMsg,
plotViewId,
pPlotViewGroupName,
splitParameters))
{
assert(splitParameters[0] != nullptr);
result.axisRectName = *splitParameters[0];

assert(splitParameters[1] != nullptr);
result.graphId = splitParameters[1]->toInt(&result.bParsingSuccessful);

if(false == result.bParsingSuccessful)
{
result.errors.append(QString(" <Failed to convert graphId '%1' to integer>").arg(*splitParameters[1]));
}
}

return result;
}
};

#endif // PLOT_DEFINITIONS_HPP
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Q_OBJECT
void rescaleYExtended();

void appendMetadata(QCPAxisRect* pAxisRect,
QCPGraph* pGraph,
QCPAbstractPlottable* pGraph,
const tPlotData& x,
const tPlotData& y,
const tPlotGraphMetadataMap& plotGraphMetadataMap);
Expand All @@ -39,7 +39,7 @@ Q_OBJECT
QCPLegend* pLegend);

std::pair< bool, const tPlotGraphMetadataMap* > getMetadata(QCPAxisRect* pAxisRect,
QCPGraph* pGraph,
QCPAbstractPlottable* pGraph,
const tPlotData& x,
const tPlotData& y);

Expand Down Expand Up @@ -73,7 +73,7 @@ Q_OBJECT
};

typedef std::map<std::pair<tPlotData, tPlotData>, tPlotGraphMetadataMap> tPlotPointMetadataMap;
typedef std::map<QCPGraph*, tPlotPointMetadataMap> tPlotGraphsMetadataMap;
typedef std::map<QCPAbstractPlottable*, tPlotPointMetadataMap> tPlotGraphsMetadataMap;

struct tAxisRectData
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

#include "common/Definitions.hpp"

#include "components/log/api/CLog.hpp"

#include "../api/CCustomPlotExtended.hpp"

#include "DMA_Plantuml.hpp"
Expand All @@ -31,6 +33,8 @@ CCustomPlotExtended::CCustomPlotExtended(QWidget *pParent):
setInteraction(QCP::iRangeDrag, true);
setInteraction(QCP::iRangeZoom, true);

addLayer("axis_rect_label", nullptr);

connect(this, &QCustomPlot::legendClick, this, [&](QCPLegend*, QCPAbstractLegendItem* item, QMouseEvent* event)
{
QCPPlottableLegendItem *pItem = qobject_cast<QCPPlottableLegendItem*>(item);
Expand Down Expand Up @@ -128,9 +132,9 @@ void CCustomPlotExtended::changeLegendItemVisibility(QCPPlottableLegendItem* pIt
uint32_t visiblePlotsNumber = 0u;
bool bIsSingleVisiblePlot = true;

for(const auto pGraph : pAxisRect->graphs())
for(const auto pPlottable : pAxisRect->plottables())
{
if(true == pGraph->visible())
if(true == pPlottable->visible())
{
++visiblePlotsNumber;

Expand Down Expand Up @@ -170,29 +174,29 @@ void CCustomPlotExtended::updateOpactity()
auto* pAxisRect = axisRectPair.first;
const auto& axisRectType = axisRectPair.second.plotViewAxisType;

for(auto* pGraph : pAxisRect->graphs())
for(auto* pPlottable : pAxisRect->plottables())
{
if(axisRectType == ePlotViewAxisType::e_LINEAR)
if(axisRectType == ePlotViewAxisType::e_LINEAR || axisRectType == ePlotViewAxisType::e_GANTT)
{
// Adjusting the pen (line) opacity
QPen pen = pGraph->pen();
QPen pen = pPlottable->pen();
QColor penColor = pen.color();
penColor.setAlpha(mUsedOpacity ? mUsedOpacity : sMaxOpacity);
pen.setColor(penColor);
pGraph->setPen(pen);
pPlottable->setPen(pen);

// If you also want to adjust the brush (fill) opacity
QBrush brush = pGraph->brush();
QBrush brush = pPlottable->brush();
QColor brushColor = brush.color();
brushColor.setAlpha(mUsedOpacity);
brush.setColor(brushColor);
pGraph->setBrush(brush);
pPlottable->setBrush(brush);
}
else if(axisRectType == ePlotViewAxisType::e_POINT)
{
// turn off lines and filling
pGraph->setPen(Qt::NoPen);
pGraph->setBrush(Qt::NoBrush);
pPlottable->setPen(Qt::NoPen);
pPlottable->setBrush(Qt::NoBrush);
}
}
}
Expand Down Expand Up @@ -234,6 +238,48 @@ bool CCustomPlotExtended::setAxisRectRescaleData(QCPAxisRect* pAxisRect,

void CCustomPlotExtended::rescaleExtended()
{
auto maxLeftMargin = 0;

for(const auto& data_pair : mPlotAxisRectDataMap)
{
auto* pAxisRect = data_pair.first;
if(nullptr != pAxisRect)
{
auto* pLeftAxis = pAxisRect->axis(QCPAxis::atLeft);

if(nullptr != pLeftAxis)
{
pAxisRect->update(QCPLayoutElement::upPreparation);
pAxisRect->update(QCPLayoutElement::upMargins);
auto leftMargin = pAxisRect->margins().left();

if(maxLeftMargin < leftMargin)
{
maxLeftMargin = leftMargin;
}
}
}
}

for(const auto& data_pair : mPlotAxisRectDataMap)
{
auto* pAxisRect = data_pair.first;
if(nullptr != pAxisRect)
{
auto* pLeftAxis = pAxisRect->axis(QCPAxis::atLeft);

if(nullptr != pLeftAxis)
{
auto leftMargin = pAxisRect->margins().left();
pLeftAxis->setPadding(maxLeftMargin - leftMargin);
}

auto margins = pAxisRect->margins();
margins.setTop(20);
pAxisRect->setMargins(margins);
}
}

rescaleXExtended();
rescaleYExtended();
}
Expand Down Expand Up @@ -409,7 +455,7 @@ void CCustomPlotExtended::resizeEvent(QResizeEvent* event)
}

void CCustomPlotExtended::appendMetadata(QCPAxisRect* pAxisRect,
QCPGraph* pGraph,
QCPAbstractPlottable* pGraph,
const tPlotData& x,
const tPlotData& y,
const tPlotGraphMetadataMap& plotGraphMetadataMap)
Expand All @@ -418,7 +464,7 @@ void CCustomPlotExtended::appendMetadata(QCPAxisRect* pAxisRect,
}

std::pair< bool, const tPlotGraphMetadataMap* > CCustomPlotExtended::getMetadata(QCPAxisRect* pAxisRect,
QCPGraph* pGraph,
QCPAbstractPlottable* pGraph,
const tPlotData& x,
const tPlotData& y)
{
Expand Down Expand Up @@ -545,7 +591,7 @@ void CCustomPlotExtended::filterGraphBySelectedItem()

if(numberOfGraphs != numberOfVisibleGraphs && numberOfVisibleGraphs > 1 && nullptr == pSelectedLegendItem)
action = eAction::eDoNothing;
else if(numberOfVisibleGraphs > 1 && numberOfVisibleGraphs > 1 && nullptr != pSelectedLegendItem)
else if(numberOfVisibleGraphs > 1 && nullptr != pSelectedLegendItem)
action = eAction::eApplyFiltrer;
else if(numberOfGraphs > 1 && numberOfVisibleGraphs == 1 && nullptr != pSelectedLegendItem)
action = eAction::eRemoveFiltrer;
Expand Down
Loading

0 comments on commit 714cbd5

Please sign in to comment.