33#include <rtl/math.hxx>
37#include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
38#include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
39#include <com/sun/star/chart/ChartAxisPosition.hpp>
40#include <com/sun/star/chart/ChartAxisType.hpp>
41#include <com/sun/star/chart/TimeIncrement.hpp>
42#include <com/sun/star/chart/TimeInterval.hpp>
43#include <com/sun/star/chart/TimeUnit.hpp>
44#include <com/sun/star/chart/XAxis.hpp>
45#include <com/sun/star/chart/XAxisSupplier.hpp>
46#include <com/sun/star/chart/XChartDocument.hpp>
47#include <com/sun/star/chart2/AxisType.hpp>
48#include <com/sun/star/chart2/XChartDocument.hpp>
49#include <com/sun/star/chart2/XCoordinateSystemContainer.hpp>
51#include <com/sun/star/drawing/LineStyle.hpp>
68 {
XML_AUTO, css::chart::ChartAxisType::AUTOMATIC },
69 {
XML_TEXT, css::chart::ChartAxisType::CATEGORY },
70 {
XML_DATE, css::chart::ChartAxisType::DATE },
82 SchXMLCategoriesContext( SvXMLImport& rImport,
85 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
override;
91 DateScaleContext( SvXMLImport& rImport,
95 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
override;
104 SvXMLImport& rImport,
106 std::vector< SchXMLAxis >& rAxes,
107 OUString & rCategoriesAddress,
108 bool bAddMissingXAxisForNetCharts,
109 bool bAdaptWrongPercentScaleValues,
110 bool bAdaptXAxisOrientationForOld2DBarCharts,
111 bool& rbAxisPositionAttributeImported ) :
113 m_rImportHelper( rImpHelper ),
114 m_xDiagram( xDiagram ),
116 m_rCategoriesAddress( rCategoriesAddress ),
118 m_bAxisTypeImported(false),
119 m_bDateScaleImported(false),
120 m_bAddMissingXAxisForNetCharts( bAddMissingXAxisForNetCharts ),
121 m_bAdaptWrongPercentScaleValues( bAdaptWrongPercentScaleValues ),
122 m_bAdaptXAxisOrientationForOld2DBarCharts( bAdaptXAxisOrientationForOld2DBarCharts ),
123 m_rbAxisPositionAttributeImported( rbAxisPositionAttributeImported )
134 if( !xAxisSuppl.is() )
137 xAxis = xAxisSuppl->getAxis(rCurrentAxis.
eDimension);
139 xAxis = xAxisSuppl->getSecondaryAxis(rCurrentAxis.
eDimension);
151 if( !xDiaProp.is() || !xAxis.is() )
173 SAL_INFO(
"xmloff.chart",
"Invalid axis" );
177 xResult.set( xAxis->getAxisTitle(), uno::UNO_QUERY );
185 if( !xDiaProp.is() || !xAxis.is() )
210 SAL_INFO(
"xmloff.chart",
"Invalid axis" );
217 xGridProp = xAxis->getMajorGrid();
219 xGridProp = xAxis->getMinorGrid();
225 xGridProp->setPropertyValue(
"LineColor",
227 if (!sAutoStyleName.isEmpty())
233 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
238 switch(aIter.getToken())
269 sal_Int32 nNumOfAxes =
m_rAxes.size();
270 for( sal_Int32 nCurrent = 0; nCurrent < nNumOfAxes; nCurrent++ )
281 sal_Int32 nDimensionIndex, sal_Int32 nAxisIndex )
288 if( xChart2Document.is() )
292 uno::Sequence< Reference< chart2::XCoordinateSystem > >
293 aCooSysSeq( xCooSysCnt->getCoordinateSystems());
294 sal_Int32 nCooSysIndex = 0;
295 if( nCooSysIndex < aCooSysSeq.getLength() )
298 if( xCooSys.is() && nDimensionIndex < xCooSys->getDimension() )
300 const sal_Int32 nMaxAxisIndex = xCooSys->getMaximumAxisIndexByDimension(nDimensionIndex);
301 if( nAxisIndex <= nMaxAxisIndex )
302 xAxis = xCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
307 catch( uno::Exception & )
309 SAL_INFO(
"xmloff.chart",
"Couldn't get axis" );
315bool lcl_divideBy100(
uno::Any& rDoubleAny )
317 bool bChanged =
false;
319 if( (rDoubleAny>>=fValue) && (fValue!=0.0) )
322 rDoubleAny <<= fValue;
328bool lcl_AdaptWrongPercentScaleValues(chart2::ScaleData& rScaleData)
330 bool bChanged = lcl_divideBy100( rScaleData.Minimum );
331 bChanged = lcl_divideBy100( rScaleData.Maximum ) || bChanged;
332 bChanged = lcl_divideBy100( rScaleData.Origin ) || bChanged;
333 bChanged = lcl_divideBy100( rScaleData.IncrementData.Distance ) || bChanged;
366 SAL_INFO(
"xmloff.chart",
"Invalid axis" );
373 catch( beans::UnknownPropertyException & )
375 SAL_INFO(
"xmloff.chart",
"Couldn't turn on axis" );
379 bool bSettingZAxisSucceeded =
false;
382 xDiaProp->getPropertyValue(
aPropName ) >>= bSettingZAxisSucceeded;
384 catch( beans::UnknownPropertyException & )
386 SAL_INFO(
"xmloff.chart",
"Couldn't turn on z axis" );
388 if( !bSettingZAxisSucceeded )
398 xDiaProp->setPropertyValue(
"HasXAxis",
uno::Any(
true) );
400 catch( beans::UnknownPropertyException & )
402 SAL_INFO(
"xmloff.chart",
"Couldn't turn on x axis" );
417 m_xAxisProps->setPropertyValue(
"DisplayLabels", aFalseBool );
423 if(
GetImport().getGeneratorVersion() != SvXMLImport::ProductVersionUnknown )
424 m_xAxisProps->setPropertyValue(
"TryStaggeringFirst", aTrueBool );
427 m_xAxisProps->setPropertyValue(
"AutoOrigin", aTrueBool );
450 chart2::ScaleData aScaleData( xAxis->getScaleData());
451 if( lcl_AdaptWrongPercentScaleValues(aScaleData) )
452 xAxis->setScaleData( aScaleData );
461 if( xAxisSuppl.is() )
464 pPropStyleContext->FillPropertySet(xXAxisProp);
472 chart2::ScaleData aScaleData;
473 aScaleData.AxisType = chart2::AxisType::CATEGORY;
474 aScaleData.Orientation = chart2::AxisOrientation_MATHEMATICAL;
475 xAxis->setScaleData( aScaleData );
480 if( xNewAxisProp.is() )
482 xNewAxisProp->setPropertyValue(
"LineStyle"
483 ,
uno::Any(drawing::LineStyle_NONE));
489 bool bIs3DChart =
false;
490 if( xDiaProp.is() && ( xDiaProp->getPropertyValue(
"Dim3D") >>= bIs3DChart )
494 if( xChart2Document.is() )
497 if( xCooSysCnt.is() )
499 uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems() );
500 if( aCooSysSeq.hasElements() )
502 bool bSwapXandYAxis =
false;
505 if( xCooSysProp.is() && ( xCooSysProp->getPropertyValue(
"SwapXAndYAxis") >>= bSwapXandYAxis )
511 chart2::ScaleData aScaleData = xAxis->getScaleData();
512 aScaleData.Orientation = chart2::AxisOrientation_REVERSE;
513 xAxis->setScaleData( aScaleData );
523 u"CrossoverPosition", pPropStyleContext, pStylesCtxt ).
hasValue();
535 chart2::ScaleData aScaleData(xAxis->getScaleData());
536 bool bIs3DChart =
false;
537 double fMajorOrigin = -1;
538 OUString sChartType =
m_xDiagram->getDiagramType();
539 if ((xDiaProp->getPropertyValue(
"Dim3D") >>= bIs3DChart) && bIs3DChart
540 && (sChartType ==
"com.sun.star.chart.BarDiagram" || sChartType ==
"com.sun.star.chart.StockDiagram"))
542 aScaleData.ShiftedCategoryPosition =
true;
543 xAxis->setScaleData(aScaleData);
545 else if ((
m_xAxisProps->getPropertyValue(
"MajorOrigin") >>= fMajorOrigin)
546 && (rtl::math::approxEqual(fMajorOrigin, 0.0) || rtl::math::approxEqual(fMajorOrigin, 0.5)))
548 aScaleData.ShiftedCategoryPosition = rtl::math::approxEqual(fMajorOrigin, 0.5);
549 xAxis->setScaleData(aScaleData);
564 if( xTitleProp.is() )
570 catch( beans::UnknownPropertyException & )
572 SAL_INFO(
"xmloff.chart",
"Property String for Title not available" );
579 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
594 return new SchXMLCategoriesContext(
GetImport(),
605 bool bIsMajor =
true;
606 OUString sAutoStyleName;
610 switch (aIter.getToken())
617 sAutoStyleName = aIter.toString();
645 chart2::ScaleData aScaleData( xAxis->getScaleData());
646 aScaleData.AutoDateAxis =
false;
647 xAxis->setScaleData( aScaleData );
662 xAxis = rCooSys->getAxisByDimension( nDimensionIndex, nAxisIndex );
664 catch( uno::Exception & )
673 std::u16string_view rChartTypeServiceName,
674 std::u16string_view rODFVersionOfFile,
675 bool bAxisPositionAttributeImported )
677 if( !(rODFVersionOfFile.empty() || rODFVersionOfFile ==
u"1.0" || rODFVersionOfFile ==
u"1.1"
678 || ( rODFVersionOfFile ==
u"1.2" && !bAxisPositionAttributeImported )) )
684 uno::Sequence< Reference< chart2::XCoordinateSystem > > aCooSysSeq( xCooSysCnt->getCoordinateSystems());
685 if( aCooSysSeq.hasElements() )
701 if( xMainXAxisProp.is() && xMainYAxisProp.is() )
703 chart2::ScaleData aMainXScale = xMainXAxis->getScaleData();
704 if( rChartTypeServiceName ==
u"com.sun.star.chart2.ScatterChartType" )
706 xMainYAxisProp->setPropertyValue(
"CrossoverPosition"
707 ,
uno::Any( css::chart::ChartAxisPosition_VALUE) );
708 double fCrossoverValue = 0.0;
709 aMainXScale.Origin >>= fCrossoverValue;
710 xMainYAxisProp->setPropertyValue(
"CrossoverValue"
713 if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
715 xMainYAxisProp->setPropertyValue(
"LabelPosition"
716 ,
uno::Any( css::chart::ChartAxisLabelPosition_OUTSIDE_END) );
717 xMainYAxisProp->setPropertyValue(
"MarkPosition"
718 ,
uno::Any( css::chart::ChartAxisMarkPosition_AT_LABELS) );
719 if( xSecondaryYAxisProp.is() )
720 xSecondaryYAxisProp->setPropertyValue(
"CrossoverPosition"
721 ,
uno::Any( css::chart::ChartAxisPosition_START) );
725 xMainYAxisProp->setPropertyValue(
"LabelPosition"
726 ,
uno::Any( css::chart::ChartAxisLabelPosition_OUTSIDE_START) );
727 xMainYAxisProp->setPropertyValue(
"MarkPosition"
728 ,
uno::Any( css::chart::ChartAxisMarkPosition_AT_LABELS) );
729 if( xSecondaryYAxisProp.is() )
730 xSecondaryYAxisProp->setPropertyValue(
"CrossoverPosition"
731 ,
uno::Any( css::chart::ChartAxisPosition_END) );
736 if( aMainXScale.Orientation == chart2::AxisOrientation_REVERSE )
738 xMainYAxisProp->setPropertyValue(
"CrossoverPosition"
739 ,
uno::Any( css::chart::ChartAxisPosition_END) );
740 if( xSecondaryYAxisProp.is() )
741 xSecondaryYAxisProp->setPropertyValue(
"CrossoverPosition"
742 ,
uno::Any( css::chart::ChartAxisPosition_START) );
746 xMainYAxisProp->setPropertyValue(
"CrossoverPosition"
747 ,
uno::Any( css::chart::ChartAxisPosition_START) );
748 if( xSecondaryYAxisProp.is() )
749 xSecondaryYAxisProp->setPropertyValue(
"CrossoverPosition"
750 ,
uno::Any( css::chart::ChartAxisPosition_END) );
754 chart2::ScaleData aMainYScale = xMainYAxis->getScaleData();
755 xMainXAxisProp->setPropertyValue(
"CrossoverPosition"
756 ,
uno::Any( css::chart::ChartAxisPosition_VALUE) );
757 double fCrossoverValue = 0.0;
758 aMainYScale.Origin >>= fCrossoverValue;
759 xMainXAxisProp->setPropertyValue(
"CrossoverValue"
762 if( aMainYScale.Orientation == chart2::AxisOrientation_REVERSE )
764 xMainXAxisProp->setPropertyValue(
"LabelPosition"
765 ,
uno::Any( css::chart::ChartAxisLabelPosition_OUTSIDE_END) );
766 xMainXAxisProp->setPropertyValue(
"MarkPosition"
767 ,
uno::Any( css::chart::ChartAxisMarkPosition_AT_LABELS) );
768 if( xSecondaryXAxisProp.is() )
769 xSecondaryXAxisProp->setPropertyValue(
"CrossoverPosition"
770 ,
uno::Any( css::chart::ChartAxisPosition_START) );
774 xMainXAxisProp->setPropertyValue(
"LabelPosition"
775 ,
uno::Any( css::chart::ChartAxisLabelPosition_OUTSIDE_START) );
776 xMainXAxisProp->setPropertyValue(
"MarkPosition"
777 ,
uno::Any( css::chart::ChartAxisMarkPosition_AT_LABELS) );
778 if( xSecondaryXAxisProp.is() )
779 xSecondaryXAxisProp->setPropertyValue(
"CrossoverPosition"
780 ,
uno::Any( css::chart::ChartAxisPosition_END) );
786 catch( uno::Exception & )
791SchXMLCategoriesContext::SchXMLCategoriesContext(
792 SvXMLImport& rImport,
793 OUString& rAddress ) :
795 mrAddress( rAddress )
799void SchXMLCategoriesContext::startFastElement( sal_Int32 ,
800 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
805 mrAddress = aIter.toString();
811DateScaleContext::DateScaleContext(
812 SvXMLImport& rImport,
815 m_xAxisProps( rAxisProps )
823 sal_Int32 nTimeUnit = css::chart::TimeUnit::DAY;
825 nTimeUnit = css::chart::TimeUnit::DAY;
827 nTimeUnit = css::chart::TimeUnit::MONTH;
829 nTimeUnit = css::chart::TimeUnit::YEAR;
835void DateScaleContext::startFastElement( sal_Int32 ,
836 const css::uno::Reference< css::xml::sax::XFastAttributeList >& xAttrList )
838 if( !m_xAxisProps.is() )
842 bool bSetNewIncrement=
false;
843 chart::TimeIncrement aIncrement;
844 m_xAxisProps->getPropertyValue(
"TimeIncrement") >>= aIncrement;
848 switch( aIter.getToken() )
852 aIncrement.TimeResolution <<= lcl_getTimeUnit(aIter);
853 bSetNewIncrement =
true;
858 chart::TimeInterval aInterval(1,0);
859 aIncrement.MajorTimeInterval >>= aInterval;
861 aIncrement.MajorTimeInterval <<= aInterval;
862 bSetNewIncrement =
true;
867 chart::TimeInterval aInterval(1,0);
868 aIncrement.MajorTimeInterval >>= aInterval;
869 aInterval.TimeUnit = lcl_getTimeUnit(aIter);
870 aIncrement.MajorTimeInterval <<= aInterval;
871 bSetNewIncrement =
true;
876 chart::TimeInterval aInterval(1,0);
877 aIncrement.MinorTimeInterval >>= aInterval;
879 aIncrement.MinorTimeInterval <<= aInterval;
880 bSetNewIncrement =
true;
885 chart::TimeInterval aInterval(1,0);
886 aIncrement.MinorTimeInterval >>= aInterval;
887 aInterval.TimeUnit = lcl_getTimeUnit(aIter);
888 aIncrement.MinorTimeInterval <<= aInterval;
889 bSetNewIncrement =
true;
897 if( bSetNewIncrement )
898 m_xAxisProps->setPropertyValue(
"TimeIncrement",
uno::Any( aIncrement ) );
const SvXMLEnumMapEntry< SchXMLAxisDimension > aXMLAxisDimensionMap[]
static Reference< chart::XAxis > lcl_getChartAxis(const SchXMLAxis &rCurrentAxis, const Reference< chart::XDiagram > &rDiagram)
const SvXMLEnumMapEntry< sal_uInt16 > aXMLAxisTypeMap[]
SchXMLAxis m_aCurrentAxis
static void CorrectAxisPositions(const css::uno::Reference< css::chart2::XChartDocument > &xNewDoc, std::u16string_view rChartTypeServiceName, std::u16string_view rODFVersionOfFile, bool bAxisPositionAttributeImported)
SchXMLAxisContext(SchXMLImportHelper &rImpHelper, SvXMLImport &rImport, css::uno::Reference< css::chart::XDiagram > const &xDiagram, std::vector< SchXMLAxis > &aAxes, OUString &rCategoriesAddress, bool bAddMissingXAxisForNetCharts, bool bAdaptWrongPercentScaleValues, bool bAdaptXAxisOrientationForOld2DBarCharts, bool &rbAxisPositionAttributeImported)
virtual void SAL_CALL startFastElement(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList) override
bool m_bDateScaleImported
css::uno::Reference< css::chart::XDiagram > m_xDiagram
SchXMLImportHelper & m_rImportHelper
virtual void SAL_CALL endFastElement(sal_Int32 nElement) override
endFastElement is called before a context will be destructed, but after an elements context has been ...
virtual css::uno::Reference< css::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext(sal_Int32 nElement, const css::uno::Reference< css::xml::sax::XFastAttributeList > &AttrList) override
bool m_bAdaptWrongPercentScaleValues
void CreateGrid(const OUString &sAutoStyleName, bool bIsMajor)
std::vector< SchXMLAxis > & m_rAxes
bool m_bAddMissingXAxisForNetCharts
bool & m_rbAxisPositionAttributeImported
virtual ~SchXMLAxisContext() override
bool m_bAdaptXAxisOrientationForOld2DBarCharts
OUString m_aAutoStyleName
css::uno::Reference< css::drawing::XShape > getTitleShape() const
css::uno::Reference< css::beans::XPropertySet > m_xAxisProps
OUString & m_rCategoriesAddress
With this class you can import a <chart:chart> element containing its data as <table:table> element o...
const css::uno::Reference< css::chart::XChartDocument > & GetChartDocument() const
SvXMLStylesContext * GetAutoStylesContext() const
void FillAutoStyle(const OUString &rAutoStyleName, const css::uno::Reference< css::beans::XPropertySet > &rProp)
Fill in the autostyle.
static XmlStyleFamily GetChartFamilyID()
This class deliberately does not support XWeak, to improve performance when loading large documents.
virtual void SAL_CALL startFastElement(sal_Int32 Element, const css::uno::Reference< css::xml::sax::XFastAttributeList > &Attribs) override
SvXMLImport & GetImport()
const SvXMLStyleContext * FindStyleChildContext(XmlStyleFamily nFamily, const OUString &rName, bool bCreateIndex=false) const
static bool convertEnum(EnumT &rEnum, std::u16string_view rValue, const SvXMLEnumMapEntry< EnumT > *pMap)
convert string to enum using given enum map, if the enum is not found in the map, this method will re...
static bool convertNumber(sal_Int32 &rValue, std::u16string_view aString, sal_Int32 nMin=SAL_MIN_INT32, sal_Int32 nMax=SAL_MAX_INT32)
constexpr ::Color COL_BLACK(0x00, 0x00, 0x00)
#define SAL_INFO(area, stream)
FastAttributeList & castToFastAttributeList(const css::uno::Reference< css::xml::sax::XFastAttributeList > &xAttrList)
Handling of tokens in XML:
@ XML_MINOR_INTERVAL_VALUE
@ XML_MAJOR_INTERVAL_UNIT
@ XML_MAJOR_INTERVAL_VALUE
@ XML_MINOR_INTERVAL_UNIT
bool IsXMLToken(std::u16string_view rString, enum XMLTokenEnum eToken)
compare eToken to the string
enum SchXMLAxisDimension eDimension
#define XMLOFF_WARN_UNKNOWN_ELEMENT(area, token)
#define XMLOFF_WARN_UNKNOWN(area, rIter)
#define XML_ELEMENT(prefix, name)