fdo77216-Charts-Scattered chart: Chart gets distorted on RT

In case there is some text entered in place of X coordinates for scatter chart
then x coordinates should be taken as 1,2,3....
MS Word does the same thing

Change-Id: I1db0fd64c6ac0f4d5e77a9676812f5e26577ecf6
Reviewed-on: https://gerrit.libreoffice.org/9011
Tested-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
This commit is contained in:
Sourav
2014-04-15 16:39:52 +05:30
committed by Markus Mohrhard
parent 89e14d6c31
commit a211c75400
3 changed files with 54 additions and 1 deletions

View File

@@ -36,6 +36,7 @@ public:
void testStockChart();
void testBarChart();
void testCrosses();
void testScatterChart();
void testChartDataTable();
void testChartExternalData();
void testEmbeddingsGrabBag();
@@ -64,6 +65,7 @@ public:
CPPUNIT_TEST(testStockChart);
CPPUNIT_TEST(testBarChart);
CPPUNIT_TEST(testCrosses);
CPPUNIT_TEST(testScatterChart);
CPPUNIT_TEST(testChartDataTable);
CPPUNIT_TEST(testChartExternalData);
CPPUNIT_TEST(testEmbeddingsGrabBag);
@@ -117,6 +119,14 @@ protected:
* Same as the assertXPath(), but don't assert: return the string instead.
*/
OUString getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute);
/**
Assert that rXPath exists, and its content equals rContent.
*/
void assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent);
/**
Same as the assertXPathContent(), but don't assert: return the string instead.
*/
OUString getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath);
private:
};
@@ -211,6 +221,24 @@ void Chart2ExportTest::assertXPath(xmlDocPtr pXmlDoc, const OString& rXPath, int
nNumberOfNodes, xmlXPathNodeSetGetLength(pXmlNodes));
}
void Chart2ExportTest::assertXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath, const OUString& rContent)
{
CPPUNIT_ASSERT_EQUAL_MESSAGE("XPath contents of child does not match", rContent, getXPathContent(pXmlDoc, rXPath));
}
OUString Chart2ExportTest::getXPathContent(xmlDocPtr pXmlDoc, const OString& rXPath)
{
xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
CPPUNIT_ASSERT_MESSAGE(OString("XPath '" + rXPath + "' not found").getStr(),
xmlXPathNodeSetGetLength(pXmlNodes) > 0);
xmlNodePtr pXmlNode = pXmlNodes->nodeTab[0];
_xmlNode *pNode = &(pXmlNode->children[0]);
return pNode ? OUString::createFromAscii((const char*)((pXmlNode->children[0]).content)) : OUString();
}
OUString Chart2ExportTest::getXPath(xmlDocPtr pXmlDoc, const OString& rXPath, const OString& rAttribute)
{
xmlNodeSetPtr pXmlNodes = getXPathNode(pXmlDoc, rXPath);
@@ -479,6 +507,16 @@ void Chart2ExportTest::testCrosses()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:catAx/c:crosses", "val", "autoZero");
}
void Chart2ExportTest::testScatterChart()
{
load("/chart2/qa/extras/data/docx/", "fdo77216.docx");
xmlDocPtr pXmlDoc = parseExport("word/charts/chart", "Office Open XML Text");
if (!pXmlDoc)
return;
assertXPathContent(pXmlDoc, "//c:scatterChart/c:ser[1]/c:xVal[1]/c:numRef[1]/c:numCache[1]/c:pt[1]/c:v[1]", "1");
}
void Chart2ExportTest::testChartDataTable()
{
load("/chart2/qa/extras/data/docx/", "testChartDataTable.docx");

Binary file not shown.

View File

@@ -2008,6 +2008,14 @@ void ChartExport::exportSeriesValues( const Reference< chart2::data::XDataSequen
pFS->singleElement( FSNS( XML_c, XML_ptCount ),
XML_val, I32S( ptCount ),
FSEND );
sal_Bool bIsNumberValue = sal_True;
sal_Bool bXSeriesValue = sal_False;
double Value = 1.0;
if(nValueType == XML_xVal)
bXSeriesValue = sal_True;
for( sal_Int32 i = 0; i < ptCount; i++ )
{
pFS->startElement( FSNS( XML_c, XML_pt ),
@@ -2015,8 +2023,15 @@ void ChartExport::exportSeriesValues( const Reference< chart2::data::XDataSequen
FSEND );
pFS->startElement( FSNS( XML_c, XML_v ),
FSEND );
if (!rtl::math::isNan(aValues[i]))
if (bIsNumberValue && !rtl::math::isNan(aValues[i]))
pFS->write( aValues[i] );
else if(bXSeriesValue)
{
//In Case aValues is not a number for X Values...We write X values as 1,2,3....MS Word does the same thing.
pFS->write( Value );
Value = Value + 1;
bIsNumberValue = sal_False;
}
pFS->endElement( FSNS( XML_c, XML_v ) );
pFS->endElement( FSNS( XML_c, XML_pt ) );
}