LegendColumns.cs 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704
  1. // Licensed to the .NET Foundation under one or more agreements.
  2. // The .NET Foundation licenses this file to you under the MIT license.
  3. // See the LICENSE file in the project root for more information.
  4. //
  5. // Purpose: LegendCell and LegendCellColumn classes allow to
  6. // create highly customize legends. Please refer to
  7. // Chart documentation which contains images and
  8. // samples describing this functionality.
  9. //
  10. using System;
  11. using System.ComponentModel;
  12. using System.Diagnostics.CodeAnalysis;
  13. using System.Globalization;
  14. using FastReport.DataVisualization.Charting.Utilities;
  15. namespace FastReport.DataVisualization.Charting
  16. {
  17. using System.Drawing;
  18. using System.Drawing.Design;
  19. using System.Drawing.Drawing2D;
  20. using SizeF = System.Drawing.SizeF;
  21. #region Enumerations
  22. /// <summary>
  23. /// An enumeration of legend cell types.
  24. /// </summary>
  25. public enum LegendCellType
  26. {
  27. /// <summary>
  28. /// Legend cell contains text.
  29. /// </summary>
  30. Text,
  31. /// <summary>
  32. /// Legend cell contains series symbol.
  33. /// </summary>
  34. SeriesSymbol,
  35. /// <summary>
  36. /// Legend cell contains image.
  37. /// </summary>
  38. Image
  39. }
  40. /// <summary>
  41. /// An enumeration of legend cell column types.
  42. /// </summary>
  43. public enum LegendCellColumnType
  44. {
  45. /// <summary>
  46. /// Legend column contains text.
  47. /// </summary>
  48. Text,
  49. /// <summary>
  50. /// Legend column contains series symbol.
  51. /// </summary>
  52. SeriesSymbol
  53. }
  54. #endregion // Enumerations
  55. /// <summary>
  56. /// The LegendCellColumn class represents a cell column in a legend,
  57. /// used to extend the functionality of the default legend. It contains
  58. /// visual appearance properties, legend header settings and also determine
  59. /// how and in which order cells are formed for each of the legend items.
  60. /// </summary>
  61. [
  62. SRDescription("DescriptionAttributeLegendCellColumn_LegendCellColumn"),
  63. ]
  64. public class LegendCellColumn : ChartNamedElement
  65. {
  66. #region Fields
  67. // Legend column type
  68. private LegendCellColumnType _columnType = LegendCellColumnType.Text;
  69. // Legend column text
  70. private string _text = KeywordName.LegendText;
  71. // Legend column text color
  72. private Color _foreColor = Color.Empty;
  73. // Legend column back color
  74. private Color _backColor = Color.Empty;
  75. // Font cache
  76. private FontCache _fontCache = new FontCache();
  77. // Legend column text font
  78. private Font _font = null;
  79. // Legend column series symbol size
  80. private Size _seriesSymbolSize = new Size(200, 70);
  81. // Legend column content allignment
  82. private ContentAlignment _alignment = ContentAlignment.MiddleCenter;
  83. // Legend column tooltip
  84. private string _toolTip = string.Empty;
  85. // Legend column margins
  86. private Margins _margins = new Margins(0, 0, 15, 15);
  87. // Legend column header text
  88. private string _headerText = string.Empty;
  89. // Legend column/cell content allignment
  90. private StringAlignment _headerAlignment = StringAlignment.Center;
  91. // Legend column header text color
  92. private Color _headerForeColor = Color.Black;
  93. // Legend column header text back color
  94. private Color _headerBackColor = Color.Empty;
  95. // Legend column header text font
  96. private Font _headerFont = null;
  97. // Minimum column width
  98. private int _minimumCellWidth = -1;
  99. // Maximum column width
  100. private int _maximumCellWidth = -1;
  101. #endregion // Fields
  102. #region Constructors
  103. /// <summary>
  104. /// LegendCellColumn constructor.
  105. /// </summary>
  106. public LegendCellColumn()
  107. : this(string.Empty, LegendCellColumnType.Text, KeywordName.LegendText, ContentAlignment.MiddleCenter)
  108. {
  109. _headerFont = _fontCache.DefaultBoldFont;
  110. }
  111. /// <summary>
  112. /// LegendCellColumn constructor.
  113. /// </summary>
  114. /// <param name="headerText">Column header text.</param>
  115. /// <param name="columnType">Column type.</param>
  116. /// <param name="text">Column cell text.</param>
  117. public LegendCellColumn(string headerText, LegendCellColumnType columnType, string text) : this(headerText, columnType, text, ContentAlignment.MiddleCenter)
  118. {
  119. }
  120. /// <summary>
  121. /// Legend column object constructor.
  122. /// </summary>
  123. /// <param name="headerText">Column header text.</param>
  124. /// <param name="columnType">Column type.</param>
  125. /// <param name="text">Column cell text .</param>
  126. /// <param name="alignment">Column cell content alignment.</param>
  127. public LegendCellColumn(string headerText, LegendCellColumnType columnType, string text, ContentAlignment alignment)
  128. {
  129. this._headerText = headerText;
  130. this._columnType = columnType;
  131. this._text = text;
  132. this._alignment = alignment;
  133. this._margins.Element = this;
  134. }
  135. #endregion // Constructors
  136. #region Properties
  137. /// <summary>
  138. /// Gets or sets name of legend column.
  139. /// </summary>
  140. [
  141. SRCategory("CategoryAttributeMisc"),
  142. SRDescription("DescriptionAttributeLegendCellColumn_Name"),
  143. ]
  144. public override string Name
  145. {
  146. get
  147. {
  148. return base.Name;
  149. }
  150. set
  151. {
  152. base.Name = value;
  153. CallOnModifing();
  154. }
  155. }
  156. /// <summary>
  157. /// Gets legend this column belongs too.
  158. /// </summary>
  159. [
  160. Browsable(false),
  161. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  162. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  163. ]
  164. public virtual Legend Legend
  165. {
  166. get
  167. {
  168. if (Parent != null)
  169. return Parent.Parent as Legend;
  170. else
  171. return null;
  172. }
  173. }
  174. /// <summary>
  175. /// Gets or sets legend column type. This is only applicable to items that are automatically generated for the series.
  176. /// </summary>
  177. [
  178. SRCategory("CategoryAttributeSeriesItems"),
  179. DefaultValue(LegendCellColumnType.Text),
  180. SRDescription("DescriptionAttributeLegendCellColumn_ColumnType"),
  181. ParenthesizePropertyNameAttribute(true)
  182. ]
  183. public virtual LegendCellColumnType ColumnType
  184. {
  185. get
  186. {
  187. return this._columnType;
  188. }
  189. set
  190. {
  191. this._columnType = value;
  192. this.Invalidate();
  193. CallOnModifing();
  194. }
  195. }
  196. /// <summary>
  197. /// Gets or sets legend column text. This is only applicable to items that are automatically generated for the series.
  198. /// Set the ColumnType property to text to use this property.
  199. /// </summary>
  200. [
  201. SRCategory("CategoryAttributeSeriesItems"),
  202. DefaultValue(KeywordName.LegendText),
  203. SRDescription("DescriptionAttributeLegendCellColumn_Text"),
  204. #if DESIGNER
  205. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  206. #endif
  207. ]
  208. public virtual string Text
  209. {
  210. get
  211. {
  212. return this._text;
  213. }
  214. set
  215. {
  216. this._text = value;
  217. this.Invalidate();
  218. CallOnModifing();
  219. }
  220. }
  221. /// <summary>
  222. /// Gets or sets the text color of the legend column.
  223. /// </summary>
  224. [
  225. SRCategory("CategoryAttributeSeriesItems"),
  226. DefaultValue(typeof(Color), ""),
  227. SRDescription("DescriptionAttributeForeColor"),
  228. TypeConverter(typeof(ColorConverter)),
  229. #if DESIGNER
  230. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  231. #endif
  232. ]
  233. public virtual Color ForeColor
  234. {
  235. get
  236. {
  237. return this._foreColor;
  238. }
  239. set
  240. {
  241. this._foreColor = value;
  242. this.Invalidate();
  243. CallOnModifing();
  244. }
  245. }
  246. /// <summary>
  247. /// Gets or sets the background color of the legend column.
  248. /// </summary>
  249. [
  250. SRCategory("CategoryAttributeSeriesItems"),
  251. DefaultValue(typeof(Color), ""),
  252. SRDescription("DescriptionAttributeBackColor"),
  253. TypeConverter(typeof(ColorConverter)),
  254. #if DESIGNER
  255. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  256. #endif
  257. ]
  258. public virtual Color BackColor
  259. {
  260. get
  261. {
  262. return this._backColor;
  263. }
  264. set
  265. {
  266. this._backColor = value;
  267. this.Invalidate();
  268. CallOnModifing();
  269. }
  270. }
  271. /// <summary>
  272. /// Gets or sets the font of the legend column text.
  273. /// </summary>
  274. [
  275. SRCategory("CategoryAttributeSeriesItems"),
  276. DefaultValue(null),
  277. SRDescription("DescriptionAttributeLegendCellColumn_Font"),
  278. ]
  279. public virtual Font Font
  280. {
  281. get
  282. {
  283. return this._font;
  284. }
  285. set
  286. {
  287. this._font = value;
  288. this.Invalidate();
  289. CallOnModifing();
  290. }
  291. }
  292. /// <summary>
  293. /// Gets or sets the series symbol size of the legend column
  294. /// for the items automatically generated for the series.
  295. /// </summary>
  296. [
  297. SRCategory("CategoryAttributeSeriesItems"),
  298. DefaultValue(typeof(Size), "200, 70"),
  299. SRDescription("DescriptionAttributeLegendCellColumn_SeriesSymbolSize"),
  300. ]
  301. public virtual Size SeriesSymbolSize
  302. {
  303. get
  304. {
  305. return this._seriesSymbolSize;
  306. }
  307. set
  308. {
  309. if (value.Width < 0 || value.Height < 0)
  310. {
  311. throw (new ArgumentException(SR.ExceptionSeriesSymbolSizeIsNegative, "value"));
  312. }
  313. this._seriesSymbolSize = value;
  314. this.Invalidate();
  315. CallOnModifing();
  316. }
  317. }
  318. /// <summary>
  319. /// Gets or sets the content alignment of the legend column.
  320. /// This is only applicable to items that are automatically generated for the series.
  321. /// </summary>
  322. [
  323. SRCategory("CategoryAttributeSeriesItems"),
  324. DefaultValue(ContentAlignment.MiddleCenter),
  325. SRDescription("DescriptionAttributeLegendCellColumn_Alignment"),
  326. ]
  327. public virtual ContentAlignment Alignment
  328. {
  329. get
  330. {
  331. return this._alignment;
  332. }
  333. set
  334. {
  335. this._alignment = value;
  336. this.Invalidate();
  337. CallOnModifing();
  338. }
  339. }
  340. /// <summary>
  341. /// Gets or sets the margins of the legend column (as a percentage of legend font size).
  342. /// This is only applicable to items that are automatically generated for the series.
  343. /// </summary>
  344. [
  345. SRCategory("CategoryAttributeSeriesItems"),
  346. DefaultValue(typeof(Margins), "0,0,15,15"),
  347. SRDescription("DescriptionAttributeLegendCellColumn_Margins"),
  348. SerializationVisibilityAttribute(SerializationVisibility.Attribute),
  349. DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
  350. NotifyParentPropertyAttribute(true),
  351. ]
  352. public virtual Margins Margins
  353. {
  354. get
  355. {
  356. return this._margins;
  357. }
  358. set
  359. {
  360. this._margins = value;
  361. this.Invalidate();
  362. CallOnModifing();
  363. // Set common elements of the new margins class
  364. if (this.Legend != null)
  365. {
  366. this._margins.Common = this.Legend.Common;
  367. }
  368. }
  369. }
  370. /// <summary>
  371. /// Returns true if property should be serialized. This is for internal use only.
  372. /// </summary>
  373. [EditorBrowsableAttribute(EditorBrowsableState.Never)]
  374. public bool ShouldSerializeMargins()
  375. {
  376. if (this._margins.Top == 0 &&
  377. this._margins.Bottom == 0 &&
  378. this._margins.Left == 15 &&
  379. this._margins.Right == 15)
  380. {
  381. return false;
  382. }
  383. return true;
  384. }
  385. /// <summary>
  386. /// Gets or sets the legend column tooltip. This is only applicable to items that are automatically generated for the series.
  387. /// </summary>
  388. [
  389. SRCategory("CategoryAttributeSeriesItems"),
  390. SRDescription("DescriptionAttributeToolTip"),
  391. DefaultValue(""),
  392. #if DESIGNER
  393. Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
  394. #endif
  395. ]
  396. public virtual string ToolTip
  397. {
  398. set
  399. {
  400. this._toolTip = value;
  401. CallOnModifing();
  402. if (Chart != null &&
  403. Chart.selection != null)
  404. {
  405. Chart.selection.enabledChecked = false;
  406. }
  407. }
  408. get
  409. {
  410. return this._toolTip;
  411. }
  412. }
  413. /// <summary>
  414. /// Gets or sets the legend column header text.
  415. /// </summary>
  416. [
  417. SRCategory("CategoryAttributeHeader"),
  418. DefaultValue(""),
  419. SRDescription("DescriptionAttributeLegendCellColumn_HeaderText"),
  420. ]
  421. public virtual string HeaderText
  422. {
  423. get
  424. {
  425. return this._headerText;
  426. }
  427. set
  428. {
  429. this._headerText = value;
  430. this.Invalidate();
  431. CallOnModifing();
  432. }
  433. }
  434. /// <summary>
  435. /// Gets or sets the color of the legend column header text.
  436. /// </summary>
  437. [
  438. SRCategory("CategoryAttributeHeader"),
  439. DefaultValue(typeof(Color), "Black"),
  440. SRDescription("DescriptionAttributeLegendCellColumn_HeaderColor"),
  441. TypeConverter(typeof(ColorConverter)),
  442. #if DESIGNER
  443. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  444. #endif
  445. ]
  446. public virtual Color HeaderForeColor
  447. {
  448. get
  449. {
  450. return this._headerForeColor;
  451. }
  452. set
  453. {
  454. this._headerForeColor = value;
  455. this.Invalidate();
  456. CallOnModifing();
  457. }
  458. }
  459. /// <summary>
  460. /// Gets or sets the background color of the legend column header.
  461. /// </summary>
  462. [
  463. SRCategory("CategoryAttributeHeader"),
  464. DefaultValue(typeof(Color), ""),
  465. SRDescription("DescriptionAttributeHeaderBackColor"),
  466. TypeConverter(typeof(ColorConverter)),
  467. #if DESIGNER
  468. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  469. #endif
  470. ]
  471. public virtual Color HeaderBackColor
  472. {
  473. get
  474. {
  475. return this._headerBackColor;
  476. }
  477. set
  478. {
  479. this._headerBackColor = value;
  480. this.Invalidate();
  481. CallOnModifing();
  482. }
  483. }
  484. /// <summary>
  485. /// Gets or sets the font of the legend column header.
  486. /// </summary>
  487. [
  488. SRCategory("CategoryAttributeHeader"),
  489. DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt, style=Bold"),
  490. SRDescription("DescriptionAttributeLegendCellColumn_HeaderFont"),
  491. ]
  492. public virtual Font HeaderFont
  493. {
  494. get
  495. {
  496. return this._headerFont;
  497. }
  498. set
  499. {
  500. this._headerFont = value;
  501. this.Invalidate();
  502. CallOnModifing();
  503. }
  504. }
  505. /// <summary>
  506. /// Gets or sets the horizontal text alignment of the legend column header.
  507. /// </summary>
  508. [
  509. SRCategory("CategoryAttributeHeader"),
  510. DefaultValue(typeof(StringAlignment), "Center"),
  511. SRDescription("DescriptionAttributeLegendCellColumn_HeaderTextAlignment"),
  512. ]
  513. public StringAlignment HeaderAlignment
  514. {
  515. get
  516. {
  517. return this._headerAlignment;
  518. }
  519. set
  520. {
  521. if (value != this._headerAlignment)
  522. {
  523. this._headerAlignment = value;
  524. this.Invalidate();
  525. CallOnModifing();
  526. }
  527. }
  528. }
  529. /// <summary>
  530. /// Gets or sets the minimum width (as a percentage of legend font size) of legend column. Set this property to -1 for automatic calculation.
  531. /// </summary>
  532. [
  533. SRCategory("CategoryAttributeSize"),
  534. DefaultValue(-1),
  535. TypeConverter(typeof(IntNanValueConverter)),
  536. SRDescription("DescriptionAttributeLegendCellColumn_MinimumWidth"),
  537. ]
  538. public virtual int MinimumWidth
  539. {
  540. get
  541. {
  542. return this._minimumCellWidth;
  543. }
  544. set
  545. {
  546. if (value < -1)
  547. {
  548. throw (new ArgumentException(SR.ExceptionMinimumCellWidthIsWrong, "value"));
  549. }
  550. this._minimumCellWidth = value;
  551. this.Invalidate();
  552. CallOnModifing();
  553. }
  554. }
  555. /// <summary>
  556. /// Gets or sets the maximum width (as a percentage of legend font size) of legend column. Set this property to -1 for automatic calculation.
  557. /// </summary>
  558. [
  559. SRCategory("CategoryAttributeSize"),
  560. DefaultValue(-1),
  561. TypeConverter(typeof(IntNanValueConverter)),
  562. SRDescription("DescriptionAttributeLegendCellColumn_MaximumWidth"),
  563. ]
  564. public virtual int MaximumWidth
  565. {
  566. get
  567. {
  568. return this._maximumCellWidth;
  569. }
  570. set
  571. {
  572. if (value < -1)
  573. {
  574. throw (new ArgumentException(SR.ExceptionMaximumCellWidthIsWrong, "value"));
  575. }
  576. this._maximumCellWidth = value;
  577. this.Invalidate();
  578. CallOnModifing();
  579. }
  580. }
  581. #endregion // Properties
  582. #region Methods
  583. /// <summary>
  584. /// Creates a new LegendCell object and copies all properties from the
  585. /// current column into the newly created one.
  586. /// </summary>
  587. /// <returns>A new copy of the LegendCell</returns>
  588. internal LegendCell CreateNewCell()
  589. {
  590. LegendCell newCell = new LegendCell();
  591. newCell.CellType = (this.ColumnType == LegendCellColumnType.SeriesSymbol) ? LegendCellType.SeriesSymbol : LegendCellType.Text;
  592. newCell.Text = this.Text;
  593. newCell.ToolTip = this.ToolTip;
  594. newCell.SeriesSymbolSize = this.SeriesSymbolSize;
  595. newCell.Alignment = this.Alignment;
  596. newCell.Margins = new Margins(this.Margins.Top, this.Margins.Bottom, this.Margins.Left, this.Margins.Right);
  597. newCell.Margins.Element = this;
  598. return newCell;
  599. }
  600. #endregion // Methods
  601. #region IDisposable Members
  602. /// <summary>
  603. /// Releases unmanaged and - optionally - managed resources
  604. /// </summary>
  605. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  606. protected override void Dispose(bool disposing)
  607. {
  608. if (disposing)
  609. {
  610. if (_fontCache != null)
  611. {
  612. _fontCache.Dispose();
  613. _fontCache = null;
  614. }
  615. }
  616. }
  617. #endregion
  618. }
  619. /// <summary>
  620. /// The LegendCell class represents a single cell in the chart legend.
  621. /// Legend contains several legend items. Each item contains several
  622. /// cells which form the vertical columns. This class provides properties
  623. /// which determine content of the cell and its visual appearance. It
  624. /// also contains method which determine the size of the cell and draw
  625. /// cell in the chart.
  626. /// </summary>
  627. [
  628. SRDescription("DescriptionAttributeLegendCell_LegendCell"),
  629. ]
  630. public class LegendCell : ChartNamedElement
  631. {
  632. #region Fields
  633. // Legend cell type
  634. private LegendCellType _cellType = LegendCellType.Text;
  635. // Legend cell text
  636. private string _text = string.Empty;
  637. // Legend cell text color
  638. private Color _foreColor = Color.Empty;
  639. // Legend cell back color
  640. private Color _backColor = Color.Empty;
  641. // Font cache
  642. private FontCache _fontCache = new FontCache();
  643. // Legend cell text font
  644. private Font _font = null;
  645. // Legend cell image name
  646. private string _image = string.Empty;
  647. // Legend cell image transparent color
  648. private Color _imageTransparentColor = Color.Empty;
  649. // Legend cell image size
  650. private Size _imageSize = Size.Empty;
  651. // Legend cell series symbol size
  652. private Size _seriesSymbolSize = new Size(200, 70);
  653. // Legend cell content allignment
  654. private ContentAlignment _alignment = ContentAlignment.MiddleCenter;
  655. // Numer of cells this cell uses to show it's content
  656. private int _cellSpan = 1;
  657. // Legend cell tooltip
  658. private string _toolTip = string.Empty;
  659. // Legend cell margins
  660. private Margins _margins = new Margins(0, 0, 15, 15);
  661. // Cell row index
  662. private int _rowIndex = -1;
  663. // Position where cell is drawn in pixel coordinates.
  664. // Exncludes margins and space required for separators
  665. internal Rectangle cellPosition = Rectangle.Empty;
  666. // Position where cell is drawn in pixel coordinates.
  667. // Includes margins and space required for separators
  668. internal Rectangle cellPositionWithMargins = Rectangle.Empty;
  669. // Last cached cell size.
  670. private Size _cachedCellSize = Size.Empty;
  671. // Font reduced value used to calculate last cached cell size
  672. private int _cachedCellSizeFontReducedBy = 0;
  673. #endregion // Fields
  674. #region Constructors
  675. /// <summary>
  676. /// LegendCell constructor.
  677. /// </summary>
  678. public LegendCell()
  679. {
  680. this.Intitialize(LegendCellType.Text, string.Empty, ContentAlignment.MiddleCenter);
  681. }
  682. /// <summary>
  683. /// LegendCell constructor.
  684. /// </summary>
  685. /// <param name="text">Cell text or image name, depending on the type.</param>
  686. public LegendCell(string text)
  687. {
  688. this.Intitialize(LegendCellType.Text, text, ContentAlignment.MiddleCenter);
  689. }
  690. /// <summary>
  691. /// LegendCell constructor.
  692. /// </summary>
  693. /// <param name="cellType">Cell type.</param>
  694. /// <param name="text">Cell text or image name, depending on the type.</param>
  695. public LegendCell(LegendCellType cellType, string text)
  696. {
  697. this.Intitialize(cellType, text, ContentAlignment.MiddleCenter);
  698. }
  699. /// <summary>
  700. /// LegendCell constructor.
  701. /// </summary>
  702. /// <param name="cellType">Cell type.</param>
  703. /// <param name="text">Cell text or image name, depending on the type.</param>
  704. /// <param name="alignment">Cell content alignment.</param>
  705. public LegendCell(LegendCellType cellType, string text, ContentAlignment alignment)
  706. {
  707. this.Intitialize(cellType, text, alignment);
  708. }
  709. /// <summary>
  710. /// Initializes newly created object.
  711. /// </summary>
  712. /// <param name="cellType">Cell type.</param>
  713. /// <param name="text">Cell text or image name depending on the type.</param>
  714. /// <param name="alignment">Cell content alignment.</param>
  715. private void Intitialize(LegendCellType cellType, string text, ContentAlignment alignment)
  716. {
  717. this._cellType = cellType;
  718. if (this._cellType == LegendCellType.Image)
  719. {
  720. this._image = text;
  721. }
  722. else
  723. {
  724. this._text = text;
  725. }
  726. this._alignment = alignment;
  727. }
  728. #endregion // Constructors
  729. #region Properties
  730. /// <summary>
  731. /// Gets or sets the name of the legend cell.
  732. /// </summary>
  733. [
  734. SRCategory("CategoryAttributeMisc"),
  735. SRDescription("DescriptionAttributeLegendCell_Name"),
  736. ]
  737. public override string Name
  738. {
  739. get
  740. {
  741. return base.Name;
  742. }
  743. set
  744. {
  745. base.Name = value;
  746. CallOnModifing();
  747. }
  748. }
  749. /// <summary>
  750. /// Gets or sets the type of the legend cell.
  751. /// </summary>
  752. [
  753. SRCategory("CategoryAttributeAppearance"),
  754. DefaultValue(LegendCellType.Text),
  755. SRDescription("DescriptionAttributeLegendCell_CellType"),
  756. ParenthesizePropertyNameAttribute(true)
  757. ]
  758. public virtual LegendCellType CellType
  759. {
  760. get
  761. {
  762. return this._cellType;
  763. }
  764. set
  765. {
  766. this._cellType = value;
  767. this.Invalidate();
  768. CallOnModifing();
  769. }
  770. }
  771. /// <summary>
  772. /// Gets legend this column/cell belongs too.
  773. /// </summary>
  774. [
  775. Browsable(false),
  776. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  777. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  778. ]
  779. public virtual Legend Legend
  780. {
  781. get
  782. {
  783. LegendItem item = this.LegendItem;
  784. if (item != null)
  785. return item.Legend;
  786. else
  787. return null;
  788. }
  789. }
  790. /// <summary>
  791. /// Gets legend item this cell belongs too.
  792. /// </summary>
  793. [
  794. Browsable(false),
  795. DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
  796. SerializationVisibilityAttribute(SerializationVisibility.Hidden),
  797. ]
  798. public virtual LegendItem LegendItem
  799. {
  800. get
  801. {
  802. if (Parent != null)
  803. return Parent.Parent as LegendItem;
  804. else
  805. return null;
  806. }
  807. }
  808. internal override IChartElement Parent
  809. {
  810. get { return base.Parent; }
  811. set
  812. {
  813. base.Parent = value;
  814. if (_margins != null)
  815. _margins.Element = this;
  816. }
  817. }
  818. /// <summary>
  819. /// Gets or sets the text of the legend cell. Set CellType to text to use this property.
  820. /// </summary>
  821. [
  822. SRCategory("CategoryAttributeAppearance"),
  823. DefaultValue(""),
  824. SRDescription("DescriptionAttributeLegendCell_Text"),
  825. ]
  826. public virtual string Text
  827. {
  828. get
  829. {
  830. return this._text;
  831. }
  832. set
  833. {
  834. this._text = value;
  835. this.Invalidate();
  836. CallOnModifing();
  837. }
  838. }
  839. /// <summary>
  840. /// Gets or sets the text color of the legend cell. Set CellType to text to use this property.
  841. /// </summary>
  842. [
  843. SRCategory("CategoryAttributeAppearance"),
  844. DefaultValue(typeof(Color), ""),
  845. SRDescription("DescriptionAttributeForeColor"),
  846. TypeConverter(typeof(ColorConverter)),
  847. #if DESIGNER
  848. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  849. #endif
  850. ]
  851. public virtual Color ForeColor
  852. {
  853. get
  854. {
  855. return this._foreColor;
  856. }
  857. set
  858. {
  859. this._foreColor = value;
  860. this.Invalidate();
  861. CallOnModifing();
  862. }
  863. }
  864. /// <summary>
  865. /// Gets or sets the background color of the legend cell.
  866. /// </summary>
  867. [
  868. SRCategory("CategoryAttributeAppearance"),
  869. DefaultValue(typeof(Color), ""),
  870. SRDescription("DescriptionAttributeBackColor"),
  871. TypeConverter(typeof(ColorConverter)),
  872. #if DESIGNER
  873. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  874. #endif
  875. ]
  876. public virtual Color BackColor
  877. {
  878. get
  879. {
  880. return this._backColor;
  881. }
  882. set
  883. {
  884. this._backColor = value;
  885. this.Invalidate();
  886. CallOnModifing();
  887. }
  888. }
  889. /// <summary>
  890. /// Gets or sets the font of the legend cell. Set CellType to text to use this property.
  891. /// </summary>
  892. [
  893. SRCategory("CategoryAttributeAppearance"),
  894. DefaultValue(null),
  895. SRDescription("DescriptionAttributeLegendCell_Font"),
  896. ]
  897. public virtual Font Font
  898. {
  899. get
  900. {
  901. return this._font;
  902. }
  903. set
  904. {
  905. this._font = value;
  906. this.Invalidate();
  907. CallOnModifing();
  908. }
  909. }
  910. /// <summary>
  911. /// Gets or sets the URL of the image of the legend cell. Set CellType to image to use this property.
  912. /// </summary>
  913. [
  914. SRCategory("CategoryAttributeAppearance"),
  915. DefaultValue(""),
  916. SRDescription("DescriptionAttributeLegendCell_Image"),
  917. #if DESIGNER
  918. Editor(typeof(ImageValueEditor), typeof(UITypeEditor)),
  919. #endif
  920. ]
  921. public virtual string Image
  922. {
  923. get
  924. {
  925. return this._image;
  926. }
  927. set
  928. {
  929. this._image = value;
  930. this.Invalidate();
  931. CallOnModifing();
  932. }
  933. }
  934. /// <summary>
  935. /// Gets or sets a color which will be replaced with a transparent color while drawing the image. Set CellType to image to use this property.
  936. /// </summary>
  937. [
  938. SRCategory("CategoryAttributeAppearance"),
  939. DefaultValue(typeof(Color), ""),
  940. SRDescription("DescriptionAttributeImageTransparentColor"),
  941. TypeConverter(typeof(ColorConverter)),
  942. #if DESIGNER
  943. Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
  944. #endif
  945. ]
  946. public virtual Color ImageTransparentColor
  947. {
  948. get
  949. {
  950. return this._imageTransparentColor;
  951. }
  952. set
  953. {
  954. this._imageTransparentColor = value;
  955. this.Invalidate();
  956. CallOnModifing();
  957. }
  958. }
  959. /// <summary>
  960. /// Gets or sets the image size (as a percentage of legend font size) of the legend cell.
  961. /// Set CellType to Image to use this property.
  962. /// </summary>
  963. /// <remarks>
  964. /// If property is set to Size.IsEmpty, the original image pixels size is used.
  965. /// </remarks>
  966. [
  967. SRCategory("CategoryAttributeLayout"),
  968. DefaultValue(typeof(Size), "0, 0"),
  969. TypeConverter(typeof(SizeEmptyValueConverter)),
  970. SRDescription("DescriptionAttributeLegendCell_ImageSize"),
  971. ]
  972. public virtual Size ImageSize
  973. {
  974. get
  975. {
  976. return this._imageSize;
  977. }
  978. set
  979. {
  980. if (value.Width < 0 || value.Height < 0)
  981. {
  982. throw (new ArgumentException(SR.ExceptionLegendCellImageSizeIsNegative, "value"));
  983. }
  984. this._imageSize = value;
  985. this.Invalidate();
  986. CallOnModifing();
  987. }
  988. }
  989. /// <summary>
  990. /// Gets or sets the series symbol size (as a percentage of legend font size) of the legend cell.
  991. /// Set CellType to SeriesSymbol to use this property.
  992. /// </summary>
  993. [
  994. SRCategory("CategoryAttributeLayout"),
  995. DefaultValue(typeof(Size), "200, 70"),
  996. SRDescription("DescriptionAttributeLegendCell_SeriesSymbolSize"),
  997. ]
  998. public virtual Size SeriesSymbolSize
  999. {
  1000. get
  1001. {
  1002. return this._seriesSymbolSize;
  1003. }
  1004. set
  1005. {
  1006. if (value.Width < 0 || value.Height < 0)
  1007. {
  1008. throw (new ArgumentException(SR.ExceptionLegendCellSeriesSymbolSizeIsNegative, "value"));
  1009. }
  1010. this._seriesSymbolSize = value;
  1011. this.Invalidate();
  1012. CallOnModifing();
  1013. }
  1014. }
  1015. /// <summary>
  1016. /// Gets or sets the content alignment of the legend cell.
  1017. /// </summary>
  1018. [
  1019. SRCategory("CategoryAttributeLayout"),
  1020. DefaultValue(ContentAlignment.MiddleCenter),
  1021. SRDescription("DescriptionAttributeLegendCell_Alignment"),
  1022. ]
  1023. public virtual ContentAlignment Alignment
  1024. {
  1025. get
  1026. {
  1027. return this._alignment;
  1028. }
  1029. set
  1030. {
  1031. this._alignment = value;
  1032. this.Invalidate();
  1033. CallOnModifing();
  1034. }
  1035. }
  1036. /// <summary>
  1037. /// Gets or sets the number of horizontal cells used to draw the content.
  1038. /// </summary>
  1039. [
  1040. SRCategory("CategoryAttributeLayout"),
  1041. DefaultValue(1),
  1042. SRDescription("DescriptionAttributeLegendCell_CellSpan"),
  1043. ]
  1044. public virtual int CellSpan
  1045. {
  1046. get
  1047. {
  1048. return this._cellSpan;
  1049. }
  1050. set
  1051. {
  1052. if (value < 1)
  1053. {
  1054. throw (new ArgumentException(SR.ExceptionLegendCellSpanIsLessThenOne, "value"));
  1055. }
  1056. this._cellSpan = value;
  1057. this.Invalidate();
  1058. CallOnModifing();
  1059. }
  1060. }
  1061. /// <summary>
  1062. /// Gets or sets the legend cell margins (as a percentage of legend font size).
  1063. /// </summary>
  1064. [
  1065. SRCategory("CategoryAttributeLayout"),
  1066. DefaultValue(typeof(Margins), "0,0,15,15"),
  1067. SRDescription("DescriptionAttributeLegendCell_Margins"),
  1068. SerializationVisibilityAttribute(SerializationVisibility.Attribute),
  1069. NotifyParentPropertyAttribute(true),
  1070. ]
  1071. public virtual Margins Margins
  1072. {
  1073. get
  1074. {
  1075. return this._margins;
  1076. }
  1077. set
  1078. {
  1079. this._margins = value;
  1080. this.Invalidate();
  1081. CallOnModifing();
  1082. // Set common elements of the new margins class
  1083. if (this.Legend != null)
  1084. {
  1085. this._margins.Common = this.Common;
  1086. }
  1087. }
  1088. }
  1089. /// <summary>
  1090. /// Returns true if property should be serialized. This method is for internal use only.
  1091. /// </summary>
  1092. [EditorBrowsableAttribute(EditorBrowsableState.Never)]
  1093. internal bool ShouldSerializeMargins()
  1094. {
  1095. if (this._margins.Top == 0 &&
  1096. this._margins.Bottom == 0 &&
  1097. this._margins.Left == 15 &&
  1098. this._margins.Right == 15)
  1099. {
  1100. return false;
  1101. }
  1102. return true;
  1103. }
  1104. /// <summary>
  1105. /// Gets or sets the tooltip of the legend cell.
  1106. /// </summary>
  1107. [
  1108. SRCategory("CategoryAttributeMapArea"),
  1109. SRDescription("DescriptionAttributeToolTip"),
  1110. DefaultValue(""),
  1111. ]
  1112. public virtual string ToolTip
  1113. {
  1114. set
  1115. {
  1116. this._toolTip = value;
  1117. CallOnModifing();
  1118. if (this.Chart != null &&
  1119. this.Chart.selection != null)
  1120. {
  1121. this.Chart.selection.enabledChecked = false;
  1122. }
  1123. }
  1124. get
  1125. {
  1126. return this._toolTip;
  1127. }
  1128. }
  1129. #endregion // Properties
  1130. #region Methods
  1131. /// <summary>
  1132. /// Resets cached cell values.
  1133. /// </summary>
  1134. internal void ResetCache()
  1135. {
  1136. this._cachedCellSize = Size.Empty;
  1137. this._cachedCellSizeFontReducedBy = 0;
  1138. }
  1139. /// <summary>
  1140. /// Sets cell position in relative coordinates.
  1141. /// </summary>
  1142. /// <param name="rowIndex">Cell row index.</param>
  1143. /// <param name="position">Cell position.</param>
  1144. /// <param name="singleWCharacterSize">Size of the 'W' character used to calculate elements.</param>
  1145. internal void SetCellPosition(
  1146. int rowIndex,
  1147. Rectangle position,
  1148. Size singleWCharacterSize)
  1149. {
  1150. // Set cell position
  1151. this.cellPosition = position;
  1152. this.cellPositionWithMargins = position;
  1153. this._rowIndex = rowIndex;
  1154. // Adjust cell position by specified margin
  1155. this.cellPosition.X += (int)(this.Margins.Left * singleWCharacterSize.Width / 100f);
  1156. this.cellPosition.Y += (int)(this.Margins.Top * singleWCharacterSize.Height / 100f);
  1157. this.cellPosition.Width -= (int)(this.Margins.Left * singleWCharacterSize.Width / 100f)
  1158. + (int)(this.Margins.Right * singleWCharacterSize.Width / 100f);
  1159. this.cellPosition.Height -= (int)(this.Margins.Top * singleWCharacterSize.Height / 100f)
  1160. + (int)(this.Margins.Bottom * singleWCharacterSize.Height / 100f);
  1161. // Adjust cell position by space required for the separatorType
  1162. if (LegendItem != null &&
  1163. LegendItem.SeparatorType != LegendSeparatorStyle.None)
  1164. {
  1165. this.cellPosition.Height -= this.Legend.GetSeparatorSize(LegendItem.SeparatorType).Height;
  1166. }
  1167. }
  1168. /// <summary>
  1169. /// Measures legend cell size in chart relative coordinates.
  1170. /// </summary>
  1171. /// <param name="graph">
  1172. /// Chart graphics.
  1173. /// </param>
  1174. /// <param name="fontSizeReducedBy">
  1175. /// A positive or negative integer value that determines the how standard cell font size
  1176. /// should be adjusted. As a result smaller or larger font can be used.
  1177. /// </param>
  1178. /// <param name="legendAutoFont">
  1179. /// Auto fit font used in the legend.
  1180. /// </param>
  1181. /// <param name="singleWCharacterSize">
  1182. /// Size of the 'W' character used to calculate elements.
  1183. /// </param>
  1184. /// <returns>Legend cell size.</returns>
  1185. internal Size MeasureCell(
  1186. ChartGraphics graph,
  1187. int fontSizeReducedBy,
  1188. Font legendAutoFont,
  1189. Size singleWCharacterSize)
  1190. {
  1191. // Check if cached size may be reused
  1192. if (this._cachedCellSizeFontReducedBy == fontSizeReducedBy &&
  1193. !this._cachedCellSize.IsEmpty)
  1194. {
  1195. return this._cachedCellSize;
  1196. }
  1197. // Get cell font
  1198. Size cellSize = Size.Empty;
  1199. bool disposeFont = false;
  1200. Font cellFont = this.GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont);
  1201. // Measure cell content size based on the type
  1202. if (this.CellType == LegendCellType.SeriesSymbol)
  1203. {
  1204. cellSize.Width = (int)(Math.Abs(this.SeriesSymbolSize.Width) * singleWCharacterSize.Width / 100f);
  1205. cellSize.Height = (int)(Math.Abs(this.SeriesSymbolSize.Height) * singleWCharacterSize.Height / 100f);
  1206. }
  1207. else if (this.CellType == LegendCellType.Image)
  1208. {
  1209. if (this.ImageSize.IsEmpty && this.Image.Length > 0)
  1210. {
  1211. SizeF imageSize = new SizeF();
  1212. // Use original image size
  1213. if (this.Common.ImageLoader.GetAdjustedImageSize(this.Image, graph.Graphics, ref imageSize))
  1214. {
  1215. cellSize.Width = (int)imageSize.Width;
  1216. cellSize.Height = (int)imageSize.Height;
  1217. }
  1218. }
  1219. else
  1220. {
  1221. cellSize.Width = (int)(Math.Abs(this.ImageSize.Width) * singleWCharacterSize.Width / 100f);
  1222. cellSize.Height = (int)(Math.Abs(this.ImageSize.Height) * singleWCharacterSize.Height / 100f);
  1223. }
  1224. }
  1225. else if (this.CellType == LegendCellType.Text)
  1226. {
  1227. // Get current cell text taking in consideration keywords
  1228. // and automatic text wrapping.
  1229. string cellText = this.GetCellText();
  1230. // Measure text size.
  1231. // Note that extra "I" character added to add more horizontal spacing
  1232. cellSize = graph.MeasureStringAbs(cellText + "I", cellFont);
  1233. }
  1234. else
  1235. {
  1236. throw (new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(this.CellType.ToString())));
  1237. }
  1238. // Add cell margins
  1239. cellSize.Width += (int)((this.Margins.Left + this.Margins.Right) * singleWCharacterSize.Width / 100f);
  1240. cellSize.Height += (int)((this.Margins.Top + this.Margins.Bottom) * singleWCharacterSize.Height / 100f);
  1241. // Add space required for the separatorType
  1242. if (LegendItem != null &&
  1243. LegendItem.SeparatorType != LegendSeparatorStyle.None)
  1244. {
  1245. cellSize.Height += this.Legend.GetSeparatorSize(LegendItem.SeparatorType).Height;
  1246. }
  1247. // Dispose created font object
  1248. if (disposeFont)
  1249. {
  1250. cellFont.Dispose();
  1251. cellFont = null;
  1252. }
  1253. // Save calculated size
  1254. this._cachedCellSize = cellSize;
  1255. this._cachedCellSizeFontReducedBy = fontSizeReducedBy;
  1256. return cellSize;
  1257. }
  1258. /// <summary>
  1259. /// Gets cell background color.
  1260. /// </summary>
  1261. /// <returns></returns>
  1262. private Color GetCellBackColor()
  1263. {
  1264. Color resultColor = this.BackColor;
  1265. if (this.BackColor.IsEmpty && this.Legend != null)
  1266. {
  1267. // Try getting back color from the associated column
  1268. if (this.LegendItem != null)
  1269. {
  1270. // Get index of this cell
  1271. int cellIndex = this.LegendItem.Cells.IndexOf(this);
  1272. if (cellIndex >= 0)
  1273. {
  1274. // Check if associated column exsists
  1275. if (cellIndex < this.Legend.CellColumns.Count &&
  1276. !this.Legend.CellColumns[cellIndex].BackColor.IsEmpty)
  1277. {
  1278. resultColor = this.Legend.CellColumns[cellIndex].BackColor;
  1279. }
  1280. }
  1281. }
  1282. // Get font from the legend isInterlaced
  1283. if (resultColor.IsEmpty &&
  1284. this.Legend.InterlacedRows &&
  1285. this._rowIndex % 2 != 0)
  1286. {
  1287. if (this.Legend.InterlacedRowsColor.IsEmpty)
  1288. {
  1289. // Automatically determine background color
  1290. // If isInterlaced strips color is not set - use darker color of the area
  1291. if (this.Legend.BackColor == Color.Empty)
  1292. {
  1293. resultColor = Color.LightGray;
  1294. }
  1295. else if (this.Legend.BackColor == Color.Transparent)
  1296. {
  1297. if (Chart.BackColor != Color.Transparent &&
  1298. Chart.BackColor != Color.Black)
  1299. {
  1300. resultColor = ChartGraphics.GetGradientColor(Chart.BackColor, Color.Black, 0.2);
  1301. }
  1302. else
  1303. {
  1304. resultColor = Color.LightGray;
  1305. }
  1306. }
  1307. else
  1308. {
  1309. resultColor = ChartGraphics.GetGradientColor(this.Legend.BackColor, Color.Black, 0.2);
  1310. }
  1311. }
  1312. else
  1313. {
  1314. resultColor = this.Legend.InterlacedRowsColor;
  1315. }
  1316. }
  1317. }
  1318. return resultColor;
  1319. }
  1320. /// <summary>
  1321. /// Gets default cell font. Font can be specified in the cell, column or in the legend.
  1322. /// </summary>
  1323. /// <param name="legendAutoFont">Auto fit font used in the legend.</param>
  1324. /// <param name="fontSizeReducedBy">Number of points legend auto-font reduced by.</param>
  1325. /// <param name="disposeFont">Returns a flag if result font object should be disposed.</param>
  1326. /// <returns>Default cell font.</returns>
  1327. private Font GetCellFont(Font legendAutoFont, int fontSizeReducedBy, out bool disposeFont)
  1328. {
  1329. Font cellFont = this.Font;
  1330. disposeFont = false;
  1331. // Check if font is not set in the cell and legend object reference is valid
  1332. if (cellFont == null &&
  1333. this.Legend != null)
  1334. {
  1335. // Try getting font from the associated column
  1336. if (this.LegendItem != null)
  1337. {
  1338. // Get index of this cell
  1339. int cellIndex = this.LegendItem.Cells.IndexOf(this);
  1340. if (cellIndex >= 0)
  1341. {
  1342. // Check if associated column exsists
  1343. if (cellIndex < this.Legend.CellColumns.Count &&
  1344. this.Legend.CellColumns[cellIndex].Font != null)
  1345. {
  1346. cellFont = this.Legend.CellColumns[cellIndex].Font;
  1347. }
  1348. }
  1349. }
  1350. // Get font from the legend
  1351. if (cellFont == null)
  1352. {
  1353. cellFont = legendAutoFont;
  1354. // No further processing required.
  1355. // Font is already reduced.
  1356. return cellFont;
  1357. }
  1358. }
  1359. // Check if font size should be adjusted
  1360. if (cellFont != null && fontSizeReducedBy != 0)
  1361. {
  1362. // New font is created anf it must be disposed
  1363. disposeFont = true;
  1364. // Calculate new font size
  1365. int newFontSize = (int)Math.Round(cellFont.Size - fontSizeReducedBy);
  1366. if (newFontSize < 1)
  1367. {
  1368. // Font can't be less than size 1
  1369. newFontSize = 1;
  1370. }
  1371. // Create new font
  1372. cellFont = new Font(
  1373. cellFont.FontFamily,
  1374. newFontSize,
  1375. cellFont.Style,
  1376. cellFont.Unit);
  1377. }
  1378. return cellFont;
  1379. }
  1380. /// <summary>
  1381. /// Helper function that returns cell tooltip.
  1382. /// </summary>
  1383. /// <remarks>
  1384. /// Tooltip can be set in the cell or in the legend item. Cell
  1385. /// tooltip always has a higher priority.
  1386. /// </remarks>
  1387. /// <returns>Returns cell text.</returns>
  1388. private string GetCellToolTip()
  1389. {
  1390. // Check if tooltip is set in the cell (highest priority)
  1391. if (this.ToolTip.Length > 0)
  1392. {
  1393. return this.ToolTip;
  1394. }
  1395. // Check if tooltip is set in associated legend item
  1396. if (this.LegendItem != null)
  1397. {
  1398. return this.LegendItem.ToolTip;
  1399. }
  1400. return string.Empty;
  1401. }
  1402. /// <summary>
  1403. /// Helper function that returns cell url.
  1404. /// </summary>
  1405. /// <remarks>
  1406. /// Url can be set in the cell or in the legend item. Cell
  1407. /// tooltip always has a higher priority.
  1408. /// </remarks>
  1409. /// <returns>Returns cell text.</returns>
  1410. private string GetCellUrl()
  1411. {
  1412. return string.Empty;
  1413. }
  1414. /// <summary>
  1415. /// Helper function that returns cell url.
  1416. /// </summary>
  1417. /// <remarks>
  1418. /// Url can be set in the cell or in the legend item. Cell
  1419. /// tooltip always has a higher priority.
  1420. /// </remarks>
  1421. /// <returns>Returns cell text.</returns>
  1422. private string GetCellMapAreaAttributes()
  1423. {
  1424. return string.Empty;
  1425. }
  1426. /// <summary>
  1427. /// Helper function that returns cell url.
  1428. /// </summary>
  1429. /// <remarks>
  1430. /// Url can be set in the cell or in the legend item. Cell
  1431. /// tooltip always has a higher priority.
  1432. /// </remarks>
  1433. /// <returns>Returns cell text.</returns>
  1434. private string GetCellPostBackValue()
  1435. {
  1436. return string.Empty;
  1437. }
  1438. /// <summary>
  1439. /// Helper function that returns the exact text presented in the cell.
  1440. /// </summary>
  1441. /// <remarks>
  1442. /// This method replaces the "\n" substring with the new line character
  1443. /// and automatically wrap text if required.
  1444. /// </remarks>
  1445. /// <returns>Returns cell text.</returns>
  1446. private string GetCellText()
  1447. {
  1448. // Replace all "\n" strings with the new line character
  1449. string resultString = this.Text.Replace("\\n", "\n");
  1450. // Replace the KeywordName.LegendText keyword with legend item Name property
  1451. if (this.LegendItem != null)
  1452. {
  1453. resultString = resultString.Replace(KeywordName.LegendText, this.LegendItem.Name);
  1454. }
  1455. else
  1456. {
  1457. resultString = resultString.Replace(KeywordName.LegendText, "");
  1458. }
  1459. // Check if text width exceeds recomended character length
  1460. if (this.Legend != null)
  1461. {
  1462. int recomendedTextLength = this.Legend.TextWrapThreshold;
  1463. if (recomendedTextLength > 0 &&
  1464. resultString.Length > recomendedTextLength)
  1465. {
  1466. // Iterate through all text characters
  1467. int lineLength = 0;
  1468. for (int charIndex = 0; charIndex < resultString.Length; charIndex++)
  1469. {
  1470. // Reset line length when new line character is found
  1471. if (resultString[charIndex] == '\n')
  1472. {
  1473. lineLength = 0;
  1474. continue;
  1475. }
  1476. // Increase line length counter
  1477. ++lineLength;
  1478. // Check if current character is a white space and
  1479. // current line length exceeds the recomended values.
  1480. if (char.IsWhiteSpace(resultString, charIndex) &&
  1481. lineLength >= recomendedTextLength)
  1482. {
  1483. // Insert new line character in the string
  1484. lineLength = 0;
  1485. resultString = resultString.Substring(0, charIndex) + "\n" +
  1486. resultString.Substring(charIndex + 1).TrimStart();
  1487. }
  1488. }
  1489. }
  1490. }
  1491. return resultString;
  1492. }
  1493. /// <summary>
  1494. /// Helper function that returns cell text color.
  1495. /// </summary>
  1496. /// <returns>Cell text color.</returns>
  1497. private Color GetCellForeColor()
  1498. {
  1499. // Check if cell text color defined in the cell
  1500. if (!this.ForeColor.IsEmpty)
  1501. {
  1502. return this.ForeColor;
  1503. }
  1504. // Check if color from the Column or legend should be used
  1505. if (this.Legend != null)
  1506. {
  1507. // Try getting font from the associated column
  1508. if (this.LegendItem != null)
  1509. {
  1510. // Get index of this cell
  1511. int cellIndex = this.LegendItem.Cells.IndexOf(this);
  1512. if (cellIndex >= 0)
  1513. {
  1514. // Check if associated column exsists
  1515. if (cellIndex < this.Legend.CellColumns.Count &&
  1516. !this.Legend.CellColumns[cellIndex].ForeColor.IsEmpty)
  1517. {
  1518. return this.Legend.CellColumns[cellIndex].ForeColor;
  1519. }
  1520. }
  1521. }
  1522. // Use legend text color
  1523. return this.Legend.ForeColor;
  1524. }
  1525. return Color.Black;
  1526. }
  1527. #endregion // Methods
  1528. #region Cell Painting Methods
  1529. /// <summary>
  1530. /// Paints content of the legend cell.
  1531. /// </summary>
  1532. /// <param name="chartGraph">Chart graphics to draw content on.</param>
  1533. /// <param name="fontSizeReducedBy">Number that determines how much the cell font should be reduced by.</param>
  1534. /// <param name="legendAutoFont">Auto-fit font used in the legend.</param>
  1535. /// <param name="singleWCharacterSize">Size of the 'W' character in auto-fit font.</param>
  1536. internal void Paint(
  1537. ChartGraphics chartGraph,
  1538. int fontSizeReducedBy,
  1539. Font legendAutoFont,
  1540. Size singleWCharacterSize)
  1541. {
  1542. // Check cell size before painting
  1543. if (this.cellPosition.Width <= 0 || this.cellPosition.Height <= 0)
  1544. {
  1545. return;
  1546. }
  1547. // Chart elements painting mode
  1548. if (this.Common.ProcessModePaint)
  1549. {
  1550. // Check if cell background should be painted
  1551. Color cellBackColor = this.GetCellBackColor();
  1552. RectangleF rectRelative = chartGraph.GetRelativeRectangle(this.cellPositionWithMargins);
  1553. if (!cellBackColor.IsEmpty)
  1554. {
  1555. chartGraph.FillRectangleRel(
  1556. rectRelative,
  1557. cellBackColor,
  1558. ChartHatchStyle.None,
  1559. string.Empty,
  1560. ChartImageWrapMode.Tile,
  1561. Color.Empty,
  1562. ChartImageAlignmentStyle.Center,
  1563. GradientStyle.None,
  1564. Color.Empty,
  1565. Color.Empty,
  1566. 0,
  1567. ChartDashStyle.NotSet,
  1568. Color.Empty,
  1569. 0,
  1570. PenAlignment.Inset);
  1571. }
  1572. // Fire an event for custom cell back drawing
  1573. this.Chart.CallOnPrePaint(new ChartPaintEventArgs(this, chartGraph, this.Common, new ElementPosition(rectRelative.X, rectRelative.Y, rectRelative.Width, rectRelative.Height)));
  1574. // Check legend cell type
  1575. switch (this.CellType)
  1576. {
  1577. case (LegendCellType.Text):
  1578. this.PaintCellText(chartGraph, fontSizeReducedBy, legendAutoFont);
  1579. break;
  1580. case (LegendCellType.Image):
  1581. this.PaintCellImage(chartGraph, singleWCharacterSize);
  1582. break;
  1583. case (LegendCellType.SeriesSymbol):
  1584. this.PaintCellSeriesSymbol(chartGraph, singleWCharacterSize);
  1585. break;
  1586. default:
  1587. throw (new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(this.CellType.ToString())));
  1588. }
  1589. // Fire an event for custom cell drawing
  1590. this.Chart.CallOnPostPaint(new ChartPaintEventArgs(this, chartGraph, this.Common, new ElementPosition(rectRelative.X, rectRelative.Y, rectRelative.Width, rectRelative.Height)));
  1591. }
  1592. #if DEBUG
  1593. // Draw bounding rectangle for debug purpose
  1594. // RectangleF absRectangle = this.cellPosition;
  1595. // chartGraph.DrawRectangle(Pens.Red, absRectangle.X, absRectangle.Y, absRectangle.Width, absRectangle.Height);
  1596. #endif // DEBUG
  1597. // Legend cell selection mode
  1598. if (this.Common.ProcessModeRegions)
  1599. {
  1600. // Add hot region.
  1601. // Note that legend cell is passed as sub-object of legend item
  1602. this.Common.HotRegionsList.AddHotRegion(
  1603. chartGraph.GetRelativeRectangle(this.cellPositionWithMargins),
  1604. this.GetCellToolTip(),
  1605. this.GetCellUrl(),
  1606. this.GetCellMapAreaAttributes(),
  1607. this.GetCellPostBackValue(),
  1608. this.LegendItem,
  1609. this,
  1610. ChartElementType.LegendItem,
  1611. this.LegendItem.SeriesName);
  1612. }
  1613. }
  1614. /// <summary>
  1615. /// Draw legend cell text.
  1616. /// </summary>
  1617. /// <param name="chartGraph">Chart graphics to draw the text on.</param>
  1618. /// <param name="fontSizeReducedBy">Number that determines how much the cell font should be reduced by.</param>
  1619. /// <param name="legendAutoFont">Auto-fit font used in the legend.</param>
  1620. private void PaintCellText(
  1621. ChartGraphics chartGraph,
  1622. int fontSizeReducedBy,
  1623. Font legendAutoFont)
  1624. {
  1625. // Get cell font
  1626. bool disposeFont = false;
  1627. Font cellFont = this.GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont);
  1628. // Start Svg Selection mode
  1629. chartGraph.StartHotRegion(this.GetCellUrl(), this.GetCellToolTip());
  1630. // Create font brush
  1631. using (SolidBrush fontBrush = new SolidBrush(this.GetCellForeColor()))
  1632. {
  1633. // Create cell text format
  1634. using (StringFormat format = new StringFormat(StringFormat.GenericDefault))
  1635. {
  1636. format.FormatFlags = StringFormatFlags.LineLimit;
  1637. format.Trimming = StringTrimming.EllipsisCharacter;
  1638. format.Alignment = StringAlignment.Center;
  1639. if (this.Alignment == ContentAlignment.BottomLeft ||
  1640. this.Alignment == ContentAlignment.MiddleLeft ||
  1641. this.Alignment == ContentAlignment.TopLeft)
  1642. {
  1643. format.Alignment = StringAlignment.Near;
  1644. }
  1645. else if (this.Alignment == ContentAlignment.BottomRight ||
  1646. this.Alignment == ContentAlignment.MiddleRight ||
  1647. this.Alignment == ContentAlignment.TopRight)
  1648. {
  1649. format.Alignment = StringAlignment.Far;
  1650. }
  1651. format.LineAlignment = StringAlignment.Center;
  1652. if (this.Alignment == ContentAlignment.BottomCenter ||
  1653. this.Alignment == ContentAlignment.BottomLeft ||
  1654. this.Alignment == ContentAlignment.BottomRight)
  1655. {
  1656. format.LineAlignment = StringAlignment.Far;
  1657. }
  1658. else if (this.Alignment == ContentAlignment.TopCenter ||
  1659. this.Alignment == ContentAlignment.TopLeft ||
  1660. this.Alignment == ContentAlignment.TopRight)
  1661. {
  1662. format.LineAlignment = StringAlignment.Near;
  1663. }
  1664. // Measure string height out of one character
  1665. SizeF charSize = chartGraph.MeasureStringAbs(this.GetCellText(), cellFont, new SizeF(10000f, 10000f), format);
  1666. // If height of one characte is more than rectangle heigjt - remove LineLimit flag
  1667. if (charSize.Height > this.cellPosition.Height && (format.FormatFlags & StringFormatFlags.LineLimit) != 0)
  1668. {
  1669. format.FormatFlags ^= StringFormatFlags.LineLimit;
  1670. }
  1671. else if (charSize.Height < this.cellPosition.Height && (format.FormatFlags & StringFormatFlags.LineLimit) == 0)
  1672. {
  1673. format.FormatFlags |= StringFormatFlags.LineLimit;
  1674. }
  1675. // Draw text
  1676. chartGraph.DrawStringRel(
  1677. this.GetCellText(),
  1678. cellFont,
  1679. fontBrush,
  1680. chartGraph.GetRelativeRectangle(this.cellPosition),
  1681. format);
  1682. }
  1683. }
  1684. // End Svg Selection mode
  1685. chartGraph.EndHotRegion();
  1686. // Dispose created cell font object
  1687. if (disposeFont)
  1688. {
  1689. cellFont.Dispose();
  1690. cellFont = null;
  1691. }
  1692. }
  1693. /// <summary>
  1694. /// Paints cell image.
  1695. /// </summary>
  1696. /// <param name="chartGraph">Graphics used to draw cell image.</param>
  1697. /// <param name="singleWCharacterSize">Size of the 'W' character in auto-fit font.</param>
  1698. private void PaintCellImage(
  1699. ChartGraphics chartGraph,
  1700. Size singleWCharacterSize)
  1701. {
  1702. if (this.Image.Length > 0)
  1703. {
  1704. // Get image size in relative coordinates
  1705. Rectangle imagePosition = Rectangle.Empty;
  1706. System.Drawing.Image image = this.Common.ImageLoader.LoadImage(this.Image);
  1707. SizeF imageSize = new SizeF();
  1708. ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref imageSize);
  1709. imagePosition.Width = (int)imageSize.Width;
  1710. imagePosition.Height = (int)imageSize.Height;
  1711. // Calculate cell position
  1712. Rectangle imageCellPosition = this.cellPosition;
  1713. imageCellPosition.Width = imagePosition.Width;
  1714. imageCellPosition.Height = imagePosition.Height;
  1715. if (!this.ImageSize.IsEmpty)
  1716. {
  1717. // Adjust cell size using image symbol size specified
  1718. if (this.ImageSize.Width > 0)
  1719. {
  1720. int newWidth = (int)(this.ImageSize.Width * singleWCharacterSize.Width / 100f);
  1721. if (newWidth > this.cellPosition.Width)
  1722. {
  1723. newWidth = this.cellPosition.Width;
  1724. }
  1725. imageCellPosition.Width = newWidth;
  1726. }
  1727. if (this.ImageSize.Height > 0)
  1728. {
  1729. int newHeight = (int)(this.ImageSize.Height * singleWCharacterSize.Height / 100f);
  1730. if (newHeight > this.cellPosition.Height)
  1731. {
  1732. newHeight = this.cellPosition.Height;
  1733. }
  1734. imageCellPosition.Height = newHeight;
  1735. }
  1736. }
  1737. // Make sure image size fits into the cell drawing rectangle
  1738. float scaleValue = 1f;
  1739. if (imagePosition.Height > imageCellPosition.Height)
  1740. {
  1741. scaleValue = (float)imagePosition.Height / (float)imageCellPosition.Height;
  1742. }
  1743. if (imagePosition.Width > imageCellPosition.Width)
  1744. {
  1745. scaleValue = Math.Max(scaleValue, (float)imagePosition.Width / (float)imageCellPosition.Width);
  1746. }
  1747. // Scale image size
  1748. imagePosition.Height = (int)(imagePosition.Height / scaleValue);
  1749. imagePosition.Width = (int)(imagePosition.Width / scaleValue);
  1750. // Get image location
  1751. imagePosition.X = (int)((this.cellPosition.X + this.cellPosition.Width / 2f) - imagePosition.Width / 2f);
  1752. imagePosition.Y = (int)((this.cellPosition.Y + this.cellPosition.Height / 2f) - imagePosition.Height / 2f);
  1753. // Adjust image location based on the cell content alignment
  1754. if (this.Alignment == ContentAlignment.BottomLeft ||
  1755. this.Alignment == ContentAlignment.MiddleLeft ||
  1756. this.Alignment == ContentAlignment.TopLeft)
  1757. {
  1758. imagePosition.X = this.cellPosition.X;
  1759. }
  1760. else if (this.Alignment == ContentAlignment.BottomRight ||
  1761. this.Alignment == ContentAlignment.MiddleRight ||
  1762. this.Alignment == ContentAlignment.TopRight)
  1763. {
  1764. imagePosition.X = this.cellPosition.Right - imagePosition.Width;
  1765. }
  1766. if (this.Alignment == ContentAlignment.BottomCenter ||
  1767. this.Alignment == ContentAlignment.BottomLeft ||
  1768. this.Alignment == ContentAlignment.BottomRight)
  1769. {
  1770. imagePosition.Y = this.cellPosition.Bottom - imagePosition.Height;
  1771. }
  1772. else if (this.Alignment == ContentAlignment.TopCenter ||
  1773. this.Alignment == ContentAlignment.TopLeft ||
  1774. this.Alignment == ContentAlignment.TopRight)
  1775. {
  1776. imagePosition.Y = this.cellPosition.Y;
  1777. }
  1778. // Set image transparent color
  1779. System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
  1780. if (this.ImageTransparentColor != Color.Empty)
  1781. {
  1782. imageAttributes.SetColorKey(this.ImageTransparentColor, this.ImageTransparentColor, System.Drawing.Imaging.ColorAdjustType.Default);
  1783. }
  1784. // Increase quality of image scaling
  1785. SmoothingMode oldSmoothingMode = chartGraph.SmoothingMode;
  1786. CompositingQuality oldCompositingQuality = chartGraph.Graphics.CompositingQuality;
  1787. InterpolationMode oldInterpolationMode = chartGraph.Graphics.InterpolationMode;
  1788. chartGraph.SmoothingMode = SmoothingMode.AntiAlias;
  1789. chartGraph.Graphics.CompositingQuality = CompositingQuality.HighQuality;
  1790. chartGraph.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
  1791. // Draw image
  1792. chartGraph.DrawImage(
  1793. image,
  1794. imagePosition,
  1795. 0,
  1796. 0,
  1797. image.Width,
  1798. image.Height,
  1799. GraphicsUnit.Pixel,
  1800. imageAttributes);
  1801. // Restore graphics settings
  1802. chartGraph.SmoothingMode = oldSmoothingMode;
  1803. chartGraph.Graphics.CompositingQuality = oldCompositingQuality;
  1804. chartGraph.Graphics.InterpolationMode = oldInterpolationMode;
  1805. }
  1806. }
  1807. /// <summary>
  1808. /// Paint a series symbol in the cell.
  1809. /// </summary>
  1810. /// <param name="chartGraph">Chart graphics</param>
  1811. /// <param name="singleWCharacterSize">Size of the 'W' character in auto-fit font.</param>
  1812. private void PaintCellSeriesSymbol(
  1813. ChartGraphics chartGraph,
  1814. SizeF singleWCharacterSize)
  1815. {
  1816. //Cache legend item
  1817. LegendItem legendItem = this.LegendItem;
  1818. // Calculate cell position
  1819. Rectangle seriesMarkerPosition = this.cellPosition;
  1820. // Adjust cell size using image symbol size specified
  1821. if (this.SeriesSymbolSize.Width >= 0)
  1822. {
  1823. int newWidth = (int)(this.SeriesSymbolSize.Width * singleWCharacterSize.Width / 100f);
  1824. if (newWidth > this.cellPosition.Width)
  1825. {
  1826. newWidth = this.cellPosition.Width;
  1827. }
  1828. seriesMarkerPosition.Width = newWidth;
  1829. }
  1830. if (this.SeriesSymbolSize.Height >= 0)
  1831. {
  1832. int newHeight = (int)(this.SeriesSymbolSize.Height * singleWCharacterSize.Height / 100f);
  1833. if (newHeight > this.cellPosition.Height)
  1834. {
  1835. newHeight = this.cellPosition.Height;
  1836. }
  1837. seriesMarkerPosition.Height = newHeight;
  1838. }
  1839. // Check for empty size
  1840. if (seriesMarkerPosition.Height <= 0 || seriesMarkerPosition.Width <= 0)
  1841. {
  1842. return;
  1843. }
  1844. // Get symbol location
  1845. seriesMarkerPosition.X = (int)((this.cellPosition.X + this.cellPosition.Width / 2f) - seriesMarkerPosition.Width / 2f);
  1846. seriesMarkerPosition.Y = (int)((this.cellPosition.Y + this.cellPosition.Height / 2f) - seriesMarkerPosition.Height / 2f);
  1847. // Adjust image location based on the cell content alignment
  1848. if (this.Alignment == ContentAlignment.BottomLeft ||
  1849. this.Alignment == ContentAlignment.MiddleLeft ||
  1850. this.Alignment == ContentAlignment.TopLeft)
  1851. {
  1852. seriesMarkerPosition.X = this.cellPosition.X;
  1853. }
  1854. else if (this.Alignment == ContentAlignment.BottomRight ||
  1855. this.Alignment == ContentAlignment.MiddleRight ||
  1856. this.Alignment == ContentAlignment.TopRight)
  1857. {
  1858. seriesMarkerPosition.X = this.cellPosition.Right - seriesMarkerPosition.Width;
  1859. }
  1860. if (this.Alignment == ContentAlignment.BottomCenter ||
  1861. this.Alignment == ContentAlignment.BottomLeft ||
  1862. this.Alignment == ContentAlignment.BottomRight)
  1863. {
  1864. seriesMarkerPosition.Y = this.cellPosition.Bottom - seriesMarkerPosition.Height;
  1865. }
  1866. else if (this.Alignment == ContentAlignment.TopCenter ||
  1867. this.Alignment == ContentAlignment.TopLeft ||
  1868. this.Alignment == ContentAlignment.TopRight)
  1869. {
  1870. seriesMarkerPosition.Y = this.cellPosition.Y;
  1871. }
  1872. // Start Svg Selection mode
  1873. chartGraph.StartHotRegion(this.GetCellUrl(), this.GetCellToolTip());
  1874. // Draw legend item image
  1875. if (legendItem.Image.Length > 0)
  1876. {
  1877. // Get image size
  1878. Rectangle imageScale = Rectangle.Empty;
  1879. System.Drawing.Image image = this.Common.ImageLoader.LoadImage(legendItem.Image);
  1880. if (image != null)
  1881. {
  1882. SizeF imageSize = new SizeF();
  1883. ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref imageSize);
  1884. imageScale.Width = (int)imageSize.Width;
  1885. imageScale.Height = (int)imageSize.Height;
  1886. // Make sure image size fits into the drawing rectangle
  1887. float scaleValue = 1f;
  1888. if (imageScale.Height > seriesMarkerPosition.Height)
  1889. {
  1890. scaleValue = (float)imageScale.Height / (float)seriesMarkerPosition.Height;
  1891. }
  1892. if (imageScale.Width > seriesMarkerPosition.Width)
  1893. {
  1894. scaleValue = Math.Max(scaleValue, (float)imageScale.Width / (float)seriesMarkerPosition.Width);
  1895. }
  1896. // Scale image size
  1897. imageScale.Height = (int)(imageScale.Height / scaleValue);
  1898. imageScale.Width = (int)(imageScale.Width / scaleValue);
  1899. imageScale.X = (int)((seriesMarkerPosition.X + seriesMarkerPosition.Width / 2f) - imageScale.Width / 2f);
  1900. imageScale.Y = (int)((seriesMarkerPosition.Y + seriesMarkerPosition.Height / 2f) - imageScale.Height / 2f);
  1901. // Set image transparent color
  1902. System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
  1903. if (legendItem.BackImageTransparentColor != Color.Empty)
  1904. {
  1905. imageAttributes.SetColorKey(legendItem.BackImageTransparentColor, legendItem.BackImageTransparentColor, System.Drawing.Imaging.ColorAdjustType.Default);
  1906. }
  1907. // Draw image
  1908. chartGraph.DrawImage(
  1909. image,
  1910. imageScale,
  1911. 0,
  1912. 0,
  1913. image.Width,
  1914. image.Height,
  1915. GraphicsUnit.Pixel,
  1916. imageAttributes);
  1917. }
  1918. }
  1919. else
  1920. {
  1921. int maxShadowOffset = (int)Math.Round((3 * chartGraph.Graphics.DpiX) / 96);
  1922. int maxBorderWidth = (int)Math.Round((3 * chartGraph.Graphics.DpiX) / 96);
  1923. if (legendItem.ImageStyle == LegendImageStyle.Rectangle)
  1924. {
  1925. int maxBorderWidthRect = (int)Math.Round((2 * chartGraph.Graphics.DpiX) / 96);
  1926. // Draw series rectangle
  1927. chartGraph.FillRectangleRel(
  1928. chartGraph.GetRelativeRectangle(seriesMarkerPosition),
  1929. legendItem.Color,
  1930. legendItem.BackHatchStyle,
  1931. legendItem.Image,
  1932. legendItem.backImageWrapMode,
  1933. legendItem.BackImageTransparentColor,
  1934. legendItem.backImageAlign,
  1935. legendItem.backGradientStyle,
  1936. legendItem.backSecondaryColor,
  1937. legendItem.borderColor,
  1938. (legendItem.BorderWidth > maxBorderWidthRect) ? maxBorderWidthRect : legendItem.BorderWidth,
  1939. legendItem.BorderDashStyle,
  1940. legendItem.ShadowColor,
  1941. (legendItem.ShadowOffset > maxShadowOffset) ? maxShadowOffset : legendItem.ShadowOffset,
  1942. PenAlignment.Inset);
  1943. }
  1944. if (legendItem.ImageStyle == LegendImageStyle.Line)
  1945. {
  1946. // Prepare line coordinates
  1947. Point point1 = new Point();
  1948. point1.X = seriesMarkerPosition.X;
  1949. point1.Y = (int)(seriesMarkerPosition.Y + seriesMarkerPosition.Height / 2F);
  1950. Point point2 = new Point();
  1951. point2.Y = point1.Y;
  1952. point2.X = seriesMarkerPosition.Right;
  1953. // Disable antialiasing
  1954. SmoothingMode oldMode = chartGraph.SmoothingMode;
  1955. chartGraph.SmoothingMode = SmoothingMode.None;
  1956. // Draw line
  1957. chartGraph.DrawLineRel(
  1958. legendItem.Color,
  1959. (legendItem.borderWidth > maxBorderWidth) ? maxBorderWidth : legendItem.borderWidth,
  1960. legendItem.borderDashStyle,
  1961. chartGraph.GetRelativePoint(point1),
  1962. chartGraph.GetRelativePoint(point2),
  1963. legendItem.shadowColor,
  1964. (legendItem.shadowOffset > maxShadowOffset) ? maxShadowOffset : legendItem.shadowOffset);
  1965. // Restore antialiasing mode
  1966. chartGraph.SmoothingMode = oldMode;
  1967. }
  1968. // Draw symbol (for line also)
  1969. if (legendItem.ImageStyle == LegendImageStyle.Marker ||
  1970. legendItem.ImageStyle == LegendImageStyle.Line)
  1971. {
  1972. MarkerStyle markerStyle = legendItem.markerStyle;
  1973. if (legendItem.style == LegendImageStyle.Marker)
  1974. {
  1975. markerStyle = (legendItem.markerStyle == MarkerStyle.None) ?
  1976. MarkerStyle.Circle : legendItem.markerStyle;
  1977. }
  1978. if (markerStyle != MarkerStyle.None ||
  1979. legendItem.markerImage.Length > 0)
  1980. {
  1981. // Calculate marker size
  1982. int markerSize = (int)Math.Min(seriesMarkerPosition.Width, seriesMarkerPosition.Height);
  1983. markerSize = (int)Math.Min(legendItem.markerSize, (legendItem.style == LegendImageStyle.Line) ? 2f * (markerSize / 3f) : markerSize);
  1984. // Reduce marker size to fit border
  1985. int markerBorderWidth = (legendItem.MarkerBorderWidth > maxBorderWidth) ? maxBorderWidth : legendItem.MarkerBorderWidth;
  1986. if (markerBorderWidth > 0)
  1987. {
  1988. markerSize -= markerBorderWidth;
  1989. if (markerSize < 1)
  1990. {
  1991. markerSize = 1;
  1992. }
  1993. }
  1994. // Draw marker
  1995. Point point = new Point();
  1996. point.X = (int)(seriesMarkerPosition.X + seriesMarkerPosition.Width / 2f);
  1997. point.Y = (int)(seriesMarkerPosition.Y + seriesMarkerPosition.Height / 2f);
  1998. // Calculate image scale
  1999. Rectangle imageScale = Rectangle.Empty;
  2000. if (legendItem.markerImage.Length > 0)
  2001. {
  2002. // Get image size
  2003. System.Drawing.Image image = this.Common.ImageLoader.LoadImage(legendItem.markerImage);
  2004. SizeF imageSize = new SizeF();
  2005. ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref imageSize);
  2006. imageScale.Width = (int)imageSize.Width;
  2007. imageScale.Height = (int)imageSize.Height;
  2008. // Make sure image size fits into the drawing rectangle
  2009. float scaleValue = 1f;
  2010. if (imageScale.Height > seriesMarkerPosition.Height)
  2011. {
  2012. scaleValue = (float)imageScale.Height / (float)seriesMarkerPosition.Height;
  2013. }
  2014. if (imageScale.Width > seriesMarkerPosition.Width)
  2015. {
  2016. scaleValue = Math.Max(scaleValue, (float)imageScale.Width / (float)seriesMarkerPosition.Width);
  2017. }
  2018. // Scale image size
  2019. imageScale.Height = (int)(imageScale.Height / scaleValue);
  2020. imageScale.Width = (int)(imageScale.Width / scaleValue);
  2021. }
  2022. // Adjust marker position so that it always drawn on pixel
  2023. // boundary.
  2024. PointF pointF = new PointF(point.X, point.Y);
  2025. if ((markerSize % 2) != 0.0)
  2026. {
  2027. pointF.X -= 0.5f;
  2028. pointF.Y -= 0.5f;
  2029. }
  2030. // Draw marker if it's not image
  2031. chartGraph.DrawMarkerRel(
  2032. chartGraph.GetRelativePoint(pointF),
  2033. markerStyle,
  2034. markerSize,
  2035. (legendItem.markerColor == Color.Empty) ? legendItem.Color : legendItem.markerColor,
  2036. (legendItem.markerBorderColor == Color.Empty) ? legendItem.borderColor : legendItem.markerBorderColor,
  2037. markerBorderWidth,
  2038. legendItem.markerImage,
  2039. legendItem.markerImageTransparentColor,
  2040. (legendItem.shadowOffset > maxShadowOffset) ? maxShadowOffset : legendItem.shadowOffset,
  2041. legendItem.shadowColor,
  2042. imageScale);
  2043. }
  2044. }
  2045. }
  2046. // End Svg Selection mode
  2047. chartGraph.EndHotRegion();
  2048. }
  2049. #endregion // Cell Painting Methods
  2050. #region IDisposable Members
  2051. /// <summary>
  2052. /// Releases unmanaged and - optionally - managed resources
  2053. /// </summary>
  2054. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  2055. protected override void Dispose(bool disposing)
  2056. {
  2057. if (disposing)
  2058. {
  2059. if (_fontCache != null)
  2060. {
  2061. _fontCache.Dispose();
  2062. _fontCache = null;
  2063. }
  2064. }
  2065. base.Dispose(disposing);
  2066. }
  2067. #endregion
  2068. }
  2069. /// <summary>
  2070. /// The Margins class represents the margins for various chart elements.
  2071. /// </summary>
  2072. [
  2073. SRDescription("DescriptionAttributeMargins_Margins"),
  2074. TypeConverter(typeof(MarginExpandableObjectConverter)),
  2075. ]
  2076. public class Margins
  2077. {
  2078. #region Fields
  2079. // Top margin
  2080. private int _top = 0;
  2081. // Bottom margin
  2082. private int _bottom = 0;
  2083. // Left margin
  2084. private int _left = 0;
  2085. // Right margin
  2086. private int _right = 0;
  2087. // Reference to common chart elements which allows to invalidate
  2088. // chart when one of the properties is changed.
  2089. internal CommonElements Common = null;
  2090. internal ChartElement Element;
  2091. #endregion // Fields
  2092. #region Constructor
  2093. /// <summary>
  2094. /// Margins constructor.
  2095. /// </summary>
  2096. public Margins()
  2097. {
  2098. Element = null;
  2099. }
  2100. /// <summary>
  2101. /// Margins constructor.
  2102. /// </summary>
  2103. /// <param name="top">Top margin.</param>
  2104. /// <param name="bottom">Bottom margin.</param>
  2105. /// <param name="left">Left margin.</param>
  2106. /// <param name="right">Right margin.</param>
  2107. public Margins(int top, int bottom, int left, int right)
  2108. {
  2109. this._top = top;
  2110. this._bottom = bottom;
  2111. this._left = left;
  2112. this._right = right;
  2113. Element = null;
  2114. }
  2115. #endregion // Constructor
  2116. #region Properties
  2117. /// <summary>
  2118. /// Gets or sets the top margin.
  2119. /// </summary>
  2120. [
  2121. SRCategory("CategoryAttributeMisc"),
  2122. DefaultValue(0),
  2123. SRDescription("DescriptionAttributeMargins_Top"),
  2124. RefreshPropertiesAttribute(RefreshProperties.All),
  2125. NotifyParentPropertyAttribute(true),
  2126. ]
  2127. public int Top
  2128. {
  2129. get
  2130. {
  2131. return this._top;
  2132. }
  2133. set
  2134. {
  2135. if (value < 0)
  2136. {
  2137. throw (new ArgumentException(SR.ExceptionMarginTopIsNegative, "value"));
  2138. }
  2139. this._top = value;
  2140. this.Invalidate();
  2141. if (Element != null)
  2142. Element.CallOnModifing();
  2143. }
  2144. }
  2145. /// <summary>
  2146. /// Gets or sets the bottom margin.
  2147. /// </summary>
  2148. [
  2149. SRCategory("CategoryAttributeMisc"),
  2150. DefaultValue(0),
  2151. SRDescription("DescriptionAttributeMargins_Bottom"),
  2152. RefreshPropertiesAttribute(RefreshProperties.All),
  2153. NotifyParentPropertyAttribute(true),
  2154. ]
  2155. public int Bottom
  2156. {
  2157. get
  2158. {
  2159. return this._bottom;
  2160. }
  2161. set
  2162. {
  2163. if (value < 0)
  2164. {
  2165. throw (new ArgumentException(SR.ExceptionMarginBottomIsNegative, "value"));
  2166. }
  2167. this._bottom = value;
  2168. this.Invalidate();
  2169. if (Element != null)
  2170. Element.CallOnModifing();
  2171. }
  2172. }
  2173. /// <summary>
  2174. /// Gets or sets the left margin.
  2175. /// </summary>
  2176. [
  2177. SRCategory("CategoryAttributeMisc"),
  2178. DefaultValue(0),
  2179. RefreshPropertiesAttribute(RefreshProperties.All),
  2180. SRDescription("DescriptionAttributeMargins_Left"),
  2181. NotifyParentPropertyAttribute(true),
  2182. ]
  2183. public int Left
  2184. {
  2185. get
  2186. {
  2187. return this._left;
  2188. }
  2189. set
  2190. {
  2191. if (value < 0)
  2192. {
  2193. throw (new ArgumentException(SR.ExceptionMarginLeftIsNegative, "value"));
  2194. }
  2195. this._left = value;
  2196. this.Invalidate();
  2197. if (Element != null)
  2198. Element.CallOnModifing();
  2199. }
  2200. }
  2201. /// <summary>
  2202. /// Gets or sets the right margin.
  2203. /// </summary>
  2204. [
  2205. SRCategory("CategoryAttributeMisc"),
  2206. DefaultValue(0),
  2207. SRDescription("DescriptionAttributeMargins_Right"),
  2208. RefreshPropertiesAttribute(RefreshProperties.All),
  2209. NotifyParentPropertyAttribute(true),
  2210. ]
  2211. public int Right
  2212. {
  2213. get
  2214. {
  2215. return this._right;
  2216. }
  2217. set
  2218. {
  2219. if (value < 0)
  2220. {
  2221. throw (new ArgumentException(SR.ExceptionMarginRightIsNegative, "value"));
  2222. }
  2223. this._right = value;
  2224. this.Invalidate();
  2225. if (Element != null)
  2226. Element.CallOnModifing();
  2227. }
  2228. }
  2229. #endregion // Properties
  2230. #region Methods
  2231. /// <summary>
  2232. /// Convert margins object to string.
  2233. /// </summary>
  2234. /// <returns>A string that represents the margins object.</returns>
  2235. [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
  2236. public override string ToString()
  2237. {
  2238. return string.Format(
  2239. CultureInfo.InvariantCulture,
  2240. "{0:D}, {1:D}, {2:D}, {3:D}",
  2241. this.Top,
  2242. this.Bottom,
  2243. this.Left,
  2244. this.Right);
  2245. }
  2246. /// <summary>
  2247. /// Determines whether the specified Object is equal to the current Object.
  2248. /// </summary>
  2249. /// <param name="obj">
  2250. /// The Object to compare with the current Object.
  2251. /// </param>
  2252. /// <returns>
  2253. /// True if the specified Object is equal to the current Object; otherwise, false.
  2254. /// </returns>
  2255. [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
  2256. public override bool Equals(object obj)
  2257. {
  2258. Margins margins = obj as Margins;
  2259. if (margins != null)
  2260. {
  2261. if (this.Top == margins.Top &&
  2262. this.Bottom == margins.Bottom &&
  2263. this.Left == margins.Left &&
  2264. this.Right == margins.Right)
  2265. {
  2266. return true;
  2267. }
  2268. }
  2269. return false;
  2270. }
  2271. /// <summary>
  2272. /// Gets object hash code.
  2273. /// </summary>
  2274. /// <returns>Margins object hash value.</returns>
  2275. [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
  2276. public override int GetHashCode()
  2277. {
  2278. return this.Top.GetHashCode() + this.Bottom.GetHashCode() + this.Left.GetHashCode() + this.Right.GetHashCode();
  2279. }
  2280. /// <summary>
  2281. /// Checks if there is no margin.
  2282. /// </summary>
  2283. /// <returns>
  2284. /// <b>True</b> if all margins values are zeros.
  2285. /// </returns>
  2286. public bool IsEmpty()
  2287. {
  2288. return (this.Top == 0 && this.Bottom == 0 && this.Left == 0 && this.Right == 0);
  2289. }
  2290. /// <summary>
  2291. /// Converts Margins class to RectangleF class.
  2292. /// </summary>
  2293. /// <returns>A RectangleF class that contains the values of the margins.</returns>
  2294. public RectangleF ToRectangleF()
  2295. {
  2296. return new RectangleF(this.Left, this.Top, this.Right, this.Bottom);
  2297. }
  2298. /// <summary>
  2299. /// Invalidates chart.
  2300. /// </summary>
  2301. private void Invalidate()
  2302. {
  2303. if (this.Common != null && this.Common.Chart != null)
  2304. {
  2305. this.Common.Chart.Invalidate();
  2306. }
  2307. }
  2308. #endregion // Methods
  2309. }
  2310. /// <summary>
  2311. /// <b>LegendCellCollection</b> is a strongly typed collection of LegendCell objects.
  2312. /// </summary>
  2313. [
  2314. SRDescription("DescriptionAttributeLegendCellCollection_LegendCellCollection"),
  2315. ]
  2316. public class LegendCellCollection : ChartNamedElementCollection<LegendCell>
  2317. {
  2318. #region Constructors
  2319. /// <summary>
  2320. /// LegendCellCollection constructor.
  2321. /// </summary>
  2322. /// <remarks>
  2323. /// This constructor is for internal use and should not be part of documentation.
  2324. /// </remarks>
  2325. /// <param name="parent">Legend item this collection belongs to.</param>
  2326. internal LegendCellCollection(LegendItem parent) : base(parent)
  2327. {
  2328. }
  2329. #endregion
  2330. #region Methods
  2331. /// <summary>
  2332. /// Adds a cell to the end of the collection.
  2333. /// </summary>
  2334. /// <param name="cellType">
  2335. /// A <see cref="LegendCellType"/> value representing the cell type.
  2336. /// </param>
  2337. /// <param name="text">
  2338. /// A <b>string</b> value representing cell text or image name depending
  2339. /// on the <b>cellType</b> parameter.
  2340. /// </param>
  2341. /// <param name="alignment">
  2342. /// A <see cref="ContentAlignment"/> value representing cell content alignment.
  2343. /// </param>
  2344. /// <returns>
  2345. /// Index of the newly added object.
  2346. /// </returns>
  2347. public int Add(LegendCellType cellType, string text, ContentAlignment alignment)
  2348. {
  2349. Add(new LegendCell(cellType, text, alignment));
  2350. return Count - 1;
  2351. }
  2352. /// <summary>
  2353. /// Inserts a cell into the collection.
  2354. /// </summary>
  2355. /// <param name="index">
  2356. /// Index to insert the object at.
  2357. /// </param>
  2358. /// <param name="cellType">
  2359. /// A <see cref="LegendCellType"/> value representing the cell type.
  2360. /// </param>
  2361. /// <param name="text">
  2362. /// A <b>string</b> value representing cell text or image name depending
  2363. /// on the <b>cellType</b> parameter.
  2364. /// </param>
  2365. /// <param name="alignment">
  2366. /// A <see cref="ContentAlignment"/> value representing cell content alignment.
  2367. /// </param>
  2368. public void Insert(int index, LegendCellType cellType, string text, ContentAlignment alignment)
  2369. {
  2370. this.Insert(index, new LegendCell(cellType, text, alignment));
  2371. }
  2372. #endregion
  2373. }
  2374. /// <summary>
  2375. /// The <b>LegendCellColumnCollection</b> class is a strongly typed collection
  2376. /// of LegendCellColumn objects.
  2377. /// </summary>
  2378. [
  2379. SRDescription("DescriptionAttributeLegendCellColumnCollection_LegendCellColumnCollection"),
  2380. ]
  2381. public class LegendCellColumnCollection : ChartNamedElementCollection<LegendCellColumn>
  2382. {
  2383. #region Construction and Initialization
  2384. /// <summary>
  2385. /// LegendCellColumnCollection constructor.
  2386. /// </summary>
  2387. /// <remarks>
  2388. /// This constructor is for internal use and should not be part of documentation.
  2389. /// </remarks>
  2390. /// <param name="legend">
  2391. /// Chart legend which this collection belongs to.
  2392. /// </param>
  2393. internal LegendCellColumnCollection(Legend legend)
  2394. : base(legend)
  2395. {
  2396. }
  2397. #endregion // Construction and Initialization
  2398. #region IDisposable Members
  2399. /// <summary>
  2400. /// Releases unmanaged and - optionally - managed resources
  2401. /// </summary>
  2402. /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
  2403. protected override void Dispose(bool disposing)
  2404. {
  2405. if (disposing)
  2406. {
  2407. //Free managed resources
  2408. foreach (LegendCellColumn item in this)
  2409. {
  2410. item.Dispose();
  2411. }
  2412. this.ClearItems();
  2413. }
  2414. base.Dispose(disposing);
  2415. }
  2416. #endregion
  2417. }
  2418. }