diff options
author | Vladimir Glazunov <vg@openoffice.org> | 2010-03-23 15:50:29 +0100 |
---|---|---|
committer | Vladimir Glazunov <vg@openoffice.org> | 2010-03-23 15:50:29 +0100 |
commit | 8a0f23349d4acee6fadb9b628d1080ee219a7ffe (patch) | |
tree | 5902ab4a51dc2d2733fa90bd1c9763ce92db5f37 /chart2/source | |
parent | 2fbd5327d5fda2e415557ed7b03bb181ae5ce2a1 (diff) | |
parent | eee5ae330a49c18c4fe8666bc1c2dbc949dc0914 (diff) |
CWS-TOOLING: integrate CWS chartlayout
Diffstat (limited to 'chart2/source')
-rw-r--r-- | chart2/source/view/charttypes/VSeriesPlotter.cxx | 8 | ||||
-rw-r--r-- | chart2/source/view/main/ChartView.cxx | 73 | ||||
-rw-r--r-- | chart2/source/view/main/VLegend.cxx | 108 | ||||
-rw-r--r-- | chart2/source/view/main/VTitle.cxx | 15 |
4 files changed, 156 insertions, 48 deletions
diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index ccba1fdc4106..37888c8f0a9b 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -560,11 +560,17 @@ uno::Reference< drawing::XShape > VSeriesPlotter::createDataLabel( const uno::Re 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 ); - aSymbolPosition.Y += (nYDiff * 25/200); + + // #i109336# Improve auto positioning in chart + aSymbolPosition.Y += ( nYDiff / 4 ); if(LABEL_ALIGN_LEFT==eAlignment || LABEL_ALIGN_LEFT_TOP==eAlignment diff --git a/chart2/source/view/main/ChartView.cxx b/chart2/source/view/main/ChartView.cxx index da8798fe31b6..87bd4d1c97ba 100644 --- a/chart2/source/view/main/ChartView.cxx +++ b/chart2/source/view/main/ChartView.cxx @@ -2155,7 +2155,7 @@ void changePositionOfAxisTitle( VTitle* pVTitle, TitleAlignment eAlignment pVTitle->changePosition( aNewPosition ); } -std::auto_ptr<VTitle> lcl_createTitle( const uno::Reference< XTitle >& xTitle +std::auto_ptr<VTitle> lcl_createTitle( TitleHelper::eTitleType eType , const uno::Reference< drawing::XShapes>& xPageShapes , const uno::Reference< lang::XMultiServiceFactory>& xShapeFactory , const uno::Reference< frame::XModel >& xChartModel @@ -2165,10 +2165,32 @@ std::auto_ptr<VTitle> lcl_createTitle( const uno::Reference< XTitle >& xTitle , bool& rbAutoPosition ) { std::auto_ptr<VTitle> apVTitle; + + // #i109336# Improve auto positioning in chart + double fPercentage = lcl_getPageLayoutDistancePercentage(); + sal_Int32 nXDistance = static_cast< sal_Int32 >( rPageSize.Width * fPercentage ); + sal_Int32 nYDistance = static_cast< sal_Int32 >( rPageSize.Height * fPercentage ); + if ( eType == TitleHelper::MAIN_TITLE ) + { + sal_Int32 nYOffset = 135; // 1/100 mm + nYDistance += nYOffset; + } + else if ( eType == TitleHelper::TITLE_AT_STANDARD_X_AXIS_POSITION ) + { + sal_Int32 nYOffset = 420; // 1/100 mm + nYDistance = nYOffset; + } + else if ( eType == TitleHelper::TITLE_AT_STANDARD_Y_AXIS_POSITION ) + { + sal_Int32 nXOffset = 450; // 1/100 mm + nXDistance = nXOffset; + } + + uno::Reference< XTitle > xTitle( TitleHelper::getTitle( eType, xChartModel ) ); if(xTitle.is()) { rtl::OUString aCompleteString( TitleHelper::getCompleteString( xTitle ) ); - if( aCompleteString.getLength()==0 ) + if ( aCompleteString.getLength() == 0 ) return apVTitle;//don't create empty titles as the resulting diagram position is wrong then //create title @@ -2182,8 +2204,6 @@ std::auto_ptr<VTitle> lcl_createTitle( const uno::Reference< XTitle >& xTitle //position rbAutoPosition=true; awt::Point aNewPosition(0,0); - sal_Int32 nYDistance = static_cast<sal_Int32>(rPageSize.Height*lcl_getPageLayoutDistancePercentage()); - sal_Int32 nXDistance = static_cast<sal_Int32>(rPageSize.Width*lcl_getPageLayoutDistancePercentage()); chart2::RelativePosition aRelativePosition; uno::Reference< beans::XPropertySet > xProp(xTitle, uno::UNO_QUERY); if( xProp.is() && (xProp->getPropertyValue( C2U( "RelativePosition" ) )>>=aRelativePosition) ) @@ -2247,6 +2267,37 @@ std::auto_ptr<VTitle> lcl_createTitle( const uno::Reference< XTitle >& xTitle break; } } + else + { + // #i109336# Improve auto positioning in chart + switch ( eAlignment ) + { + case ALIGN_TOP: + { + rRemainingSpace.Y += nYDistance; + rRemainingSpace.Height -= nYDistance; + } + break; + case ALIGN_BOTTOM: + { + rRemainingSpace.Height -= nYDistance; + } + break; + case ALIGN_LEFT: + { + rRemainingSpace.X += nXDistance; + rRemainingSpace.Width -= nXDistance; + } + break; + case ALIGN_RIGHT: + { + rRemainingSpace.Width -= nXDistance; + } + break; + default: + break; + } + } return apVTitle; } @@ -2476,13 +2527,13 @@ void ChartView::createShapes() bool bAutoPositionDummy = true; //------------ create main title shape - lcl_createTitle( TitleHelper::getTitle( TitleHelper::MAIN_TITLE, m_xChartModel ), xPageShapes, m_xShapeFactory, m_xChartModel + lcl_createTitle( TitleHelper::MAIN_TITLE, xPageShapes, m_xShapeFactory, m_xChartModel , aRemainingSpace, aPageSize, ALIGN_TOP, bAutoPositionDummy ); if(aRemainingSpace.Width<=0||aRemainingSpace.Height<=0) return; //------------ create sub title shape - lcl_createTitle( TitleHelper::getTitle( TitleHelper::SUB_TITLE, m_xChartModel ), xPageShapes, m_xShapeFactory, m_xChartModel + lcl_createTitle( TitleHelper::SUB_TITLE, xPageShapes, m_xShapeFactory, m_xChartModel , aRemainingSpace, aPageSize, ALIGN_TOP, bAutoPositionDummy ); if(aRemainingSpace.Width<=0||aRemainingSpace.Height<=0) return; @@ -2506,7 +2557,7 @@ void ChartView::createShapes() bool bAutoPosition_XTitle = true; std::auto_ptr<VTitle> apVTitle_X; if( ChartTypeHelper::isSupportingMainAxis( xChartType, nDimension, 0 ) ) - apVTitle_X = lcl_createTitle( TitleHelper::getTitle( TitleHelper::TITLE_AT_STANDARD_X_AXIS_POSITION, m_xChartModel ), xPageShapes, m_xShapeFactory, m_xChartModel + apVTitle_X = lcl_createTitle( TitleHelper::TITLE_AT_STANDARD_X_AXIS_POSITION, xPageShapes, m_xShapeFactory, m_xChartModel , aRemainingSpace, aPageSize, ALIGN_BOTTOM, bAutoPosition_XTitle ); if(aRemainingSpace.Width<=0||aRemainingSpace.Height<=0) return; @@ -2515,7 +2566,7 @@ void ChartView::createShapes() bool bAutoPosition_YTitle = true; std::auto_ptr<VTitle> apVTitle_Y; if( ChartTypeHelper::isSupportingMainAxis( xChartType, nDimension, 1 ) ) - apVTitle_Y = lcl_createTitle( TitleHelper::getTitle( TitleHelper::TITLE_AT_STANDARD_Y_AXIS_POSITION, m_xChartModel ), xPageShapes, m_xShapeFactory, m_xChartModel + apVTitle_Y = lcl_createTitle( TitleHelper::TITLE_AT_STANDARD_Y_AXIS_POSITION, xPageShapes, m_xShapeFactory, m_xChartModel , aRemainingSpace, aPageSize, ALIGN_LEFT, bAutoPosition_YTitle ); if(aRemainingSpace.Width<=0||aRemainingSpace.Height<=0) return; @@ -2524,7 +2575,7 @@ void ChartView::createShapes() bool bAutoPosition_ZTitle = true; std::auto_ptr<VTitle> apVTitle_Z; if( ChartTypeHelper::isSupportingMainAxis( xChartType, nDimension, 2 ) ) - apVTitle_Z = lcl_createTitle( TitleHelper::getTitle( TitleHelper::Z_AXIS_TITLE, m_xChartModel ), xPageShapes, m_xShapeFactory, m_xChartModel + apVTitle_Z = lcl_createTitle( TitleHelper::Z_AXIS_TITLE, xPageShapes, m_xShapeFactory, m_xChartModel , aRemainingSpace, aPageSize, ALIGN_RIGHT, bAutoPosition_ZTitle ); if(aRemainingSpace.Width<=0||aRemainingSpace.Height<=0) return; @@ -2536,7 +2587,7 @@ void ChartView::createShapes() bool bAutoPosition_SecondXTitle = true; std::auto_ptr<VTitle> apVTitle_SecondX; if( ChartTypeHelper::isSupportingSecondaryAxis( xChartType, nDimension, 0 ) ) - apVTitle_SecondX = lcl_createTitle( TitleHelper::getTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, m_xChartModel ), xPageShapes, m_xShapeFactory, m_xChartModel + apVTitle_SecondX = lcl_createTitle( TitleHelper::SECONDARY_X_AXIS_TITLE, xPageShapes, m_xShapeFactory, m_xChartModel , aRemainingSpace, aPageSize, bIsVertical? ALIGN_RIGHT : ALIGN_TOP, bAutoPosition_SecondXTitle ); if(aRemainingSpace.Width<=0||aRemainingSpace.Height<=0) return; @@ -2545,7 +2596,7 @@ void ChartView::createShapes() bool bAutoPosition_SecondYTitle = true; std::auto_ptr<VTitle> apVTitle_SecondY; if( ChartTypeHelper::isSupportingSecondaryAxis( xChartType, nDimension, 1 ) ) - apVTitle_SecondY = lcl_createTitle( TitleHelper::getTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, m_xChartModel ), xPageShapes, m_xShapeFactory, m_xChartModel + apVTitle_SecondY = lcl_createTitle( TitleHelper::SECONDARY_Y_AXIS_TITLE, xPageShapes, m_xShapeFactory, m_xChartModel , aRemainingSpace, aPageSize, bIsVertical? ALIGN_TOP : ALIGN_RIGHT, bAutoPosition_SecondYTitle ); if(aRemainingSpace.Width<=0||aRemainingSpace.Height<=0) return; diff --git a/chart2/source/view/main/VLegend.cxx b/chart2/source/view/main/VLegend.cxx index 1b6abd9bb812..f0bcc12c0440 100644 --- a/chart2/source/view/main/VLegend.cxx +++ b/chart2/source/view/main/VLegend.cxx @@ -258,10 +258,11 @@ void lcl_placeLegendEntries( double fViewFontSize = lcl_CalcViewFontSize( xProperties, rPageSize ); // padding as percentage of the font height - double fXPadding = (1.0 / 5.0); - double fYPadding = (1.0 / 3.0); - double fXOffset = (1.0 / 5.0); - double fYOffset = (1.0 / 5.0); + // #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 ); @@ -273,8 +274,11 @@ void lcl_placeLegendEntries( rEntries, xShapeFactory, xTarget, aTextShapes, rTextProperties ); OSL_ASSERT( aTextShapes.size() == rEntries.size()); - awt::Size aMaxSymbolExtent( static_cast< sal_Int32 >( fViewFontSize * 3.0 / 2.0 ), - static_cast< sal_Int32 >( fViewFontSize )); + // #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; @@ -391,8 +395,13 @@ void lcl_placeLegendEntries( sal_Int32 nSymbolXPos = nCurrentXPos + ((aMaxSymbolExtent.Width - aSymbolSize.Width) / 2); if( !bSymbolsLeftSide ) nSymbolXPos = nSymbolXPos - aMaxSymbolExtent.Width; - xSymbol->setPosition( awt::Point( nSymbolXPos, - nCurrentYPos + ((aMaxSymbolExtent.Height - aSymbolSize.Height) / 2))); + + // #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 ); + xSymbol->setPosition( awt::Point( nSymbolXPos, nSymbolYPos ) ); } // position text shape @@ -435,37 +444,60 @@ void lcl_placeLegendEntries( rOutLegendSize.Height = nMaxYPos + nYPadding; } -double lcl_getPageLayoutDistancePercentage() +// #i109336# Improve auto positioning in chart +sal_Int32 lcl_getLegendLeftRightMargin() { - return 0.02; + return 210; // 1/100 mm +} + +// #i109336# Improve auto positioning in chart +sal_Int32 lcl_getLegendTopBottomMargin() +{ + return 185; // 1/100 mm } chart2::RelativePosition lcl_getDefaultPosition( LegendPosition ePos, const awt::Rectangle& rOutAvailableSpace, const awt::Size & rPageSize ) { - // shift legend about 2% of page size into the primary direction by default - const double fDefaultDistance = lcl_getPageLayoutDistancePercentage(); chart2::RelativePosition aResult; switch( ePos ) { case LegendPosition_LINE_START: - aResult = chart2::RelativePosition( - fDefaultDistance, 0.5, drawing::Alignment_LEFT ); + { + // #i109336# Improve auto positioning in chart + const double fDefaultDistance = ( static_cast< double >( lcl_getLegendLeftRightMargin() ) / + static_cast< double >( rPageSize.Width ) ); + aResult = chart2::RelativePosition( + fDefaultDistance, 0.5, drawing::Alignment_LEFT ); + } break; case LegendPosition_LINE_END: - aResult = chart2::RelativePosition( - 1.0 - fDefaultDistance, 0.5, drawing::Alignment_RIGHT ); + { + // #i109336# Improve auto positioning in chart + const double fDefaultDistance = ( static_cast< double >( lcl_getLegendLeftRightMargin() ) / + static_cast< double >( rPageSize.Width ) ); + aResult = chart2::RelativePosition( + 1.0 - fDefaultDistance, 0.5, drawing::Alignment_RIGHT ); + } break; case LegendPosition_PAGE_START: { + // #i109336# Improve auto positioning in chart + const double fDefaultDistance = ( static_cast< double >( lcl_getLegendTopBottomMargin() ) / + static_cast< double >( rPageSize.Height ) ); double fDistance = (static_cast<double>(rOutAvailableSpace.Y)/static_cast<double>(rPageSize.Height)) + fDefaultDistance; aResult = chart2::RelativePosition( 0.5, fDistance, drawing::Alignment_TOP ); } break; case LegendPosition_PAGE_END: - aResult = chart2::RelativePosition( - 0.5, 1.0 - fDefaultDistance, drawing::Alignment_BOTTOM ); + { + // #i109336# Improve auto positioning in chart + const double fDefaultDistance = ( static_cast< double >( lcl_getLegendTopBottomMargin() ) / + static_cast< double >( rPageSize.Height ) ); + aResult = chart2::RelativePosition( + 0.5, 1.0 - fDefaultDistance, drawing::Alignment_BOTTOM ); + } break; case LegendPosition_CUSTOM: @@ -498,31 +530,34 @@ awt::Point lcl_calculatePositionAndRemainingSpace( aResult, aLegendSize, aRelPos.Anchor ); // adapt rRemainingSpace if LegendPosition is not CUSTOM - sal_Int32 nYDistance = static_cast<sal_Int32>(rPageSize.Height*lcl_getPageLayoutDistancePercentage()); - sal_Int32 nXDistance = static_cast<sal_Int32>(rPageSize.Width*lcl_getPageLayoutDistancePercentage()); - rRemainingSpace.Width-=nXDistance; - rRemainingSpace.Height-=nYDistance; + // #i109336# Improve auto positioning in chart + sal_Int32 nXDistance = lcl_getLegendLeftRightMargin(); + sal_Int32 nYDistance = lcl_getLegendTopBottomMargin(); switch( ePos ) { case LegendPosition_LINE_START: - { - sal_Int32 nExtent = aLegendSize.Width; - rRemainingSpace.Width -= nExtent; - rRemainingSpace.X += ( nExtent + nXDistance ); - } + { + sal_Int32 nExtent = aLegendSize.Width; + rRemainingSpace.Width -= ( nExtent + nXDistance ); + rRemainingSpace.X += ( nExtent + nXDistance ); + } break; case LegendPosition_LINE_END: - rRemainingSpace.Width -= ( aLegendSize.Width ); + { + rRemainingSpace.Width -= ( aLegendSize.Width + nXDistance ); + } break; case LegendPosition_PAGE_START: - { - sal_Int32 nExtent = aLegendSize.Height; - rRemainingSpace.Height -= nExtent; - rRemainingSpace.Y += ( nExtent + nYDistance ); - } + { + sal_Int32 nExtent = aLegendSize.Height; + rRemainingSpace.Height -= ( nExtent + nYDistance ); + rRemainingSpace.Y += ( nExtent + nYDistance ); + } break; case LegendPosition_PAGE_END: - rRemainingSpace.Height -= ( aLegendSize.Height ); + { + rRemainingSpace.Height -= ( aLegendSize.Height + nYDistance ); + } break; default: @@ -672,8 +707,9 @@ void VLegend::createShapes( tPropertyValues aLineFillProperties; tPropertyValues aTextProperties; - // limit the width of texts to 20% of the total available width - sal_Int32 nMaxLabelWidth = rAvailableSpace.Width / 5; + // 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; if( xLegendProp.is()) diff --git a/chart2/source/view/main/VTitle.cxx b/chart2/source/view/main/VTitle.cxx index f804a505219f..f62142735b7c 100644 --- a/chart2/source/view/main/VTitle.cxx +++ b/chart2/source/view/main/VTitle.cxx @@ -253,6 +253,21 @@ void VTitle::createShapes( } } + // #i109336# Improve auto positioning in chart + float fFontHeight = 0.0; + if ( xShapeProp.is() && ( xShapeProp->getPropertyValue( C2U( "CharHeight" ) ) >>= fFontHeight ) ) + { + fFontHeight *= ( 2540. / 72. ); // pt -> 1/100 mm + float fXFraction = 0.18; + sal_Int32 nXDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * fXFraction ) ); + float fYFraction = 0.30; + sal_Int32 nYDistance = static_cast< sal_Int32 >( ::rtl::math::round( fFontHeight * fYFraction ) ); + xShapeProp->setPropertyValue( C2U( "TextLeftDistance" ), uno::makeAny( nXDistance ) ); + xShapeProp->setPropertyValue( C2U( "TextRightDistance" ), uno::makeAny( nXDistance ) ); + xShapeProp->setPropertyValue( C2U( "TextUpperDistance" ), uno::makeAny( nYDistance ) ); + xShapeProp->setPropertyValue( C2U( "TextLowerDistance" ), uno::makeAny( nYDistance ) ); + } + try { double fAngleDegree = 0; |