Skip to content

Commit 3002b34

Browse files
Chart Legend Entries issue with text settings (#1492)
* Added fix for Chart Legend Entries issue with text settings * Added fix for datalabel * Added datalabel formatting issues fix * Fixed test to avoid validation error on colors --------- Co-authored-by: Ossian Edström <[email protected]>
1 parent ff5cd29 commit 3002b34

File tree

8 files changed

+45
-22
lines changed

8 files changed

+45
-22
lines changed

src/EPPlus/Drawing/Chart/ExcelChartDataLabelCollection.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ private XmlElement CreateElement(int idx)
7878
XmlElement pointNode;
7979
if (idx < _list.Count)
8080
{
81-
pointNode = TopNode.OwnerDocument.CreateElement("c", "dLbl", ExcelPackage.schemaMain);
81+
pointNode = TopNode.OwnerDocument.CreateElement("c", "dLbl", @"http://schemas.openxmlformats.org/drawingml/2006/chart");
8282
TopNode.InsertBefore(pointNode, _list[idx].TopNode);
8383
}
8484
else

src/EPPlus/Drawing/Chart/ExcelChartDataLabelStandard.cs

+17-6
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,10 @@ public class ExcelChartDataLabelStandard : ExcelChartDataLabel
2727
internal ExcelChartDataLabelStandard(ExcelChart chart, XmlNamespaceManager ns, XmlNode node, string nodeName, string[] schemaNodeOrder)
2828
: base(chart, ns, node, nodeName, "c")
2929
{
30-
AddSchemaNodeOrder([""], LabelNodeHolder.DataLabels.NodeOrder);
31-
var order = SchemaNodeOrder;
32-
3330
if (nodeName == "dLbl" || nodeName == "")
3431
{
35-
AddSchemaNodeOrder([""], LabelNodeHolder.DataLabel.NodeOrder);
36-
32+
SchemaNodeOrder = LabelNodeHolder.DataLabel.NodeOrder;
33+
3734
TopNode = node;
3835

3936
var extPath = "c:extLst/c:ext";
@@ -57,6 +54,8 @@ internal ExcelChartDataLabelStandard(ExcelChart chart, XmlNamespaceManager ns, X
5754
}
5855
else
5956
{
57+
SchemaNodeOrder = schemaNodeOrder;
58+
6059
var fullNodeName = "c:" + nodeName;
6160
var topNode = GetNode(fullNodeName);
6261
if (topNode == null)
@@ -65,6 +64,7 @@ internal ExcelChartDataLabelStandard(ExcelChart chart, XmlNamespaceManager ns, X
6564
topNode.InnerXml = "<c:showLegendKey val=\"0\" /><c:showVal val=\"0\" /><c:showCatName val=\"0\" /><c:showSerName val=\"0\" /><c:showPercent val=\"0\" /><c:showBubbleSize val=\"0\" /> <c:separator>\r\n</c:separator><c:showLeaderLines val=\"0\" />";
6665
}
6766
TopNode = topNode;
67+
SchemaNodeOrder = LabelNodeHolder.DataLabels.NodeOrder;
6868
}
6969
}
7070

@@ -161,11 +161,22 @@ public override bool ShowLeaderLines
161161
{
162162
get
163163
{
164+
if(TopNode.LocalName == "dLbl")
165+
{
166+
return GetXmlNodeBool(showLeaderLinesPath, TopNode.ParentNode);
167+
}
164168
return GetXmlNodeBool(showLeaderLinesPath);
165169
}
166170
set
167171
{
168-
SetXmlNodeString(showLeaderLinesPath, value ? "1" : "0");
172+
if (TopNode.LocalName == "dLbl")
173+
{
174+
SetXmlNodeString(TopNode.ParentNode, showBubbleSizePath, value ? "1" : "0");
175+
}
176+
else
177+
{
178+
SetXmlNodeString(showLeaderLinesPath, value ? "1" : "0");
179+
}
169180
}
170181
}
171182
const string showBubbleSizePath = "c:showBubbleSize/@val";

src/EPPlus/Drawing/Chart/ExcelChartSerieDataLabel.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public sealed class ExcelChartSerieDataLabel : ExcelChartDataLabelStandard
2727
{
2828
internal ExcelChartSerieDataLabel(ExcelChart chart, XmlNamespaceManager ns, XmlNode node, string[] schemaNodeOrder)
2929
: base(chart, ns,node,"dLbls", schemaNodeOrder)
30-
{
30+
{
3131
Position = eLabelPosition.Center;
3232
}
3333
ExcelChartDataLabelCollection _dataLabels = null;

src/EPPlus/Style/ExcelTextFont.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,13 @@ protected internal void CreateTopNode()
101101
if (_path!="" && TopNode==_rootNode)
102102
{
103103
_initXml?.Invoke();
104-
CreateNode(_path);
105-
TopNode = _rootNode.SelectSingleNode(_path, NameSpaceManager);
106-
CreateNode("../../../a:bodyPr") ;
107-
CreateNode("../../../a:lstStyle");
104+
if (TopNode == _rootNode && string.IsNullOrEmpty(_path)==false)
105+
{
106+
CreateNode(_path);
107+
TopNode = _rootNode.SelectSingleNode(_path, NameSpaceManager);
108+
CreateNode("../../../a:bodyPr");
109+
CreateNode("../../../a:lstStyle");
110+
}
108111
}
109112
else if (TopNode.ParentNode?.ParentNode?.ParentNode?.LocalName == "rich")
110113
{

src/EPPlus/XmlHelper.cs

+14
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,20 @@ internal bool GetXmlNodeBool(string path)
989989
{
990990
return GetXmlNodeBool(path, false);
991991
}
992+
/// <summary>
993+
/// Get xmlNodeBool from parent node
994+
/// </summary>
995+
/// <param name="path"></param>
996+
/// <param name="parentNode"></param>
997+
/// <returns></returns>
998+
internal bool GetXmlNodeBool(string path, XmlNode parentNode)
999+
{
1000+
var tempNode = TopNode;
1001+
TopNode = parentNode;
1002+
var retVal = GetXmlNodeBool(path, TopNode);
1003+
TopNode = tempNode;
1004+
return retVal;
1005+
}
9921006
internal bool GetXmlNodeBool(string path, bool blankValue)
9931007
{
9941008
string value = GetXmlNodeString(path);

src/EPPlusTest/Drawing/Chart/DatalabelTest.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -296,9 +296,9 @@ void AdjustDataLabelItem(ref ExcelChartDataLabelItem label)
296296
}
297297

298298
[TestMethod]
299-
public void TwoLabelsOnSameSeries()
299+
public void DataLabelsMultipleOneSeries()
300300
{
301-
using (var pck = OpenPackage("ColumnChartStuffEasy.xlsx", true))
301+
using (var pck = OpenPackage("DataLabelsMultipleOneSeries.xlsx", true))
302302
{
303303
var cSheet = pck.Workbook.Worksheets.Add("ColumnChartSheet");
304304

src/EPPlusTest/FormulaParsing/Excel/Functions/RefAndLookup/GetPivotData/GetPivotDataTests_Grouping.cs

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
using OfficeOpenXml;
33
using OfficeOpenXml.Table.PivotTable;
44
using System;
5-
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
9-
using OfficeOpenXml.Table.PivotTable.Calculation.Functions;
10-
using OfficeOpenXml.Table.PivotTable.Calculation;
11-
using FakeItEasy;
125
namespace EPPlusTest.FormulaParsing.Excel.Functions.RefAndLookup
136
{
147
[TestClass]
@@ -156,6 +149,7 @@ public void GetPivotData_Grouping_YearMonth()
156149
[TestMethod]
157150
public void GetPivotData_Grouping_YearMonthDay()
158151
{
152+
SwitchToCulture();
159153
var ws = _package.Workbook.Worksheets.Add("DateGroup_YearMonthDay");
160154
var pt = ws.PivotTables.Add(ws.Cells["A1"], _dateWs1.Cells["K1:O11"], "PivotTable3");
161155
var rf = pt.RowFields.Add(pt.Fields[4]);
@@ -180,6 +174,7 @@ public void GetPivotData_Grouping_YearMonthDay()
180174
Assert.AreEqual(1D, (double)ws.Cells["G9"].Value);
181175
Assert.AreEqual(ErrorValues.RefError, ws.Cells["G10"].Value);
182176
Assert.AreEqual(2881D, (double)ws.Cells["G11"].Value);
177+
SwitchBackToCurrentCulture();
183178
}
184179
[TestMethod]
185180
public void GetPivotData_Grouping_Hour()

src/EPPlusTest/LoadFunctions/LoadFromCollectionTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ public void ShouldSetHyperlinkForURIs()
582582
var ns = package.Workbook.Styles.CreateNamedStyle("Hyperlink");
583583
ns.BuildInId = 8;
584584
ns.Style.Font.UnderLine = true;
585-
ns.Style.Font.Color.SetColor(System.Drawing.Color.FromArgb(0x0563C1));
585+
ns.Style.Font.Color.SetColor(System.Drawing.Color.FromArgb(0xFF,0x05 ,0x63, 0xC1));
586586

587587
var r = sheet.Cells["A1"].LoadFromCollection(items, true, TableStyles.Medium1);
588588
sheet.Cells["E2:E5"].StyleName = "Hyperlink";

0 commit comments

Comments
 (0)