37#include <unonames.hxx>
40#include <com/sun/star/chart/MissingValueTreatment.hpp>
41#include <com/sun/star/chart/XDiagramPositioning.hpp>
42#include <com/sun/star/chart2/XAnyDescriptionAccess.hpp>
43#include <com/sun/star/chart2/AxisType.hpp>
44#include <com/sun/star/chart2/DataPointGeometry3D.hpp>
45#include <com/sun/star/chart2/RelativePosition.hpp>
46#include <com/sun/star/chart2/RelativeSize.hpp>
47#include <com/sun/star/chart2/StackingDirection.hpp>
49#include <com/sun/star/util/CloseVetoException.hpp>
50#include <com/sun/star/util/NumberFormat.hpp>
51#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
55#include <rtl/math.hxx>
70using ::com::sun::star::uno::Reference;
71using ::com::sun::star::uno::Sequence;
72using ::com::sun::star::uno::Any;
73using ::com::sun::star::chart2::XAnyDescriptionAccess;
80 bool& rbFound,
bool& rbAmbiguous,
89 const std::vector< rtl::Reference< DataSeries > > & aSeries = xChartType->getDataSeries2();
91 chart2::StackingDirection eCommonDirection = chart2::StackingDirection_NO_STACKING;
92 bool bDirectionInitialized =
false;
96 const sal_Int32 nSeriesCount = aSeries.size();
97 sal_Int32
i = (nSeriesCount == 1) ? 0: 1;
98 for( ;
i<nSeriesCount; ++
i )
101 chart2::StackingDirection eCurrentDirection = eCommonDirection;
103 bool bSuccess = ( aSeries[
i]->getPropertyValue(
"StackingDirection" ) >>= eCurrentDirection );
104 OSL_ASSERT( bSuccess );
105 if( ! bDirectionInitialized )
107 eCommonDirection = eCurrentDirection;
108 bDirectionInitialized =
true;
112 if( eCommonDirection != eCurrentDirection )
122 if( eCommonDirection == chart2::StackingDirection_Z_STACKING )
124 else if( eCommonDirection == chart2::StackingDirection_Y_STACKING )
129 if( xCorrespondingCoordinateSystem.is() )
131 if( 1 < xCorrespondingCoordinateSystem->getDimension() )
133 sal_Int32 nAxisIndex = 0;
138 xCorrespondingCoordinateSystem->getAxisByDimension2( 1,nAxisIndex );
141 chart2::ScaleData aScaleData = xAxis->getScaleData();
142 if( aScaleData.AxisType==chart2::AxisType::PERCENT )
150 catch(
const uno::Exception & )
162 return (nAxisIndex==0);
171 OUString aMainSeq( xChartType->getRoleOfSequenceForSeriesLabel() );
173 const std::vector< rtl::Reference< DataSeries > > & aSeriesSeq = xChartType->getDataSeries2();
178 if( !xLabeledSeq.is() )
181 if( !xValueSeq.is() )
183 rRet = xValueSeq->generateLabel( chart2::data::LabelOrigin_LONG_SIDE );
184 if( rRet.hasElements() )
195 const std::vector< rtl::Reference< ChartType > > & aChartTypes( xCooSys->getChartTypes2() );
199 if( aRet.hasElements() )
220 if( !xChartDoc.is() )
223 ScaleData aScale( xAxis->getScaleData() );
224 if( xChartDoc->hasInternalDataProvider() )
228 if( xDataAccess.is() )
231 auto aAnyCategoriesRange = asNonConstRange(aAnyCategories);
233 sal_Int32 nN = aAnyCategories.getLength();
237 if( rCat.getLength() > 1 )
239 if( rCat.getLength() == 1 )
241 Any& rAny = rCat.getArray()[0];
242 if( !(rAny>>=fTest) )
244 rAny <<= std::numeric_limits<double>::quiet_NaN();
248 xDataAccess->setAnyRowDescriptions( aAnyCategories );
251 Reference< beans::XPropertySet > xAxisProps( xAxis, uno::UNO_QUERY );
252 if( xAxisProps.is() )
254 sal_Int32 nNumberFormat = -1;
257 Reference< util::XNumberFormats > xNumberFormats( xChartDoc->getNumberFormats() );
258 if( xNumberFormats.is() )
260 Reference< beans::XPropertySet > xKeyProps;
263 xKeyProps = xNumberFormats->getByKey( nNumberFormat );
265 catch(
const uno::Exception & )
269 sal_Int32
nType = util::NumberFormat::UNDEFINED;
271 xKeyProps->getPropertyValue(
"Type" ) >>=
nType;
272 if( !( nType & util::NumberFormat::DATE ) )
276 Sequence<sal_Int32> aKeySeq = xNumberFormats->queryKeys( util::NumberFormat::DATE, rLocaleDataWrapper.
getLanguageTag().
getLocale(),
true );
277 if( aKeySeq.hasElements() )
285 if( aScale.AxisType != chart2::AxisType::DATE )
287 aScale.AxisType = chart2::AxisType::DATE;
288 xAxis->setScaleData( aScale );
295 if( !xChartDoc.is() )
297 ScaleData aScale( xAxis->getScaleData() );
298 if( aScale.AxisType != chart2::AxisType::CATEGORY )
301 aScale.AxisType = chart2::AxisType::CATEGORY;
302 aScale.AutoDateAxis =
false;
303 xAxis->setScaleData( aScale );
318 lcl_switchToDateCategories( xChartDoc, xAxis );
333 lcl_switchToTextCategories( xChartDoc, xAxis );
340 bool bIsDate =
false;
341 if( !xNumberFormats.is() )
347 sal_Int32
nType = util::NumberFormat::UNDEFINED;
348 xKeyProps->getPropertyValue(
"Type" ) >>=
nType;
349 bIsDate =
nType & util::NumberFormat::DATE;
369 if( xNumberFormats.is() )
373 if( aKeySeq.hasElements() )
390 SAL_WARN(
"chart2",
"DiagramHelper::getDateTimeInputNumberFormat - no SvNumberFormatter");
415 if( xNumberFormats.is() )
419 if( aKeySeq.hasElements() )
435 if( !xFirstType.is() || !xSecondType.is() )
440 std::sort( aFirstRoles.begin(), aFirstRoles.end() );
441 std::sort( aSecondRoles.begin(), aSecondRoles.end() );
442 return ( aFirstRoles == aSecondRoles );
454 const awt::Rectangle& rPosRect )
458 bool bChanged =
false;
464 RelativePosition aOldPos;
466 xDiagram->getPropertyValue(
"RelativePosition" ) >>= aOldPos;
467 xDiagram->getPropertyValue(
"RelativeSize" ) >>= aOldSize;
469 RelativePosition aNewPos;
470 aNewPos.Anchor = drawing::Alignment_TOP_LEFT;
471 aNewPos.Primary = double(rPosRect.X)/double(aPageSize.Width);
472 aNewPos.Secondary = double(rPosRect.Y)/double(aPageSize.Height);
474 chart2::RelativeSize aNewSize;
475 aNewSize.Primary = double(rPosRect.Width)/double(aPageSize.Width);
476 aNewSize.Secondary = double(rPosRect.Height)/double(aPageSize.Height);
482 if( (aNewPos.Primary + aNewSize.Primary) > 1.0 )
483 aNewPos.Primary = 1.0 - aNewSize.Primary;
484 if( (aNewPos.Secondary + aNewSize.Secondary) > 1.0 )
485 aNewPos.Secondary = 1.0 - aNewSize.Secondary;
487 xDiagram->setPropertyValue(
"RelativePosition",
uno::Any(aNewPos) );
488 xDiagram->setPropertyValue(
"RelativeSize",
uno::Any(aNewSize) );
490 bChanged = (aOldPos.Anchor!=aNewPos.Anchor) ||
491 (aOldPos.Primary!=aNewPos.Primary) ||
492 (aOldPos.Secondary!=aNewPos.Secondary) ||
493 (aOldSize.Primary!=aNewSize.Primary) ||
494 (aOldSize.Secondary!=aNewSize.Secondary);
500 awt::Rectangle aRet(-1,-1,-1,-1);
508 RelativePosition aRelPos;
510 xDiagram->getPropertyValue(
"RelativePosition" ) >>= aRelPos;
511 xDiagram->getPropertyValue(
"RelativeSize" ) >>= aRelSize;
514 static_cast< sal_Int32
>( aRelSize.Primary * aPageSize.Width ),
515 static_cast< sal_Int32
>( aRelSize.Secondary * aPageSize.Height ));
518 static_cast< sal_Int32
>( aRelPos.Primary * aPageSize.Width ),
519 static_cast< sal_Int32
>( aRelPos.Secondary * aPageSize.Height ));
523 aRet = awt::Rectangle(aAbsPosLeftTop.X, aAbsPosLeftTop.Y, aAbsSize.Width, aAbsSize.Height );
529 ChartModel& rModel,
bool bResetModifiedState,
bool bConvertAlsoFromAutoPositioning )
536 if( xDiagramPositioning.is() && ( bConvertAlsoFromAutoPositioning || !xDiagramPositioning->isAutomaticDiagramPositioning() )
537 && !xDiagramPositioning->isExcludingDiagramPositioning() )
540 bool bModelWasModified = rModel.isModified();
541 xDiagramPositioning->setDiagramPositionExcludingAxes( xDiagramPositioning->calculateDiagramPositionExcludingAxes() );
542 if(bResetModifiedState && !bModelWasModified )
543 rModel.setModified(
false);
const LanguageTag & GetLanguageTag() const
const LocaleDataWrapper & GetLocaleDataWrapper() const
static const AllSettings & GetSettings()
LanguageType getLanguageType(bool bResolveSystem=true) const
const css::lang::Locale & getLocale(bool bResolveSystem=true) const
const LanguageTag & getLanguageTag() const
static void removeExplicitScaling(css::chart2::ScaleData &rScaleData)
static css::awt::Size getPageSize(const rtl::Reference<::chart::ChartModel > &xModel)
static rtl::Reference< ::chart::BaseCoordinateSystem > getFirstCoordinateSystem(const rtl::Reference<::chart::ChartModel > &xModel)
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static bool setDiagramPositioning(const rtl::Reference<::chart::ChartModel > &xChartModel, const css::awt::Rectangle &rPosRect)
static SAL_DLLPRIVATE bool areChartTypesCompatible(const rtl::Reference< ::chart::ChartType > &xFirstType, const rtl::Reference< ::chart::ChartType > &xSecondType)
static StackMode getStackModeFromChartType(const rtl::Reference< ::chart::ChartType > &xChartType, bool &rbFound, bool &rbAmbiguous, const rtl::Reference< ::chart::BaseCoordinateSystem > &xCorrespondingCoordinateSystem)
Retrieves the stackmode of the first DataSeries or none.
static void switchToDateCategories(const rtl::Reference<::chart::ChartModel > &xChartDoc)
static sal_Int32 getPercentNumberFormat(const css::uno::Reference< css::util::XNumberFormatsSupplier > &xNumberFormatsSupplier)
static SAL_DLLPRIVATE css::uno::Sequence< OUString > generateAutomaticCategoriesFromCooSys(const rtl::Reference< ::chart::BaseCoordinateSystem > &xCooSys)
static css::awt::Rectangle getDiagramRectangleFromModel(const rtl::Reference<::chart::ChartModel > &xChartModel)
static bool switchDiagramPositioningToExcludingPositioning(ChartModel &rModel, bool bResetModifiedState, bool bConvertAlsoFromAutoPositioning)
static bool isSeriesAttachedToMainAxis(const rtl::Reference< ::chart::DataSeries > &xDataSeries)
static css::uno::Sequence< OUString > getExplicitSimpleCategories(ChartModel &rModel)
static bool isDateNumberFormat(sal_Int32 nNumberFormat, const css::uno::Reference< css::util::XNumberFormats > &xNumberFormats)
static sal_Int32 getDateNumberFormat(const css::uno::Reference< css::util::XNumberFormatsSupplier > &xNumberFormatsSupplier)
static void switchToTextCategories(const rtl::Reference<::chart::ChartModel > &xChartDoc)
static sal_Int32 getDateTimeInputNumberFormat(const css::uno::Reference< css::util::XNumberFormatsSupplier > &xNumberFormatsSupplier, double fNumber)
css::uno::Sequence< OUString > const & getSimpleCategories()
static css::awt::Point getUpperLeftCornerOfAnchoredObject(css::awt::Point aPoint, css::awt::Size aObjectSize, css::drawing::Alignment aAnchor)
returns the upper left corner of an object that has size aObjectSize and where the point indicated by...
#define DBG_UNHANDLED_EXCEPTION(...)
#define SAL_WARN(area, stream)
OOO_DLLPUBLIC_CHARTTOOLS css::uno::Reference< css::chart2::data::XLabeledDataSequence > getDataSequenceByRole(const css::uno::Reference< css::chart2::data::XDataSource > &xSource, const OUString &aRole, bool bMatchPrefix=false)
Retrieves the data sequence in the given data source that matches the given role.
OOO_DLLPUBLIC_CHARTTOOLS sal_Int32 getAttachedAxisIndex(const rtl::Reference< ::chart::DataSeries > &xSeries)
static void lcl_generateAutomaticCategoriesFromChartType(Sequence< OUString > &rRet, const rtl::Reference< ChartType > &xChartType)
static void lcl_ensureRange0to1(double &rValue)
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
UNOTOOLS_DLLPUBLIC SvtSaveOptions::ODFSaneDefaultVersion GetODFSaneDefaultVersion()
constexpr OUStringLiteral CHART_UNONAME_NUMFMT