From 8c2fc62830fad37c7ad63bd91b3f30578fe45c84 Mon Sep 17 00:00:00 2001 From: Furkan Date: Mon, 15 May 2023 13:40:15 +0000 Subject: [PATCH] EVerything ok now --- src/ParamOutputImpl/Plot/AxisLegendManager.cc | 2 +- src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.cc | 19 +++++++++++++------ src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.hh | 11 ++++++++--- src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.cc | 31 ++++++++++++++++++++++--------- src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.hh | 5 +++++ src/ParamOutputImpl/Plot/PanelPlotOutput.cc | 13 ++++++++----- src/ParamOutputImpl/Plot/PanelPlotOutput.hh | 4 ++-- 7 files changed, 59 insertions(+), 26 deletions(-) diff --git a/src/ParamOutputImpl/Plot/AxisLegendManager.cc b/src/ParamOutputImpl/Plot/AxisLegendManager.cc index 6f4a4e2..112ddcb 100644 --- a/src/ParamOutputImpl/Plot/AxisLegendManager.cc +++ b/src/ParamOutputImpl/Plot/AxisLegendManager.cc @@ -152,7 +152,7 @@ namespace plot yAxisTextLegend = pHistogramProperties->getHistotypeProperties().getHisto1DFunction()->getTextLegend(); Label yLabel(lYAxis->_legend.getFont(),lYAxis->_color); yLabel._text = yAxisTextLegend; - lYAxis->_legend.pushLabel(yLabel); + lYAxis->_legend.setLabel(yLabel); } Color compLegendColor = lYAxis->_color; diff --git a/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.cc b/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.cc index fdae3e5..0435d3a 100644 --- a/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.cc +++ b/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.cc @@ -34,13 +34,13 @@ std::map> Histo1DFunction::getGridValues(double* xData, // Density function for 1DHistogram void Density1DFunction::apply(std::vector> &grid, double* xData, int nbData, Range xRange, - double& xBinSize, double& yMin, double& yMax) + double& xBinSize, bool yIsLog, double& yMin, double& yMax) { if(!_cacheGrid.empty()){ grid = _cacheGrid; return; } - yMin = 0; + yMin = (yIsLog) ? 1 : 0; yMax = 0; std::map> allValues; @@ -48,7 +48,8 @@ void Density1DFunction::apply(std::vector> &grid, doub for (unsigned int i(0); i < allValues.size(); ++i){ if (allValues[i].size() > 0) - _cacheGrid.push_back(std::make_pair(xRange.getMin()+xBinSize*i,allValues[i].size())); + _cacheGrid.push_back(std::make_pair(xRange.getMin()+xBinSize*i, + (yIsLog) ? log10(allValues[i].size()) : allValues[i].size() )); if(yMax < allValues[i].size()) yMax = allValues[i].size(); @@ -60,7 +61,7 @@ void Density1DFunction::apply(std::vector> &grid, doub // NormDensity1DFunction function for 1DHistogram void NormDensity1DFunction::apply(std::vector> &grid, double* xData, int nbData, Range xRange, - double& xBinSize, double& yMin, double& yMax) + double& xBinSize, bool yIsLog, double& yMin, double& yMax) { if(!_cacheGrid.empty()){ @@ -68,7 +69,7 @@ void NormDensity1DFunction::apply(std::vector> &grid, return; } - yMin = 0; + yMin = (yIsLog) ? 1 : 0; yMax = 0; std::map> allValues; @@ -81,10 +82,16 @@ void NormDensity1DFunction::apply(std::vector> &grid, for (unsigned int i(0); i < allValues.size(); ++i){ if (allValues[i].size() > 0) - _cacheGrid.push_back(std::make_pair(xRange.getMin()+xBinSize*i,allValues[i].size()/(double)nbRecord)); + _cacheGrid.push_back(std::make_pair(xRange.getMin()+xBinSize*i, + (yIsLog)? log10(allValues[i].size()/(double)nbRecord) + : allValues[i].size()/(double)nbRecord)); if(yMax < allValues[i].size()/(double)nbRecord) yMax = allValues[i].size()/(double)nbRecord; + if(yIsLog){ + if(yMin > allValues[i].size()/(double)nbRecord) + yMin = allValues[i].size()/(double)nbRecord; + } } } } /* namespace plot */ diff --git a/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.hh b/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.hh index bdaafc3..abddf4e 100644 --- a/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.hh +++ b/src/ParamOutputImpl/Plot/HistoPlot/Histo1DFunction.hh @@ -27,7 +27,8 @@ class Histo1DFunction { } ~Histo1DFunction(){} - virtual void apply(std::vector> &grid, double* xData, int nbData, Range xRange, double& xBinSize,double& yMin, double& yMax) = 0; + virtual void apply(std::vector> &grid, double* xData, int nbData, Range xRange, double& xBinSize, + bool yIsLog, double& yMin, double& yMax) = 0; virtual std::string getTextLegend() { @@ -35,6 +36,10 @@ class Histo1DFunction { } std::map> getGridValues(double* xData, int nbData, Range xRange, double xBinSize); + + void resetCache() { + _cacheGrid.clear(); + } protected: std::vector> _cacheGrid; @@ -50,7 +55,7 @@ public: ~Density1DFunction() {} virtual void apply(std::vector> &grid, double* xData, int nbData, Range xRange, - double& xBinSize, double& yMin, double& yMax); + double& xBinSize, bool yIsLog, double& yMin, double& yMax); virtual std::string getTextLegend() { return "Events"; @@ -63,7 +68,7 @@ public: ~NormDensity1DFunction() {} virtual void apply(std::vector> &grid, double* xData, int nbData, Range xRange, - double& xBinSize, double& yMin, double& yMax); + double& xBinSize, bool yIsLog, double& yMin, double& yMax); virtual std::string getTextLegend() { return "Frequency"; diff --git a/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.cc b/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.cc index ccd9a20..f0643a1 100644 --- a/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.cc +++ b/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.cc @@ -246,7 +246,6 @@ void HistoPlot::getUsedParameters(AMDA::Parameters::ParameterSPtr originalXParam void HistoPlot::configureSeriesAxis(double startDate, double stopDate) { // map - std::map lAxisRangeMap; Range lColorAxeRange; boost::shared_ptr lZAxis = _panel->getColorAxis(); @@ -278,11 +277,6 @@ void HistoPlot::configureSeriesAxis(double startDate, double stopDate) { } } - // Update range of axis. - for (auto lAxis: lAxisRangeMap) { - _panel->getAxis(lAxis.first)->setRange(lAxis.second); - } - if (lZAxis != nullptr && lColorAxeRange.isSet()) lZAxis->setRange(lColorAxeRange); } @@ -306,7 +300,7 @@ void HistoPlot::histo1DUtils(double startDate, double stopDate, HistogramSeriesP boost::shared_ptr lYAxis(_panel->getAxis(pHistogramProperties.getYAxisId())); Range lXRange = lXAxis->getRange(); - Range lYRange = lYAxis->getRange(); + Range lYRange = lYAxis->Axis::getRange(); double yMin = NAN ; double yMax = NAN ; @@ -328,7 +322,8 @@ void HistoPlot::histo1DUtils(double startDate, double stopDate, HistogramSeriesP else xValues = xData.getValues(pHistogramProperties.getIndex(), xStartIndex); - pHistogramProperties.getHistotypeProperties().getHisto1DFunction()->apply(grid,xValues,xNbValues,lXRange, xBinSize, yMin, yMax); + pHistogramProperties.getHistotypeProperties().getHisto1DFunction()->apply(grid,xValues,xNbValues,lXRange, xBinSize, + (lYAxis->_scale==Axis::Scale::LOGARITHMIC) ? true : false,yMin, yMax); if(lXAxis->_scale==Axis::Scale::LOGARITHMIC) free(xValues); @@ -347,12 +342,14 @@ void HistoPlot::drawHistogram(double startDate, double stopDate, std::string pPa std::vector> grid; Color color = pHistogramProperties.getColor(); double xBinSize = 0; + boost::shared_ptr lYAxis(_panel->getAxis(pHistogramProperties.getYAxisId())); + Range lYRange = lYAxis->getRange(); histo1DUtils(startDate, stopDate,pHistogramProperties, grid, xBinSize); PanelPlotOutput::drawHistogram(startDate,stopDate,pParamId, pHistogramProperties); - PanelPlotOutput::drawHistogramBoxes(grid,color,xBinSize); + PanelPlotOutput::drawHistogramBoxes(grid,color,xBinSize, lYRange.getMin()); } else { @@ -452,5 +449,21 @@ void HistoPlot::drawHistogram(double startDate, double stopDate, std::string pPa PanelPlotOutput::drawMatrix(matrixGrid, zMin, zMax, minValColor,maxValColor, lZAxis->_color._colorMapIndex, false); } } + +void HistoPlot::resetPlot() +{ + for (auto param: _parameterAxesList) { + + std::shared_ptr pHistogramProperties = param.getHistogramSeriesProperties() ; + if(pHistogramProperties != nullptr){ + + if(pHistogramProperties->getHistogramType() == "histogram1d"){ + + pHistogramProperties->getHistotypeProperties().getHisto1DFunction()->resetCache(); + } + } + } + PanelPlotOutput::resetPlot(); +} } diff --git a/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.hh b/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.hh index a10c6ae..e439187 100644 --- a/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.hh +++ b/src/ParamOutputImpl/Plot/HistoPlot/HistoPlot.hh @@ -60,6 +60,11 @@ public: // */ virtual void createParameters(std::list& usedParametersId_); + /** + * @overload PanelPlotOutput::resetPlot - reset plot + */ + virtual void resetPlot(); + protected: void histo1DUtils(double startDate, double stopDate, HistogramSeriesProperties &pHistogramProperties, diff --git a/src/ParamOutputImpl/Plot/PanelPlotOutput.cc b/src/ParamOutputImpl/Plot/PanelPlotOutput.cc index 0ec09d9..2e25623 100644 --- a/src/ParamOutputImpl/Plot/PanelPlotOutput.cc +++ b/src/ParamOutputImpl/Plot/PanelPlotOutput.cc @@ -1529,17 +1529,20 @@ namespace plot // Restore color. restoreColor(_pls, lInitialColor, _panel->_page->_mode); } - void PanelPlotOutput::drawHistogramBoxes(std::vector> data, Color &color, double binWidth){ + void PanelPlotOutput::drawHistogramBoxes(std::vector> data, Color &color, double binWidth, double yMin){ + for (unsigned int i(0); i < data.size(); i++ ) + { + } for (unsigned int i(0); i < data.size(); i++ ) { //plcol0(i + 1); _pls->psty( 0 ); - drawHistoBox( data[i].first, data[i].second, binWidth, color); + drawHistoBox( data[i].first, data[i].second, binWidth, color, yMin); } } - void PanelPlotOutput::drawHistoBox( PLFLT x0, PLFLT y0, double binWidth, Color &color ) + void PanelPlotOutput::drawHistoBox( PLFLT x0, PLFLT y0, double binWidth, Color &color, double yMin ) { // set color @@ -1549,13 +1552,13 @@ namespace plot PLFLT x[4], y[4]; x[0] = x0; - y[0] = 0.; + y[0] = yMin; x[1] = x0; y[1] = y0; x[2] = x0 + binWidth; y[2] = y0; x[3] = x0 + binWidth; - y[3] = 0.; + y[3] = yMin; // Fill rectangle PLINT icol = 0; diff --git a/src/ParamOutputImpl/Plot/PanelPlotOutput.hh b/src/ParamOutputImpl/Plot/PanelPlotOutput.hh index f9177f8..9f48102 100644 --- a/src/ParamOutputImpl/Plot/PanelPlotOutput.hh +++ b/src/ParamOutputImpl/Plot/PanelPlotOutput.hh @@ -284,8 +284,8 @@ public: typedef std::vector SauvaudGrid; - void drawHistogramBoxes(std::vector> data, Color &color, double binWidth); - void drawHistoBox( PLFLT x0, PLFLT y0, double binWidth, Color &color); + void drawHistogramBoxes(std::vector> data, Color &color, double binWidth, double yMin); + void drawHistoBox( PLFLT x0, PLFLT y0, double binWidth, Color &color, double yMin); /* * @brief Draw a matrix */ -- libgit2 0.21.2