diff --git chart2/source/model/template/ColumnChartType.cxx chart2/source/model/template/ColumnChartType.cxx index ed5aea8..8613b95 100644 --- chart2/source/model/template/ColumnChartType.cxx +++ chart2/source/model/template/ColumnChartType.cxx @@ -49,7 +49,9 @@ namespace enum { PROP_BARCHARTTYPE_OVERLAP_SEQUENCE, - PROP_BARCHARTTYPE_GAPWIDTH_SEQUENCE + PROP_BARCHARTTYPE_GAPWIDTH_SEQUENCE, + PROP_BARCHARTTYPE_STACKED, + PROP_BARCHARTTYPE_PERCENT }; void lcl_AddPropertiesToVector( @@ -68,6 +70,19 @@ void lcl_AddPropertiesToVector( ::getCppuType( reinterpret_cast< const Sequence< sal_Int32 > * >(0)), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "Stacked" ), + PROP_BARCHARTTYPE_STACKED, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Percent" ), + PROP_BARCHARTTYPE_PERCENT, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); } void lcl_AddDefaultsToMap( diff --git chart2/source/model/template/LineChartType.cxx chart2/source/model/template/LineChartType.cxx index 05f6b43..6ee1151 100644 --- chart2/source/model/template/LineChartType.cxx +++ chart2/source/model/template/LineChartType.cxx @@ -54,7 +54,9 @@ enum { PROP_LINECHARTTYPE_CURVE_STYLE, PROP_LINECHARTTYPE_CURVE_RESOLUTION, - PROP_LINECHARTTYPE_SPLINE_ORDER + PROP_LINECHARTTYPE_SPLINE_ORDER, + PROP_LINECHARTTYPE_STACKED, + PROP_LINECHARTTYPE_PERCENT }; void lcl_AddPropertiesToVector( @@ -79,6 +81,19 @@ void lcl_AddPropertiesToVector( ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), beans::PropertyAttribute::BOUND | beans::PropertyAttribute::MAYBEDEFAULT )); + + rOutProperties.push_back( + Property( C2U( "Stacked" ), + PROP_LINECHARTTYPE_STACKED, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); + rOutProperties.push_back( + Property( C2U( "Percent" ), + PROP_LINECHARTTYPE_PERCENT, + ::getBooleanCppuType(), + beans::PropertyAttribute::BOUND + | beans::PropertyAttribute::MAYBEDEFAULT )); } void lcl_AddDefaultsToMap( diff --git chart2/source/view/axes/ScaleAutomatism.cxx chart2/source/view/axes/ScaleAutomatism.cxx index 711a911..f750acc 100644 --- chart2/source/view/axes/ScaleAutomatism.cxx +++ chart2/source/view/axes/ScaleAutomatism.cxx @@ -132,7 +132,15 @@ void ScaleAutomatism::calculateExplicitScaleAndIncrement( if( bAutoMinimum ) { if( m_aSourceScale.AxisType==AxisType::PERCENT ) + { rExplicitScale.Minimum = 0.0; + if (!::rtl::math::isNan(m_fValueMinimum)) + { + double fMin = m_fValueMinimum / 100.0; + if (rExplicitScale.Minimum > fMin) + rExplicitScale.Minimum = fMin; + } + } else if( ::rtl::math::isNan( m_fValueMinimum ) ) rExplicitScale.Minimum = 0.0; //@todo get Minimum from scaling or from plotter???? else @@ -143,7 +151,15 @@ void ScaleAutomatism::calculateExplicitScaleAndIncrement( if( bAutoMaximum ) { if( m_aSourceScale.AxisType==AxisType::PERCENT ) + { rExplicitScale.Maximum = 1.0; + if (!::rtl::math::isNan(m_fValueMaximum)) + { + double fMax = m_fValueMaximum / 100.0; + if (rExplicitScale.Maximum < fMax) + rExplicitScale.Maximum = fMax; + } + } else if( ::rtl::math::isNan( m_fValueMaximum ) ) rExplicitScale.Maximum = 10.0; //@todo get Maximum from scaling or from plotter???? else diff --git chart2/source/view/charttypes/AreaChart.cxx chart2/source/view/charttypes/AreaChart.cxx index 84710f0..1f036c1 100644 --- chart2/source/view/charttypes/AreaChart.cxx +++ chart2/source/view/charttypes/AreaChart.cxx @@ -598,6 +598,11 @@ struct FormerPoint void AreaChart::createShapes() { + sal_Bool bPercent = sal_False; + uno::Reference< beans::XPropertySet > xPropSet(m_xChartTypeModel, uno::UNO_QUERY); + if (xPropSet.is()) + xPropSet->getPropertyValue(C2U("Percent")) >>= bPercent; + if( m_aZSlots.begin() == m_aZSlots.end() ) //no series return; @@ -734,9 +739,30 @@ void AreaChart::createShapes() if( m_nDimension==3 && m_bArea && pSeriesList->size()!=1 ) fLogicY = fabs( fLogicY ); - if( pPosHelper->isPercentY() && !::rtl::math::approxEqual( aLogicYSumMap[nAttachedAxisIndex], 0.0 ) ) + if (bPercent) + { + // This data series is percent-stacked. + + if (::rtl::math::approxEqual(aLogicYSumMap[nAttachedAxisIndex], 0.0)) + fLogicY = 0.0; + else + fLogicY = fabs( fLogicY )/aLogicYSumMap[nAttachedAxisIndex]; + + if (!pPosHelper->isPercentY()) + { + // When the axis itself is not percent-stacked, + // their internal range value is 0 - 100. So we + // need to adjust the data point values + // accordingly. + fLogicY *= 100.0; + } + } + else if (pPosHelper->isPercentY()) { - fLogicY = fabs( fLogicY )/aLogicYSumMap[nAttachedAxisIndex]; + // The data series is not percent-stacked, but the + // axis itself is. In this case, the axis' internal + // range is 0 to 1. Adjust the data point values. + fLogicY /= 100.0; } if( ::rtl::math::isNan(fLogicX) || ::rtl::math::isInf(fLogicX) diff --git chart2/source/view/charttypes/BarChart.cxx chart2/source/view/charttypes/BarChart.cxx index 7def5fa..49bb776 100644 --- chart2/source/view/charttypes/BarChart.cxx +++ chart2/source/view/charttypes/BarChart.cxx @@ -454,6 +454,11 @@ void BarChart::adaptOverlapAndGapwidthForGroupBarsPerAxis() void BarChart::createShapes() { + uno::Reference< beans::XPropertySet > xPropSet(m_xChartTypeModel, uno::UNO_QUERY); + sal_Bool bPercent = sal_False; + if (xPropSet.is()) + xPropSet->getPropertyValue(C2U("Percent")) >>= bPercent; + if( m_aZSlots.begin() == m_aZSlots.end() ) //no series return; diff --git chart2/source/view/charttypes/VSeriesPlotter.cxx chart2/source/view/charttypes/VSeriesPlotter.cxx index c0cedb1..1e651ca 100644 --- chart2/source/view/charttypes/VSeriesPlotter.cxx +++ chart2/source/view/charttypes/VSeriesPlotter.cxx @@ -1154,6 +1154,15 @@ double VSeriesPlotter::getMaximumX() double VSeriesPlotter::getMinimumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) { + sal_Bool bPercent = sal_False; + uno::Reference< beans::XPropertySet > xPropSet(m_xChartTypeModel, uno::UNO_QUERY); + if (xPropSet.is()) + xPropSet->getPropertyValue(C2U("Percent")) >>= bPercent; + + if (bPercent) + // This plotter is percent-stacked. + return 0.0; + if( !m_bCategoryXAxis ) { double fMinY, fMaxY; @@ -1188,6 +1197,15 @@ double VSeriesPlotter::getMinimumYInRange( double fMinimumX, double fMaximumX, s double VSeriesPlotter::getMaximumYInRange( double fMinimumX, double fMaximumX, sal_Int32 nAxisIndex ) { + sal_Bool bPercent = sal_False; + uno::Reference< beans::XPropertySet > xPropSet(m_xChartTypeModel, uno::UNO_QUERY); + if (xPropSet.is()) + xPropSet->getPropertyValue(C2U("Percent")) >>= bPercent; + + if (bPercent) + // This plotter is percent-stacked. + return 100.0; + if( !m_bCategoryXAxis ) { double fMinY, fMaxY; diff --git chart2/source/view/main/ChartView.cxx chart2/source/view/main/ChartView.cxx index 63075dc..189cc7d 100644 --- chart2/source/view/main/ChartView.cxx +++ chart2/source/view/main/ChartView.cxx @@ -1448,7 +1448,15 @@ sal_Int32 ExplicitValueProvider::getExplicitNumberFormatKeyForAxis( if( nDimensionIndex == 0 ) aRoleToMatch = C2U("values-x"); Sequence< Reference< XChartType > > aChartTypes( xCTCnt->getChartTypes()); - for( sal_Int32 nCTIdx=0; nCTIdx 0) + // When multiple chart types share the same axis, always + // use the first chart type for automatic detection of + // desired number format. This is in line with the + // fact that the axis type is also determined from the + // first chart type alone. + nCTCount = 1; + for( sal_Int32 nCTIdx=0; nCTIdxgetRoleOfSequenceForSeriesLabel();