PageRenderTime 48ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/AODL/Document/Content/Charts/ChartPlotArea.cs

https://bitbucket.org/chrisc/aodl
C# | 414 lines | 207 code | 56 blank | 151 comment | 10 complexity | 65a26a8df8acbda79b50374d14ffccbe MD5 | raw file
  1. /*************************************************************************
  2. *
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
  4. *
  5. * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
  6. *
  7. * Use is subject to license terms.
  8. *
  9. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  10. * use this file except in compliance with the License. You may obtain a copy
  11. * of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also
  12. * obtain a copy of the License at http://odftoolkit.org/docs/license.txt
  13. *
  14. * Unless required by applicable law or agreed to in writing, software
  15. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  16. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. *
  18. * See the License for the specific language governing permissions and
  19. * limitations under the License.
  20. *
  21. ************************************************************************/
  22. using System.Xml.Linq;
  23. using AODL.Document.Styles;
  24. namespace AODL.Document.Content.Charts
  25. {
  26. /// <summary>
  27. /// Summary description for ChartPlotArea.
  28. /// </summary>
  29. public class ChartPlotArea : IContent, IContentContainer
  30. {
  31. /// <summary>
  32. /// Initializes a new instance of the ChartPlotArea class.
  33. /// </summary>
  34. /// <param name="document">The document.</param>
  35. /// <param name="node">The node.</param>
  36. public ChartPlotArea(IDocument document, XElement node)
  37. {
  38. Document = document;
  39. Node = node;
  40. InitStandards();
  41. }
  42. public ChartPlotArea(Chart chart) : this(chart, null)
  43. {
  44. }
  45. /// <summary>
  46. /// Initializes a new instance of the ChartPlotArea class.
  47. /// </summary>
  48. /// <param name="chart">The chart.</param>
  49. /// <param name="styleName">The style name.</param>
  50. public ChartPlotArea(Chart chart, string styleName)
  51. {
  52. Chart = chart;
  53. Document = chart.Document;
  54. Node = new XElement(Ns.Chart + "plot-area");
  55. InitStandards();
  56. StyleName = styleName;
  57. PlotAreaStyle = new PlotAreaStyle(chart.Document, styleName);
  58. chart.Styles.Add(PlotAreaStyle);
  59. InitPlotArea();
  60. chart.Content.Add(this);
  61. }
  62. public Chart Chart { get; set; }
  63. /// <summary>
  64. /// Gets or sets the plotarea style.
  65. /// </summary>
  66. /// <value>The plotarea style.</value>
  67. public PlotAreaStyle PlotAreaStyle
  68. {
  69. get { return (PlotAreaStyle) Style; }
  70. set
  71. {
  72. StyleName = value.StyleName;
  73. Style = value;
  74. }
  75. }
  76. public AxisCollection AxisCollection { get; set; }
  77. public Dr3dLightCollection Dr3dLightCollection { get; set; }
  78. public SeriesCollection SeriesCollection { get; set; }
  79. #region plotarea properties
  80. /// <summary>
  81. /// Gets or sets the horizontal position where
  82. /// the plotarea should be
  83. /// anchored.
  84. /// </summary>
  85. public string SvgX
  86. {
  87. get { return (string) Node.Attribute(Ns.Svg + "x"); }
  88. set { Node.SetAttributeValue(Ns.Svg + "x", value); }
  89. }
  90. /// <summary>
  91. /// Gets or sets the vertical position where
  92. /// the plotarea should be
  93. /// anchored.
  94. /// </summary>
  95. public string SvgY
  96. {
  97. get { return (string) Node.Attribute(Ns.Svg + "y"); }
  98. set { Node.SetAttributeValue(Ns.Svg + "y", value); }
  99. }
  100. /// <summary>
  101. /// the width of the plotarea
  102. /// </summary>
  103. public string Width
  104. {
  105. get { return (string) Node.Attribute(Ns.Svg + "width"); }
  106. set { Node.SetAttributeValue(Ns.Svg + "width", value); }
  107. }
  108. /// <summary>
  109. /// the height of the plotarea
  110. /// </summary>
  111. public string Height
  112. {
  113. get { return (string) Node.Attribute(Ns.Svg + "height"); }
  114. set { Node.SetAttributeValue(Ns.Svg + "height", value); }
  115. }
  116. /// <summary>
  117. /// sets and gets the data source has labels
  118. /// </summary>
  119. public string DataSourceHasLabels
  120. {
  121. get { return (string) Node.Attribute(Ns.Chart + "data-source-has-labels"); }
  122. set { Node.SetAttributeValue(Ns.Chart + "data-source-has-labels", value); }
  123. }
  124. /// <summary>
  125. /// gets and sets the table number list
  126. /// </summary>
  127. public string TableNumberList
  128. {
  129. get { return (string) Node.Attribute(Ns.Chart + "table-number-list"); }
  130. set { Node.SetAttributeValue(Ns.Chart + "table-number-list", value); }
  131. }
  132. /// <summary>
  133. /// gets and sets the dr3dvrp
  134. /// </summary>
  135. public string Dr3dVrp
  136. {
  137. get { return (string) Node.Attribute(Ns.Dr3d + "vrp"); }
  138. set { Node.SetAttributeValue(Ns.Dr3d + "vrp", value); }
  139. }
  140. /// <summary>
  141. /// gets and sets the dr3dvpn
  142. /// </summary>
  143. public string Dr3dVpn
  144. {
  145. get { return (string) Node.Attribute(Ns.Dr3d + "vpn"); }
  146. set { Node.SetAttributeValue(Ns.Dr3d + "vpn", value); }
  147. }
  148. /// <summary>
  149. /// gets and sets the dr3dvup
  150. /// </summary>
  151. public string Dr3dVup
  152. {
  153. get { return (string) Node.Attribute(Ns.Dr3d + "vup"); }
  154. set { Node.SetAttributeValue(Ns.Dr3d + "vup", value); }
  155. }
  156. /// <summary>
  157. /// gets and sets the projection
  158. /// </summary>
  159. public string Projection
  160. {
  161. get { return (string) Node.Attribute(Ns.Dr3d + "projection"); }
  162. set { Node.SetAttributeValue(Ns.Dr3d + "projection", value); }
  163. }
  164. /// <summary>
  165. /// gets and sets the distance
  166. /// </summary>
  167. public string Distance
  168. {
  169. get { return (string) Node.Attribute(Ns.Dr3d + "distance"); }
  170. set { Node.SetAttributeValue(Ns.Dr3d + "distance", value); }
  171. }
  172. /// <summary>
  173. /// gets and sets the focallength
  174. /// </summary>
  175. public string FocalLength
  176. {
  177. get { return (string) Node.Attribute(Ns.Dr3d + "focal-length"); }
  178. set { Node.SetAttributeValue(Ns.Dr3d + "focal-length", value); }
  179. }
  180. /// <summary>
  181. /// gets and sets the shadowslant
  182. /// </summary>
  183. public string ShadowSlant
  184. {
  185. get { return (string) Node.Attribute(Ns.Dr3d + "shadow-slant"); }
  186. set { Node.SetAttributeValue(Ns.Dr3d + "shadow-slant", value); }
  187. }
  188. /// <summary>
  189. /// gets and sets the shademode
  190. /// </summary>
  191. public string ShadeMode
  192. {
  193. get { return (string) Node.Attribute(Ns.Dr3d + "shade-mode"); }
  194. set { Node.SetAttributeValue(Ns.Dr3d + "shade-mode", value); }
  195. }
  196. /// <summary>
  197. /// gets and sets the ambientcolor
  198. /// </summary>
  199. public string AmbientColor
  200. {
  201. get { return (string) Node.Attribute(Ns.Dr3d + "ambient-color"); }
  202. set { Node.SetAttributeValue(Ns.Dr3d + "ambient-color", value); }
  203. }
  204. /// <summary>
  205. /// gets and sets the lightingmode
  206. /// </summary>
  207. public string LightingMode
  208. {
  209. get { return (string) Node.Attribute(Ns.Dr3d + "lighting-mode"); }
  210. set { Node.SetAttributeValue(Ns.Dr3d + "lighting-mode", value); }
  211. }
  212. /// <summary>
  213. /// gets and sets table cell range
  214. /// </summary>
  215. public string TableCellRange
  216. {
  217. get { return (string) Node.Attribute(Ns.Table + "cell-range-address"); }
  218. set { Node.SetAttributeValue(Ns.Table + "cell-range-address", value); }
  219. }
  220. #endregion
  221. private void InitStandards()
  222. {
  223. Content = new ContentCollection();
  224. AxisCollection = new AxisCollection();
  225. Dr3dLightCollection = new Dr3dLightCollection();
  226. SeriesCollection = new SeriesCollection();
  227. // AxisCollection.Inserted += new ZipStream.CollectionWithEvents.CollectionChange (AxisCollection_Inserted);
  228. // AxisCollection.Removed += new ZipStream.CollectionWithEvents.CollectionChange (AxisCollection_Removed);
  229. // Dr3dLightCollection.Inserted += new ZipStream.CollectionWithEvents.CollectionChange (Dr3dLightCollection_Inserted);
  230. // Dr3dLightCollection.Removed += new ZipStream.CollectionWithEvents.CollectionChange (Dr3dLightCollection_Removed);
  231. // SeriesCollection.Inserted += new ZipStream.CollectionWithEvents.CollectionChange (SeriesCollection_Inserted);
  232. // SeriesCollection.Removed += new ZipStream.CollectionWithEvents.CollectionChange (SeriesCollection_Removed);
  233. Content.Inserted += Content_Inserted;
  234. Content.Removed += Content_Removed;
  235. }
  236. /// <summary>
  237. /// Content_s the inserted.
  238. /// </summary>
  239. /// <param name="index">The index.</param>
  240. /// <param name="value">The value.</param>
  241. private void Content_Inserted(int index, object value)
  242. {
  243. Node.Add(((IContent) value).Node);
  244. }
  245. /// <summary>
  246. /// Content_s the removed.
  247. /// </summary>
  248. /// <param name="index">The index.</param>
  249. /// <param name="value">The value.</param>
  250. private static void Content_Removed(int index, object value)
  251. {
  252. ((IContent) value).Node.Remove();
  253. }
  254. /// <summary>
  255. /// Builds the node.
  256. /// </summary>
  257. /// <returns>XElement</returns>
  258. public XElement BuildNode()
  259. {
  260. foreach (ChartAxis axes in AxisCollection)
  261. {
  262. Node.Add(new XElement(axes.Node));
  263. }
  264. foreach (Dr3dLight light in Dr3dLightCollection)
  265. {
  266. Node.Add(light.Node);
  267. }
  268. foreach (ChartSeries series in SeriesCollection)
  269. {
  270. //node=this.Chart .ChartDoc.ImportNode (series.BuildNode (),true );
  271. Node.Add(series.BuildNode());
  272. }
  273. return Node;
  274. }
  275. /// <summary>
  276. /// if fistLine has labels or not
  277. /// </summary>
  278. /// <returns></returns>
  279. public bool FirstLineHasLabels()
  280. {
  281. if (DataSourceHasLabels == "row" || DataSourceHasLabels == "both")
  282. return true;
  283. return false;
  284. }
  285. /// <summary>
  286. /// if fistColumnl has labels
  287. /// </summary>
  288. /// <returns></returns>
  289. public bool FirstColumnHasLabels()
  290. {
  291. if (DataSourceHasLabels == "column" || DataSourceHasLabels == "both")
  292. return true;
  293. return false;
  294. }
  295. /// <summary>
  296. /// Init the plotarea
  297. /// </summary>
  298. public void InitPlotArea()
  299. {
  300. string seriesSource = PlotAreaStyle.PlotAreaProperties.SeriesSource;
  301. if (seriesSource == null)
  302. PlotAreaStyle.PlotAreaProperties.SeriesSource = "columns";
  303. //SeriesSource= this.PlotAreaStyle .PlotAreaProperties .SeriesSource;
  304. }
  305. #region IContentContainer Member
  306. /// <summary>
  307. /// Gets or sets the content.
  308. /// </summary>
  309. /// <value>The content.</value>
  310. public ContentCollection Content { get; set; }
  311. #endregion
  312. #region IContent Member
  313. private IStyle _style;
  314. /// <summary>
  315. /// Gets or sets the node.
  316. /// </summary>
  317. /// <value>The node.</value>
  318. public XElement Node { get; set; }
  319. /// <summary>
  320. /// Gets or sets the name of the style.
  321. /// </summary>
  322. /// <value>The name of the style.</value>
  323. public string StyleName
  324. {
  325. get { return (string) Node.Attribute(Ns.Chart + "style-name"); }
  326. set { Node.SetAttributeValue(Ns.Chart + "style-name", value); }
  327. }
  328. /// <summary>
  329. /// Every object (typeof(IContent)) have to know his document.
  330. /// </summary>
  331. /// <value></value>
  332. public IDocument Document { get; set; }
  333. /// <summary>
  334. /// A Style class wich is referenced with the content object.
  335. /// If no style is available this is null.
  336. /// </summary>
  337. /// <value></value>
  338. public IStyle Style
  339. {
  340. get { return _style; }
  341. set
  342. {
  343. StyleName = value.StyleName;
  344. _style = value;
  345. }
  346. }
  347. /// <summary>
  348. /// Gets or sets the node.
  349. /// </summary>
  350. /// <value>The node.</value>
  351. XNode IContent.Node
  352. {
  353. get { return Node; }
  354. set { Node = (XElement) value; }
  355. }
  356. #endregion
  357. }
  358. }