Kaydet (Commit) f6f27ae3 authored tarafından Winfried Donkers's avatar Winfried Donkers Kaydeden (comit) Eike Rathke

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: 's avatarEike Rathke <erack@redhat.com>
üst bae3031f
......@@ -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:
......@@ -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) )
......
/* -*- 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: */
......@@ -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 )
......
/* -*- 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: */
......@@ -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 );
......
......@@ -39,5 +39,18 @@
<!-- 0x004586 0xff420e 0xffd320 0x579d1c 0x7e0021 0x83caff 0x314004 0xaecf00 0x4b1f6f 0xff950e 0xc5000b 0x0084d1 -->
</prop>
</group>
<group oor:name="ErrorProperties">
<info>
<desc>Specifies properties for error presentation in new charts.</desc>
</info>
<prop oor:name="ErrorRectangle" oor:type="xs:boolean" oor:nillable="false">
<!-- UIHints: Tools - Options - Advanced -->
<info>
<desc>Option to show errors as rectangles in charts.</desc>
<label>Error rectangles</label>
</info>
<value>false</value>
</prop>
</group>
</component>
</oor:component-schema>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment