Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataPreprocessing/HeuristicLab.ExtLibs/HeuristicLab.EPPlus/3.1.3/EPPlus-3.1.3/Drawing/Chart/ExcelChartLegend.cs @ 10475

Last change on this file since 10475 was 9580, checked in by sforsten, 12 years ago

#1730:

  • added SymbolicDataAnalysisExpressionExcelFormatter
  • changed modifiers in SymbolicExpressionTreeChart of methods SaveImageAsBitmap and SaveImageAsEmf to public
  • added menu item ExportSymbolicSolutionToExcelMenuItem to export a symbolic solution to an excel file
  • added EPPlus-3.1.3 to ExtLibs
File size: 7.0 KB
Line 
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-10-01
30 * Jan Källman    License changed GPL-->LGPL 2011-12-16
31 *******************************************************************************/
32using System;
33using System.Collections.Generic;
34using System.Text;
35using System.Xml;
36using OfficeOpenXml.Style;
37
38namespace OfficeOpenXml.Drawing.Chart
39{
40    /// <summary>
41    /// Position of the legend
42    /// </summary>
43    public enum eLegendPosition
44    {
45        Top,
46        Left,
47        Right,
48        Bottom,
49        TopRight
50    }
51    /// <summary>
52    /// Chart ledger
53    /// </summary>
54    public class ExcelChartLegend : XmlHelper
55    {
56        ExcelChart _chart;
57        internal ExcelChartLegend(XmlNamespaceManager ns, XmlNode node, ExcelChart chart)
58           : base(ns,node)
59       {
60           _chart=chart;
61           SchemaNodeOrder = new string[] { "legendPos", "layout","overlay", "txPr", "bodyPr", "lstStyle", "spPr" };
62       }
63        const string POSITION_PATH = "c:legendPos/@val";
64        /// <summary>
65        /// Position of the Legend
66        /// </summary>
67        public eLegendPosition Position
68        {
69            get
70            {
71                switch(GetXmlNodeString(POSITION_PATH).ToLower())
72                {
73                    case "t":
74                        return eLegendPosition.Top;
75                    case "b":
76                        return eLegendPosition.Bottom;
77                    case "l":
78                        return eLegendPosition.Left;
79                    case "tr":
80                        return eLegendPosition.TopRight;
81                    default:
82                        return eLegendPosition.Right;
83                }
84            }
85            set
86            {
87                if (TopNode == null) throw(new Exception("Can't set position. Chart has no legend"));
88                switch (value)
89                {
90                    case eLegendPosition.Top:
91                        SetXmlNodeString(POSITION_PATH, "t");
92                        break;
93                    case eLegendPosition.Bottom:
94                        SetXmlNodeString(POSITION_PATH, "b");
95                        break;
96                    case eLegendPosition.Left:
97                        SetXmlNodeString(POSITION_PATH, "l");
98                        break;
99                    case eLegendPosition.TopRight:
100                        SetXmlNodeString(POSITION_PATH, "tr");
101                        break;
102                    default:
103                        SetXmlNodeString(POSITION_PATH, "r");
104                        break;
105                }
106            }
107        }
108        const string OVERLAY_PATH = "c:overlay/@val";
109        /// <summary>
110        /// If the legend overlays other objects
111        /// </summary>
112        public bool Overlay
113        {
114            get
115            {
116                return GetXmlNodeBool(OVERLAY_PATH);
117            }
118            set
119            {
120                if (TopNode == null) throw (new Exception("Can't set overlay. Chart has no legend"));
121                SetXmlNodeBool(OVERLAY_PATH, value);
122            }
123        }
124        ExcelDrawingFill _fill = null;
125        /// <summary>
126        /// Fill style
127        /// </summary>
128        public ExcelDrawingFill Fill
129        {
130            get
131            {
132                if (_fill == null)
133                {
134                    _fill = new ExcelDrawingFill(NameSpaceManager, TopNode, "c:spPr");
135                }
136                return _fill;
137            }
138        }
139        ExcelDrawingBorder _border = null;
140        /// <summary>
141        /// Border style
142        /// </summary>
143        public ExcelDrawingBorder Border
144        {
145            get
146            {
147                if (_border == null)
148                {
149                    _border = new ExcelDrawingBorder(NameSpaceManager, TopNode, "c:spPr/a:ln");
150                }
151                return _border;
152            }
153        }
154        ExcelTextFont _font = null;
155        /// <summary>
156        /// Font properties
157        /// </summary>
158        public ExcelTextFont Font
159        {
160            get
161            {
162                if (_font == null)
163                {
164                    if (TopNode.SelectSingleNode("c:txPr",NameSpaceManager) == null)
165                    {
166                        CreateNode("c:txPr/a:bodyPr");
167                        CreateNode("c:txPr/a:lstStyle");
168                    }
169                    _font = new ExcelTextFont(NameSpaceManager, TopNode, "c:txPr/a:p/a:pPr/a:defRPr", new string[] { "legendPos", "layout", "pPr", "defRPr", "solidFill", "uFill", "latin", "cs", "r", "rPr", "t" });
170                }
171                return _font;
172            }
173        }
174        /// <summary>
175        /// Remove the legend
176        /// </summary>
177        public void Remove()
178        {
179            if (TopNode == null) return;
180            TopNode.ParentNode.RemoveChild(TopNode);
181            TopNode = null;
182        }
183        /// <summary>
184        /// Add a legend to the chart
185        /// </summary>
186        public void Add()
187        {
188            if(TopNode!=null) return;
189
190            //XmlHelper xml = new XmlHelper(NameSpaceManager, _chart.ChartXml);
191            XmlHelper xml = XmlHelperFactory.Create(NameSpaceManager, _chart.ChartXml);
192            xml.SchemaNodeOrder=_chart.SchemaNodeOrder;
193
194            xml.CreateNode("c:chartSpace/c:chart/c:legend");
195            TopNode = _chart.ChartXml.SelectSingleNode("c:chartSpace/c:chart/c:legend", NameSpaceManager);
196            TopNode.InnerXml="<c:legendPos val=\"r\" /><c:layout />";                       
197        }
198    }
199}
Note: See TracBrowser for help on using the repository browser.