diff options
author | Winfried Donkers <winfrieddonkers@libreoffice.org> | 2019-02-02 13:05:03 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2019-05-20 12:58:31 +0200 |
commit | f6f27ae31a26bf6cecbf9205ef28a6bad3d06864 (patch) | |
tree | de50544bd58cb239b773397b99d865d40a433e7d /chart2 | |
parent | bae3031fac4bac621b5bfa9a907d87981d5fac29 (diff) |
tdf#90180 Add option to show errors as rectangles in diagrams with error bars.
The option is saved in registrymodifications.xcu, not yet in the document.
(cherry picked from commit 0fc471e8218b53b8b9e505d2af3e015abf3910f3)
Change-Id: I6facc8d6e456046003f2c38ce79a1fcfc712d027
Reviewed-on: https://gerrit.libreoffice.org/67280
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'chart2')
-rw-r--r-- | chart2/Library_chartcore.mk | 3 | ||||
-rw-r--r-- | chart2/source/view/charttypes/AreaChart.cxx | 27 | ||||
-rw-r--r-- | chart2/source/view/charttypes/ConfigAccess.cxx | 80 | ||||
-rw-r--r-- | chart2/source/view/charttypes/VSeriesPlotter.cxx | 161 | ||||
-rw-r--r-- | chart2/source/view/inc/ConfigAccess.hxx | 40 | ||||
-rw-r--r-- | chart2/source/view/inc/VSeriesPlotter.hxx | 15 |
6 files changed, 320 insertions, 6 deletions
diff --git a/chart2/Library_chartcore.mk b/chart2/Library_chartcore.mk index 86eae1a11941..e671110a753f 100644 --- a/chart2/Library_chartcore.mk +++ b/chart2/Library_chartcore.mk @@ -91,6 +91,7 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\ chart2/source/view/charttypes/BubbleChart \ chart2/source/view/charttypes/CandleStickChart \ chart2/source/view/charttypes/CategoryPositionHelper \ + chart2/source/view/charttypes/ConfigAccess \ chart2/source/view/charttypes/NetChart \ chart2/source/view/charttypes/PieChart \ chart2/source/view/charttypes/Splines \ @@ -237,5 +238,5 @@ $(eval $(call gb_Library_add_exception_objects,chartcore,\ chart2/source/tools/WrappedPropertySet \ chart2/source/tools/XMLRangeHelper \ )) - + # vim: set noet sw=4 ts=4: diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx index 2fa4f4e66dd0..2699121ed357 100644 --- a/chart2/source/view/charttypes/AreaChart.cxx +++ b/chart2/source/view/charttypes/AreaChart.cxx @@ -30,6 +30,7 @@ #include <Stripe.hxx> #include <DateHelper.hxx> #include <unonames.hxx> +#include <ConfigAccess.hxx> #include <com/sun/star/chart2/Symbol.hpp> #include <com/sun/star/chart/DataLabelPlacement.hpp> @@ -873,12 +874,28 @@ void AreaChart::createShapes() //@todo other symbol styles } } - //create error bars - if (bCreateXErrorBar) - createErrorBar_X( aUnscaledLogicPosition, *pSeries, nIndex, m_xErrorBarTarget ); + //create error bars or rectangles, depending on configuration + if ( ConfigAccess::getUseErrorRectangle() ) + { + if ( bCreateXErrorBar || bCreateYErrorBar ) + { + createErrorRectangle( + aUnscaledLogicPosition, + *pSeries, + nIndex, + m_xErrorBarTarget, + bCreateXErrorBar, + bCreateYErrorBar ); + } + } + else + { + if (bCreateXErrorBar) + createErrorBar_X( aUnscaledLogicPosition, *pSeries, nIndex, m_xErrorBarTarget ); - if (bCreateYErrorBar) - createErrorBar_Y( aUnscaledLogicPosition, *pSeries, nIndex, m_xErrorBarTarget, nullptr ); + if (bCreateYErrorBar) + createErrorBar_Y( aUnscaledLogicPosition, *pSeries, nIndex, m_xErrorBarTarget, nullptr ); + } //create data point label if( pSeries->getDataPointLabelIfLabel(nIndex) ) diff --git a/chart2/source/view/charttypes/ConfigAccess.cxx b/chart2/source/view/charttypes/ConfigAccess.cxx new file mode 100644 index 000000000000..bca2b6dd99ef --- /dev/null +++ b/chart2/source/view/charttypes/ConfigAccess.cxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <ConfigAccess.hxx> + +#include <unotools/syslocale.hxx> +#include <unotools/configitem.hxx> +#include <unotools/localedatawrapper.hxx> +#include <o3tl/any.hxx> +#include <rtl/instance.hxx> + +namespace chart +{ +using namespace ::com::sun::star; + +class ChartConfigItem : public ::utl::ConfigItem +{ +private: + virtual void ImplCommit() override; + +public: + ChartConfigItem(); + + bool getUseErrorRectangle(); + virtual void Notify(const uno::Sequence<OUString>& aPropertyNames) override; +}; + +ChartConfigItem::ChartConfigItem() + : ConfigItem("Office.Chart/ErrorProperties") +{ +} + +void ChartConfigItem::ImplCommit() {} +void ChartConfigItem::Notify(const uno::Sequence<OUString>&) {} + +bool ChartConfigItem::getUseErrorRectangle() +{ + uno::Sequence<OUString> aNames(1); + aNames[0] = "ErrorRectangle"; + + auto b = o3tl::tryAccess<bool>(GetProperties(aNames)[0]); + return b && *b; +} + +namespace +{ +//a ChartConfigItem Singleton +struct theChartConfigItem : public rtl::Static<ChartConfigItem, theChartConfigItem> +{ +}; +} + +namespace ConfigAccess +{ +bool getUseErrorRectangle() +{ + bool bResult(theChartConfigItem::get().getUseErrorRectangle()); + return bResult; +} +} //namespace ConfigAccess + +} //namespace chart + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/charttypes/VSeriesPlotter.cxx b/chart2/source/view/charttypes/VSeriesPlotter.cxx index c7de326f0d8d..17f044654535 100644 --- a/chart2/source/view/charttypes/VSeriesPlotter.cxx +++ b/chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -1070,6 +1070,167 @@ void VSeriesPlotter::createErrorBar( } +void VSeriesPlotter::addErrorBorder( + const drawing::Position3D& rPos0 + ,const drawing::Position3D& rPos1 + ,const uno::Reference< drawing::XShapes >& rTarget + ,const uno::Reference< beans::XPropertySet >& rErrorBorderProp ) +{ + drawing::PolyPolygonShape3D aPoly; + sal_Int32 nSequenceIndex = 0; + AddPointToPoly( aPoly, rPos0, nSequenceIndex ); + AddPointToPoly( aPoly, rPos1, nSequenceIndex ); + uno::Reference< drawing::XShape > xShape = m_pShapeFactory->createLine2D( + rTarget, PolyToPointSequence( aPoly) ); + setMappedProperties( xShape, rErrorBorderProp, + PropertyMapper::getPropertyNameMapForLineProperties() ); +} + +void VSeriesPlotter::createErrorRectangle( + const drawing::Position3D& rUnscaledLogicPosition + ,VDataSeries& rVDataSeries + ,sal_Int32 nIndex + ,const uno::Reference< drawing::XShapes >& rTarget + ,bool bUseXErrorData + ,bool bUseYErrorData ) +{ + if ( m_nDimension != 2 ) + return; + + // error border properties + Reference< beans::XPropertySet > xErrorBorderPropX, xErrorBorderPropY; + if ( bUseXErrorData ) + { + xErrorBorderPropX = rVDataSeries.getXErrorBarProperties( nIndex ); + if ( !xErrorBorderPropX.is() ) + return; + } + uno::Reference< drawing::XShapes > xErrorBorder_ShapesX( + getErrorBarsGroupShape( rVDataSeries, rTarget, false ) ); + + if ( bUseYErrorData ) + { + xErrorBorderPropY = rVDataSeries.getYErrorBarProperties( nIndex ); + if ( !xErrorBorderPropY.is() ) + return; + } + uno::Reference< drawing::XShapes > xErrorBorder_ShapesY( + getErrorBarsGroupShape( rVDataSeries, rTarget, true ) ); + + if( !ChartTypeHelper::isSupportingStatisticProperties( m_xChartTypeModel, m_nDimension ) ) + return; + + try + { + bool bShowXPositive = false; + bool bShowXNegative = false; + bool bShowYPositive = false; + bool bShowYNegative = false; + + sal_Int32 nErrorBorderStyleX = css::chart::ErrorBarStyle::VARIANCE; + sal_Int32 nErrorBorderStyleY = css::chart::ErrorBarStyle::VARIANCE; + + if ( bUseXErrorData ) + { + xErrorBorderPropX->getPropertyValue( "ErrorBarStyle" ) >>= nErrorBorderStyleX; + xErrorBorderPropX->getPropertyValue( "ShowPositiveError") >>= bShowXPositive; + xErrorBorderPropX->getPropertyValue( "ShowNegativeError") >>= bShowXNegative; + } + if ( bUseYErrorData ) + { + xErrorBorderPropY->getPropertyValue( "ErrorBarStyle" ) >>= nErrorBorderStyleY; + xErrorBorderPropY->getPropertyValue( "ShowPositiveError") >>= bShowYPositive; + xErrorBorderPropY->getPropertyValue( "ShowNegativeError") >>= bShowYNegative; + } + + if ( bUseXErrorData && nErrorBorderStyleX == css::chart::ErrorBarStyle::NONE ) + bUseXErrorData = false; + if ( bUseYErrorData && nErrorBorderStyleY == css::chart::ErrorBarStyle::NONE ) + bUseYErrorData = false; + + if ( !bShowXPositive && !bShowXNegative && !bShowYPositive && !bShowYNegative ) + return; + + if ( !m_pPosHelper ) + return; + + drawing::Position3D aUnscaledLogicPosition( rUnscaledLogicPosition ); + if ( bUseXErrorData && nErrorBorderStyleX == css::chart::ErrorBarStyle::STANDARD_DEVIATION ) + aUnscaledLogicPosition.PositionX = rVDataSeries.getXMeanValue(); + if ( bUseYErrorData && nErrorBorderStyleY == css::chart::ErrorBarStyle::STANDARD_DEVIATION ) + aUnscaledLogicPosition.PositionY = rVDataSeries.getYMeanValue(); + + const double fX = aUnscaledLogicPosition.PositionX; + const double fY = aUnscaledLogicPosition.PositionY; + const double fZ = aUnscaledLogicPosition.PositionZ; + double fScaledX = fX; + m_pPosHelper->doLogicScaling( &fScaledX, nullptr, nullptr ); + + uno::Sequence< double > aDataX( rVDataSeries.getAllX() ); + uno::Sequence< double > aDataY( rVDataSeries.getAllY() ); + + double fPosX = 0.0; + double fPosY = 0.0; + double fNegX = 0.0; + double fNegY = 0.0; + if ( bUseXErrorData ) + { + if ( bShowXPositive ) + fPosX = lcl_getErrorBarLogicLength( aDataX, xErrorBorderPropX, + nErrorBorderStyleX, nIndex, true, false ); + if ( bShowXNegative ) + fNegX = lcl_getErrorBarLogicLength( aDataX, xErrorBorderPropX, + nErrorBorderStyleX, nIndex, false, false ); + } + + if ( bUseYErrorData ) + { + if ( bShowYPositive ) + fPosY = lcl_getErrorBarLogicLength( aDataY, xErrorBorderPropY, + nErrorBorderStyleY, nIndex, true, true ); + if ( bShowYNegative ) + fNegY = lcl_getErrorBarLogicLength( aDataY, xErrorBorderPropY, + nErrorBorderStyleY, nIndex, false, true ); + } + + if ( !( ::rtl::math::isFinite( fPosX ) && + ::rtl::math::isFinite( fPosY ) && + ::rtl::math::isFinite( fNegX ) && + ::rtl::math::isFinite( fNegY ) ) ) + return; + + drawing::Position3D aBottomLeft( lcl_transformMixedToScene( m_pPosHelper, + fX - fNegX, fY - fNegY, fZ ) ); + drawing::Position3D aTopLeft( lcl_transformMixedToScene( m_pPosHelper, + fX - fNegX, fY + fPosY, fZ ) ); + drawing::Position3D aTopRight( lcl_transformMixedToScene( m_pPosHelper, + fX + fPosX, fY + fPosY, fZ ) ); + drawing::Position3D aBottomRight( lcl_transformMixedToScene( m_pPosHelper, + fX + fPosX, fY - fNegY, fZ ) ); + if ( bUseXErrorData ) + { + // top border + addErrorBorder( aTopLeft, aTopRight, xErrorBorder_ShapesX, xErrorBorderPropX ); + + // bottom border + addErrorBorder( aBottomRight, aBottomLeft, xErrorBorder_ShapesX, xErrorBorderPropX ); + } + + if ( bUseYErrorData ) + { + // left border + addErrorBorder( aBottomLeft, aTopLeft, xErrorBorder_ShapesY, xErrorBorderPropY ); + + // right border + addErrorBorder( aTopRight, aBottomRight, xErrorBorder_ShapesY, xErrorBorderPropY ); + } + } + catch( const uno::Exception & ) + { + DBG_UNHANDLED_EXCEPTION("chart2", "Exception in createErrorRectangle(). "); + } +} + void VSeriesPlotter::createErrorBar_X( const drawing::Position3D& rUnscaledLogicPosition , VDataSeries& rVDataSeries, sal_Int32 nPointIndex , const uno::Reference< drawing::XShapes >& xTarget ) diff --git a/chart2/source/view/inc/ConfigAccess.hxx b/chart2/source/view/inc/ConfigAccess.hxx new file mode 100644 index 000000000000..556b371f1d81 --- /dev/null +++ b/chart2/source/view/inc/ConfigAccess.hxx @@ -0,0 +1,40 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CHART2_SOURCE_VIEW_INC_CONFIGACCESS_HXX +#define INCLUDED_CHART2_SOURCE_VIEW_INC_CONFIGACCESS_HXX + +namespace chart +{ +namespace ConfigAccess +{ +/** @descr Retrieve the setting for showing errors in charts from the registry + settings of the Calc application. + + If this setting is not found, it is set to false (the default setting). + + @return boolean UseErrorRectangle. + */ +bool getUseErrorRectangle(); +} + +} //namespace chart +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/chart2/source/view/inc/VSeriesPlotter.hxx b/chart2/source/view/inc/VSeriesPlotter.hxx index 445411523359..ab6f8a81005b 100644 --- a/chart2/source/view/inc/VSeriesPlotter.hxx +++ b/chart2/source/view/inc/VSeriesPlotter.hxx @@ -367,6 +367,21 @@ protected: , const double* pfScaledLogicX ); + void createErrorRectangle( + const css::drawing::Position3D& rUnscaledLogicPosition + , VDataSeries& rVDataSeries + , sal_Int32 nIndex + , const css::uno::Reference< css::drawing::XShapes >& rTarget + , bool bUseXErrorData + , bool bUseYErrorData + ); + + void addErrorBorder( + const css::drawing::Position3D& rPos0 + , const css::drawing::Position3D& rPos1 + , const css::uno::Reference< css::drawing::XShapes >& rTarget + , const css::uno::Reference< css::beans::XPropertySet >& rErrorBorderProp ); + void createErrorBar_X( const css::drawing::Position3D& rUnscaledLogicPosition , VDataSeries& rVDataSeries, sal_Int32 nPointIndex , const css::uno::Reference< css::drawing::XShapes >& xTarget ); |