Kaydet (Commit) 7f373a4c authored tarafından Balazs Varga's avatar Balazs Varga Kaydeden (comit) László Németh

tdf#48041 Chart: do not duplicate major value

axis labels and vertical axis lines. If the same
value labels follow each other, because of
the number format, only display them once.

Change-Id: I3c5577a0e86c475cb2fafb62d63f991cef7229d8
Reviewed-on: https://gerrit.libreoffice.org/73200
Tested-by: Jenkins
Reviewed-by: 's avatarLászló Németh <nemeth@numbertext.org>
üst 90ace7be
......@@ -118,6 +118,8 @@ public:
void testTdf116163();
void testTdf48041();
void testTdf121205();
void testTdf114179();
......@@ -199,6 +201,8 @@ public:
CPPUNIT_TEST(testTdf116163);
CPPUNIT_TEST(testTdf48041);
CPPUNIT_TEST(testTdf121205);
CPPUNIT_TEST(testTdf114179);
......@@ -1746,6 +1750,57 @@ void Chart2ImportTest::testTdf116163()
CPPUNIT_ASSERT_EQUAL(OUString("Dddd..."), xLabel3->getString());
}
void Chart2ImportTest::testTdf48041()
{
load("/chart2/qa/extras/data/pptx/", "tdf48041.pptx");
Reference<chart2::XChartDocument> xChartDoc(getChartDocFromDrawImpress(0, 0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xChartDoc.is());
Reference<chart2::XAxis> xYAxis = getAxisFromDoc(xChartDoc, 0, 1, 0);
CPPUNIT_ASSERT(xYAxis.is());
chart2::ScaleData aScaleData = xYAxis->getScaleData();
CPPUNIT_ASSERT(aScaleData.Scaling.is());
// Check visible text
uno::Reference<drawing::XDrawPageSupplier> xDrawPageSupplier(xChartDoc, uno::UNO_QUERY);
uno::Reference<drawing::XDrawPage> xDrawPage = xDrawPageSupplier->getDrawPage();
uno::Reference<drawing::XShapes> xShapes(xDrawPage->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT(xShapes.is());
const OUString sYAxisName = "CID/D=0:CS=0:Axis=1,0"; // Y Axis
uno::Reference<drawing::XShape> xYAxisShape = getShapeByName(xShapes, sYAxisName,
// Axis occurs twice in chart xshape representation so need to get the one related to labels
[](const uno::Reference<drawing::XShape>& rXShape) -> bool
{
uno::Reference<drawing::XShapes> xAxisShapes(rXShape, uno::UNO_QUERY);
CPPUNIT_ASSERT(xAxisShapes.is());
uno::Reference<drawing::XShape> xChildShape(xAxisShapes->getByIndex(0), uno::UNO_QUERY);
uno::Reference< drawing::XShapeDescriptor > xShapeDescriptor(xChildShape, uno::UNO_QUERY_THROW);
return (xShapeDescriptor->getShapeType() == "com.sun.star.drawing.TextShape");
});
CPPUNIT_ASSERT(xYAxisShape.is());
// Check label count
uno::Reference<container::XIndexAccess> xIndexAccess(xYAxisShape, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(static_cast<sal_Int32>(6), xIndexAccess->getCount());
// Check text
uno::Reference<text::XTextRange> xLabel0(xIndexAccess->getByIndex(0), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("0"), xLabel0->getString());
uno::Reference<text::XTextRange> xLabel1(xIndexAccess->getByIndex(1), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("1"), xLabel1->getString());
uno::Reference<text::XTextRange> xLabel2(xIndexAccess->getByIndex(2), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("2"), xLabel2->getString());
uno::Reference<text::XTextRange> xLabel3(xIndexAccess->getByIndex(3), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("3"), xLabel3->getString());
uno::Reference<text::XTextRange> xLabel4(xIndexAccess->getByIndex(4), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("4"), xLabel4->getString());
uno::Reference<text::XTextRange> xLabel5(xIndexAccess->getByIndex(5), uno::UNO_QUERY);
CPPUNIT_ASSERT_EQUAL(OUString("5"), xLabel5->getString());
}
void Chart2ImportTest::testTdf121205()
{
load("/chart2/qa/extras/data/pptx/", "tdf121205.pptx");
......
......@@ -28,6 +28,7 @@
#include <AxisHelper.hxx>
#include "Tickmarks_Equidistant.hxx"
#include <ExplicitCategoriesProvider.hxx>
#include <com/sun/star/chart2/AxisType.hpp>
#include <rtl/math.hxx>
#include <tools/color.hxx>
......@@ -1551,11 +1552,35 @@ sal_Int32 VCartesianAxis::estimateMaximumAutoMainIncrementCount()
sal_Int32 nTotalAvailable = nMaxHeight;
sal_Int32 nSingleNeeded = m_nMaximumTextHeightSoFar;
sal_Int32 nMaxSameLabel = 0;
//for horizontal axis:
if( (m_nDimensionIndex == 0 && !m_aAxisProperties.m_bSwapXAndY)
|| (m_nDimensionIndex == 1 && m_aAxisProperties.m_bSwapXAndY) )
{
if (m_aAxisProperties.m_nAxisType != css::chart2::AxisType::DATE)
{
// tdf#48041: do not duplicate the value labels because of rounding
FixedNumberFormatter aFixedNumberFormatterTest(m_xNumberFormatsSupplier, m_aAxisLabelProperties.nNumberFormatKey);
OUString sPreviousValueLabel;
sal_Int32 nSameLabel = 0;
for (sal_Int32 nLabel = 0; nLabel < static_cast<sal_Int32>(m_aAllTickInfos[0].size()); ++nLabel)
{
Color nColor = COL_AUTO;
bool bHasColor = false;
OUString sValueLabel = aFixedNumberFormatterTest.getFormattedString(m_aAllTickInfos[0][nLabel].fScaledTickValue, nColor, bHasColor);
if (sValueLabel == sPreviousValueLabel)
{
nSameLabel++;
if (nSameLabel > nMaxSameLabel)
nMaxSameLabel = nSameLabel;
}
else
nSameLabel = 0;
sPreviousValueLabel = sValueLabel;
}
}
nTotalAvailable = nMaxWidth;
nSingleNeeded = m_nMaximumTextWidthSoFar;
}
......@@ -1563,6 +1588,13 @@ sal_Int32 VCartesianAxis::estimateMaximumAutoMainIncrementCount()
if( nSingleNeeded>0 )
nRet = nTotalAvailable/nSingleNeeded;
if ( nMaxSameLabel > 0 )
{
sal_Int32 nRetNoSameLabel = m_aAllTickInfos[0].size() / (nMaxSameLabel + 1);
if ( nRet > nRetNoSameLabel )
nRet = nRetNoSameLabel;
}
return nRet;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment