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 Initial Release 2009-10-01
|
---|
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 |
|
---|
37 | namespace OfficeOpenXml.Drawing.Chart
|
---|
38 | {
|
---|
39 | /// <summary>
|
---|
40 | /// A serie for a scatter chart
|
---|
41 | /// </summary>
|
---|
42 | public sealed class ExcelBubbleChartSerie : ExcelChartSerie
|
---|
43 | {
|
---|
44 | /// <summary>
|
---|
45 | /// Default constructor
|
---|
46 | /// </summary>
|
---|
47 | /// <param name="chartSeries">Parent collection</param>
|
---|
48 | /// <param name="ns">Namespacemanager</param>
|
---|
49 | /// <param name="node">Topnode</param>
|
---|
50 | /// <param name="isPivot">Is pivotchart</param>
|
---|
51 | internal ExcelBubbleChartSerie(ExcelChartSeries chartSeries, XmlNamespaceManager ns, XmlNode node, bool isPivot) :
|
---|
52 | base(chartSeries, ns, node, isPivot)
|
---|
53 | {
|
---|
54 |
|
---|
55 | }
|
---|
56 | ExcelChartSerieDataLabel _DataLabel = null;
|
---|
57 | /// <summary>
|
---|
58 | /// Datalabel
|
---|
59 | /// </summary>
|
---|
60 | public ExcelChartSerieDataLabel DataLabel
|
---|
61 | {
|
---|
62 | get
|
---|
63 | {
|
---|
64 | if (_DataLabel == null)
|
---|
65 | {
|
---|
66 | _DataLabel = new ExcelChartSerieDataLabel(_ns, _node);
|
---|
67 | }
|
---|
68 | return _DataLabel;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | const string BUBBLE3D_PATH = "c:bubble3D/@val";
|
---|
72 | internal bool Bubble3D
|
---|
73 | {
|
---|
74 | get
|
---|
75 | {
|
---|
76 | return GetXmlNodeBool(BUBBLE3D_PATH, true);
|
---|
77 | }
|
---|
78 | set
|
---|
79 | {
|
---|
80 | SetXmlNodeBool(BUBBLE3D_PATH, value);
|
---|
81 | }
|
---|
82 | }
|
---|
83 | const string INVERTIFNEGATIVE_PATH = "c:invertIfNegative/@val";
|
---|
84 | internal bool InvertIfNegative
|
---|
85 | {
|
---|
86 | get
|
---|
87 | {
|
---|
88 | return GetXmlNodeBool(INVERTIFNEGATIVE_PATH, true);
|
---|
89 | }
|
---|
90 | set
|
---|
91 | {
|
---|
92 | SetXmlNodeBool(INVERTIFNEGATIVE_PATH, value);
|
---|
93 | }
|
---|
94 | }
|
---|
95 | public override string Series
|
---|
96 | {
|
---|
97 | get
|
---|
98 | {
|
---|
99 | return base.Series;
|
---|
100 | }
|
---|
101 | set
|
---|
102 | {
|
---|
103 | base.Series = value;
|
---|
104 | if(string.IsNullOrEmpty(BubbleSize))
|
---|
105 | {
|
---|
106 | GenerateLit();
|
---|
107 | }
|
---|
108 | }
|
---|
109 | }
|
---|
110 | const string BUBBLESIZE_TOPPATH = "c:bubbleSize";
|
---|
111 | const string BUBBLESIZE_PATH = BUBBLESIZE_TOPPATH + "/c:numRef/c:f";
|
---|
112 | public string BubbleSize
|
---|
113 | {
|
---|
114 | get
|
---|
115 | {
|
---|
116 | return GetXmlNodeString(BUBBLESIZE_PATH);
|
---|
117 | }
|
---|
118 | set
|
---|
119 | {
|
---|
120 | if(string.IsNullOrEmpty(value))
|
---|
121 | {
|
---|
122 | GenerateLit();
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | SetXmlNodeString(BUBBLESIZE_PATH, ExcelCellBase.GetFullAddress(_chartSeries.Chart.WorkSheet.Name, value));
|
---|
127 |
|
---|
128 | XmlNode cache = TopNode.SelectSingleNode(string.Format("{0}/c:numCache", BUBBLESIZE_PATH), _ns);
|
---|
129 | if (cache != null)
|
---|
130 | {
|
---|
131 | cache.ParentNode.RemoveChild(cache);
|
---|
132 | }
|
---|
133 |
|
---|
134 | DeleteNode(string.Format("{0}/c:numLit", BUBBLESIZE_TOPPATH));
|
---|
135 | //XmlNode lit = TopNode.SelectSingleNode(string.Format("{0}/c:numLit", _xSeriesTopPath), _ns);
|
---|
136 | //if (lit != null)
|
---|
137 | //{
|
---|
138 | // lit.ParentNode.RemoveChild(lit);
|
---|
139 | //}
|
---|
140 | }
|
---|
141 | }
|
---|
142 | }
|
---|
143 |
|
---|
144 | internal void GenerateLit()
|
---|
145 | {
|
---|
146 | var s = new ExcelAddress(Series);
|
---|
147 | var ix = 0;
|
---|
148 | var sb = new StringBuilder();
|
---|
149 | for (int row = s._fromRow; row <= s._toRow; row++)
|
---|
150 | {
|
---|
151 | for (int c = s._fromCol; c <= s._toCol; c++)
|
---|
152 | {
|
---|
153 | sb.AppendFormat("<c:pt idx=\"{0}\"><c:v>1</c:v></c:pt>", ix++);
|
---|
154 | }
|
---|
155 | }
|
---|
156 | CreateNode(BUBBLESIZE_TOPPATH + "/c:numLit", true);
|
---|
157 | XmlNode lit = TopNode.SelectSingleNode(string.Format("{0}/c:numLit", BUBBLESIZE_TOPPATH), _ns);
|
---|
158 | lit.InnerXml = string.Format("<c:formatCode>General</c:formatCode><c:ptCount val=\"{0}\"/>{1}", ix, sb.ToString());
|
---|
159 | }
|
---|
160 | }
|
---|
161 | }
|
---|