[Libreoffice-commits] core.git: 2 commits - chart2/qa oox/source
Kohei Yoshida
kohei.yoshida at collabora.com
Thu Aug 7 16:02:02 PDT 2014
chart2/qa/extras/chart2export.cxx | 17 ++++++++
chart2/qa/extras/data/docx/bar-chart-labels.docx |binary
oox/source/export/chartexport.cxx | 44 +++++++++++++++++++----
3 files changed, 54 insertions(+), 7 deletions(-)
New commits:
commit 7b8073906adca8dae24c04a23708a3f3d582218f
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Aug 7 18:57:50 2014 -0400
Ensure we export correct labal placement value for percent/stacked charts.
Normal charts allow a variety of label placement options, but percent/stacked
charts only allow three variants, and exporting a wrong value would trigger
MS Office to think the file is corrupt.
Change-Id: I8bdc1dc072b29e8df2c506b6b16c61279df12045
diff --git a/oox/source/export/chartexport.cxx b/oox/source/export/chartexport.cxx
index 0845f71..882c52c 100644
--- a/oox/source/export/chartexport.cxx
+++ b/oox/source/export/chartexport.cxx
@@ -86,6 +86,7 @@
#include <xmloff/SchXMLSeriesHelper.hxx>
#include "ColorPropertySet.hxx"
#include <set>
+#include <boost/unordered_set.hpp>
#include <rtl/math.hxx>
@@ -443,6 +444,8 @@ ChartExport::ChartExport( sal_Int32 nXmlNamespace, FSHelperPtr pFS, Reference< f
, mbHasCategoryLabels( false )
, mbHasZAxis( false )
, mbIs3DChart( false )
+ , mbStacked(false)
+ , mbPercent(false)
{
}
@@ -2540,9 +2543,24 @@ struct LabelPlacementParam
bool mbExport;
sal_Int32 meDefault;
+ boost::unordered_set<sal_Int32> maAllowedValues;
+
LabelPlacementParam() :
mbExport(true),
meDefault(css::chart::DataLabelPlacement::OUTSIDE) {}
+
+ void allowAll()
+ {
+ maAllowedValues.insert(css::chart::DataLabelPlacement::OUTSIDE);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::INSIDE);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::CENTER);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::NEAR_ORIGIN);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::TOP);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::BOTTOM);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::LEFT);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::RIGHT);
+ maAllowedValues.insert(css::chart::DataLabelPlacement::AVOID_OVERLAP);
+ }
};
const char* toOOXMLPlacement( sal_Int32 nPlacement )
@@ -2597,7 +2615,11 @@ void writeLabelProperties(
{
sal_Int32 nLabelPlacement = rLabelParam.meDefault;
if (xPropSet->getPropertyValue("LabelPlacement") >>= nLabelPlacement)
+ {
+ if (!rLabelParam.maAllowedValues.count(nLabelPlacement))
+ nLabelPlacement = rLabelParam.meDefault;
pFS->singleElement(FSNS(XML_c, XML_dLblPos), XML_val, toOOXMLPlacement(nLabelPlacement), FSEND);
+ }
}
pFS->singleElement(FSNS(XML_c, XML_showLegendKey), XML_val, BS(aLabel.ShowLegendSymbol), FSEND);
@@ -2633,6 +2655,7 @@ void ChartExport::exportDataLabels(
LabelPlacementParam aParam;
aParam.mbExport = !mbIs3DChart;
aParam.meDefault = rInfo.mnDefLabelPos;
+ aParam.allowAll();
switch (getChartType()) // diagram chart type
{
case chart::TYPEID_PIE:
@@ -2641,9 +2664,18 @@ void ChartExport::exportDataLabels(
break;
case chart::TYPEID_DOUGHNUT:
case chart::TYPEID_AREA:
- // Doughnut charts don't support label placement.
+ // Doughnut and area charts don't support label placement.
aParam.mbExport = false;
break;
+ case chart::TYPEID_BAR:
+ if (mbStacked || mbPercent)
+ {
+ aParam.maAllowedValues.clear();
+ aParam.maAllowedValues.insert(css::chart::DataLabelPlacement::CENTER);
+ aParam.maAllowedValues.insert(css::chart::DataLabelPlacement::INSIDE);
+ aParam.maAllowedValues.insert(css::chart::DataLabelPlacement::NEAR_ORIGIN);
+ aParam.meDefault = css::chart::DataLabelPlacement::CENTER;
+ }
default:
;
}
@@ -2768,17 +2800,15 @@ void ChartExport::exportGrouping( bool isBar )
FSHelperPtr pFS = GetFS();
Reference< XPropertySet > xPropSet( mxDiagram , uno::UNO_QUERY);
// grouping
- bool bStacked = false;
if( GetProperty( xPropSet, "Stacked" ) )
- mAny >>= bStacked;
- bool bPercentage = false;
+ mAny >>= mbStacked;
if( GetProperty( xPropSet, "Percent" ) )
- mAny >>= bPercentage;
+ mAny >>= mbPercent;
const char* grouping = NULL;
- if( bStacked )
+ if (mbStacked)
grouping = "stacked";
- else if( bPercentage )
+ else if (mbPercent)
grouping = "percentStacked";
else
{
commit 3119e04b45a5598833aee2b114f6abcaf3c6808c
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date: Thu Aug 7 18:57:17 2014 -0400
Write test for exporting data label positions for percent stack bar chart.
Change-Id: Idebb56fc96828ec38d5c239c16e5b413a50c837f
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx
index 664dba5..a76b43d 100644
--- a/chart2/qa/extras/chart2export.cxx
+++ b/chart2/qa/extras/chart2export.cxx
@@ -71,6 +71,7 @@ public:
void testAxisNumberFormatODS();
void testDataLabelBordersDOCX();
void testDataLabel3DChartDOCX();
+ void testDataLabelBarChartDOCX();
void testDataLabelDoughnutChartDOCX();
void testDataLabelAreaChartDOCX();
void testDataLabelDefaultLineChartDOCX();
@@ -110,6 +111,7 @@ public:
CPPUNIT_TEST(testAxisNumberFormatODS);
CPPUNIT_TEST(testDataLabelBordersDOCX);
CPPUNIT_TEST(testDataLabel3DChartDOCX);
+ CPPUNIT_TEST(testDataLabelBarChartDOCX);
CPPUNIT_TEST(testDataLabelDoughnutChartDOCX);
CPPUNIT_TEST(testDataLabelAreaChartDOCX);
CPPUNIT_TEST(testDataLabelDefaultLineChartDOCX);
@@ -826,6 +828,21 @@ void Chart2ExportTest::testDataLabel3DChartDOCX()
assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:bar3DChart/c:ser/c:dLbls/c:dLbl/c:dLblPos", 0);
}
+void Chart2ExportTest::testDataLabelBarChartDOCX()
+{
+ load("/chart2/qa/extras/data/docx/", "bar-chart-labels.docx");
+
+ Reference<chart2::XChartDocument> xChartDoc(getChartDocFromWriter(0), uno::UNO_QUERY);
+ CPPUNIT_ASSERT(xChartDoc.is());
+
+ xmlDocPtr pXmlDoc = parseExport("word/charts/chart","Office Open XML Text");
+ CPPUNIT_ASSERT(pXmlDoc);
+
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[1]/c:dLbls/c:dLblPos", "val", "ctr");
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[2]/c:dLbls/c:dLblPos", "val", "inEnd");
+ assertXPath(pXmlDoc, "/c:chartSpace/c:chart/c:plotArea/c:barChart/c:ser[3]/c:dLbls/c:dLblPos", "val", "inBase");
+}
+
void Chart2ExportTest::testDataLabelDoughnutChartDOCX()
{
load("/chart2/qa/extras/data/docx/", "doughnut-chart-labels.docx");
diff --git a/chart2/qa/extras/data/docx/bar-chart-labels.docx b/chart2/qa/extras/data/docx/bar-chart-labels.docx
new file mode 100755
index 0000000..9ff8b4f
Binary files /dev/null and b/chart2/qa/extras/data/docx/bar-chart-labels.docx differ
More information about the Libreoffice-commits
mailing list