diff options
author | Ingrid Halama [iha] <Ingrid.Halama@oracle.com> | 2011-02-07 00:10:55 +0100 |
---|---|---|
committer | Ingrid Halama [iha] <Ingrid.Halama@oracle.com> | 2011-02-07 00:10:55 +0100 |
commit | 34da9193218bfbbb036ffcc3fc3b26f2251403fb (patch) | |
tree | e00d3e1faa891aa383b5b23c3dc750ebd0a2807a /chart2 | |
parent | 7bafb42bf101d13ab336221652124376661f1d05 (diff) |
chart52: #i82802# bigger legend keys for lines and dashes
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/source/view/charttypes/AreaChart.cxx | 4 | ||||
-rw-r--r-- | chart2/source/view/charttypes/CandleStickChart.cxx | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | chart2/source/view/charttypes/VSeriesPlotter.cxx | 167 | ||||
-rw-r--r-- | chart2/source/view/inc/LegendEntryProvider.hxx | 14 | ||||
-rw-r--r-- | chart2/source/view/inc/VLegendSymbolFactory.hxx | 8 | ||||
-rw-r--r-- | chart2/source/view/inc/VSeriesPlotter.hxx | 14 | ||||
-rw-r--r-- | chart2/source/view/main/VLegend.cxx | 117 | ||||
-rw-r--r-- | chart2/source/view/main/VLegendSymbolFactory.cxx | 232 |
8 files changed, 282 insertions, 276 deletions
diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index f07189615781..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> @@ -153,7 +155,7 @@ LegendSymbolStyle AreaChart::getLegendSymbolStyle() { if( m_bArea || m_nDimension == 3 ) return LegendSymbolStyle_BOX; - return LegendSymbolStyle_LINE_WITH_SYMBOL; + return LegendSymbolStyle_LINE; } uno::Any AreaChart::getExplicitSymbol( const VDataSeries& rSeries, sal_Int32 nPointIndex ) diff --git a/chart2/source/view/charttypes/CandleStickChart.cxx b/chart2/source/view/charttypes/CandleStickChart.cxx index 3ce3cf661d5d..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 LegendSymbolStyle_VERTICAL_LINE; + return LegendSymbolStyle_LINE; } //----------------------------------------------------------------- diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index 85963fc46cb4..4866191333ec 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 ); } } @@ -1819,7 +1822,8 @@ bool VSeriesPlotter::shouldSnapRectToUsedArea() } std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntries( - ::com::sun::star::chart::ChartLegendExpansion eLegendExpansion + 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 @@ -1851,7 +1855,7 @@ std::vector< ViewLegendEntry > 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 @@ -1885,12 +1889,102 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntries( 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< VDataSeries* > aSeriesList = aXSlotIter->m_aSeriesVector; + aAllSeries.insert( aAllSeries.end(), aSeriesList.begin(), aSeriesList.end() ); + } + } + return aAllSeries; +} + +bool VSeriesPlotter::HasDashedLines( const uno::Reference< beans::XPropertySet >& xProps ) +{ + bool bHasDashedLines = false; + drawing::LineStyle aLineStyle = drawing::LineStyle_NONE; + if( xProps.is() && ( xProps->getPropertyValue( C2U("LineStyle")) >>= aLineStyle ) && + ( aLineStyle == drawing::LineStyle_DASH ) ) + { + bHasDashedLines = true; + } + return bHasDashedLines; +} + +bool VSeriesPlotter::HasRegressionCurves( const VDataSeries& rSeries, bool& rbHasDashedLines ) +{ + 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() && !RegressionCurveHelper::isMeanValueLine( aCurves[i] ) ) + { + bHasRegressionCurves = true; + if( HasDashedLines( uno::Reference< beans::XPropertySet >( aCurves[i], uno::UNO_QUERY ) ) ) + rbHasDashedLines = true; + } + } + } + return bHasRegressionCurves; +} LegendSymbolStyle VSeriesPlotter::getLegendSymbolStyle() { return LegendSymbolStyle_BOX; } +awt::Size VSeriesPlotter::getPreferredLegendKeyAspectRatio() +{ + awt::Size aRet(1000,1000); + if( m_nDimension==3 ) + return aRet; + + bool bSeriesHasLines = (getLegendSymbolStyle() == LegendSymbolStyle_LINE); + bool bHasLines = bSeriesHasLines; + 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( bSeriesHasLines && HasDashedLines( (*aSeriesIter)->getPropertiesOfSeries() ) ) + { + bHasDashedLines = true; + break; + } + bool bRegressionHasDashedLines=false; + if( VSeriesPlotter::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*/ ) { @@ -1898,7 +1992,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 ) { @@ -1913,15 +2008,13 @@ Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForSeries( // legend-symbol type switch( eLegendSymbolStyle ) { - case LegendSymbolStyle_VERTICAL_LINE: - case LegendSymbolStyle_DIAGONAL_LINE: - 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 )); @@ -1929,7 +2022,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 ) @@ -1945,9 +2039,7 @@ Reference< drawing::XShape > VSeriesPlotter::createLegendSymbolForPoint( // legend-symbol type switch( eLegendSymbolStyle ) { - case LegendSymbolStyle_VERTICAL_LINE: - case LegendSymbolStyle_DIAGONAL_LINE: - case LegendSymbolStyle_LINE_WITH_SYMBOL: + case LegendSymbolStyle_LINE: ePropType = VLegendSymbolFactory::PROP_TYPE_LINE_SERIES; break; default: @@ -1978,14 +2070,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 > VSeriesPlotter::createLegendEntriesForSeries( - const VDataSeries& rSeries + const awt::Size& rEntryKeyAspectRatio + , const VDataSeries& rSeries , const Reference< beans::XPropertySet >& xTextProperties , const Reference< drawing::XShapes >& xTarget , const Reference< lang::XMultiServiceFactory >& xShapeFactory @@ -2014,7 +2107,7 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntriesForSeries( 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 @@ -2044,7 +2137,7 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntriesForSeries( // 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()) @@ -2086,8 +2179,8 @@ std::vector< ViewLegendEntry > VSeriesPlotter::createLegendEntriesForSeries( uno::Reference< drawing::XShapes > xSymbolGroup( ShapeFactory(xShapeFactory).createGroup2D( xTarget )); // create the symbol - Reference< drawing::XShape > xShape( VLegendSymbolFactory::createSymbol( - xSymbolGroup, 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() )); diff --git a/chart2/source/view/inc/LegendEntryProvider.hxx b/chart2/source/view/inc/LegendEntryProvider.hxx index 74b731cd9e55..1ecc78107d2b 100644 --- a/chart2/source/view/inc/LegendEntryProvider.hxx +++ b/chart2/source/view/inc/LegendEntryProvider.hxx @@ -46,18 +46,9 @@ enum LegendSymbolStyle */ LegendSymbolStyle_BOX, - /** A line extending from the top edge to the bottom edge - */ - LegendSymbolStyle_VERTICAL_LINE, - - /** A line spanning the diagonal of the box you would get with - <member>BOX</member>. - */ - LegendSymbolStyle_DIAGONAL_LINE, - /** A line like with a symbol. */ - LegendSymbolStyle_LINE_WITH_SYMBOL, + LegendSymbolStyle_LINE, /** A bordered circle which has the same bounding-box as the <member>BOX</member>. @@ -83,7 +74,10 @@ struct ViewLegendEntry class LegendEntryProvider { public: + 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, diff --git a/chart2/source/view/inc/VLegendSymbolFactory.hxx b/chart2/source/view/inc/VLegendSymbolFactory.hxx index 3dc42f7c207a..4ea3c67d5ece 100644 --- a/chart2/source/view/inc/VLegendSymbolFactory.hxx +++ b/chart2/source/view/inc/VLegendSymbolFactory.hxx @@ -50,6 +50,7 @@ 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, LegendSymbolStyle eStyle, @@ -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 cf4d5073b775..0360771ea606 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -207,6 +207,7 @@ public: //------------------------------------------------------------------------- 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, @@ -220,20 +221,25 @@ public: virtual LegendSymbolStyle getLegendSymbolStyle(); + virtual com::sun::star::awt::Size getPreferredLegendKeyAspectRatio(); + 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< ViewLegendEntry > createLegendEntriesForSeries( + const ::com::sun::star::awt::Size& rEntryKeyAspectRatio, const VDataSeries& rSeries, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xTextProperties, @@ -245,6 +251,10 @@ public: ::com::sun::star::uno::XComponentContext >& xContext ); + ::std::vector< VDataSeries* > getAllSeries(); + static bool HasDashedLines( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xProps ); + static bool HasRegressionCurves( const VDataSeries& rSeries, bool& rbHasDashedLines ); + //------------------------------------------------------------------------- //------------------------------------------------------------------------- diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 4751d2ccd879..022de4f0305c 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -236,7 +236,7 @@ awt::Size lcl_createTextShapes( } void lcl_collectColumnWidths( std::vector< sal_Int32 >& rColumnWidths, const sal_Int32 nNumberOfRows, const sal_Int32 nNumberOfColumns - , const ::std::vector< Reference< drawing::XShape > > aTextShapes, const awt::Size& aMaxSymbolExtent ) + , const ::std::vector< Reference< drawing::XShape > > aTextShapes, sal_Int32 nSymbolPlusDistanceWidth ) { rColumnWidths.clear(); sal_Int32 nRow = 0; @@ -250,7 +250,7 @@ void lcl_collectColumnWidths( std::vector< sal_Int32 >& rColumnWidths, const sal if( nEntry < nNumberOfEntries ) { awt::Size aTextSize( aTextShapes[ nEntry ]->getSize() ); - sal_Int32 nWidth = aMaxSymbolExtent.Width + aTextSize.Width; + sal_Int32 nWidth = nSymbolPlusDistanceWidth + aTextSize.Width; if( nRow==0 ) rColumnWidths.push_back( nWidth ); else @@ -306,38 +306,29 @@ 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 awt::Size & rAvailableSpace, - const awt::Size & rPageSize ) + const awt::Size & rAvailableSpace ) { bool bIsCustomSize = (eExpansion == ::com::sun::star::chart::ChartLegendExpansion_CUSTOM); awt::Size aResultingLegendSize(0,0); if( bIsCustomSize ) aResultingLegendSize = rAvailableSpace; - //todo - double fViewFontSize = lcl_CalcViewFontSize( xProperties, rPageSize ); - - // 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; - - sal_Int32 nXPadding = static_cast< sal_Int32 >( fViewFontSize * fXPadding ); - sal_Int32 nYPadding = static_cast< sal_Int32 >( fViewFontSize * fYPadding ); - sal_Int32 nXOffset = static_cast< sal_Int32 >( fViewFontSize * fXOffset ); - sal_Int32 nYOffset = static_cast< sal_Int32 >( fViewFontSize * fYOffset ); // #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 nMaxTextWidth = rAvailableSpace.Width - (2 * nXOffset) - aMaxSymbolExtent.Width; + 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 * nXOffset) - nSymbolPlusDistanceWidth; rtl::OUString aPropNameTextMaximumFrameWidth( C2U("TextMaximumFrameWidth") ); uno::Any* pFrameWidthAny = PropertyMapper::getValuePointer( rTextProperties.second, rTextProperties.first, aPropNameTextMaximumFrameWidth); if(pFrameWidthAny) @@ -355,7 +346,7 @@ awt::Size lcl_placeLegendEntries( awt::Size aMaxEntryExtent = lcl_createTextShapes( rEntries, xShapeFactory, xTarget, aTextShapes, rTextProperties ); OSL_ASSERT( aTextShapes.size() == rEntries.size()); - sal_Int32 nMaxEntryWidth = 2 * nXOffset + aMaxSymbolExtent.Width + aMaxEntryExtent.Width; + sal_Int32 nMaxEntryWidth = 2 * nXOffset + nSymbolPlusDistanceWidth + aMaxEntryExtent.Width; sal_Int32 nMaxEntryHeight = nYOffset + aMaxEntryExtent.Height; sal_Int32 nNumberOfEntries = rEntries.size(); @@ -378,7 +369,7 @@ awt::Size lcl_placeLegendEntries( if( !xShape.is() ) continue; awt::Size aSize( xShape->getSize() ); - sal_Int32 nNewWidth = aSize.Width + aMaxSymbolExtent.Width; + sal_Int32 nNewWidth = aSize.Width + nSymbolPlusDistanceWidth; sal_Int32 nCurrentColumnCount = aColumnWidths.size(); //are we allowed to add a new column? @@ -562,7 +553,7 @@ awt::Size lcl_placeLegendEntries( if( eExpansion != ::com::sun::star::chart::ChartLegendExpansion_CUSTOM ) { - lcl_collectColumnWidths( aColumnWidths, nNumberOfRows, nNumberOfColumns, aTextShapes, aMaxSymbolExtent ); + lcl_collectColumnWidths( aColumnWidths, nNumberOfRows, nNumberOfColumns, aTextShapes, nSymbolPlusDistanceWidth ); lcl_collectRowHeighs( aRowHeights, nNumberOfRows, nNumberOfColumns, aTextShapes ); nTextLineHeight = lcl_getTextLineHeight( aRowHeights, nNumberOfRows, fViewFontSize ); } @@ -590,9 +581,9 @@ awt::Size lcl_placeLegendEntries( if( xTextShape.is() ) { awt::Size aTextSize( xTextShape->getSize() ); - sal_Int32 nTextXPos = nCurrentXPos + aMaxSymbolExtent.Width; + sal_Int32 nTextXPos = nCurrentXPos + nSymbolPlusDistanceWidth; if( !bSymbolsLeftSide ) - nTextXPos = nCurrentXPos - aMaxSymbolExtent.Width - aTextSize.Width; + nTextXPos = nCurrentXPos - nSymbolPlusDistanceWidth - aTextSize.Width; xTextShape->setPosition( awt::Point( nTextXPos, nCurrentYPos )); } @@ -600,27 +591,31 @@ awt::Size lcl_placeLegendEntries( 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; - + nSymbolXPos = nCurrentXPos - rMaxSymbolExtent.Width; sal_Int32 nSymbolYPos = nCurrentYPos + ( ( nTextLineHeight - aSymbolSize.Height ) / 2 ); xSymbol->setPosition( awt::Point( nSymbolXPos, nSymbolYPos ) ); } - nCurrentYPos += aRowHeights[ nRow ] + nYOffset; + nCurrentYPos += aRowHeights[ nRow ]; + if( nRow+1 < nNumberOfRows ) + nCurrentYPos += nYOffset; nMaxYPos = ::std::max( nMaxYPos, nCurrentYPos ); } if( bSymbolsLeftSide ) - nCurrentXPos += ( aColumnWidths[nColumn] + nXOffset ); + { + nCurrentXPos += aColumnWidths[nColumn]; + if( nColumn+1 < nNumberOfColumns ) + nCurrentXPos += nXOffset; + } else - nCurrentXPos -= ( aColumnWidths[nColumn] + nXOffset ); + { + nCurrentXPos -= aColumnWidths[nColumn]; + if( nColumn+1 < nNumberOfColumns ) + nCurrentXPos -= nXOffset; + } } if( !bIsCustomSize ) @@ -945,27 +940,45 @@ 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 ) { - std::vector< ViewLegendEntry > aNewEntries = pLegendEntryProvider->createLegendEntries( eExpansion, xLegendProp, xLegendContainer, m_xShapeFactory, m_xContext ); - aViewEntries.insert( aViewEntries.end(), aNewEntries.begin(), aNewEntries.end() ); + 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 - aLegendSize = lcl_placeLegendEntries( aViewEntries, eExpansion, bSymbolsLeftSide - , xLegendProp, aTextProperties, xLegendContainer, m_xShapeFactory - , aLegendSize, rPageSize ); + aLegendSize = lcl_placeLegendEntries( aViewEntries, eExpansion, bSymbolsLeftSide, fViewFontSize, aMaxSymbolExtent + , aTextProperties, xLegendContainer, m_xShapeFactory, aLegendSize ); if( xBorder.is() ) xBorder->setSize( aLegendSize ); diff --git a/chart2/source/view/main/VLegendSymbolFactory.cxx b/chart2/source/view/main/VLegendSymbolFactory.cxx index 633ecb768021..35ad3b0234c8 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,6 +102,7 @@ namespace chart { Reference< drawing::XShape > VLegendSymbolFactory::createSymbol( + const awt::Size& rEntryKeyAspectRatio, const Reference< drawing::XShapes > xSymbolContainer, LegendSymbolStyle eStyle, const Reference< lang::XMultiServiceFactory > & xShapeFactory, @@ -113,8 +111,7 @@ Reference< drawing::XShape > VLegendSymbolFactory::createSymbol( { Reference< drawing::XShape > xResult; - if( ! (xSymbolContainer.is() && - xShapeFactory.is())) + if( ! (xSymbolContainer.is() && xShapeFactory.is())) return xResult; xResult.set( xShapeFactory->createInstance( @@ -124,191 +121,94 @@ 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 LegendSymbolStyle_BOX: - case LegendSymbolStyle_VERTICAL_LINE: - case LegendSymbolStyle_DIAGONAL_LINE: - case LegendSymbolStyle_LINE_WITH_SYMBOL: - case LegendSymbolStyle_CIRCLE: - { - Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle( - xResultGroup, aBoundSize )); - break; - } - - default: - break; - } + Reference< drawing::XShape > xBound( ShapeFactory(xShapeFactory).createInvisibleRectangle( + xResultGroup, rEntryKeyAspectRatio )); // create symbol - switch( eStyle ) + try { - case LegendSymbolStyle_BOX: - case 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 == 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 == LegendSymbolStyle_BOX || - eStyle == 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 LegendSymbolStyle_VERTICAL_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( 0, 2000 )); - xLine->setPosition( awt::Point( 1500, 0 )); - - 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 LegendSymbolStyle_DIAGONAL_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( 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 ); + 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 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; - 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 ) + else // eStyle == LegendSymbolStyle_BOX + { + Reference< drawing::XShape > xShape( xShapeFactory->createInstance( + C2U( "com.sun.star.drawing.RectangleShape" )), uno::UNO_QUERY ); + if( xShape.is() ) { - 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; - - default: - // just to remove warning (there is an auto-generated extra label) - break; + } + } + catch( uno::Exception & ex ) + { + ASSERT_EXCEPTION( ex ); } return xResult; |