1 | /*******************************************************************************
|
---|
2 | * You may amend and distribute as you like, but don't remove this header!
|
---|
3 | *
|
---|
4 | * EPPlus provides server-side generation of Excel 2007/2010 spreadsheets.
|
---|
5 | * See http://www.codeplex.com/EPPlus for details.
|
---|
6 | *
|
---|
7 | * Copyright (C) 2011 Jan Källman
|
---|
8 | *
|
---|
9 | * This library is free software; you can redistribute it and/or
|
---|
10 | * modify it under the terms of the GNU Lesser General Public
|
---|
11 | * License as published by the Free Software Foundation; either
|
---|
12 | * version 2.1 of the License, or (at your option) any later version.
|
---|
13 |
|
---|
14 | * This library is distributed in the hope that it will be useful,
|
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
---|
17 | * See the GNU Lesser General Public License for more details.
|
---|
18 | *
|
---|
19 | * The GNU Lesser General Public License can be viewed at http://www.opensource.org/licenses/lgpl-license.php
|
---|
20 | * If you unfamiliar with this license or have questions about it, here is an http://www.gnu.org/licenses/gpl-faq.html
|
---|
21 | *
|
---|
22 | * All code and executables are provided "as is" with no warranty either express or implied.
|
---|
23 | * The author accepts no liability for any damage or loss of business that this product may cause.
|
---|
24 | *
|
---|
25 | * Code change notes:
|
---|
26 | *
|
---|
27 | * Author Change Date
|
---|
28 | *******************************************************************************
|
---|
29 | * Jan Källman Added 2009-12-30
|
---|
30 | * Jan Källman License changed GPL-->LGPL 2011-12-16
|
---|
31 | *******************************************************************************/
|
---|
32 | using System;
|
---|
33 | using System.Collections.Generic;
|
---|
34 | using System.Text;
|
---|
35 | using System.Xml;
|
---|
36 | using OfficeOpenXml.Style;
|
---|
37 |
|
---|
38 | namespace OfficeOpenXml.Drawing.Chart
|
---|
39 | {
|
---|
40 | /// <summary>
|
---|
41 | /// Datalabel on chart level.
|
---|
42 | /// This class is inherited by ExcelChartSerieDataLabel
|
---|
43 | /// </summary>
|
---|
44 | public class ExcelChartDataLabel : XmlHelper
|
---|
45 | {
|
---|
46 | internal ExcelChartDataLabel(XmlNamespaceManager ns, XmlNode node)
|
---|
47 | : base(ns,node)
|
---|
48 | {
|
---|
49 | XmlNode topNode = node.SelectSingleNode("c:dLbls", NameSpaceManager);
|
---|
50 | if (topNode == null)
|
---|
51 | {
|
---|
52 | topNode = node.OwnerDocument.CreateElement("c", "dLbls", ExcelPackage.schemaChart);
|
---|
53 | //node.InsertAfter(_topNode, node.SelectSingleNode("c:order", NameSpaceManager));
|
---|
54 | InserAfter(node, "c:marker,c:tx,c:order,c:ser", topNode);
|
---|
55 | SchemaNodeOrder = new string[] { "spPr", "txPr", "dLblPos", "showLegendKey", "showVal", "showCatName", "showSerName", "showPercent", "showBubbleSize", "separator", "showLeaderLines" };
|
---|
56 | 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\" />";
|
---|
57 | }
|
---|
58 | TopNode = topNode;
|
---|
59 | }
|
---|
60 | #region "Public properties"
|
---|
61 | const string showValPath = "c:showVal/@val";
|
---|
62 | /// <summary>
|
---|
63 | /// Show the values
|
---|
64 | /// </summary>
|
---|
65 | public bool ShowValue
|
---|
66 | {
|
---|
67 | get
|
---|
68 | {
|
---|
69 | return GetXmlNodeBool(showValPath);
|
---|
70 | }
|
---|
71 | set
|
---|
72 | {
|
---|
73 | SetXmlNodeString(showValPath, value ? "1" : "0");
|
---|
74 | }
|
---|
75 | }
|
---|
76 | const string showCatPath = "c:showCatName/@val";
|
---|
77 | /// <summary>
|
---|
78 | /// Show category names
|
---|
79 | /// </summary>
|
---|
80 | public bool ShowCategory
|
---|
81 | {
|
---|
82 | get
|
---|
83 | {
|
---|
84 | return GetXmlNodeBool(showCatPath);
|
---|
85 | }
|
---|
86 | set
|
---|
87 | {
|
---|
88 | SetXmlNodeString(showCatPath, value ? "1" : "0");
|
---|
89 | }
|
---|
90 | }
|
---|
91 | const string showSerPath = "c:showSerName/@val";
|
---|
92 | /// <summary>
|
---|
93 | /// Show series names
|
---|
94 | /// </summary>
|
---|
95 | public bool ShowSeriesName
|
---|
96 | {
|
---|
97 | get
|
---|
98 | {
|
---|
99 | return GetXmlNodeBool(showSerPath);
|
---|
100 | }
|
---|
101 | set
|
---|
102 | {
|
---|
103 | SetXmlNodeString(showSerPath, value ? "1" : "0");
|
---|
104 | }
|
---|
105 | }
|
---|
106 | const string showPerentPath = "c:showPercent/@val";
|
---|
107 | /// <summary>
|
---|
108 | /// Show percent values
|
---|
109 | /// </summary>
|
---|
110 | public bool ShowPercent
|
---|
111 | {
|
---|
112 | get
|
---|
113 | {
|
---|
114 | return GetXmlNodeBool(showPerentPath);
|
---|
115 | }
|
---|
116 | set
|
---|
117 | {
|
---|
118 | SetXmlNodeString(showPerentPath, value ? "1" : "0");
|
---|
119 | }
|
---|
120 | }
|
---|
121 | const string showLeaderLinesPath = "c:showLeaderLines/@val";
|
---|
122 | /// <summary>
|
---|
123 | /// Show the leader lines
|
---|
124 | /// </summary>
|
---|
125 | public bool ShowLeaderLines
|
---|
126 | {
|
---|
127 | get
|
---|
128 | {
|
---|
129 | return GetXmlNodeBool(showLeaderLinesPath);
|
---|
130 | }
|
---|
131 | set
|
---|
132 | {
|
---|
133 | SetXmlNodeString(showLeaderLinesPath, value ? "1" : "0");
|
---|
134 | }
|
---|
135 | }
|
---|
136 | const string showBubbleSizePath = "c:showBubbleSize/@val";
|
---|
137 | /// <summary>
|
---|
138 | /// Bubble Size.
|
---|
139 | /// </summary>
|
---|
140 | public bool ShowBubbleSize
|
---|
141 | {
|
---|
142 | get
|
---|
143 | {
|
---|
144 | return GetXmlNodeBool(showBubbleSizePath);
|
---|
145 | }
|
---|
146 | set
|
---|
147 | {
|
---|
148 | SetXmlNodeString(showBubbleSizePath, value ? "1" : "0");
|
---|
149 | }
|
---|
150 | }
|
---|
151 | const string showLegendKeyPath = "c:showLegendKey/@val";
|
---|
152 | public bool ShowLegendKey
|
---|
153 | {
|
---|
154 | get
|
---|
155 | {
|
---|
156 | return GetXmlNodeBool(showLegendKeyPath);
|
---|
157 | }
|
---|
158 | set
|
---|
159 | {
|
---|
160 | SetXmlNodeString(showLegendKeyPath, value ? "1" : "0");
|
---|
161 | }
|
---|
162 | }
|
---|
163 | const string separatorPath = "c:separator";
|
---|
164 | /// <summary>
|
---|
165 | /// Separator string
|
---|
166 | /// </summary>
|
---|
167 | public string Separator
|
---|
168 | {
|
---|
169 | get
|
---|
170 | {
|
---|
171 | return GetXmlNodeString(separatorPath);
|
---|
172 | }
|
---|
173 | set
|
---|
174 | {
|
---|
175 | if (string.IsNullOrEmpty(value))
|
---|
176 | {
|
---|
177 | DeleteNode(separatorPath);
|
---|
178 | }
|
---|
179 | else
|
---|
180 | {
|
---|
181 | SetXmlNodeString(separatorPath, value);
|
---|
182 | }
|
---|
183 | }
|
---|
184 | }
|
---|
185 |
|
---|
186 | ExcelDrawingFill _fill = null;
|
---|
187 | /// <summary>
|
---|
188 | /// Access fill properties
|
---|
189 | /// </summary>
|
---|
190 | public ExcelDrawingFill Fill
|
---|
191 | {
|
---|
192 | get
|
---|
193 | {
|
---|
194 | if (_fill == null)
|
---|
195 | {
|
---|
196 | _fill = new ExcelDrawingFill(NameSpaceManager, TopNode, "c:spPr");
|
---|
197 | }
|
---|
198 | return _fill;
|
---|
199 | }
|
---|
200 | }
|
---|
201 | ExcelDrawingBorder _border = null;
|
---|
202 | /// <summary>
|
---|
203 | /// Access border properties
|
---|
204 | /// </summary>
|
---|
205 | public ExcelDrawingBorder Border
|
---|
206 | {
|
---|
207 | get
|
---|
208 | {
|
---|
209 | if (_border == null)
|
---|
210 | {
|
---|
211 | _border = new ExcelDrawingBorder(NameSpaceManager, TopNode, "c:spPr/a:ln");
|
---|
212 | }
|
---|
213 | return _border;
|
---|
214 | }
|
---|
215 | }
|
---|
216 | string[] _paragraphSchemaOrder = new string[] { "spPr", "txPr", "dLblPos", "showVal", "showCatName", "showSerName", "showPercent", "separator", "showLeaderLines", "pPr", "defRPr", "solidFill", "uFill", "latin", "cs", "r", "rPr", "t" };
|
---|
217 | ExcelTextFont _font = null;
|
---|
218 | /// <summary>
|
---|
219 | /// Access font properties
|
---|
220 | /// </summary>
|
---|
221 | public ExcelTextFont Font
|
---|
222 | {
|
---|
223 | get
|
---|
224 | {
|
---|
225 | if (_font == null)
|
---|
226 | {
|
---|
227 | if (TopNode.SelectSingleNode("c:txPr", NameSpaceManager) == null)
|
---|
228 | {
|
---|
229 | CreateNode("c:txPr/a:bodyPr");
|
---|
230 | CreateNode("c:txPr/a:lstStyle");
|
---|
231 | }
|
---|
232 | _font = new ExcelTextFont(NameSpaceManager, TopNode, "c:txPr/a:p/a:pPr/a:defRPr", _paragraphSchemaOrder);
|
---|
233 | }
|
---|
234 | return _font;
|
---|
235 | }
|
---|
236 | }
|
---|
237 | #endregion
|
---|
238 | #region "Position Enum Translation"
|
---|
239 | protected string GetPosText(eLabelPosition pos)
|
---|
240 | {
|
---|
241 | switch (pos)
|
---|
242 | {
|
---|
243 | case eLabelPosition.Bottom:
|
---|
244 | return "b";
|
---|
245 | case eLabelPosition.Center:
|
---|
246 | return "ctr";
|
---|
247 | case eLabelPosition.InBase:
|
---|
248 | return "inBase";
|
---|
249 | case eLabelPosition.InEnd:
|
---|
250 | return "inEnd";
|
---|
251 | case eLabelPosition.Left:
|
---|
252 | return "l";
|
---|
253 | case eLabelPosition.Right:
|
---|
254 | return "r";
|
---|
255 | case eLabelPosition.Top:
|
---|
256 | return "t";
|
---|
257 | case eLabelPosition.OutEnd:
|
---|
258 | return "outEnd";
|
---|
259 | default:
|
---|
260 | return "bestFit";
|
---|
261 | }
|
---|
262 | }
|
---|
263 |
|
---|
264 | protected eLabelPosition GetPosEnum(string pos)
|
---|
265 | {
|
---|
266 | switch (pos)
|
---|
267 | {
|
---|
268 | case "b":
|
---|
269 | return eLabelPosition.Bottom;
|
---|
270 | case "ctr":
|
---|
271 | return eLabelPosition.Center;
|
---|
272 | case "inBase":
|
---|
273 | return eLabelPosition.InBase;
|
---|
274 | case "inEnd":
|
---|
275 | return eLabelPosition.InEnd;
|
---|
276 | case "l":
|
---|
277 | return eLabelPosition.Left;
|
---|
278 | case "r":
|
---|
279 | return eLabelPosition.Right;
|
---|
280 | case "t":
|
---|
281 | return eLabelPosition.Top;
|
---|
282 | case "outEnd":
|
---|
283 | return eLabelPosition.OutEnd;
|
---|
284 | default:
|
---|
285 | return eLabelPosition.BestFit;
|
---|
286 | }
|
---|
287 | }
|
---|
288 | #endregion
|
---|
289 | }
|
---|
290 | }
|
---|