summaryrefslogtreecommitdiffstats
path: root/chart2/source
diff options
context:
space:
mode:
authorDennis Francis <dennisfrancis.in@gmail.com>2021-09-02 14:33:55 +0530
committerMiklos Vajna <vmiklos@collabora.com>2021-09-06 08:47:50 +0200
commitf547cf17a179ebd7de5c2b4dd2d00d0027a25429 (patch)
tree764038da5e3280c93099d2ca3ef2731484ece324 /chart2/source
parenttdf#142965 color filter: allow filtering by no fill/automatic color (diff)
downloadcore-f547cf17a179ebd7de5c2b4dd2d00d0027a25429.tar.gz
core-f547cf17a179ebd7de5c2b4dd2d00d0027a25429.zip
[API CHANGE] oox: fix import of chart date categories
Before this fix, date categories imported in oox's DataSourceContext were stored as formatted strings according to number format code in <c:formatCode> under the <c:cat> tree. As a result chart2 could not recognize them as dates. This causes problems like: * The axis that is linked to date categories cannot use the scaling/range-selection(min/max)/increments specs mentioned as axis properties. This results in distorted/unreadable chart renders w.r.t the date axis. * No re-formatting is attempted as per the number format provided for axis. This patch introduces a role qualifer argument to the XDataProvider interface method createDataSequenceByValueArray to support categories of date type via this method. When exporting to oox, write date categories and format code under <c:cat> <c:numRef> <c:numCache> This patch also fixes some discrepancies in date axis interval computation (auto mode) found by already existing unit tests. Change-Id: Ibc53b0a56fdddba80ba452d5567ce98d80460ea7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/121525 Tested-by: Jenkins Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'chart2/source')
-rw-r--r--chart2/source/inc/InternalDataProvider.hxx6
-rw-r--r--chart2/source/tools/InternalDataProvider.cxx20
-rw-r--r--chart2/source/view/axes/ScaleAutomatism.cxx4
-rw-r--r--chart2/source/view/axes/VCoordinateSystem.cxx6
-rw-r--r--chart2/source/view/charttypes/AreaChart.cxx4
5 files changed, 29 insertions, 11 deletions
diff --git a/chart2/source/inc/InternalDataProvider.hxx b/chart2/source/inc/InternalDataProvider.hxx
index 1e5821f94e6c..34c5d4831c17 100644
--- a/chart2/source/inc/InternalDataProvider.hxx
+++ b/chart2/source/inc/InternalDataProvider.hxx
@@ -112,7 +112,8 @@ public:
const OUString& aRangeRepresentation ) override;
virtual css::uno::Reference<css::chart2::data::XDataSequence> SAL_CALL
- createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation ) override;
+ createDataSequenceByValueArray( const OUString& aRole, const OUString& aRangeRepresentation,
+ const OUString& aRoleQualifier ) override;
virtual css::uno::Reference< css::sheet::XRangeSelection > SAL_CALL getRangeSelection() override;
@@ -183,7 +184,8 @@ private:
createDataSequenceAndAddToMap( const OUString & rRangeRepresentation );
css::uno::Reference<css::chart2::data::XDataSequence>
- createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole );
+ createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole,
+ std::u16string_view rRoleQualifier);
void deleteMapReferences( const OUString & rRangeRepresentation );
diff --git a/chart2/source/tools/InternalDataProvider.cxx b/chart2/source/tools/InternalDataProvider.cxx
index 505159fa87b6..abbcc077e1c0 100644
--- a/chart2/source/tools/InternalDataProvider.cxx
+++ b/chart2/source/tools/InternalDataProvider.cxx
@@ -483,7 +483,7 @@ void InternalDataProvider::decreaseMapReferences(
Reference< chart2::data::XDataSequence > InternalDataProvider::createDataSequenceAndAddToMap(
const OUString & rRangeRepresentation )
{
- Reference<chart2::data::XDataSequence> xSeq = createDataSequenceFromArray(rRangeRepresentation, u"");
+ Reference<chart2::data::XDataSequence> xSeq = createDataSequenceFromArray(rRangeRepresentation, u"", u"");
if (xSeq.is())
return xSeq;
@@ -493,7 +493,7 @@ Reference< chart2::data::XDataSequence > InternalDataProvider::createDataSequenc
}
uno::Reference<chart2::data::XDataSequence>
-InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole )
+InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, std::u16string_view rRole, std::u16string_view rRoleQualifier )
{
if (rArrayStr.indexOf('{') != 0 || rArrayStr[rArrayStr.getLength()-1] != '}')
{
@@ -620,9 +620,19 @@ InternalDataProvider::createDataSequenceFromArray( const OUString& rArrayStr, st
{
// Category labels.
+ // Store date categories as numbers.
+ bool bStoreNumeric = rRoleQualifier == u"date";
+ double fValue;
for (size_t i = 0; i < aRawElems.size(); ++i)
{
- std::vector<uno::Any> aLabels(1, uno::Any(aRawElems[i]));
+ if (bStoreNumeric)
+ {
+ bool bGetDouble = bAllNumeric && !aRawElems[i].isEmpty();
+ fValue = bGetDouble ? aRawElems[i].toDouble() :
+ std::numeric_limits<double>::quiet_NaN();
+ }
+ std::vector<uno::Any> aLabels(1,
+ bStoreNumeric ? uno::Any(fValue) : uno::Any(aRawElems[i]));
m_aInternalData.setComplexRowLabel(i, aLabels);
}
@@ -831,9 +841,9 @@ Reference< chart2::data::XDataSequence > SAL_CALL InternalDataProvider::createDa
Reference<chart2::data::XDataSequence> SAL_CALL
InternalDataProvider::createDataSequenceByValueArray(
- const OUString& aRole, const OUString& aRangeRepresentation )
+ const OUString& aRole, const OUString& aRangeRepresentation, const OUString& aRoleQualifier )
{
- return createDataSequenceFromArray(aRangeRepresentation, aRole);
+ return createDataSequenceFromArray(aRangeRepresentation, aRole, aRoleQualifier);
}
Reference< sheet::XRangeSelection > SAL_CALL InternalDataProvider::getRangeSelection()
diff --git a/chart2/source/view/axes/ScaleAutomatism.cxx b/chart2/source/view/axes/ScaleAutomatism.cxx
index 09da37aba034..7748df078ec6 100644
--- a/chart2/source/view/axes/ScaleAutomatism.cxx
+++ b/chart2/source/view/axes/ScaleAutomatism.cxx
@@ -654,7 +654,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForDateTimeAxis(
nDaysPerInterval = 1.0;
}
- nNumer = static_cast<sal_Int32>( rtl::math::approxCeil( nIntervalDays/nDaysPerInterval ) );
+ nNumer = static_cast<sal_Int32>( rtl::math::approxFloor( nIntervalDays/nDaysPerInterval ) );
if(nNumer<=0)
nNumer=1;
if( rExplicitIncrement.MajorTimeInterval.TimeUnit == DAY )
@@ -665,7 +665,7 @@ void ScaleAutomatism::calculateExplicitIncrementAndScaleForDateTimeAxis(
{
rExplicitIncrement.MajorTimeInterval.TimeUnit = MONTH;
nDaysPerInterval = 31.0;
- nNumer = static_cast<sal_Int32>( rtl::math::approxCeil( nIntervalDays/nDaysPerInterval ) );
+ nNumer = static_cast<sal_Int32>( rtl::math::approxFloor( nIntervalDays/nDaysPerInterval ) );
if(nNumer<=0)
nNumer=1;
}
diff --git a/chart2/source/view/axes/VCoordinateSystem.cxx b/chart2/source/view/axes/VCoordinateSystem.cxx
index ded24e5b1353..7259f3e92043 100644
--- a/chart2/source/view/axes/VCoordinateSystem.cxx
+++ b/chart2/source/view/axes/VCoordinateSystem.cxx
@@ -341,7 +341,8 @@ void VCoordinateSystem::updateScalesAndIncrementsOnAxes()
void VCoordinateSystem::prepareAutomaticAxisScaling( ScaleAutomatism& rScaleAutomatism, sal_Int32 nDimIndex, sal_Int32 nAxisIndex )
{
- if( rScaleAutomatism.getScale().AxisType==AxisType::DATE && nDimIndex==0 )
+ bool bDateAxisX = (rScaleAutomatism.getScale().AxisType == AxisType::DATE) && (nDimIndex == 0);
+ if( bDateAxisX )
{
// This is a date X dimension. Determine proper time resolution.
sal_Int32 nTimeResolution = css::chart::TimeUnit::MONTH;
@@ -384,6 +385,9 @@ void VCoordinateSystem::prepareAutomaticAxisScaling( ScaleAutomatism& rScaleAuto
m_aMergedMinMaxSupplier.isExpandWideValuesToZero( nDimIndex ),
m_aMergedMinMaxSupplier.isExpandNarrowValuesTowardZero( nDimIndex ) );
+ if (bDateAxisX)
+ return;
+
VAxisBase* pVAxis = getVAxis(nDimIndex, nAxisIndex);
if( pVAxis )
rScaleAutomatism.setMaximumAutoMainIncrementCount( pVAxis->estimateMaximumAutoMainIncrementCount() );
diff --git a/chart2/source/view/charttypes/AreaChart.cxx b/chart2/source/view/charttypes/AreaChart.cxx
index 37b90cdfdbc0..e0a70af5339f 100644
--- a/chart2/source/view/charttypes/AreaChart.cxx
+++ b/chart2/source/view/charttypes/AreaChart.cxx
@@ -693,6 +693,8 @@ void AreaChart::createShapes()
uno::Reference< drawing::XShapes > xSeriesGroupShape_Shapes = getSeriesGroupShapeFrontChild(pSeries.get(), m_xSeriesTarget);
sal_Int32 nAttachedAxisIndex = pSeries->getAttachedAxisIndex();
+ double fXMin, fXMax;
+ pSeries->getMinMaxXValue(fXMin, fXMax);
PlottingPositionHelper& rPosHelper = getPlottingPositionHelper(nAttachedAxisIndex);
m_pPosHelper = &rPosHelper;
@@ -713,7 +715,7 @@ void AreaChart::createShapes()
double fLogicX = pSeries->getXValue(nIndex);
if (bDateCategory)
{
- if (std::isnan(fLogicX))
+ if (std::isnan(fLogicX) || (fLogicX < fXMin || fLogicX > fXMax))
continue;
fLogicX = DateHelper::RasterizeDateValue( fLogicX, m_aNullDate, m_nTimeResolution );