Use struct to group together parameters to reduce number of method args.

And to make it easier to share common parameters between methods.

Change-Id: Ibdbad66ea8f2f30b4518f9ecaec2f43087c54837
This commit is contained in:
Kohei Yoshida
2014-08-13 14:26:16 -04:00
parent 8bd81a6520
commit be0de8b9db
2 changed files with 81 additions and 72 deletions

View File

@@ -34,11 +34,33 @@
#include <boost/scoped_ptr.hpp> #include <boost/scoped_ptr.hpp>
namespace chart
{
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::chart2; using namespace ::com::sun::star::chart2;
namespace chart {
struct PieChart::ShapeParam
{
double mfUnitCircleStartAngleDegree;
double mfUnitCircleWidthAngleDegree;
double mfUnitCircleOuterRadius;
double mfUnitCircleInnerRadius;
double mfExplodePercentage;
double mfLogicYSum;
double mfLogicZ;
double mfDepth;
ShapeParam() :
mfUnitCircleStartAngleDegree(0.0),
mfUnitCircleWidthAngleDegree(0.0),
mfUnitCircleOuterRadius(0.0),
mfUnitCircleInnerRadius(0.0),
mfExplodePercentage(0.0),
mfLogicYSum(0.0),
mfLogicZ(0.0),
mfDepth(0.0) {}
};
class PiePositionHelper : public PolarPlottingPositionHelper class PiePositionHelper : public PolarPlottingPositionHelper
{ {
public: public:
@@ -163,21 +185,19 @@ bool PieChart::shouldSnapRectToUsedArea()
} }
uno::Reference< drawing::XShape > PieChart::createDataPoint( uno::Reference< drawing::XShape > PieChart::createDataPoint(
const uno::Reference< drawing::XShapes >& xTarget const uno::Reference<drawing::XShapes>& xTarget,
, const uno::Reference< beans::XPropertySet >& xObjectProperties const uno::Reference<beans::XPropertySet>& xObjectProperties,
, double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree tPropertyNameValueMap* pOverwritePropertiesMap,
, double fUnitCircleInnerRadius, double fUnitCircleOuterRadius const ShapeParam& rParam )
, double fLogicZ, double fDepth, double fExplodePercentage
, tPropertyNameValueMap* pOverwritePropertiesMap )
{ {
//transform position: //transform position:
drawing::Direction3D aOffset; drawing::Direction3D aOffset;
if( !::rtl::math::approxEqual( fExplodePercentage, 0.0 ) ) if (!::rtl::math::approxEqual(rParam.mfExplodePercentage, 0.0))
{ {
double fAngle = fUnitCircleStartAngleDegree + fUnitCircleWidthAngleDegree/2.0; double fAngle = rParam.mfUnitCircleStartAngleDegree + rParam.mfUnitCircleWidthAngleDegree/2.0;
double fRadius = (fUnitCircleOuterRadius-fUnitCircleInnerRadius)*fExplodePercentage; double fRadius = (rParam.mfUnitCircleOuterRadius-rParam.mfUnitCircleInnerRadius)*rParam.mfExplodePercentage;
drawing::Position3D aOrigin = m_pPosHelper->transformUnitCircleToScene( 0, 0, fLogicZ ); drawing::Position3D aOrigin = m_pPosHelper->transformUnitCircleToScene(0, 0, rParam.mfLogicZ);
drawing::Position3D aNewOrigin = m_pPosHelper->transformUnitCircleToScene( fAngle, fRadius, fLogicZ ); drawing::Position3D aNewOrigin = m_pPosHelper->transformUnitCircleToScene(fAngle, fRadius, rParam.mfLogicZ);
aOffset = aNewOrigin - aOrigin; aOffset = aNewOrigin - aOrigin;
} }
@@ -186,16 +206,16 @@ uno::Reference< drawing::XShape > PieChart::createDataPoint(
if(m_nDimension==3) if(m_nDimension==3)
{ {
xShape = m_pShapeFactory->createPieSegment( xTarget xShape = m_pShapeFactory->createPieSegment( xTarget
, fUnitCircleStartAngleDegree, fUnitCircleWidthAngleDegree , rParam.mfUnitCircleStartAngleDegree, rParam.mfUnitCircleWidthAngleDegree
, fUnitCircleInnerRadius, fUnitCircleOuterRadius , rParam.mfUnitCircleInnerRadius, rParam.mfUnitCircleOuterRadius
, aOffset, B3DHomMatrixToHomogenMatrix( m_pPosHelper->getUnitCartesianToScene() ) , aOffset, B3DHomMatrixToHomogenMatrix( m_pPosHelper->getUnitCartesianToScene() )
, fDepth ); , rParam.mfDepth );
} }
else else
{ {
xShape = m_pShapeFactory->createPieSegment2D( xTarget xShape = m_pShapeFactory->createPieSegment2D( xTarget
, fUnitCircleStartAngleDegree, fUnitCircleWidthAngleDegree , rParam.mfUnitCircleStartAngleDegree, rParam.mfUnitCircleWidthAngleDegree
, fUnitCircleInnerRadius, fUnitCircleOuterRadius , rParam.mfUnitCircleInnerRadius, rParam.mfUnitCircleOuterRadius
, aOffset, B3DHomMatrixToHomogenMatrix( m_pPosHelper->getUnitCartesianToScene() ) ); , aOffset, B3DHomMatrixToHomogenMatrix( m_pPosHelper->getUnitCartesianToScene() ) );
} }
this->setMappedProperties( xShape, xObjectProperties, PropertyMapper::getPropertyNameMapForFilledSeriesProperties(), pOverwritePropertiesMap ); this->setMappedProperties( xShape, xObjectProperties, PropertyMapper::getPropertyNameMapForFilledSeriesProperties(), pOverwritePropertiesMap );
@@ -204,19 +224,16 @@ uno::Reference< drawing::XShape > PieChart::createDataPoint(
void PieChart::createTextLabelShape( void PieChart::createTextLabelShape(
const uno::Reference<drawing::XShapes>& xTextTarget, const uno::Reference<drawing::XShapes>& xTextTarget,
VDataSeries& rSeries, sal_Int32 nPointIndex, VDataSeries& rSeries, sal_Int32 nPointIndex, ShapeParam& rParam )
double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree,
double fUnitCircleOuterRadius, double fUnitCircleInnerRadius, double fExplodePercentage,
double fLogicYSum, double fLogicZ )
{ {
if (!rSeries.getDataPointLabelIfLabel(nPointIndex)) if (!rSeries.getDataPointLabelIfLabel(nPointIndex))
return; return;
if( !::rtl::math::approxEqual( fExplodePercentage, 0.0 ) ) if (!rtl::math::approxEqual(rParam.mfExplodePercentage, 0.0))
{ {
double fExplodeOffset = (fUnitCircleOuterRadius-fUnitCircleInnerRadius)*fExplodePercentage; double fExplodeOffset = (rParam.mfUnitCircleOuterRadius-rParam.mfUnitCircleInnerRadius)*rParam.mfExplodePercentage;
fUnitCircleInnerRadius += fExplodeOffset; rParam.mfUnitCircleInnerRadius += fExplodeOffset;
fUnitCircleOuterRadius += fExplodeOffset; rParam.mfUnitCircleOuterRadius += fExplodeOffset;
} }
sal_Int32 nLabelPlacement = rSeries.getLabelPlacement( sal_Int32 nLabelPlacement = rSeries.getLabelPlacement(
@@ -240,12 +257,12 @@ void PieChart::createTextLabelShape(
PolarLabelPositionHelper aPolarPosHelper(m_pPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory); PolarLabelPositionHelper aPolarPosHelper(m_pPosHelper,m_nDimension,m_xLogicTarget,m_pShapeFactory);
awt::Point aScreenPosition2D( awt::Point aScreenPosition2D(
aPolarPosHelper.getLabelScreenPositionAndAlignmentForUnitCircleValues(eAlignment, nLabelPlacement aPolarPosHelper.getLabelScreenPositionAndAlignmentForUnitCircleValues(eAlignment, nLabelPlacement
, fUnitCircleStartAngleDegree, fUnitCircleWidthAngleDegree , rParam.mfUnitCircleStartAngleDegree, rParam.mfUnitCircleWidthAngleDegree
, fUnitCircleInnerRadius, fUnitCircleOuterRadius, fLogicZ+0.5, 0 )); , rParam.mfUnitCircleInnerRadius, rParam.mfUnitCircleOuterRadius, rParam.mfLogicZ+0.5, 0 ));
PieLabelInfo aPieLabelInfo; PieLabelInfo aPieLabelInfo;
aPieLabelInfo.aFirstPosition = basegfx::B2IVector( aScreenPosition2D.X, aScreenPosition2D.Y ); aPieLabelInfo.aFirstPosition = basegfx::B2IVector( aScreenPosition2D.X, aScreenPosition2D.Y );
awt::Point aOrigin( aPolarPosHelper.transformSceneToScreenPosition( m_pPosHelper->transformUnitCircleToScene( 0.0, 0.0, fLogicZ+1.0 ) ) ); awt::Point aOrigin( aPolarPosHelper.transformSceneToScreenPosition( m_pPosHelper->transformUnitCircleToScene( 0.0, 0.0, rParam.mfLogicZ+1.0 ) ) );
aPieLabelInfo.aOrigin = basegfx::B2IVector( aOrigin.X, aOrigin.Y ); aPieLabelInfo.aOrigin = basegfx::B2IVector( aOrigin.X, aOrigin.Y );
//add a scaling independent Offset if requested //add a scaling independent Offset if requested
@@ -259,7 +276,7 @@ void PieChart::createTextLabelShape(
double nVal = rSeries.getYValue(nPointIndex); double nVal = rSeries.getYValue(nPointIndex);
aPieLabelInfo.xTextShape = createDataLabel( aPieLabelInfo.xTextShape = createDataLabel(
xTextTarget, rSeries, nPointIndex, nVal, fLogicYSum, aScreenPosition2D, eAlignment); xTextTarget, rSeries, nPointIndex, nVal, rParam.mfLogicYSum, aScreenPosition2D, eAlignment);
uno::Reference< container::XChild > xChild( aPieLabelInfo.xTextShape, uno::UNO_QUERY ); uno::Reference< container::XChild > xChild( aPieLabelInfo.xTextShape, uno::UNO_QUERY );
if( xChild.is() ) if( xChild.is() )
@@ -409,6 +426,8 @@ void PieChart::createShapes()
for( double fSlotX=0; aXSlotIter != aXSlotEnd && (m_bUseRings||fSlotX<0.5 ); ++aXSlotIter, fSlotX+=1.0 ) for( double fSlotX=0; aXSlotIter != aXSlotEnd && (m_bUseRings||fSlotX<0.5 ); ++aXSlotIter, fSlotX+=1.0 )
{ {
ShapeParam aParam;
::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector); ::std::vector< VDataSeries* >* pSeriesList = &(aXSlotIter->m_aSeriesVector);
if( pSeriesList->size()<=0 )//there should be only one series in each x slot if( pSeriesList->size()<=0 )//there should be only one series in each x slot
continue; continue;
@@ -420,7 +439,6 @@ void PieChart::createShapes()
m_pPosHelper->m_fAngleDegreeOffset = pSeries->getStartingAngle(); m_pPosHelper->m_fAngleDegreeOffset = pSeries->getStartingAngle();
double fLogicYSum = 0.0;
//iterate through all points to get the sum //iterate through all points to get the sum
sal_Int32 nPointIndex=0; sal_Int32 nPointIndex=0;
sal_Int32 nPointCount=pSeries->getTotalPointCount(); sal_Int32 nPointCount=pSeries->getTotalPointCount();
@@ -433,10 +451,12 @@ void PieChart::createShapes()
} }
if( ::rtl::math::isNan(fY) ) if( ::rtl::math::isNan(fY) )
continue; continue;
fLogicYSum += fabs(fY); aParam.mfLogicYSum += fabs(fY);
} }
if(fLogicYSum==0.0)
if (aParam.mfLogicYSum == 0.0)
continue; continue;
double fLogicYForNextPoint = 0.0; double fLogicYForNextPoint = 0.0;
//iterate through all points to create shapes //iterate through all points to create shapes
for( nPointIndex = 0; nPointIndex < nPointCount; nPointIndex++ ) for( nPointIndex = 0; nPointIndex < nPointCount; nPointIndex++ )
@@ -447,7 +467,7 @@ void PieChart::createShapes()
if( !bIsVisible ) if( !bIsVisible )
continue; continue;
double fDepth = this->getTransformedDepth() * (n3DRelativeHeight / 100.0); aParam.mfDepth = this->getTransformedDepth() * (n3DRelativeHeight / 100.0);
uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShape(pSeries, xSeriesTarget); uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShape(pSeries, xSeriesTarget);
//collect data point information (logic coordinates, style ): //collect data point information (logic coordinates, style ):
@@ -464,14 +484,14 @@ void PieChart::createShapes()
//iterate through all subsystems to create partial points //iterate through all subsystems to create partial points
{ {
//logic values on angle axis: //logic values on angle axis:
double fLogicStartAngleValue = fLogicYPos/fLogicYSum; double fLogicStartAngleValue = fLogicYPos / aParam.mfLogicYSum;
double fLogicEndAngleValue = (fLogicYPos+fLogicYValue)/fLogicYSum; double fLogicEndAngleValue = (fLogicYPos+fLogicYValue) / aParam.mfLogicYSum;
double fExplodePercentage=0.0; aParam.mfExplodePercentage = 0.0;
bool bDoExplode = ( nExplodeableSlot == static_cast< ::std::vector< VDataSeriesGroup >::size_type >(fSlotX) ); bool bDoExplode = ( nExplodeableSlot == static_cast< ::std::vector< VDataSeriesGroup >::size_type >(fSlotX) );
if(bDoExplode) try if(bDoExplode) try
{ {
xPointProperties->getPropertyValue( "Offset") >>= fExplodePercentage; xPointProperties->getPropertyValue( "Offset") >>= aParam.mfExplodePercentage;
} }
catch( const uno::Exception& e ) catch( const uno::Exception& e )
{ {
@@ -479,10 +499,10 @@ void PieChart::createShapes()
} }
//transforme to unit circle: //transforme to unit circle:
double fUnitCircleWidthAngleDegree = m_pPosHelper->getWidthAngleDegree( fLogicStartAngleValue, fLogicEndAngleValue ); aParam.mfUnitCircleWidthAngleDegree = m_pPosHelper->getWidthAngleDegree( fLogicStartAngleValue, fLogicEndAngleValue );
double fUnitCircleStartAngleDegree = m_pPosHelper->transformToAngleDegree( fLogicStartAngleValue ); aParam.mfUnitCircleStartAngleDegree = m_pPosHelper->transformToAngleDegree( fLogicStartAngleValue );
double fUnitCircleInnerRadius = m_pPosHelper->transformToRadius( fLogicInnerRadius ); aParam.mfUnitCircleInnerRadius = m_pPosHelper->transformToRadius( fLogicInnerRadius );
double fUnitCircleOuterRadius = m_pPosHelper->transformToRadius( fLogicOuterRadius ); aParam.mfUnitCircleOuterRadius = m_pPosHelper->transformToRadius( fLogicOuterRadius );
//point color: //point color:
boost::scoped_ptr< tPropertyNameValueMap > apOverwritePropertiesMap(NULL); boost::scoped_ptr< tPropertyNameValueMap > apOverwritePropertiesMap(NULL);
@@ -496,12 +516,10 @@ void PieChart::createShapes()
} }
//create data point //create data point
double fLogicZ = -1.0; // For 3D pie chart label position aParam.mfLogicZ = -1.0; // For 3D pie chart label position
uno::Reference<drawing::XShape> xPointShape( uno::Reference<drawing::XShape> xPointShape =
createDataPoint( xSeriesGroupShape_Shapes, xPointProperties createDataPoint(
, fUnitCircleStartAngleDegree, fUnitCircleWidthAngleDegree xSeriesGroupShape_Shapes, xPointProperties, apOverwritePropertiesMap.get(), aParam);
, fUnitCircleInnerRadius, fUnitCircleOuterRadius
, fLogicZ, fDepth, fExplodePercentage, apOverwritePropertiesMap.get() ) );
if(bHasFillColorMapping) if(bHasFillColorMapping)
{ {
@@ -514,11 +532,7 @@ void PieChart::createShapes()
} }
//create label //create label
createTextLabelShape( createTextLabelShape(xTextTarget, *pSeries, nPointIndex, aParam);
xTextTarget, *pSeries, nPointIndex,
fUnitCircleStartAngleDegree, fUnitCircleWidthAngleDegree,
fUnitCircleOuterRadius, fUnitCircleInnerRadius,
fExplodePercentage, fLogicYSum, fLogicZ);
if(!bDoExplode) if(!bDoExplode)
{ {
@@ -529,12 +543,12 @@ void PieChart::createShapes()
{ {
//enable dragging of outer segments //enable dragging of outer segments
double fAngle = fUnitCircleStartAngleDegree + fUnitCircleWidthAngleDegree/2.0; double fAngle = aParam.mfUnitCircleStartAngleDegree + aParam.mfUnitCircleWidthAngleDegree/2.0;
double fMaxDeltaRadius = fUnitCircleOuterRadius-fUnitCircleInnerRadius; double fMaxDeltaRadius = aParam.mfUnitCircleOuterRadius-aParam.mfUnitCircleInnerRadius;
drawing::Position3D aOrigin = m_pPosHelper->transformUnitCircleToScene( fAngle, fUnitCircleOuterRadius, fLogicZ ); drawing::Position3D aOrigin = m_pPosHelper->transformUnitCircleToScene( fAngle, aParam.mfUnitCircleOuterRadius, aParam.mfLogicZ );
drawing::Position3D aNewOrigin = m_pPosHelper->transformUnitCircleToScene( fAngle, fUnitCircleOuterRadius + fMaxDeltaRadius, fLogicZ ); drawing::Position3D aNewOrigin = m_pPosHelper->transformUnitCircleToScene( fAngle, aParam.mfUnitCircleOuterRadius + fMaxDeltaRadius, aParam.mfLogicZ );
sal_Int32 nOffsetPercent( static_cast<sal_Int32>(fExplodePercentage * 100.0) ); sal_Int32 nOffsetPercent( static_cast<sal_Int32>(aParam.mfExplodePercentage * 100.0) );
awt::Point aMinimumPosition( PlottingPositionHelper::transformSceneToScreenPosition( awt::Point aMinimumPosition( PlottingPositionHelper::transformSceneToScreenPosition(
aOrigin, m_xLogicTarget, m_pShapeFactory, m_nDimension ) ); aOrigin, m_xLogicTarget, m_pShapeFactory, m_nDimension ) );

View File

@@ -30,7 +30,8 @@ class PiePositionHelper;
class PieChart : public VSeriesPlotter class PieChart : public VSeriesPlotter
{ {
// public methods struct ShapeParam;
public: public:
PieChart( const ::com::sun::star::uno::Reference< PieChart( const ::com::sun::star::uno::Reference<
::com::sun::star::chart2::XChartType >& xChartTypeModel ::com::sun::star::chart2::XChartType >& xChartTypeModel
@@ -63,22 +64,16 @@ private: //methods
//no default constructor //no default constructor
PieChart(); PieChart();
::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > css::uno::Reference<css::drawing::XShape>
createDataPoint( const ::com::sun::star::uno::Reference< createDataPoint(
::com::sun::star::drawing::XShapes >& xTarget const css::uno::Reference<css::drawing::XShapes>& xTarget,
, const ::com::sun::star::uno::Reference< const css::uno::Reference<css::beans::XPropertySet>& xObjectProperties,
::com::sun::star::beans::XPropertySet >& xObjectProperties tPropertyNameValueMap* pOverWritePropertiesMap,
, double fUnitCircleStartAngleDegree, double fWidthAngleDegree const ShapeParam& rParam );
, double fUnitCircleInnerRadius, double fUnitCircleOuterRadius
, double fLogicZ, double fDepth, double fExplodePercentage
, tPropertyNameValueMap* pOverWritePropertiesMap );
void createTextLabelShape( void createTextLabelShape(
const css::uno::Reference<css::drawing::XShapes>& xTextTarget, const css::uno::Reference<css::drawing::XShapes>& xTextTarget,
VDataSeries& rSeries, sal_Int32 nPointIndex, VDataSeries& rSeries, sal_Int32 nPointIndex, ShapeParam& rParam );
double fUnitCircleStartAngleDegree, double fUnitCircleWidthAngleDegree,
double fUnitCircleOuterRadius, double fUnitCircleInnerRadius, double fExplodePercentage,
double fLogicYSum, double fLogicZ );
double getMaxOffset(); double getMaxOffset();
bool detectLabelOverlapsAndMove(const ::com::sun::star::awt::Size& rPageSize);//returns true when there might be more to do bool detectLabelOverlapsAndMove(const ::com::sun::star::awt::Size& rPageSize);//returns true when there might be more to do