/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
// Check we have the Pivot Table
OUString sPivotTableName(u"DataPilot1"_ustr);
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
CPPUNIT_ASSERT(xDataPilotTable.is());
// Check that we don't have any pivot chart in the document
uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
// Create a new pivot chart
xTablePivotCharts->addNewByName(u"Chart"_ustr, awt::Rectangle{0, 0, 9000, 9000}, sPivotTableName);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// Get the pivot chart document so we can access its data
xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
// Check the first data series
{
std::vector<double> aReference { 10162.033139 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
CPPUNIT_ASSERT_EQUAL(u"Big"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
} // Check the second data series
{
std::vector<double> aReference { 16614.523063 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
CPPUNIT_ASSERT_EQUAL(u"Medium"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
} // Check the third data series
{
std::vector<double> aReference { 27944.146101 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 2);
CPPUNIT_ASSERT_EQUAL(u"Small"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
}
// Enable column totals and check the data is still unchanged
{
uno::Reference<beans::XPropertySet> xProperties(xDataPilotTable, uno::UNO_QUERY_THROW);
xProperties->setPropertyValue(u"ColumnGrand"_ustr, uno::Any(true));
}
// Check the first data series
{
std::vector<double> aReference { 10162.033139 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 0)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 0);
CPPUNIT_ASSERT_EQUAL(u"Big"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
} // Check the second data series
{
std::vector<double> aReference { 16614.523063 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 1)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 1);
CPPUNIT_ASSERT_EQUAL(u"Medium"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
} // Check the third data series
{
std::vector<double> aReference { 27944.146101 };
xSequence = getDataSequenceFromDocByRole(xChartDoc, u"values-y", 2)->getData();
lclCheckSequence(aReference, xSequence, 1E-3);
Reference<chart2::data::XDataSequence> xLabelDataSequence = getLabelDataSequenceFromDoc(xChartDoc, 2);
CPPUNIT_ASSERT_EQUAL(u"Small"_ustr, xLabelDataSequence->getData()[0].get<OUString>());
}
}
void PivotChartTest::testPivotChartWithOneColumnField()
{ // We put one field as COLUMN field only and one DATA field. We expect we will get as many data series // in the pivot table as many distinct column values we have (with this example data 3: DE, EN, FR).
// Check that we don't have any pivot chart in the document
uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
// Create a new pivot chart
xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// Get the pivot chart document so we can access its data
xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
CPPUNIT_ASSERT(xChartDoc.is());
CPPUNIT_ASSERT_EQUAL(sal_Int32(3), getNumberOfDataSeries(xChartDoc)); // Check data series 1
{
std::vector<double> aReference { 1738.0 };
void PivotChartTest::testPivotChartWithOneRowField()
{ // We put one field as ROW field only and one DATA field. We expect we will get one data series // in the pivot table.
// Check that we don't have any pivot chart in the document
uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
// Create a new pivot chart
xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// Get the pivot chart document so we can access its data
xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
CPPUNIT_ASSERT(xChartDoc.is());
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc)); // Check data series 1
{
std::vector<double> aReference { 1738.0, 2003.0, 1936.0 };
// TEST
Reference<chart2::XChartDocument> xChartDoc;
// Check we have the Pivot Table
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
CPPUNIT_ASSERT(xDataPilotTable.is());
// refetch the XDataPilotDescriptor
xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
// Check that we don't have any pivot chart in the document
uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
// Create a new pivot chart
xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// Get the pivot chart document so we can access its data
xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
// Data to column fields
lclModifyOrientation(xDataPilotDescriptor, u"Data", sheet::DataPilotFieldOrientation_COLUMN);
// Change the order of column fields: expected data, type, country
lclModifyOrientation(xDataPilotDescriptor, u"Country", sheet::DataPilotFieldOrientation_HIDDEN);
lclModifyOrientation(xDataPilotDescriptor, u"Type", sheet::DataPilotFieldOrientation_HIDDEN);
// TEST
uno::Sequence<uno::Any> xSequence;
Reference<chart2::XChartDocument> xChartDoc;
// Check we have the Pivot Table
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
CPPUNIT_ASSERT(xDataPilotTable.is());
// refetch the XDataPilotDescriptor
xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
// Check that we don't have any pivot chart in the document
uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
// Create a new pivot chart
xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// Get the pivot chart document so we can access its data
xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
CPPUNIT_ASSERT(xChartDoc.is());
// Test case with defaults
// Check when using defaults the data is as expected
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
{
std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
// Test case where we enable subtotals (auto) and set the outline subtotals at the bottom // We don't expect any change in data as every extra subtotal row should be ignored
// Enable subtotals - set to auto
uno::Sequence<sheet::GeneralFunction> aGeneralFunctionSequence{ sheet::GeneralFunction_AUTO };
lclModifySubtotals(xDataPilotDescriptor, u"Country", aGeneralFunctionSequence); // Set Subtotals layout to bottom + add empty lines
aLayoutInfoValue.AddEmptyLines = true;
aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_BOTTOM;
lclModifyLayoutInfo(xDataPilotDescriptor, u"Country", aLayoutInfoValue);
// Check data is unchanged
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
{
std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
// Test case where we enable subtotals (auto) and set the outline subtotals at the top // We don't expect any change in data as every extra subtotal row should be ignored
// Enable subtotals - set to auto
aGeneralFunctionSequence.getArray()[0] = sheet::GeneralFunction_AUTO;
lclModifySubtotals(xDataPilotDescriptor, u"Country", aGeneralFunctionSequence); // Set Subtotals layout to top + add empty lines
aLayoutInfoValue.AddEmptyLines = true;
aLayoutInfoValue.LayoutMode = sheet::DataPilotFieldLayoutMode::OUTLINE_SUBTOTALS_TOP;
lclModifyLayoutInfo(xDataPilotDescriptor, u"Country", aLayoutInfoValue);
// Check data is unchanged
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), getNumberOfDataSeries(xChartDoc));
{
std::vector<double> aReference { 1116.0, 622.0, 298.0, 562.0, 1143.0, 1168.0, 768.0 };
// TEST
Reference<chart2::XChartDocument> xChartDoc;
// Check we have the Pivot Table
uno::Reference<sheet::XDataPilotTable> xDataPilotTable = getPivotTableByName(1, sPivotTableName );
CPPUNIT_ASSERT(xDataPilotTable.is());
// refetch the XDataPilotDescriptor
xDataPilotDescriptor.set(xDataPilotTable, uno::UNO_QUERY_THROW);
// Check that we don't have any pivot chart in the document
uno::Reference<table::XTablePivotCharts> xTablePivotCharts = getTablePivotChartsFromSheet(1 );
uno::Reference<container::XIndexAccess> xIndexAccess(xTablePivotCharts, UNO_QUERY_THROW);
CPPUNIT_ASSERT_EQUAL(sal_Int32(0), xIndexAccess->getCount());
// Create a new pivot chart
xTablePivotCharts->addNewByName(u"PivotChart"_ustr, awt::Rectangle{ 9000, 9000, 21000, 18000 }, sPivotTableName);
CPPUNIT_ASSERT_EQUAL(sal_Int32(1), xIndexAccess->getCount());
// Get the pivot chart document so we can access its data
xChartDoc.set(getPivotChartDocFromSheet(xTablePivotCharts, 0));
CPPUNIT_ASSERT(xChartDoc.is());
// Check if Date category is date formatted.
lclCheckCategories( { u"12/11/15"_ustr, u""_ustr, u""_ustr, u""_ustr, u""_ustr, u""_ustr, u"12/14/15"_ustr, u"12/17/15"_ustr, u"01/20/16"_ustr, u""_ustr, u""_ustr, u"03/21/17"_ustr },
lclGetCategories( xChartDoc )[0]->getValues() );
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.