diff options
author | Björn Milcke <bm@openoffice.org> | 2003-12-12 16:02:52 +0000 |
---|---|---|
committer | Björn Milcke <bm@openoffice.org> | 2003-12-12 16:02:52 +0000 |
commit | 3f82286c81d8bd6374ba21465dc8e82ee09a8bc0 (patch) | |
tree | d24fada8ab7209fa95db2572e6873ae865dd10cb /chart2/source/view/main/PlotterBase.cxx | |
parent | 53b815b0302288e84302c631ffadcece22e3f500 (diff) |
error bars implemented
Diffstat (limited to 'chart2/source/view/main/PlotterBase.cxx')
-rw-r--r-- | chart2/source/view/main/PlotterBase.cxx | 216 |
1 files changed, 214 insertions, 2 deletions
diff --git a/chart2/source/view/main/PlotterBase.cxx b/chart2/source/view/main/PlotterBase.cxx index 1d79ff0e04b4..52a27d1729e0 100644 --- a/chart2/source/view/main/PlotterBase.cxx +++ b/chart2/source/view/main/PlotterBase.cxx @@ -2,9 +2,9 @@ * * $RCSfile: PlotterBase.cxx,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: bm $ $Date: 2003-12-08 15:46:24 $ + * last change: $Author: bm $ $Date: 2003-12-12 17:02:51 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,10 +61,20 @@ #include "PlotterBase.hxx" #include "PlottingPositionHelper.hxx" #include "ShapeFactory.hxx" +#include "StatisticsHelper.hxx" +#include "CommonConverters.hxx" +#include "macros.hxx" + +#ifndef INCLUDED_RTL_MATH_HXX +#include <rtl/math.hxx> +#endif #ifndef _DRAFTS_COM_SUN_STAR_CHART2_DATAPOINTLABEL_HPP_ #include <drafts/com/sun/star/chart2/DataPointLabel.hpp> #endif +#ifndef _DRAFTS_COM_SUN_STAR_CHART2_ERRORBARSTYLE_HPP_ +#include <drafts/com/sun/star/chart2/ErrorBarStyle.hpp> +#endif /* #ifndef _SV_GEN_HXX @@ -75,6 +85,8 @@ #include <tools/debug.hxx> #endif +#include <algorithm> + //............................................................................. namespace chart { @@ -150,6 +162,206 @@ uno::Reference< drawing::XShapes > PlotterBase::createGroupShape( } } +namespace +{ +double lcl_getErrorBarLogicLength( + const uno::Sequence< double > & rData, + uno::Reference< beans::XPropertySet > xProp, + ErrorBarStyle eErrorBarStyle, + sal_Int32 nIndex, + bool bPositive ) +{ + double fResult; + ::rtl::math::setNan( & fResult ); + try + { + switch( eErrorBarStyle ) + { + case ErrorBarStyle_VARIANCE: + fResult = StatisticsHelper::getVariance( rData ); + break; + case ErrorBarStyle_STANDARD_DEVIATION: + fResult = StatisticsHelper::getStandardDeviation( rData ); + break; + case ErrorBarStyle_RELATIVE: + { + double fPercent; + if( xProp->getPropertyValue( bPositive + ? C2U("PositiveError") + : C2U("NegativeError")) >>= fPercent ) + { + if( ! ::rtl::math::isNan( rData[nIndex] ) && + ! ::rtl::math::isNan( fPercent )) + { + fResult = rData[nIndex] * fPercent / 100.0; + } + } + } + break; + case ErrorBarStyle_ABSOLUTE: + xProp->getPropertyValue( bPositive + ? C2U("PositiveError") + : C2U("NegativeError")) >>= fResult; + break; + case ErrorBarStyle_ERROR_MARGIN: + { + // todo: check if this is really what's called error-margin + double fPercent; + if( xProp->getPropertyValue( bPositive + ? C2U("PositiveError") + : C2U("NegativeError")) >>= fPercent ) + { + double fMaxValue = *(::std::max_element( + rData.getConstArray(), + rData.getConstArray() + rData.getLength())); + if( ! ::rtl::math::isNan( fMaxValue ) && + ! ::rtl::math::isNan( fPercent )) + { + fResult = fMaxValue * fPercent / 100.0; + } + } + } + break; + case ErrorBarStyle_STANDARD_ERROR: + fResult = StatisticsHelper::getStandardError( rData ); + break; + case ErrorBarStyle_FROM_DATA: + // todo: implement + break; + + // to avoid warning + case ErrorBarStyle_MAKE_FIXED_SIZE: + break; + } + } + catch( uno::Exception & e ) + { + ASSERT_EXCEPTION( e ); + } + + return fResult; +} + +void lcl_getErrorBarPosAndSize( + double fErrorBarLength, + ShapeFactory::tErrorBarDirection eDirection, + const uno::Reference< XTransformation > & xTrans, + drawing::Position3D & rInOutNewPos, + drawing::Direction3D & rOutNewSize ) +{ + if( xTrans.is()) + { + drawing::Position3D aUpperLeft( rInOutNewPos ), aLowerRight( rInOutNewPos ); + switch( eDirection ) + { + case ShapeFactory::ERROR_BAR_UP: + aUpperLeft.PositionY += fErrorBarLength; + break; + case ShapeFactory::ERROR_BAR_DOWN: + aLowerRight.PositionY -= fErrorBarLength; + break; + case ShapeFactory::ERROR_BAR_RIGHT: + aLowerRight.PositionX += fErrorBarLength; + break; + case ShapeFactory::ERROR_BAR_LEFT: + aUpperLeft.PositionX -= fErrorBarLength; + break; + } + + rInOutNewPos = drawing::Position3D( + SequenceToPosition3D( xTrans->transform( Position3DToSequence( rInOutNewPos )))); + + drawing::Position3D aNewUpperLeft( + SequenceToPosition3D( xTrans->transform( Position3DToSequence( aUpperLeft )))); + drawing::Position3D aNewLowerRight( + SequenceToPosition3D( xTrans->transform( Position3DToSequence( aLowerRight )))); + + rOutNewSize = drawing::Direction3D( + aNewLowerRight.PositionX - aNewUpperLeft.PositionX, + aNewLowerRight.PositionY - aNewUpperLeft.PositionY, + rInOutNewPos.PositionZ ); + + // in 100th of a mm + double fFixedWidth = 200.0; + if( eDirection == ShapeFactory::ERROR_BAR_LEFT || + eDirection == ShapeFactory::ERROR_BAR_RIGHT ) + { + rOutNewSize.DirectionY = fFixedWidth; + } + else + { + rOutNewSize.DirectionX = fFixedWidth; + } + } +} +} // anonymous namespace + +// virtual +void PlotterBase::createErrorBar( + const uno::Reference< drawing::XShapes >& xTarget + , const drawing::Position3D& rPos + , const uno::Reference< beans::XPropertySet > & xErrorBarProperties + , const uno::Sequence< double > & rData + , sal_Int32 nIndex + , bool bVertical /* = true */ + ) +{ + if( ! xErrorBarProperties.is()) + return; + + try + { + sal_Bool bShowPos, bShowNeg; + ErrorBarStyle eErrorBarStyle; + + if( ! (xErrorBarProperties->getPropertyValue( C2U( "ShowPositiveError" )) >>= bShowPos )) + bShowPos = sal_False; + if( ! (xErrorBarProperties->getPropertyValue( C2U( "ShowNegativeError" )) >>= bShowNeg )) + bShowNeg = sal_False; + if( ! (xErrorBarProperties->getPropertyValue( C2U( "ErrorBarStyle" )) >>= eErrorBarStyle )) + eErrorBarStyle = ErrorBarStyle_VARIANCE; + + uno::Reference< XTransformation > xTrans( m_pPosHelper->getTransformationLogicToScene() ); + + if( bShowPos ) + { + ShapeFactory::tErrorBarDirection eErrorBarDir = + bVertical + ? ShapeFactory::ERROR_BAR_UP + : ShapeFactory::ERROR_BAR_RIGHT; + double fErrorBarLength = lcl_getErrorBarLogicLength( + rData, xErrorBarProperties, eErrorBarStyle, nIndex, true /* positive */ ); + + drawing::Position3D aPos( rPos ); + drawing::Direction3D aSize; + lcl_getErrorBarPosAndSize( fErrorBarLength, eErrorBarDir, xTrans, aPos, aSize ); + + m_pShapeFactory->createErrorBar2D( xTarget, aPos, aSize, eErrorBarDir ); + } + + if( bShowNeg ) + { + ShapeFactory::tErrorBarDirection eErrorBarDir = + bVertical + ? ShapeFactory::ERROR_BAR_DOWN + : ShapeFactory::ERROR_BAR_LEFT; + double fErrorBarLength = lcl_getErrorBarLogicLength( + rData, xErrorBarProperties, eErrorBarStyle, nIndex, false /* negative */ ); + + drawing::Position3D aPos( rPos ); + drawing::Direction3D aSize; + lcl_getErrorBarPosAndSize( fErrorBarLength, eErrorBarDir, xTrans, aPos, aSize ); + + m_pShapeFactory->createErrorBar2D( xTarget, aPos, aSize, eErrorBarDir ); + } + } + catch( uno::Exception & e ) + { + ASSERT_EXCEPTION( e ); + } + +} + /* //----------------------------------------------------------------- // chart2::XPlotter |