24#include <com/sun/star/chart/ChartAxisArrangeOrderType.hpp>
25#include <com/sun/star/chart/ChartAxisLabelPosition.hpp>
26#include <com/sun/star/chart/ChartAxisMarkPosition.hpp>
27#include <com/sun/star/chart/ChartAxisPosition.hpp>
28#include <com/sun/star/chart/TimeInterval.hpp>
29#include <com/sun/star/chart/TimeUnit.hpp>
30#include <com/sun/star/chart2/AxisType.hpp>
31#include <com/sun/star/chart2/TickmarkStyle.hpp>
32#include <com/sun/star/chart2/LinearScaling.hpp>
33#include <com/sun/star/chart2/LogarithmicScaling.hpp>
34#include <com/sun/star/chart2/XAxis.hpp>
35#include <com/sun/star/chart2/XCoordinateSystem.hpp>
36#include <com/sun/star/chart2/XTitled.hpp>
42#include <oox/token/namespaces.hxx>
43#include <oox/token/properties.hxx>
44#include <oox/token/tokens.hxx>
46#include <osl/diagnose.h>
56void lclSetValueOrClearAny( Any& orAny,
const std::optional< double >& rofValue )
58 if( rofValue.has_value() ) orAny <<= rofValue.value();
else orAny.clear();
61bool lclIsLogarithmicScale(
const AxisModel& rAxisModel )
63 return rAxisModel.mofLogBase.has_value() && (2.0 <= rAxisModel.mofLogBase.value()) && (rAxisModel.mofLogBase.value() <= 1000.0);
66sal_Int32 lclGetApiTimeUnit( sal_Int32 nTimeUnit )
71 case XML_days:
return TimeUnit::DAY;
72 case XML_months:
return TimeUnit::MONTH;
73 case XML_years:
return TimeUnit::YEAR;
74 default: OSL_ENSURE(
false,
"lclGetApiTimeUnit - unexpected time unit" );
79void lclConvertTimeInterval( Any& orInterval,
const std::optional< double >& rofUnit, sal_Int32 nTimeUnit )
81 if( rofUnit.has_value() && (1.0 <= rofUnit.value()) && (rofUnit.value() <= SAL_MAX_INT32) )
82 orInterval <<= css::chart::TimeInterval( static_cast< sal_Int32 >( rofUnit.value() ), lclGetApiTimeUnit( nTimeUnit ) );
87css::chart::ChartAxisLabelPosition lclGetLabelPosition( sal_Int32 nToken )
92 case XML_high:
return ChartAxisLabelPosition_OUTSIDE_END;
93 case XML_low:
return ChartAxisLabelPosition_OUTSIDE_START;
94 case XML_nextTo:
return ChartAxisLabelPosition_NEAR_AXIS;
96 return ChartAxisLabelPosition_NEAR_AXIS;
99sal_Int32 lclGetTickMark( sal_Int32 nToken )
101 using namespace ::com::sun::star::chart2::TickmarkStyle;
104 case XML_in:
return INNER;
105 case XML_out:
return OUTER;
106 case XML_cross:
return INNER | OUTER;
108 return css::chart2::TickmarkStyle::NONE;
115bool isPercent(
const RefVector<TypeGroupConverter>& rTypeGroups )
117 if (rTypeGroups.empty())
120 for (
auto const& typeGroup : rTypeGroups)
122 TypeGroupConverter& rConv = *typeGroup;
123 if (!rConv.isPercent())
143 const AxisModel* pCrossingAxis, sal_Int32 nAxesSetIdx,
144 sal_Int32 nAxisIdx,
bool bUseFixedInnerSize)
146 if (rTypeGroups.empty())
152 namespace cssc = ::com::sun::star::chart;
153 namespace cssc2 = ::com::sun::star::chart2;
155 const TypeGroupInfo& rTypeInfo = rTypeGroups.front()->getTypeInfo();
159 xAxis.set(
createInstance(
"com.sun.star.chart2.Axis" ), UNO_QUERY_THROW );
183 PropertySet aGridProp( xAxis->getGridProperties() );
190 if( aSubGridPropSeq.hasElements() )
200 ScaleData aScaleData = xAxis->getScaleData();
208 "AxisConverter::convertFromModel - unexpected axis model type (must: c:catAx or c:dateAx)" );
211 aScaleData.AxisType = bDateAxis ? cssc2::AxisType::DATE : cssc2::AxisType::CATEGORY;
215 if( nAxesSetIdx == 0 )
216 aScaleData.Categories = rTypeGroups.front()->createCategorySequence();
220 aScaleData.ShiftedCategoryPosition =
true;
222 aScaleData.ShiftedCategoryPosition =
false;
224 aScaleData.ShiftedCategoryPosition = pCrossingAxis->
mnCrossBetween == XML_between;
226 aScaleData.ShiftedCategoryPosition =
true;
230 OSL_ENSURE(
mrModel.
mnTypeId == C_TOKEN( valAx ),
"AxisConverter::convertFromModel - unexpected axis model type (must: c:valAx)" );
231 aScaleData.AxisType = cssc2::AxisType::REALNUMBER;
235 OSL_ENSURE(
mrModel.
mnTypeId == C_TOKEN( valAx ),
"AxisConverter::convertFromModel - unexpected axis model type (must: c:valAx)" );
236 aScaleData.AxisType = isPercent(rTypeGroups) ? cssc2::AxisType::PERCENT : cssc2::AxisType::REALNUMBER;
239 OSL_ENSURE(
mrModel.
mnTypeId == C_TOKEN( serAx ),
"AxisConverter::convertFromModel - unexpected axis model type (must: c:serAx)" );
240 OSL_ENSURE( rTypeGroups.front()->isDeep3dChart(),
"AxisConverter::convertFromModel - series axis not supported by this chart type" );
241 aScaleData.AxisType = cssc2::AxisType::SERIES;
247 switch( aScaleData.AxisType )
249 case cssc2::AxisType::CATEGORY:
250 case cssc2::AxisType::SERIES:
251 case cssc2::AxisType::DATE:
270 aScaleData.TimeIncrement.TimeResolution.clear();
275 bool bTextOverlap =
false;
280 aAxisProp.
setProperty(PROP_TextOverlap, bTextOverlap);
284 bool bTextBreak =
true;
285 double fRotationAngle = 0.0;
287 && fRotationAngle != 0.0)
288 bTextBreak = !bUseFixedInnerSize
289 && (fRotationAngle == 90.0 || fRotationAngle == 270.0);
297 case cssc2::AxisType::REALNUMBER:
298 case cssc2::AxisType::PERCENT:
301 const bool bLogScale = lclIsLogarithmicScale(
mrModel );
310 IncrementData& rIncrementData = aScaleData.IncrementData;
317 rSubIncrementSeq.realloc( 1 );
318 Any& rIntervalCount = rSubIncrementSeq.getArray()[ 0 ].IntervalCount;
319 rIntervalCount.clear();
323 rIntervalCount <<= sal_Int32( 9 );
328 if( (1.0 <= fCount) && (fCount < 1001.0) )
329 rIntervalCount <<= static_cast< sal_Int32 >( fCount );
334 rIntervalCount <<= static_cast< sal_Int32 >( 5 );
339 OSL_FAIL(
"AxisConverter::convertFromModel - unknown axis type" );
344 aScaleData.Origin.clear();
350 bool bMirrorDirection =
354 aScaleData.Orientation = bReverse ? cssc2::AxisOrientation_REVERSE : cssc2::AxisOrientation_MATHEMATICAL;
357 xAxis->setScaleData( aScaleData );
368 cssc::ChartAxisPosition eAxisPos = cssc::ChartAxisPosition_VALUE;
371 case XML_min: eAxisPos = cssc::ChartAxisPosition_START;
break;
372 case XML_max: eAxisPos = cssc::ChartAxisPosition_END;
break;
373 case XML_autoZero: eAxisPos = cssc::ChartAxisPosition_ZERO;
break;
379 bool bCrossingLogScale = pCrossingAxis && lclIsLogarithmicScale( *pCrossingAxis );
380 double fCrossingPos = bManualCrossing ?
mrModel.
mofCrossesAt.value() : (bCrossingLogScale ? 1.0 : 0.0);
405 if( xAxis.is() && rxCoordSystem.is() )
try
408 rxCoordSystem->setAxisByDimension( nAxisIdx, xAxis, nAxesSetIdx );
412 OSL_FAIL(
"AxisConverter::convertFromModel - cannot insert axis into coordinate system" );
A wrapper for a UNO property set.
bool getProperty(Type &orValue, sal_Int32 nPropId) const
Gets the specified property from the property set.
bool setProperty(sal_Int32 nPropId, const Type &rValue)
Puts the passed value into the property set.
Template for a vector of ref-counted objects with additional accessor functions.
LineProperties & getLineProperties()
virtual ~AxisConverter() override
AxisConverter(const ConverterRoot &rParent, AxisModel &rModel)
void convertFromModel(const css::uno::Reference< css::chart2::XCoordinateSystem > &rxCoordSystem, RefVector< TypeGroupConverter > &rTypeGroups, const AxisModel *pCrossingAxis, sal_Int32 nAxesSetIdx, sal_Int32 nAxisIdx, bool bUseFixedInnerSize)
Creates a chart2 axis and inserts it into the passed coordinate system.
virtual ~AxisDispUnitsConverter() override
AxisDispUnitsConverter(const ConverterRoot &rParent, AxisDispUnitsModel &rModel)
void convertFromModel(const css::uno::Reference< css::chart2::XAxis > &rxAxis)
Creates a chart2 axis and inserts it into the passed coordinate system.
Base class of all converter classes.
ObjectFormatter & getFormatter() const
Returns the object formatter.
css::uno::Reference< css::uno::XInterface > createInstance(const OUString &rServiceName) const
Creates an instance for the passed service name, using the process service factory.
ModelType & getOrCreate()
void convertFromModel(const css::uno::Reference< css::chart2::XTitled > &rxTitled, const OUString &rAutoTitle, ObjectType eObjType, sal_Int32 nMainIdx=-1, sal_Int32 nSubIdx=-1)
Creates a title text object and attaches it at the passed interface.
Reference< XComponentContext > getProcessComponentContext()
const sal_Int32 API_Y_AXIS
@ TYPECATEGORY_RADAR
Line charts (line, area, stock charts).
@ TYPECATEGORY_PIE
Radar charts (linear or filled).
const sal_Int32 API_X_AXIS
@ OBJECTTYPE_AXIS
Floor in 3D charts.
@ OBJECTTYPE_MINORGRIDLINE
Axis major grid line.
@ OBJECTTYPE_AXISTITLE
Axis line, labels, tick marks.
@ OBJECTTYPE_MAJORGRIDLINE
Axis unit label.
@ TYPEID_RADARLINE
Stock chart.
@ TYPEID_LINE
Horizontal bar chart.
@ TYPEID_HORBAR
Vertical bar chart.
@ TYPEID_RADARAREA
Linear radar chart.
@ TYPEID_STOCK
Area chart.
const sal_Int32 API_Z_AXIS
OUString OoxResId(TranslateId aId)
std::optional< sal_Int32 > moFillType
FillProperties maLineFill
End line arrow style.
OUString mnBuiltInUnit
Custom unit size on value axis.
AxisDispUnitsRef mxDispUnits
Axis title.
NumberFormat maNumberFormat
Minor grid lines formatting.
sal_Int32 mnAxisPos
Unique axis identifier.
std::optional< sal_Int32 > monBaseTimeUnit
Minimum axis value.
bool mbAuto
Type identifier of this axis.
TitleRef mxTitle
Axis label text formatting.
std::optional< double > mofMax
Logarithmic base for logarithmic axes.
sal_Int32 mnOrientation
Time unit for minor tick marks on date axis.
sal_Int32 mnMinorTickMark
Time unit for major tick marks on date axis.
std::optional< double > mofCrossesAt
Number format for axis tick labels.
sal_Int32 mnMajorTickMark
Tick mark label distance from axis.
sal_Int32 mnMajorTimeUnit
Major tick mark style.
ShapeRef mxMajorGridLines
Axis units label.
ShapeRef mxMinorGridLines
Major grid lines formatting.
sal_Int32 mnTypeId
Number of tick marks to skip.
sal_Int32 mnCrossMode
This value axis crosses between or inside category.
std::optional< double > mofMajorUnit
Position on this axis where another axis crosses.
std::optional< double > mofMinorUnit
Unit for major tick marks on date/value axis.
sal_Int32 mnMinorTimeUnit
Minor tick mark style.
bool mbDeleted
True = automatic selection of text/date axis type.
sal_Int32 mnCrossBetween
Identifier of a crossing axis.
std::optional< double > mofMin
Maximum axis value.
TextBodyRef mxTextProp
Axis line formatting.
sal_Int32 mnTickLabelPos
Axis orientation (value order min to max, or max to min).
Contains info for a chart type related to the OpenOffice.org chart module.
bool mbCategoryAxis
True = only first series visible (e.g. pie charts).
TypeCategory meTypeCategory
Unique chart type identifier.
constexpr OUStringLiteral PROP_MarkPosition
constexpr OUStringLiteral PROP_ArrangeOrder
constexpr OUStringLiteral PROP_DisplayLabels
constexpr OUStringLiteral PROP_DisplayUnits
constexpr OUStringLiteral PROP_TextRotation
constexpr OUStringLiteral PROP_CrossoverPosition
constexpr OUStringLiteral PROP_CrossoverValue
constexpr OUStringLiteral PROP_LabelPosition
constexpr OUStringLiteral PROP_BuiltInUnit
constexpr OUStringLiteral PROP_TextBreak