diff options
Diffstat (limited to 'chart2/source/view')
-rw-r--r-- | chart2/source/view/charttypes/AreaChart.cxx | 6 | ||||
-rw-r--r-- | chart2/source/view/charttypes/AreaChart.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/charttypes/BubbleChart.cxx | 2 | ||||
-rw-r--r-- | chart2/source/view/charttypes/BubbleChart.hxx | 2 | ||||
-rw-r--r-- | chart2/source/view/charttypes/CandleStickChart.cxx | 2 | ||||
-rw-r--r-- | chart2/source/view/charttypes/CandleStickChart.hxx | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | chart2/source/view/charttypes/VSeriesPlotter.cxx | 215 | ||||
-rw-r--r-- | chart2/source/view/inc/LegendEntryProvider.hxx | 57 | ||||
-rw-r--r-- | chart2/source/view/inc/VLegendSymbolFactory.hxx | 12 | ||||
-rw-r--r-- | chart2/source/view/inc/VSeriesPlotter.hxx | 36 | ||||
-rw-r--r-- | chart2/source/view/main/ChartItemPool.cxx | 5 | ||||
-rw-r--r-- | chart2/source/view/main/VLegend.cxx | 495 | ||||
-rw-r--r-- | chart2/source/view/main/VLegendSymbolFactory.cxx | 288 |
13 files changed, 645 insertions, 479 deletions
diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index 06e09d60fcf1..41bec1f9c331 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -48,9 +48,11 @@ #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> #include <com/sun/star/chart/MissingValueTreatment.hpp> + #include <tools/debug.hxx> #include <editeng/unoprnms.hxx> #include <rtl/math.hxx> + #include <com/sun/star/drawing/DoubleSequence.hpp> #include <com/sun/star/drawing/NormalsKind.hpp> #include <com/sun/star/lang/XServiceName.hpp> @@ -152,8 +154,8 @@ bool AreaChart::isSeperateStackingForDifferentSigns( sal_Int32 /*nDimensionIndex LegendSymbolStyle AreaChart::getLegendSymbolStyle() { if( m_bArea || m_nDimension == 3 ) - return chart2::LegendSymbolStyle_BOX; - return chart2::LegendSymbolStyle_LINE_WITH_SYMBOL; + return LegendSymbolStyle_BOX; + return LegendSymbolStyle_LINE; } uno::Any AreaChart::getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex ) diff --git a/chart2/source/view/charttypes/AreaChart.hxx b/chart2/source/view/charttypes/AreaChart.hxx index 4b6ff3f45251..972d97fa75ac 100644 --- a/chart2/source/view/charttypes/AreaChart.hxx +++ b/chart2/source/view/charttypes/AreaChart.hxx @@ -71,7 +71,7 @@ public: //------------------------------------------------------------------------- - virtual ::com::sun::star::chart2::LegendSymbolStyle getLegendSymbolStyle(); + virtual LegendSymbolStyle getLegendSymbolStyle(); virtual ::com::sun::star::uno::Any getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex=-1/*-1 for series symbol*/ ); //------------------------------------------------------------------------- diff --git a/chart2/source/view/charttypes/BubbleChart.cxx b/chart2/source/view/charttypes/BubbleChart.cxx index 0cbcff33bfcd..3dbbc0eaf3e2 100644 --- a/chart2/source/view/charttypes/BubbleChart.cxx +++ b/chart2/source/view/charttypes/BubbleChart.cxx @@ -175,7 +175,7 @@ bool BubbleChart::isSeperateStackingForDifferentSigns( sal_Int32 /*nDimensionInd LegendSymbolStyle BubbleChart::getLegendSymbolStyle() { - return chart2::LegendSymbolStyle_CIRCLE; + return LegendSymbolStyle_CIRCLE; } drawing::Direction3D BubbleChart::getPreferredDiagramAspectRatio() const diff --git a/chart2/source/view/charttypes/BubbleChart.hxx b/chart2/source/view/charttypes/BubbleChart.hxx index ed3d9e051cc4..f94fe9e367e7 100644 --- a/chart2/source/view/charttypes/BubbleChart.hxx +++ b/chart2/source/view/charttypes/BubbleChart.hxx @@ -61,7 +61,7 @@ public: //------------------------------------------------------------------------- - virtual ::com::sun::star::chart2::LegendSymbolStyle getLegendSymbolStyle(); + virtual LegendSymbolStyle getLegendSymbolStyle(); //------------------------------------------------------------------------- //------------------------------------------------------------------------- diff --git a/chart2/source/view/charttypes/CandleStickChart.cxx b/chart2/source/view/charttypes/CandleStickChart.cxx index 61c49c61d4a0..57d5a70e4080 100644 --- a/chart2/source/view/charttypes/CandleStickChart.cxx +++ b/chart2/source/view/charttypes/CandleStickChart.cxx @@ -86,7 +86,7 @@ bool CandleStickChart::isSeperateStackingForDifferentSigns( sal_Int32 /* nDimens LegendSymbolStyle CandleStickChart::getLegendSymbolStyle() { - return chart2::LegendSymbolStyle_VERTICAL_LINE; + return LegendSymbolStyle_LINE; } //----------------------------------------------------------------- diff --git a/chart2/source/view/charttypes/CandleStickChart.hxx b/chart2/source/view/charttypes/CandleStickChart.hxx index 6fbf980058e7..df9531ec71bf 100644 --- a/chart2/source/view/charttypes/CandleStickChart.hxx +++ b/chart2/source/view/charttypes/CandleStickChart.hxx @@ -59,7 +59,7 @@ public: //------------------------------------------------------------------------- - virtual ::com::sun::star::chart2::LegendSymbolStyle getLegendSymbolStyle(); + virtual LegendSymbolStyle getLegendSymbolStyle(); //------------------------------------------------------------------------- //------------------------------------------------------------------------- diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index c37842e19888..1077591dfce8 100644..100755 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -75,6 +75,7 @@ #include <rtl/math.hxx> #include <tools/debug.hxx> #include <basegfx/vector/b2dvector.hxx> +#include <com/sun/star/drawing/LineStyle.hpp> #include <com/sun/star/util/XCloneable.hpp> #include <svx/unoshape.hxx> @@ -107,7 +108,6 @@ VDataSeriesGroup::VDataSeriesGroup() , m_bMaxPointCountDirty(true) , m_nMaxPointCount(0) , m_aListOfCachedYValues() - { } @@ -461,13 +461,30 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re //------------------------------------------------ //prepare legend symbol + float fViewFontSize( 10.0 ); + { + uno::Reference< beans::XPropertySet > xProps( rDataSeries.getPropertiesOfPoint( nPointIndex ) ); + if( xProps.is() ) + xProps->getPropertyValue( C2U( "CharHeight" )) >>= fViewFontSize; + // pt -> 1/100th mm + fViewFontSize *= (2540.0 / 72.0); + } Reference< drawing::XShape > xSymbol; if(pLabel->ShowLegendSymbol) { + sal_Int32 nSymbolHeigth = static_cast< sal_Int32 >( fViewFontSize * 0.6 ); + awt::Size aCurrentRatio = this->getPreferredLegendKeyAspectRatio(); + sal_Int32 nSymbolWidth = aCurrentRatio.Width; + if( aCurrentRatio.Height > 0 ) + { + nSymbolWidth = nSymbolHeigth* aCurrentRatio.Width/aCurrentRatio.Height; + } + awt::Size aMaxSymbolExtent( nSymbolWidth, nSymbolHeigth ); + if( rDataSeries.isVaryColorsByPoint() ) - xSymbol.set( VSeriesPlotter::createLegendSymbolForPoint( rDataSeries, nPointIndex, xTarget_, m_xShapeFactory ) ); + xSymbol.set( VSeriesPlotter::createLegendSymbolForPoint( aMaxSymbolExtent, rDataSeries, nPointIndex, xTarget_, m_xShapeFactory ) ); else - xSymbol.set( VSeriesPlotter::createLegendSymbolForSeries( rDataSeries, xTarget_, m_xShapeFactory ) ); + xSymbol.set( VSeriesPlotter::createLegendSymbolForSeries( aMaxSymbolExtent, rDataSeries, xTarget_, m_xShapeFactory ) ); } //prepare text @@ -567,25 +584,14 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re const awt::Point aOldTextPos( xTextShape->getPosition() ); awt::Point aNewTextPos( aOldTextPos ); + awt::Point aSymbolPosition( aUnrotatedTextPos ); awt::Size aSymbolSize( xSymbol->getSize() ); awt::Size aTextSize( xTextShape->getSize() ); + sal_Int32 nXDiff = aSymbolSize.Width + static_cast< sal_Int32 >( std::max( 100.0, fViewFontSize * 0.22 ) );//minimum 1mm if( !bMultiLineLabel || nLineCountForSymbolsize <= 0 ) nLineCountForSymbolsize = 1; - sal_Int32 nYDiff = aTextSize.Height/nLineCountForSymbolsize; - sal_Int32 nXDiff = aSymbolSize.Width * nYDiff/aSymbolSize.Height; - - // #i109336# Improve auto positioning in chart - nXDiff = nXDiff * 80 / 100; - nYDiff = nYDiff * 80 / 100; - - aSymbolSize.Width = nXDiff * 75/100; - aSymbolSize.Height = nYDiff * 75/100; - - awt::Point aSymbolPosition( aUnrotatedTextPos ); - - // #i109336# Improve auto positioning in chart - aSymbolPosition.Y += ( nYDiff / 4 ); + aSymbolPosition.Y += ((aTextSize.Height/nLineCountForSymbolsize)/4); if(LABEL_ALIGN_LEFT==eAlignment || LABEL_ALIGN_LEFT_TOP==eAlignment @@ -607,10 +613,7 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re aNewTextPos.X += nXDiff/2; } - xSymbol->setSize( aSymbolSize ); xSymbol->setPosition( aSymbolPosition ); - - //set position xTextShape->setPosition( aNewTextPos ); } } @@ -1818,13 +1821,14 @@ bool VSeriesPlotter::shouldSnapRectToUsedArea() return true; } -Sequence< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntries( - LegendExpansion eLegendExpansion +std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntries( + const awt::Size& rEntryKeyAspectRatio + , ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion , const Reference< beans::XPropertySet >& xTextProperties , const Reference< drawing::XShapes >& xTarget , const Reference< lang::XMultiServiceFactory >& xShapeFactory , const Reference< uno::XComponentContext >& xContext - ) throw (uno::RuntimeException) + ) { std::vector< ViewLegendEntry > aResult; @@ -1851,7 +1855,7 @@ Sequence< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntries( if(!pSeries) continue; - std::vector< ViewLegendEntry > aSeriesEntries( this->createLegendEntriesForSeries( + std::vector< ViewLegendEntry > aSeriesEntries( this->createLegendEntriesForSeries( rEntryKeyAspectRatio, *pSeries, xTextProperties, xTarget, xShapeFactory, xContext ) ); //add series entries to the result now @@ -1865,7 +1869,7 @@ Sequence< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntries( // If the legend is wide and we have a stacked bar-chart the normal order // is the correct one bool bReverse = false; - if( eLegendExpansion != LegendExpansion_WIDE ) + if( eLegendExpansion != ::com::sun::star::chart::ChartLegendExpansion_WIDE ) { StackingDirection eStackingDirection( pSeries->getStackingDirection() ); bReverse = ( eStackingDirection == StackingDirection_Y_STACKING ); @@ -1880,24 +1884,119 @@ Sequence< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntries( } } } + } - //add charttype specific entries if any + return aResult; +} + +::std::vector< VDataSeries* > VSeriesPlotter::getAllSeries() +{ + ::std::vector< VDataSeries* > aAllSeries; + ::std::vector< ::std::vector< VDataSeriesGroup > >::iterator aZSlotIter = m_aZSlots.begin(); + const ::std::vector< ::std::vector< VDataSeriesGroup > >::const_iterator aZSlotEnd = m_aZSlots.end(); + for( ; aZSlotIter != aZSlotEnd; aZSlotIter++ ) + { + ::std::vector< VDataSeriesGroup >::iterator aXSlotIter = aZSlotIter->begin(); + const ::std::vector< VDataSeriesGroup >::const_iterator aXSlotEnd = aZSlotIter->end(); + for( ; aXSlotIter != aXSlotEnd; aXSlotIter++ ) { - std::vector< ViewLegendEntry > aChartTypeEntries( this->createLegendEntriesForChartType( - xTextProperties, xTarget, xShapeFactory, xContext ) ); - aResult.insert( aResult.end(), aChartTypeEntries.begin(), aChartTypeEntries.end() ); + ::std::vector< VDataSeries* > aSeriesList = aXSlotIter->m_aSeriesVector; + aAllSeries.insert( aAllSeries.end(), aSeriesList.begin(), aSeriesList.end() ); } } - - return ::chart::ContainerHelper::ContainerToSequence( aResult ); + return aAllSeries; } +namespace +{ +bool lcl_HasVisibleLine( const uno::Reference< beans::XPropertySet >& xProps, bool& rbHasDashedLine ) +{ + bool bHasVisibleLine = false; + rbHasDashedLine = false; + drawing::LineStyle aLineStyle = drawing::LineStyle_NONE; + if( xProps.is() && ( xProps->getPropertyValue( C2U("LineStyle")) >>= aLineStyle ) ) + { + if( aLineStyle != drawing::LineStyle_NONE ) + bHasVisibleLine = true; + if( aLineStyle == drawing::LineStyle_DASH ) + rbHasDashedLine = true; + } + return bHasVisibleLine; +} +bool lcl_HasRegressionCurves( const VDataSeries& rSeries, bool& rbHasDashedLine ) +{ + bool bHasRegressionCurves = false; + Reference< XRegressionCurveContainer > xRegrCont( rSeries.getModel(), uno::UNO_QUERY ); + if( xRegrCont.is()) + { + Sequence< Reference< XRegressionCurve > > aCurves( xRegrCont->getRegressionCurves() ); + sal_Int32 i = 0, nCount = aCurves.getLength(); + for( i=0; i<nCount; ++i ) + { + if( aCurves[i].is() ) + { + bHasRegressionCurves = true; + lcl_HasVisibleLine( uno::Reference< beans::XPropertySet >( aCurves[i], uno::UNO_QUERY ), rbHasDashedLine ); + } + } + } + return bHasRegressionCurves; +} +} LegendSymbolStyle VSeriesPlotter::getLegendSymbolStyle() { - return chart2::LegendSymbolStyle_BOX; + return LegendSymbolStyle_BOX; } +awt::Size VSeriesPlotter::getPreferredLegendKeyAspectRatio() +{ + awt::Size aRet(1000,1000); + if( m_nDimension==3 ) + return aRet; + + bool bSeriesAllowsLines = (getLegendSymbolStyle() == LegendSymbolStyle_LINE); + bool bHasLines = false; + bool bHasDashedLines = false; + ::std::vector< VDataSeries* > aAllSeries( getAllSeries() ); + ::std::vector< VDataSeries* >::const_iterator aSeriesIter = aAllSeries.begin(); + const ::std::vector< VDataSeries* >::const_iterator aSeriesEnd = aAllSeries.end(); + //iterate through all series + for( ; aSeriesIter != aSeriesEnd; aSeriesIter++ ) + { + if( bSeriesAllowsLines ) + { + bool bCurrentDashed = false; + if( lcl_HasVisibleLine( (*aSeriesIter)->getPropertiesOfSeries(), bCurrentDashed ) ) + { + bHasLines = true; + if( bCurrentDashed ) + { + bHasDashedLines = true; + break; + } + } + } + bool bRegressionHasDashedLines=false; + if( lcl_HasRegressionCurves( **aSeriesIter, bRegressionHasDashedLines ) ) + { + bHasLines = true; + if( bRegressionHasDashedLines ) + { + bHasDashedLines = true; + break; + } + } + } + if( bHasLines ) + { + if( bHasDashedLines ) + aRet = awt::Size(1600,-1); + else + aRet = awt::Size(800,-1); + } + return aRet; +} uno::Any VSeriesPlotter::getExplicitSymbol( const VDataSeries& /*rSeries*/, sal_Int32 /*nPointIndex*/ ) { @@ -1905,7 +2004,8 @@ uno::Any VSeriesPlotter::getExplicitSymbol( const VDataSeries& /*rSeries*/, sal_ } Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForSeries( - const VDataSeries& rSeries + const awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries , const Reference< drawing::XShapes >& xTarget , const Reference< lang::XMultiServiceFactory >& xShapeFactory ) { @@ -1920,17 +2020,13 @@ Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForSeries( // legend-symbol type switch( eLegendSymbolStyle ) { - case LegendSymbolStyle_HORIZONTAL_LINE: - case LegendSymbolStyle_VERTICAL_LINE: - case LegendSymbolStyle_DIAGONAL_LINE: - case LegendSymbolStyle_LINE_WITH_BOX: - case LegendSymbolStyle_LINE_WITH_SYMBOL: + case LegendSymbolStyle_LINE: ePropType = VLegendSymbolFactory::PROP_TYPE_LINE_SERIES; break; default: break; }; - Reference< drawing::XShape > xShape( VLegendSymbolFactory::createSymbol( + Reference< drawing::XShape > xShape( VLegendSymbolFactory::createSymbol( rEntryKeyAspectRatio, xTarget, eLegendSymbolStyle, xShapeFactory , rSeries.getPropertiesOfSeries(), ePropType, aExplicitSymbol )); @@ -1938,7 +2034,8 @@ Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForSeries( } Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForPoint( - const VDataSeries& rSeries + const awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries , sal_Int32 nPointIndex , const Reference< drawing::XShapes >& xTarget , const Reference< lang::XMultiServiceFactory >& xShapeFactory ) @@ -1954,11 +2051,7 @@ Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForPoint( // legend-symbol type switch( eLegendSymbolStyle ) { - case LegendSymbolStyle_HORIZONTAL_LINE: - case LegendSymbolStyle_VERTICAL_LINE: - case LegendSymbolStyle_DIAGONAL_LINE: - case LegendSymbolStyle_LINE_WITH_BOX: - case LegendSymbolStyle_LINE_WITH_SYMBOL: + case LegendSymbolStyle_LINE: ePropType = VLegendSymbolFactory::PROP_TYPE_LINE_SERIES; break; default: @@ -1989,14 +2082,15 @@ Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForPoint( } } - Reference< drawing::XShape > xShape( VLegendSymbolFactory::createSymbol( + Reference< drawing::XShape > xShape( VLegendSymbolFactory::createSymbol( rEntryKeyAspectRatio, xTarget, eLegendSymbolStyle, xShapeFactory, xPointSet, ePropType, aExplicitSymbol )); return xShape; } -std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForSeries( - const VDataSeries& rSeries +std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntriesForSeries( + const awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries , const Reference< beans::XPropertySet >& xTextProperties , const Reference< drawing::XShapes >& xTarget , const Reference< lang::XMultiServiceFactory >& xShapeFactory @@ -2025,7 +2119,7 @@ std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForSe uno::Reference< drawing::XShapes > xSymbolGroup( ShapeFactory(xShapeFactory).createGroup2D( xTarget )); // create the symbol - Reference< drawing::XShape > xShape( this->createLegendSymbolForPoint( + Reference< drawing::XShape > xShape( this->createLegendSymbolForPoint( rEntryKeyAspectRatio, rSeries, nIdx, xSymbolGroup, xShapeFactory ) ); // set CID to symbol for selection @@ -2055,7 +2149,7 @@ std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForSe // create the symbol Reference< drawing::XShape > xShape( this->createLegendSymbolForSeries( - rSeries, xSymbolGroup, xShapeFactory ) ); + rEntryKeyAspectRatio, rSeries, xSymbolGroup, xShapeFactory ) ); // set CID to symbol for selection if( xShape.is()) @@ -2085,11 +2179,10 @@ std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForSe sal_Int32 i = 0, nCount = aCurves.getLength(); for( i=0; i<nCount; ++i ) { - if( aCurves[i].is() && !RegressionCurveHelper::isMeanValueLine( aCurves[i] ) ) + if( aCurves[i].is() ) { //label - OUString aResStr( SchResId::getResString( STR_STATISTICS_IN_LEGEND )); - replaceParamterInString( aResStr, C2U("%REGRESSIONCURVE"), RegressionCurveHelper::getUINameForRegressionCurve( aCurves[i] )); + OUString aResStr( RegressionCurveHelper::getUINameForRegressionCurve( aCurves[i] ) ); replaceParamterInString( aResStr, C2U("%SERIESNAME"), aLabelText ); aEntry.aLabel = FormattedStringHelper::createFormattedStringSequence( xContext, aResStr, xTextProperties ); @@ -2097,8 +2190,8 @@ std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForSe uno::Reference< drawing::XShapes > xSymbolGroup( ShapeFactory(xShapeFactory).createGroup2D( xTarget )); // create the symbol - Reference< drawing::XShape > xShape( VLegendSymbolFactory::createSymbol( - xSymbolGroup, chart2::LegendSymbolStyle_DIAGONAL_LINE, xShapeFactory, + Reference< drawing::XShape > xShape( VLegendSymbolFactory::createSymbol( rEntryKeyAspectRatio, + xSymbolGroup, LegendSymbolStyle_LINE, xShapeFactory, Reference< beans::XPropertySet >( aCurves[i], uno::UNO_QUERY ), VLegendSymbolFactory::PROP_TYPE_LINE, uno::Any() )); @@ -2107,7 +2200,7 @@ std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForSe { aEntry.aSymbol = uno::Reference< drawing::XShape >( xSymbolGroup, uno::UNO_QUERY ); - bool bAverageLine = false;//@todo find out wether this is an average line or a regression curve + bool bAverageLine = RegressionCurveHelper::isMeanValueLine( aCurves[i] ); ObjectType eObjectType = bAverageLine ? OBJECTTYPE_DATA_AVERAGE_LINE : OBJECTTYPE_DATA_CURVE; OUString aChildParticle( ObjectIdentifier::createChildParticleWithIndex( eObjectType, i ) ); aChildParticle = ObjectIdentifier::addChildParticle( aChildParticle, ObjectIdentifier::createChildParticleWithIndex( OBJECTTYPE_LEGEND_ENTRY, 0 ) ); @@ -2127,16 +2220,6 @@ std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForSe return aResult; } -std::vector< ViewLegendEntry > SAL_CALL VSeriesPlotter::createLegendEntriesForChartType( - const Reference< beans::XPropertySet >& /* xTextProperties */, - const Reference< drawing::XShapes >& /* xTarget */, - const Reference< lang::XMultiServiceFactory >& /* xShapeFactory */, - const Reference< uno::XComponentContext >& /* xContext */ - ) -{ - return std::vector< ViewLegendEntry >(); -} - VSeriesPlotter* VSeriesPlotter::createSeriesPlotter( const uno::Reference<XChartType>& xChartTypeModel , sal_Int32 nDimensionCount diff --git a/chart2/source/view/inc/LegendEntryProvider.hxx b/chart2/source/view/inc/LegendEntryProvider.hxx index 14b6cda47870..1ecc78107d2b 100644 --- a/chart2/source/view/inc/LegendEntryProvider.hxx +++ b/chart2/source/view/inc/LegendEntryProvider.hxx @@ -27,22 +27,58 @@ #ifndef CHART2_VIEW_LEGENDENTRYPROVIDER_HXX #define CHART2_VIEW_LEGENDENTRYPROVIDER_HXX -#include <com/sun/star/chart2/LegendExpansion.hpp> - -#ifndef _COM_SUN_STAR_CHART2_VIEWLEGENDENTRYP_HPP_ -#include <com/sun/star/chart2/ViewLegendEntry.hpp> -#endif +#include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> +#include <com/sun/star/chart2/XFormattedString.hpp> +#include <com/sun/star/drawing/XShape.hpp> +#include <com/sun/star/drawing/XShapes.hpp> +#include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/uno/XComponentContext.hpp> +#include <vector> + namespace chart { +enum LegendSymbolStyle +{ + /** A square box with border. + */ + LegendSymbolStyle_BOX, + + /** A line like with a symbol. + */ + LegendSymbolStyle_LINE, + + /** A bordered circle which has the same bounding-box as the + <member>BOX</member>. + */ + LegendSymbolStyle_CIRCLE +}; + +struct ViewLegendEntry +{ + /** The legend symbol that represents a data series or other + information contained in the legend + */ + ::com::sun::star::uno::Reference< + ::com::sun::star::drawing::XShape > aSymbol; + + /** The descriptive text for a legend entry. + */ + ::com::sun::star::uno::Sequence< + ::com::sun::star::uno::Reference< + ::com::sun::star::chart2::XFormattedString > > aLabel; +}; + class LegendEntryProvider { public: - virtual ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ViewLegendEntry > SAL_CALL createLegendEntries( - ::com::sun::star::chart2::LegendExpansion eLegendExpansion, + virtual ::com::sun::star::awt::Size getPreferredLegendKeyAspectRatio()=0; + + virtual std::vector< ViewLegendEntry > createLegendEntries( + const ::com::sun::star::awt::Size& rEntryKeyAspectRatio, + ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xTextProperties, const ::com::sun::star::uno::Reference< @@ -51,10 +87,7 @@ public: ::com::sun::star::lang::XMultiServiceFactory >& xShapeFactory, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext - ) - throw (::com::sun::star::uno::RuntimeException) = 0; - -private: + ) = 0; }; } // namespace chart diff --git a/chart2/source/view/inc/VLegendSymbolFactory.hxx b/chart2/source/view/inc/VLegendSymbolFactory.hxx index a568a9ef4a85..4ea3c67d5ece 100644 --- a/chart2/source/view/inc/VLegendSymbolFactory.hxx +++ b/chart2/source/view/inc/VLegendSymbolFactory.hxx @@ -27,7 +27,7 @@ #ifndef CHART2_VLEGENDSYMBOLFACTORY_HXX #define CHART2_VLEGENDSYMBOLFACTORY_HXX -#include <com/sun/star/chart2/LegendSymbolStyle.hpp> +#include "LegendEntryProvider.hxx" #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/drawing/XShapes.hpp> @@ -50,9 +50,10 @@ public: static ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > createSymbol( + const ::com::sun::star::awt::Size& rEntryKeyAspectRatio, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes > xSymbolContainer, - ::com::sun::star::chart2::LegendSymbolStyle eStyle, + LegendSymbolStyle eStyle, const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > & xShapeFactory, const ::com::sun::star::uno::Reference< @@ -60,13 +61,6 @@ public: tPropertyType ePropertyType, const ::com::sun::star::uno::Any& rExplicitSymbol /*should contain a ::com::sun::star::chart2::Symbol without automatic symbol if the charttype does support symbols else empty*/); - enum tStockLineType - { - STOCK_LINE_TYPE_VERT, - STOCK_LINE_TYPE_OPEN, - STOCK_LINE_TYPE_CLOSE - }; - private: VLegendSymbolFactory(); }; diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 8147c3443ec6..9e427a5e2a81 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -33,7 +33,6 @@ #include "MinimumAndMaximumSupplier.hxx" #include "LegendEntryProvider.hxx" #include "ExplicitCategoriesProvider.hxx" -#include <com/sun/star/chart2/LegendSymbolStyle.hpp> #include <com/sun/star/chart2/XChartType.hpp> #include <com/sun/star/drawing/Direction3D.hpp> @@ -207,9 +206,9 @@ public: //------------------------------------------------------------------------- //------------------------------------------------------------------------- - virtual ::com::sun::star::uno::Sequence< - ::com::sun::star::chart2::ViewLegendEntry > SAL_CALL createLegendEntries( - ::com::sun::star::chart2::LegendExpansion eLegendExpansion, + virtual std::vector< ViewLegendEntry > createLegendEntries( + const ::com::sun::star::awt::Size& rEntryKeyAspectRatio, + ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xTextProperties, const ::com::sun::star::uno::Reference< @@ -218,26 +217,29 @@ public: ::com::sun::star::lang::XMultiServiceFactory >& xShapeFactory, const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& xContext - ) - throw (::com::sun::star::uno::RuntimeException); + ); + + virtual LegendSymbolStyle getLegendSymbolStyle(); + virtual com::sun::star::awt::Size getPreferredLegendKeyAspectRatio(); - virtual ::com::sun::star::chart2::LegendSymbolStyle getLegendSymbolStyle(); virtual ::com::sun::star::uno::Any getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex=-1/*-1 for series symbol*/ ); ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > createLegendSymbolForSeries( - const VDataSeries& rSeries + const ::com::sun::star::awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget , const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xShapeFactory ); ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > createLegendSymbolForPoint( - const VDataSeries& rSeries + const ::com::sun::star::awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries , sal_Int32 nPointIndex , const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShapes >& xTarget , const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& xShapeFactory ); - virtual std::vector< - ::com::sun::star::chart2::ViewLegendEntry > SAL_CALL createLegendEntriesForSeries( + virtual std::vector< ViewLegendEntry > createLegendEntriesForSeries( + const ::com::sun::star::awt::Size& rEntryKeyAspectRatio, const VDataSeries& rSeries, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xTextProperties, @@ -249,17 +251,7 @@ public: ::com::sun::star::uno::XComponentContext >& xContext ); - virtual std::vector< - ::com::sun::star::chart2::ViewLegendEntry > SAL_CALL createLegendEntriesForChartType( - const ::com::sun::star::uno::Reference< - ::com::sun::star::beans::XPropertySet >& xTextProperties, - const ::com::sun::star::uno::Reference< - ::com::sun::star::drawing::XShapes >& xTarget, - const ::com::sun::star::uno::Reference< - ::com::sun::star::lang::XMultiServiceFactory >& xShapeFactory, - const ::com::sun::star::uno::Reference< - ::com::sun::star::uno::XComponentContext >& xContext - ); + ::std::vector< VDataSeries* > getAllSeries(); //------------------------------------------------------------------------- //------------------------------------------------------------------------- diff --git a/chart2/source/view/main/ChartItemPool.cxx b/chart2/source/view/main/ChartItemPool.cxx index 60e880ab311e..c66044b9aa0d 100644 --- a/chart2/source/view/main/ChartItemPool.cxx +++ b/chart2/source/view/main/ChartItemPool.cxx @@ -44,6 +44,8 @@ #include <editeng/editids.hrc> #include <svx/svxids.hrc> +#include <com/sun/star/chart2/LegendPosition.hpp> + namespace chart { @@ -69,7 +71,8 @@ ChartItemPool::ChartItemPool(): ppPoolDefaults[SCHATTR_PERCENT_NUMBERFORMAT_SOURCE - SCHATTR_START] = new SfxBoolItem(SCHATTR_PERCENT_NUMBERFORMAT_SOURCE); //legend - ppPoolDefaults[SCHATTR_LEGEND_POS - SCHATTR_START] = new SvxChartLegendPosItem( CHLEGEND_RIGHT, SCHATTR_LEGEND_POS ); + ppPoolDefaults[SCHATTR_LEGEND_POS - SCHATTR_START] = new SfxInt32Item(SCHATTR_LEGEND_POS, ::com::sun::star::chart2::LegendPosition_LINE_END ); + ppPoolDefaults[SCHATTR_LEGEND_SHOW - SCHATTR_START] = new SfxBoolItem(SCHATTR_LEGEND_SHOW, sal_True); //text ppPoolDefaults[SCHATTR_TEXT_DEGREES - SCHATTR_START] = new SfxInt32Item(SCHATTR_TEXT_DEGREES, 0); diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index fbc74bad05a5..33e1d1f26aa4 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -36,13 +36,14 @@ #include "ShapeFactory.hxx" #include "RelativeSizeHelper.hxx" #include "LegendEntryProvider.hxx" +#include "chartview/DrawModelWrapper.hxx" #include <com/sun/star/text/XTextRange.hpp> #include <com/sun/star/text/WritingMode2.hpp> #include <com/sun/star/beans/XPropertySet.hpp> #include <com/sun/star/beans/XPropertyState.hpp> #include <com/sun/star/drawing/TextHorizontalAdjust.hpp> #include <com/sun/star/drawing/LineJoint.hpp> -#include <com/sun/star/chart2/LegendExpansion.hpp> +#include <com/sun/star/chart/ChartLegendExpansion.hpp> #include <com/sun/star/chart2/LegendPosition.hpp> #include <com/sun/star/chart2/RelativePosition.hpp> #include <rtl/ustrbuf.hxx> @@ -123,7 +124,6 @@ void lcl_getProperties( const Reference< beans::XPropertySet > & xLegendProp, tPropertyValues & rOutLineFillProperties, tPropertyValues & rOutTextProperties, - sal_Int32 nMaxLabelWidth, const awt::Size & rReferenceSize ) { // Get Line- and FillProperties from model legend @@ -146,7 +146,7 @@ void lcl_getProperties( aTextValueMap[ C2U("TextAutoGrowHeight") ] = uno::makeAny( sal_True ); aTextValueMap[ C2U("TextAutoGrowWidth") ] = uno::makeAny( sal_True ); aTextValueMap[ C2U("TextHorizontalAdjust") ] = uno::makeAny( eHorizAdjust ); - aTextValueMap[ C2U("TextMaximumFrameWidth") ] = uno::makeAny( nMaxLabelWidth ); + aTextValueMap[ C2U("TextMaximumFrameWidth") ] = uno::makeAny( rReferenceSize.Width ); //needs to be overwritten by actual available space in the legend // recalculate font size awt::Size aPropRefSize; @@ -193,16 +193,10 @@ awt::Size lcl_createTextShapes( try { // create label shape - Reference< drawing::XShape > xGroupShapeForSingleEntry( - xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.GroupShape" )), uno::UNO_QUERY_THROW ); - Reference< drawing::XShape >xEntry( + Reference< drawing::XShape > xEntry( xShapeFactory->createInstance( C2U( "com.sun.star.drawing.TextShape" )), uno::UNO_QUERY_THROW ); - xTarget->add( xGroupShapeForSingleEntry ); - - Reference< drawing::XShapes > xGroup( xGroupShapeForSingleEntry, uno::UNO_QUERY_THROW ); - xGroup->add( xEntry ); + xTarget->add( xEntry ); // set label text Sequence< Reference< XFormattedString > > aLabelSeq = (*aIt).aLabel; @@ -230,7 +224,7 @@ awt::Size lcl_createTextShapes( aResult.Height = ::std::max( aResult.Height, aCurrSize.Height ); } - rOutTextShapes.push_back( xGroupShapeForSingleEntry ); + rOutTextShapes.push_back( xEntry ); } catch( uno::Exception & ex ) { @@ -241,57 +235,272 @@ awt::Size lcl_createTextShapes( return aResult; } +void lcl_collectColumnWidths( std::vector< sal_Int32 >& rColumnWidths, const sal_Int32 nNumberOfRows, const sal_Int32 nNumberOfColumns + , const ::std::vector< Reference< drawing::XShape > > aTextShapes, sal_Int32 nSymbolPlusDistanceWidth ) +{ + rColumnWidths.clear(); + sal_Int32 nRow = 0; + sal_Int32 nColumn = 0; + sal_Int32 nNumberOfEntries = aTextShapes.size(); + for( ; nRow < nNumberOfRows; ++nRow ) + { + for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) + { + sal_Int32 nEntry = (nColumn + nRow * nNumberOfColumns); + if( nEntry < nNumberOfEntries ) + { + awt::Size aTextSize( aTextShapes[ nEntry ]->getSize() ); + sal_Int32 nWidth = nSymbolPlusDistanceWidth + aTextSize.Width; + if( nRow==0 ) + rColumnWidths.push_back( nWidth ); + else + rColumnWidths[nColumn] = ::std::max( nWidth, rColumnWidths[nColumn] ); + } + } + } +} -void lcl_placeLegendEntries( - const tViewLegendEntryContainer & rEntries, - LegendExpansion eExpansion, +void lcl_collectRowHeighs( std::vector< sal_Int32 >& rRowHeights, const sal_Int32 nNumberOfRows, const sal_Int32 nNumberOfColumns + , const ::std::vector< Reference< drawing::XShape > > aTextShapes ) +{ + // calculate maximum height for each row + // and collect column widths + rRowHeights.clear(); + sal_Int32 nRow = 0; + sal_Int32 nColumn = 0; + sal_Int32 nNumberOfEntries = aTextShapes.size(); + for( ; nRow < nNumberOfRows; ++nRow ) + { + sal_Int32 nCurrentRowHeight = 0; + for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) + { + sal_Int32 nEntry = (nColumn + nRow * nNumberOfColumns); + if( nEntry < nNumberOfEntries ) + { + awt::Size aTextSize( aTextShapes[ nEntry ]->getSize() ); + nCurrentRowHeight = ::std::max( nCurrentRowHeight, aTextSize.Height ); + } + } + rRowHeights.push_back( nCurrentRowHeight ); + } +} + +sal_Int32 lcl_getTextLineHeight( const std::vector< sal_Int32 >& aRowHeights, const sal_Int32 nNumberOfRows, double fViewFontSize ) +{ + const sal_Int32 nFontHeight = static_cast< sal_Int32 >( fViewFontSize ); + sal_Int32 nTextLineHeight = nFontHeight; + for( sal_Int32 nR=0; nR<nNumberOfRows; nR++ ) + { + sal_Int32 nFullTextHeight = aRowHeights[ nR ]; + if( ( nFullTextHeight / nFontHeight ) <= 1 ) + { + nTextLineHeight = nFullTextHeight;//found an entry with one line-> have real text height + break; + } + } + return nTextLineHeight; +} + +//returns resulting legend size +awt::Size lcl_placeLegendEntries( + tViewLegendEntryContainer & rEntries, + ::com::sun::star::chart::ChartLegendExpansion eExpansion, bool bSymbolsLeftSide, - const Reference< beans::XPropertySet > & xProperties, + double fViewFontSize, + const awt::Size& rMaxSymbolExtent, tPropertyValues & rTextProperties, const Reference< drawing::XShapes > & xTarget, const Reference< lang::XMultiServiceFactory > & xShapeFactory, - const Reference< uno::XComponentContext > & /* xContext */, - const awt::Size & rAvailableSpace, - const awt::Size & rPageSize, - awt::Size & rOutLegendSize ) + const awt::Size & rAvailableSpace ) { - double fViewFontSize = lcl_CalcViewFontSize( xProperties, rPageSize ); + bool bIsCustomSize = (eExpansion == ::com::sun::star::chart::ChartLegendExpansion_CUSTOM); + awt::Size aResultingLegendSize(0,0); + if( bIsCustomSize ) + aResultingLegendSize = rAvailableSpace; - // padding as percentage of the font height // #i109336# Improve auto positioning in chart - double fXPadding = 0.1; - double fYPadding = 0.2; - double fXOffset = 0.15; - double fYOffset = 0.15; - - const sal_Int32 nXPadding = static_cast< sal_Int32 >( fViewFontSize * fXPadding ); - const sal_Int32 nYPadding = static_cast< sal_Int32 >( fViewFontSize * fYPadding ); - const sal_Int32 nXOffset = static_cast< sal_Int32 >( fViewFontSize * fXOffset ); - const sal_Int32 nYOffset = static_cast< sal_Int32 >( fViewFontSize * fYOffset ); + sal_Int32 nXPadding = static_cast< sal_Int32 >( std::max( 100.0, fViewFontSize * 0.33 ) ); + //sal_Int32 nXPadding = static_cast< sal_Int32 >( std::max( 200.0, fViewFontSize * 0.33 ) ); + sal_Int32 nXOffset = static_cast< sal_Int32 >( std::max( 100.0, fViewFontSize * 0.66 ) ); + sal_Int32 nYPadding = static_cast< sal_Int32 >( std::max( 100.0, fViewFontSize * 0.2 ) ); + sal_Int32 nYOffset = static_cast< sal_Int32 >( std::max( 100.0, fViewFontSize * 0.2 ) ); + //sal_Int32 nYOffset = static_cast< sal_Int32 >( std::max( 230.0, fViewFontSize * 0.45 ) ); + + const sal_Int32 nSymbolToTextDistance = static_cast< sal_Int32 >( std::max( 100.0, fViewFontSize * 0.22 ) );//minimum 1mm + const sal_Int32 nSymbolPlusDistanceWidth = rMaxSymbolExtent.Width + nSymbolToTextDistance; + sal_Int32 nMaxTextWidth = rAvailableSpace.Width - (2 * nXPadding) - nSymbolPlusDistanceWidth; + rtl::OUString aPropNameTextMaximumFrameWidth( C2U("TextMaximumFrameWidth") ); + uno::Any* pFrameWidthAny = PropertyMapper::getValuePointer( rTextProperties.second, rTextProperties.first, aPropNameTextMaximumFrameWidth); + if(pFrameWidthAny) + { + if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_HIGH ) + { + // limit the width of texts to 30% of the total available width + // #i109336# Improve auto positioning in chart + nMaxTextWidth = rAvailableSpace.Width * 3 / 10; + } + *pFrameWidthAny = uno::makeAny(nMaxTextWidth); + } ::std::vector< Reference< drawing::XShape > > aTextShapes; - awt::Size aMaxEntryExtent = lcl_createTextShapes( - rEntries, xShapeFactory, xTarget, aTextShapes, rTextProperties ); + awt::Size aMaxEntryExtent = lcl_createTextShapes( rEntries, xShapeFactory, xTarget, aTextShapes, rTextProperties ); OSL_ASSERT( aTextShapes.size() == rEntries.size()); - // #i109336# Improve auto positioning in chart - double fSymbolSizeFraction = 0.8; - awt::Size aMaxSymbolExtent( static_cast< sal_Int32 >( fViewFontSize * fSymbolSizeFraction * 3.0 / 2.0 ), - static_cast< sal_Int32 >( fViewFontSize * fSymbolSizeFraction ) ); - - sal_Int32 nCurrentXPos = nXPadding; - sal_Int32 nCurrentYPos = nYPadding; - sal_Int32 nMaxEntryWidth = 2 * nXOffset + aMaxSymbolExtent.Width + aMaxEntryExtent.Width; + sal_Int32 nMaxEntryWidth = nXOffset + nSymbolPlusDistanceWidth + aMaxEntryExtent.Width; sal_Int32 nMaxEntryHeight = nYOffset + aMaxEntryExtent.Height; sal_Int32 nNumberOfEntries = rEntries.size(); - if( !bSymbolsLeftSide ) - nCurrentXPos = -nXPadding; - sal_Int32 nNumberOfColumns = 0, nNumberOfRows = 0; + std::vector< sal_Int32 > aColumnWidths; + std::vector< sal_Int32 > aRowHeights; + + sal_Int32 nTextLineHeight = static_cast< sal_Int32 >( fViewFontSize ); // determine layout depending on LegendExpansion - if( eExpansion == LegendExpansion_HIGH ) + if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_CUSTOM ) + { + sal_Int32 nCurrentRow=0; + sal_Int32 nCurrentColumn=-1; + sal_Int32 nColumnCount=0; + sal_Int32 nMaxColumnCount=-1; + for( sal_Int32 nN=0; nN<static_cast<sal_Int32>(aTextShapes.size()); nN++ ) + { + Reference< drawing::XShape > xShape( aTextShapes[nN] ); + if( !xShape.is() ) + continue; + awt::Size aSize( xShape->getSize() ); + sal_Int32 nNewWidth = aSize.Width + nSymbolPlusDistanceWidth; + sal_Int32 nCurrentColumnCount = aColumnWidths.size(); + + //are we allowed to add a new column? + if( nMaxColumnCount==-1 || (nCurrentColumn+1) < nMaxColumnCount ) + { + //try add a new column + nCurrentColumn++; + if( nCurrentColumn < nCurrentColumnCount ) + { + //check wether the current column width is sufficient for the new entry + if( aColumnWidths[nCurrentColumn]>=nNewWidth ) + { + //all good proceed with next entry + continue; + } + } + if( nCurrentColumn < nCurrentColumnCount ) + aColumnWidths[nCurrentColumn] = std::max( nNewWidth, aColumnWidths[nCurrentColumn] ); + else + aColumnWidths.push_back(nNewWidth); + + //do the columns still fit into the given size? + nCurrentColumnCount = aColumnWidths.size();//update count + sal_Int32 nSumWidth = 0; + for( sal_Int32 nC=0; nC<nCurrentColumnCount; nC++ ) + nSumWidth += aColumnWidths[nC]; + + if( nSumWidth <= rAvailableSpace.Width || nCurrentColumnCount==1 ) + { + //all good proceed with next entry + continue; + } + else + { + //not enough space for the current amount of columns + //try again with less columns + nMaxColumnCount = nCurrentColumnCount-1; + nN=-1; + nCurrentRow=0; + nCurrentColumn=-1; + nColumnCount=0; + aColumnWidths.clear(); + } + } + else + { + //add a new row and try the same entry again + nCurrentRow++; + nCurrentColumn=-1; + nN--; + } + } + nNumberOfColumns = aColumnWidths.size(); + nNumberOfRows = nCurrentRow+1; + + //check if there is not enough space so that some entries must be removed + lcl_collectRowHeighs( aRowHeights, nNumberOfRows, nNumberOfColumns, aTextShapes ); + nTextLineHeight = lcl_getTextLineHeight( aRowHeights, nNumberOfRows, fViewFontSize ); + sal_Int32 nSumHeight = 0; + for( sal_Int32 nR=0; nR<nNumberOfRows; nR++ ) + nSumHeight += aRowHeights[nR]; + sal_Int32 nRemainingSpace = rAvailableSpace.Height - nSumHeight; + + if( nRemainingSpace<0 ) + { + //remove entries that are too big + for( sal_Int32 nR=nNumberOfRows; nR--; ) + { + for( sal_Int32 nC=nNumberOfColumns; nC--; ) + { + sal_Int32 nEntry = (nC + nR * nNumberOfColumns); + if( nEntry < static_cast<sal_Int32>(aTextShapes.size()) ) + { + DrawModelWrapper::removeShape( aTextShapes[nEntry] ); + aTextShapes.pop_back(); + } + if( nEntry < nNumberOfEntries ) + { + DrawModelWrapper::removeShape( rEntries[ nEntry ].aSymbol ); + rEntries.pop_back(); + nNumberOfEntries--; + } + } + nSumHeight -= aRowHeights[nR]; + aRowHeights.pop_back(); + nRemainingSpace = rAvailableSpace.Height - nSumHeight; + if( nRemainingSpace>=0 ) + break; + } + nNumberOfRows = static_cast<sal_Int32>(aRowHeights.size()); + } + if( nRemainingSpace > 0 ) + { + sal_Int32 nNormalSpacingHeight = 2*nYPadding+(nNumberOfRows-1)*nYOffset; + if( nRemainingSpace < nNormalSpacingHeight ) + { + //reduce spacing between the entries + nYPadding = nYOffset = nRemainingSpace/(nNumberOfRows+1); + } + else + { + //we have some space left that should be spread equally between all rows + sal_Int32 nRemainingSingleSpace = (nRemainingSpace-nNormalSpacingHeight)/(nNumberOfRows+1); + nYPadding += nRemainingSingleSpace; + nYOffset += nRemainingSingleSpace; + } + } + + //check spacing between columns + sal_Int32 nSumWidth = 0; + for( sal_Int32 nC=0; nC<nNumberOfColumns; nC++ ) + nSumWidth += aColumnWidths[nC]; + nRemainingSpace = rAvailableSpace.Width - nSumWidth; + if( nRemainingSpace>=0 ) + { + sal_Int32 nNormalSpacingWidth = 2*nXPadding+(nNumberOfColumns-1)*nXOffset; + if( nRemainingSpace < nNormalSpacingWidth ) + { + //reduce spacing between the entries + nXPadding = nXOffset = nRemainingSpace/(nNumberOfColumns+1); + } + else + { + //we have some space left that should be spread equally between all columns + sal_Int32 nRemainingSingleSpace = (nRemainingSpace-nNormalSpacingWidth)/(nNumberOfColumns+1); + nXPadding += nRemainingSingleSpace; + nXOffset += nRemainingSingleSpace; + } + } + } + else if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_HIGH ) { sal_Int32 nMaxNumberOfRows = nMaxEntryHeight ? (rAvailableSpace.Height - 2*nYPadding ) / nMaxEntryHeight @@ -308,7 +517,7 @@ void lcl_placeLegendEntries( static_cast< double >( nNumberOfColumns ) )) : 0; } - else if( eExpansion == LegendExpansion_WIDE ) + else if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_WIDE ) { sal_Int32 nMaxNumberOfColumns = nMaxEntryWidth ? (rAvailableSpace.Width - 2*nXPadding ) / nMaxEntryWidth @@ -325,7 +534,7 @@ void lcl_placeLegendEntries( static_cast< double >( nNumberOfRows ) )) : 0; } - else // LegendExpansion_BALANCED + else // ::com::sun::star::chart::ChartLegendExpansion_BALANCED { double fAspect = nMaxEntryHeight ? static_cast< double >( nMaxEntryWidth ) / static_cast< double >( nMaxEntryHeight ) @@ -341,93 +550,90 @@ void lcl_placeLegendEntries( } if(nNumberOfRows<=0) - return; + return aResultingLegendSize; - // calculate maximum height for current row - std::vector< sal_Int32 > nMaxHeights( nNumberOfRows ); - sal_Int32 nRow = 0; - sal_Int32 nColumn = 0; - for( ; nRow < nNumberOfRows; ++nRow ) + if( eExpansion != ::com::sun::star::chart::ChartLegendExpansion_CUSTOM ) { - sal_Int32 nMaxHeight = 0; - for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) - { - sal_Int32 nEntry = ( eExpansion == LegendExpansion_WIDE ) - ? (nColumn + nRow * nNumberOfColumns) - // HIGH or BALANCED - : (nRow + nColumn * nNumberOfRows); - if( nEntry < nNumberOfEntries ) - nMaxHeight = ::std::max( - nMaxHeight, nYOffset + aTextShapes[ nEntry ]->getSize().Height ); - } - nMaxHeights[ nRow ] = nMaxHeight; + lcl_collectColumnWidths( aColumnWidths, nNumberOfRows, nNumberOfColumns, aTextShapes, nSymbolPlusDistanceWidth ); + lcl_collectRowHeighs( aRowHeights, nNumberOfRows, nNumberOfColumns, aTextShapes ); + nTextLineHeight = lcl_getTextLineHeight( aRowHeights, nNumberOfRows, fViewFontSize ); } - // place entries ordered in optimal-width columns + sal_Int32 nCurrentXPos = nXPadding; + sal_Int32 nCurrentYPos = nYPadding; + if( !bSymbolsLeftSide ) + nCurrentXPos = -nXPadding; + + // place entries into column and rows sal_Int32 nMaxYPos = 0; + sal_Int32 nRow = 0; + sal_Int32 nColumn = 0; for( nColumn = 0; nColumn < nNumberOfColumns; ++nColumn ) { - sal_Int32 nMaxWidth = 0; nCurrentYPos = nYPadding; - for( nRow = 0; nRow < nNumberOfRows; ++nRow ) { - sal_Int32 nEntry = ( eExpansion == LegendExpansion_WIDE ) - ? (nColumn + nRow * nNumberOfColumns) - // HIGH or BALANCED - : (nRow + nColumn * nNumberOfRows); - + sal_Int32 nEntry = (nColumn + nRow * nNumberOfColumns); if( nEntry >= nNumberOfEntries ) break; + // text shape + Reference< drawing::XShape > xTextShape( aTextShapes[nEntry] ); + if( xTextShape.is() ) + { + awt::Size aTextSize( xTextShape->getSize() ); + sal_Int32 nTextXPos = nCurrentXPos + nSymbolPlusDistanceWidth; + if( !bSymbolsLeftSide ) + nTextXPos = nCurrentXPos - nSymbolPlusDistanceWidth - aTextSize.Width; + xTextShape->setPosition( awt::Point( nTextXPos, nCurrentYPos )); + } + // symbol Reference< drawing::XShape > xSymbol( rEntries[ nEntry ].aSymbol ); - if( xSymbol.is() ) { - // Note: aspect ratio should always be 3:2 - - // set symbol size to 75% of maximum space - awt::Size aSymbolSize( - aMaxSymbolExtent.Width * 75 / 100, - aMaxSymbolExtent.Height * 75 / 100 ); - xSymbol->setSize( aSymbolSize ); - sal_Int32 nSymbolXPos = nCurrentXPos + ((aMaxSymbolExtent.Width - aSymbolSize.Width) / 2); + awt::Size aSymbolSize( rMaxSymbolExtent ); + sal_Int32 nSymbolXPos = nCurrentXPos; if( !bSymbolsLeftSide ) - nSymbolXPos = nSymbolXPos - aMaxSymbolExtent.Width; - - // #i109336# Improve auto positioning in chart - sal_Int32 nTextHeight = nMaxHeights[ nRow ] - nYOffset; - sal_Int32 nFontSize = static_cast< sal_Int32 >( fViewFontSize ); - sal_Int32 nMaxRowHeight = ( ( ( nTextHeight / nFontSize ) <= 1 ) ? nTextHeight : nFontSize ); - sal_Int32 nSymbolYPos = nCurrentYPos + ( ( nMaxRowHeight - aSymbolSize.Height ) / 2 ); + nSymbolXPos = nCurrentXPos - rMaxSymbolExtent.Width; + sal_Int32 nSymbolYPos = nCurrentYPos + ( ( nTextLineHeight - aSymbolSize.Height ) / 2 ); xSymbol->setPosition( awt::Point( nSymbolXPos, nSymbolYPos ) ); } - // position text shape - awt::Size aTextSize( aTextShapes[ nEntry ]->getSize()); - nMaxWidth = ::std::max( nMaxWidth, 2 * nXOffset + aMaxSymbolExtent.Width + aTextSize.Width ); - sal_Int32 nTextXPos = nCurrentXPos + aMaxSymbolExtent.Width; - if( !bSymbolsLeftSide ) - nTextXPos = nCurrentXPos - aMaxSymbolExtent.Width - aTextSize.Width; - aTextShapes[ nEntry ]->setPosition( awt::Point( nTextXPos, nCurrentYPos )); - - nCurrentYPos += nMaxHeights[ nRow ]; + nCurrentYPos += aRowHeights[ nRow ]; + if( nRow+1 < nNumberOfRows ) + nCurrentYPos += nYOffset; nMaxYPos = ::std::max( nMaxYPos, nCurrentYPos ); } if( bSymbolsLeftSide ) - nCurrentXPos += nMaxWidth; + { + nCurrentXPos += aColumnWidths[nColumn]; + if( nColumn+1 < nNumberOfColumns ) + nCurrentXPos += nXOffset; + } else - nCurrentXPos -= nMaxWidth; + { + nCurrentXPos -= aColumnWidths[nColumn]; + if( nColumn+1 < nNumberOfColumns ) + nCurrentXPos -= nXOffset; + } } - if( bSymbolsLeftSide ) - rOutLegendSize.Width = nCurrentXPos + nXPadding; - else + if( !bIsCustomSize ) { - sal_Int32 nLegendWidth = -(nCurrentXPos-nXPadding); - rOutLegendSize.Width = nLegendWidth; + if( bSymbolsLeftSide ) + aResultingLegendSize.Width = nCurrentXPos + nXPadding; + else + { + sal_Int32 nLegendWidth = -(nCurrentXPos-nXPadding); + aResultingLegendSize.Width = nLegendWidth; + } + aResultingLegendSize.Height = nMaxYPos + nYPadding; + } + if( !bSymbolsLeftSide ) + { + sal_Int32 nLegendWidth = aResultingLegendSize.Width; awt::Point aPos(0,0); for( sal_Int32 nEntry=0; nEntry<nNumberOfEntries; nEntry++ ) { @@ -441,7 +647,8 @@ void lcl_placeLegendEntries( xText->setPosition( aPos ); } } - rOutLegendSize.Height = nMaxYPos + nYPadding; + + return aResultingLegendSize; } // #i109336# Improve auto positioning in chart @@ -583,14 +790,6 @@ awt::Point lcl_calculatePositionAndRemainingSpace( return aResult; } -template< class T > -void lcl_appendSeqToVector( const Sequence< T > & rSource, ::std::vector< T > & rDest ) -{ - const sal_Int32 nCount = rSource.getLength(); - for( sal_Int32 i = 0; i < nCount; ++i ) - rDest.push_back( rSource[ i ] ); -} - bool lcl_shouldSymbolsBePlacedOnTheLeftSide( const Reference< beans::XPropertySet >& xLegendProp, sal_Int16 nDefaultWritingMode ) { bool bSymbolsLeftSide = true; @@ -706,23 +905,26 @@ void VLegend::createShapes( tPropertyValues aLineFillProperties; tPropertyValues aTextProperties; - // limit the width of texts to 30% of the total available width - // #i109336# Improve auto positioning in chart - sal_Int32 nMaxLabelWidth = rAvailableSpace.Width * 3 / 10; Reference< beans::XPropertySet > xLegendProp( m_xLegend, uno::UNO_QUERY ); - LegendExpansion eExpansion = LegendExpansion_HIGH; + ::com::sun::star::chart::ChartLegendExpansion eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH; + awt::Size aLegendSize( rAvailableSpace ); + if( xLegendProp.is()) { // get Expansion property xLegendProp->getPropertyValue( C2U( "Expansion" )) >>= eExpansion; - if( eExpansion == LegendExpansion_WIDE ) + if( eExpansion == ::com::sun::star::chart::ChartLegendExpansion_CUSTOM ) { - //#i80377# - nMaxLabelWidth = (rAvailableSpace.Width * 5) / 6;//completely correct would be available width minus symbol size minus distances to page ... + RelativeSize aRelativeSize; + if ((xLegendProp->getPropertyValue( C2U( "RelativeSize" )) >>= aRelativeSize)) + { + aLegendSize.Width = aRelativeSize.Primary * rPageSize.Width; + aLegendSize.Height = aRelativeSize.Secondary * rPageSize.Height; + } + else + eExpansion = ::com::sun::star::chart::ChartLegendExpansion_HIGH; } - - lcl_getProperties( xLegendProp, aLineFillProperties, aTextProperties, nMaxLabelWidth, - rPageSize ); + lcl_getProperties( xLegendProp, aLineFillProperties, aTextProperties, rPageSize ); } if( xBorder.is()) @@ -739,32 +941,47 @@ void VLegend::createShapes( } // create entries - tViewLegendEntryContainer aViewEntries; + double fViewFontSize = lcl_CalcViewFontSize( xLegendProp, rPageSize );//todo + // #i109336# Improve auto positioning in chart + sal_Int32 nSymbolHeigth = static_cast< sal_Int32 >( fViewFontSize * 0.6 ); + sal_Int32 nSymbolWidth = static_cast< sal_Int32 >( nSymbolHeigth ); + + ::std::vector< LegendEntryProvider* >::const_iterator aIter = m_aLegendEntryProviderList.begin(); + const ::std::vector< LegendEntryProvider* >::const_iterator aEnd = m_aLegendEntryProviderList.end(); + for( aIter = m_aLegendEntryProviderList.begin(); aIter != aEnd; aIter++ ) { - ::std::vector< LegendEntryProvider* >::const_iterator aIter = m_aLegendEntryProviderList.begin(); - const ::std::vector< LegendEntryProvider* >::const_iterator aEnd = m_aLegendEntryProviderList.end(); - for( ; aIter != aEnd; aIter++ ) + LegendEntryProvider* pLegendEntryProvider( *aIter ); + if( pLegendEntryProvider ) { - LegendEntryProvider* pLegendEntryProvider( *aIter ); - if( pLegendEntryProvider ) + awt::Size aCurrentRatio = pLegendEntryProvider->getPreferredLegendKeyAspectRatio(); + sal_Int32 nCurrentWidth = aCurrentRatio.Width; + if( aCurrentRatio.Height > 0 ) { - lcl_appendSeqToVector< ViewLegendEntry >( - pLegendEntryProvider->createLegendEntries( eExpansion, xLegendProp, xLegendContainer, m_xShapeFactory, m_xContext ) - , aViewEntries ); + nCurrentWidth = nSymbolHeigth* aCurrentRatio.Width/aCurrentRatio.Height; } + nSymbolWidth = std::max( nSymbolWidth, nCurrentWidth ); + } + } + awt::Size aMaxSymbolExtent( nSymbolWidth, nSymbolHeigth ); + + tViewLegendEntryContainer aViewEntries; + for( aIter = m_aLegendEntryProviderList.begin(); aIter != aEnd; aIter++ ) + { + LegendEntryProvider* pLegendEntryProvider( *aIter ); + if( pLegendEntryProvider ) + { + std::vector< ViewLegendEntry > aNewEntries = pLegendEntryProvider->createLegendEntries( aMaxSymbolExtent, eExpansion, xLegendProp, xLegendContainer, m_xShapeFactory, m_xContext ); + aViewEntries.insert( aViewEntries.end(), aNewEntries.begin(), aNewEntries.end() ); } } bool bSymbolsLeftSide = lcl_shouldSymbolsBePlacedOnTheLeftSide( xLegendProp, m_nDefaultWritingMode ); // place entries - awt::Size aLegendSize; - lcl_placeLegendEntries( aViewEntries, eExpansion, bSymbolsLeftSide - , xLegendProp, aTextProperties - , xLegendContainer, m_xShapeFactory, m_xContext - , rAvailableSpace, rPageSize, aLegendSize ); + aLegendSize = lcl_placeLegendEntries( aViewEntries, eExpansion, bSymbolsLeftSide, fViewFontSize, aMaxSymbolExtent + , aTextProperties, xLegendContainer, m_xShapeFactory, aLegendSize ); - if( xBorder.is()) + if( xBorder.is() ) xBorder->setSize( aLegendSize ); } } diff --git a/chart2/source/view/main/VLegendSymbolFactory.cxx b/chart2/source/view/main/VLegendSymbolFactory.cxx index d29b28e8dbe9..b7168bd7ee9f 100644 --- a/chart2/source/view/main/VLegendSymbolFactory.cxx +++ b/chart2/source/view/main/VLegendSymbolFactory.cxx @@ -38,9 +38,6 @@ // header for define DBG_ASSERT #include <tools/debug.hxx> -// uncomment to disable line dashes at the border of boxes -// #define DISABLE_DASHES_AT_BORDER - using namespace ::com::sun::star; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; @@ -105,16 +102,16 @@ namespace chart { Reference< drawing::XShape > VLegendSymbolFactory::createSymbol( + const awt::Size& rEntryKeyAspectRatio, const Reference< drawing::XShapes > xSymbolContainer, - chart2::LegendSymbolStyle eStyle, + LegendSymbolStyle eStyle, const Reference< lang::XMultiServiceFactory > & xShapeFactory, const Reference< beans::XPropertySet > & xLegendEntryProperties, tPropertyType ePropertyType, const uno::Any& rExplicitSymbol ) { Reference< drawing::XShape > xResult; - if( ! (xSymbolContainer.is() && - xShapeFactory.is())) + if( ! (xSymbolContainer.is() && xShapeFactory.is())) return xResult; xResult.set( xShapeFactory->createInstance( @@ -124,247 +121,92 @@ Reference< drawing::XShape > VLegendSymbolFactory::createSymbol( if( ! xResultGroup.is()) return xResult; - // aspect ratio of symbols is always 3:2 - awt::Size aBoundSize( 3000, 2000 ); - bool bUseBox = false; - // add an invisible square box to maintain aspect ratio - switch( eStyle ) - { - case chart2::LegendSymbolStyle_BOX: - case chart2::LegendSymbolStyle_HORIZONTAL_LINE: - case chart2::LegendSymbolStyle_VERTICAL_LINE: - case chart2::LegendSymbolStyle_DIAGONAL_LINE: - case chart2::LegendSymbolStyle_LINE_WITH_BOX: - case chart2::LegendSymbolStyle_LINE_WITH_SYMBOL: - case chart2::LegendSymbolStyle_CIRCLE: - { - Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle( - xResultGroup, aBoundSize )); - break; - } - - case chart2::LegendSymbolStyle_BAR: - case chart2::LegendSymbolStyle_RECTANGLE: - case chart2::LegendSymbolStyle_STRETCHED_RECTANGLE: - case chart2::LegendSymbolStyle_USER_DEFINED: - default: - break; - } + Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle( + xResultGroup, rEntryKeyAspectRatio )); // create symbol - switch( eStyle ) + try { - case chart2::LegendSymbolStyle_BOX: - case chart2::LegendSymbolStyle_BAR: - case chart2::LegendSymbolStyle_RECTANGLE: - case chart2::LegendSymbolStyle_STRETCHED_RECTANGLE: - case chart2::LegendSymbolStyle_CIRCLE: + if( eStyle == LegendSymbolStyle_LINE ) { - try + Reference< drawing::XShape > xLine( xShapeFactory->createInstance( + C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY ); + if( xLine.is()) { - Reference< drawing::XShape > xShape; + xResultGroup->add( xLine ); + xLine->setSize( awt::Size( rEntryKeyAspectRatio.Width, 0 )); + xLine->setPosition( awt::Point( 0, rEntryKeyAspectRatio.Height/2 )); - if( eStyle == chart2::LegendSymbolStyle_CIRCLE ) - xShape.set( xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.EllipseShape" )), uno::UNO_QUERY ); - else - xShape.set( xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY ); + lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); + } - if( xShape.is()) + Reference< drawing::XShape > xSymbol; + const sal_Int32 nSize = std::min(rEntryKeyAspectRatio.Width,rEntryKeyAspectRatio.Height); + chart2::Symbol aSymbol; + if( rExplicitSymbol >>= aSymbol ) + { + drawing::Direction3D aSymbolSize( nSize, nSize, 0 ); + drawing::Position3D aPos( rEntryKeyAspectRatio.Width/2, rEntryKeyAspectRatio.Height/2, 0 ); + ShapeFactory aFactory( xShapeFactory ); + if( aSymbol.Style == chart2::SymbolStyle_STANDARD ) { - xResultGroup->add( xShape ); - if( eStyle == chart2::LegendSymbolStyle_BOX || - eStyle == chart2::LegendSymbolStyle_CIRCLE ) - { - xShape->setSize( awt::Size( 2000, 2000 )); - xShape->setPosition( awt::Point( 500, 0 )); - } - else - { - xShape->setSize( aBoundSize ); - } + // take series color as fill color + xLegendEntryProperties->getPropertyValue( C2U("Color")) >>= aSymbol.FillColor; + // border of symbols always same as fill color + aSymbol.BorderColor = aSymbol.FillColor; + + xSymbol.set( aFactory.createSymbol2D( + xResultGroup, + aPos, + aSymbolSize, + aSymbol.StandardSymbol, + aSymbol.BorderColor, + aSymbol.FillColor )); } - - lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES ); - -#ifdef DISABLE_DASHES_AT_BORDER - // don't allow dashed border style - Reference< beans::XPropertySet > xShapeProp( xShape, uno::UNO_QUERY ); - if( xShapeProp.is()) + else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC ) { - drawing::LineStyle aLineStyle; - if( ( xShapeProp->getPropertyValue( C2U("LineStyle")) >>= aLineStyle ) && - aLineStyle == drawing::LineStyle_DASH ) - { - aLineStyle = drawing::LineStyle_SOLID; - xShapeProp->setPropertyValue( C2U("LineStyle"), uno::makeAny( aLineStyle )); - } + xSymbol.set( aFactory.createGraphic2D( + xResultGroup, + aPos, + aSymbolSize, + aSymbol.Graphic )); } -#endif - } - catch( uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); - } - break; - } - - case chart2::LegendSymbolStyle_HORIZONTAL_LINE: - { - try - { - Reference< drawing::XShape > xLine( - xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY ); - if( xLine.is()) + else if( aSymbol.Style == chart2::SymbolStyle_AUTO ) { - xResultGroup->add( xLine ); - xLine->setSize( awt::Size( 3000, 0 )); - xLine->setPosition( awt::Point( 0, 1000 )); - - lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); // PROP_TYPE_LINE_SERIES ); + DBG_ERROR("the given parameter is not allowed to contain an automatic symbol style"); } } - catch( uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); - } - break; } - - case chart2::LegendSymbolStyle_VERTICAL_LINE: + else if( eStyle == LegendSymbolStyle_CIRCLE ) { - try + Reference< drawing::XShape > xShape( xShapeFactory->createInstance( + C2U( "com.sun.star.drawing.EllipseShape" )), uno::UNO_QUERY ); + if( xShape.is() ) { - Reference< drawing::XShape > xLine( - xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY ); - if( xLine.is()) - { - xResultGroup->add( xLine ); - xLine->setSize( awt::Size( 0, 2000 )); - xLine->setPosition( awt::Point( 1500, 0 )); - - lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); // PROP_TYPE_LINE_SERIES ); - } - } - catch( uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); + xResultGroup->add( xShape ); + sal_Int32 nSize = std::min( rEntryKeyAspectRatio.Width, rEntryKeyAspectRatio.Height ); + xShape->setSize( awt::Size( nSize, nSize ) ); + xShape->setPosition( awt::Point( rEntryKeyAspectRatio.Width/2-nSize/2, rEntryKeyAspectRatio.Height/2-nSize/2 ) ); + lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES ); } - break; } - - case chart2::LegendSymbolStyle_DIAGONAL_LINE: + else // eStyle == LegendSymbolStyle_BOX { - try + Reference< drawing::XShape > xShape( xShapeFactory->createInstance( + C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY ); + if( xShape.is() ) { - Reference< drawing::XShape > xLine( - xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY ); - if( xLine.is()) - { - xResultGroup->add( xLine ); - xLine->setSize( awt::Size( 2000, 2000 )); - xLine->setPosition( awt::Point( 500, 0 )); - - lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); // PROP_TYPE_LINE_SERIES ); - } - } - catch( uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); + xResultGroup->add( xShape ); + xShape->setSize( rEntryKeyAspectRatio ); + xShape->setPosition( awt::Point( 0, 0 ) ); + lcl_setPropetiesToShape( xLegendEntryProperties, xShape, ePropertyType ); // PROP_TYPE_FILLED_SERIES ); } - break; } - - case chart2::LegendSymbolStyle_LINE_WITH_BOX: - bUseBox = true; - // fall-through intended - case chart2::LegendSymbolStyle_LINE_WITH_SYMBOL: - try - { - Reference< drawing::XShape > xLine( - xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.LineShape" )), uno::UNO_QUERY ); - if( xLine.is()) - { - xResultGroup->add( xLine ); - xLine->setSize( awt::Size( 3000, 0 )); - xLine->setPosition( awt::Point( 0, 1000 )); - - lcl_setPropetiesToShape( xLegendEntryProperties, xLine, ePropertyType ); - } - - Reference< drawing::XShape > xSymbol; - const sal_Int32 nSize = 1500; - if( bUseBox ) - { - xSymbol.set( xShapeFactory->createInstance( - C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY ); - xResultGroup->add( xSymbol ); - - if( xSymbol.is()) - { - xSymbol->setSize( awt::Size( nSize, nSize )); - xSymbol->setPosition( awt::Point( 1500 - nSize/2, 1000 - nSize/2 )); - - lcl_setPropetiesToShape( xLegendEntryProperties, xSymbol, ePropertyType ); - } - } - else - { - chart2::Symbol aSymbol; - - if( rExplicitSymbol >>= aSymbol ) - { - drawing::Direction3D aSymbolSize( nSize, nSize, 0 ); - drawing::Position3D aPos( 1500, 1000, 0 ); - ShapeFactory aFactory( xShapeFactory ); - if( aSymbol.Style == chart2::SymbolStyle_STANDARD ) - { - // take series color as fill color - xLegendEntryProperties->getPropertyValue( C2U("Color")) >>= aSymbol.FillColor; - // border of symbols always same as fill color - aSymbol.BorderColor = aSymbol.FillColor; - - xSymbol.set( aFactory.createSymbol2D( - xResultGroup, - aPos, - aSymbolSize, - aSymbol.StandardSymbol, - aSymbol.BorderColor, - aSymbol.FillColor )); - } - else if( aSymbol.Style == chart2::SymbolStyle_GRAPHIC ) - { - xSymbol.set( aFactory.createGraphic2D( - xResultGroup, - aPos, - aSymbolSize, - aSymbol.Graphic )); - } - else if( aSymbol.Style == chart2::SymbolStyle_AUTO ) - { - DBG_ERROR("the given parameter is not allowed to contain an automatic symbol style"); - } - } - } - } - catch( uno::Exception & ex ) - { - ASSERT_EXCEPTION( ex ); - } - break; - - case chart2::LegendSymbolStyle_USER_DEFINED: - break; - - default: - // just to remove warning (there is an auto-generated extra label) - break; + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); } return xResult; |