1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704 |
- // Licensed to the .NET Foundation under one or more agreements.
- // The .NET Foundation licenses this file to you under the MIT license.
- // See the LICENSE file in the project root for more information.
- //
- // Purpose: LegendCell and LegendCellColumn classes allow to
- // create highly customize legends. Please refer to
- // Chart documentation which contains images and
- // samples describing this functionality.
- //
- using System;
- using System.ComponentModel;
- using System.Diagnostics.CodeAnalysis;
- using System.Globalization;
- using FastReport.DataVisualization.Charting.Utilities;
- namespace FastReport.DataVisualization.Charting
- {
- using System.Drawing;
- using System.Drawing.Design;
- using System.Drawing.Drawing2D;
- using SizeF = System.Drawing.SizeF;
- #region Enumerations
- /// <summary>
- /// An enumeration of legend cell types.
- /// </summary>
- public enum LegendCellType
- {
- /// <summary>
- /// Legend cell contains text.
- /// </summary>
- Text,
- /// <summary>
- /// Legend cell contains series symbol.
- /// </summary>
- SeriesSymbol,
- /// <summary>
- /// Legend cell contains image.
- /// </summary>
- Image
- }
- /// <summary>
- /// An enumeration of legend cell column types.
- /// </summary>
- public enum LegendCellColumnType
- {
- /// <summary>
- /// Legend column contains text.
- /// </summary>
- Text,
- /// <summary>
- /// Legend column contains series symbol.
- /// </summary>
- SeriesSymbol
- }
- #endregion // Enumerations
- /// <summary>
- /// The LegendCellColumn class represents a cell column in a legend,
- /// used to extend the functionality of the default legend. It contains
- /// visual appearance properties, legend header settings and also determine
- /// how and in which order cells are formed for each of the legend items.
- /// </summary>
- [
- SRDescription("DescriptionAttributeLegendCellColumn_LegendCellColumn"),
- ]
- public class LegendCellColumn : ChartNamedElement
- {
- #region Fields
- // Legend column type
- private LegendCellColumnType _columnType = LegendCellColumnType.Text;
- // Legend column text
- private string _text = KeywordName.LegendText;
- // Legend column text color
- private Color _foreColor = Color.Empty;
- // Legend column back color
- private Color _backColor = Color.Empty;
- // Font cache
- private FontCache _fontCache = new FontCache();
- // Legend column text font
- private Font _font = null;
- // Legend column series symbol size
- private Size _seriesSymbolSize = new Size(200, 70);
- // Legend column content allignment
- private ContentAlignment _alignment = ContentAlignment.MiddleCenter;
- // Legend column tooltip
- private string _toolTip = string.Empty;
- // Legend column margins
- private Margins _margins = new Margins(0, 0, 15, 15);
- // Legend column header text
- private string _headerText = string.Empty;
- // Legend column/cell content allignment
- private StringAlignment _headerAlignment = StringAlignment.Center;
- // Legend column header text color
- private Color _headerForeColor = Color.Black;
- // Legend column header text back color
- private Color _headerBackColor = Color.Empty;
- // Legend column header text font
- private Font _headerFont = null;
- // Minimum column width
- private int _minimumCellWidth = -1;
- // Maximum column width
- private int _maximumCellWidth = -1;
- #endregion // Fields
- #region Constructors
- /// <summary>
- /// LegendCellColumn constructor.
- /// </summary>
- public LegendCellColumn()
- : this(string.Empty, LegendCellColumnType.Text, KeywordName.LegendText, ContentAlignment.MiddleCenter)
- {
- _headerFont = _fontCache.DefaultBoldFont;
- }
- /// <summary>
- /// LegendCellColumn constructor.
- /// </summary>
- /// <param name="headerText">Column header text.</param>
- /// <param name="columnType">Column type.</param>
- /// <param name="text">Column cell text.</param>
- public LegendCellColumn(string headerText, LegendCellColumnType columnType, string text) : this(headerText, columnType, text, ContentAlignment.MiddleCenter)
- {
- }
- /// <summary>
- /// Legend column object constructor.
- /// </summary>
- /// <param name="headerText">Column header text.</param>
- /// <param name="columnType">Column type.</param>
- /// <param name="text">Column cell text .</param>
- /// <param name="alignment">Column cell content alignment.</param>
- public LegendCellColumn(string headerText, LegendCellColumnType columnType, string text, ContentAlignment alignment)
- {
- this._headerText = headerText;
- this._columnType = columnType;
- this._text = text;
- this._alignment = alignment;
- this._margins.Element = this;
- }
- #endregion // Constructors
- #region Properties
- /// <summary>
- /// Gets or sets name of legend column.
- /// </summary>
- [
- SRCategory("CategoryAttributeMisc"),
- SRDescription("DescriptionAttributeLegendCellColumn_Name"),
- ]
- public override string Name
- {
- get
- {
- return base.Name;
- }
- set
- {
- base.Name = value;
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets legend this column belongs too.
- /// </summary>
- [
- Browsable(false),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden),
- ]
- public virtual Legend Legend
- {
- get
- {
- if (Parent != null)
- return Parent.Parent as Legend;
- else
- return null;
- }
- }
- /// <summary>
- /// Gets or sets legend column type. This is only applicable to items that are automatically generated for the series.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(LegendCellColumnType.Text),
- SRDescription("DescriptionAttributeLegendCellColumn_ColumnType"),
- ParenthesizePropertyNameAttribute(true)
- ]
- public virtual LegendCellColumnType ColumnType
- {
- get
- {
- return this._columnType;
- }
- set
- {
- this._columnType = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets legend column text. This is only applicable to items that are automatically generated for the series.
- /// Set the ColumnType property to text to use this property.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(KeywordName.LegendText),
- SRDescription("DescriptionAttributeLegendCellColumn_Text"),
- #if DESIGNER
- Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
- #endif
- ]
- public virtual string Text
- {
- get
- {
- return this._text;
- }
- set
- {
- this._text = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the text color of the legend column.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(typeof(Color), ""),
- SRDescription("DescriptionAttributeForeColor"),
- TypeConverter(typeof(ColorConverter)),
- #if DESIGNER
- Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
- #endif
- ]
- public virtual Color ForeColor
- {
- get
- {
- return this._foreColor;
- }
- set
- {
- this._foreColor = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the background color of the legend column.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(typeof(Color), ""),
- SRDescription("DescriptionAttributeBackColor"),
- TypeConverter(typeof(ColorConverter)),
- #if DESIGNER
- Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
- #endif
- ]
- public virtual Color BackColor
- {
- get
- {
- return this._backColor;
- }
- set
- {
- this._backColor = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the font of the legend column text.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(null),
- SRDescription("DescriptionAttributeLegendCellColumn_Font"),
- ]
- public virtual Font Font
- {
- get
- {
- return this._font;
- }
- set
- {
- this._font = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the series symbol size of the legend column
- /// for the items automatically generated for the series.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(typeof(Size), "200, 70"),
- SRDescription("DescriptionAttributeLegendCellColumn_SeriesSymbolSize"),
- ]
- public virtual Size SeriesSymbolSize
- {
- get
- {
- return this._seriesSymbolSize;
- }
- set
- {
- if (value.Width < 0 || value.Height < 0)
- {
- throw (new ArgumentException(SR.ExceptionSeriesSymbolSizeIsNegative, "value"));
- }
- this._seriesSymbolSize = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the content alignment of the legend column.
- /// This is only applicable to items that are automatically generated for the series.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(ContentAlignment.MiddleCenter),
- SRDescription("DescriptionAttributeLegendCellColumn_Alignment"),
- ]
- public virtual ContentAlignment Alignment
- {
- get
- {
- return this._alignment;
- }
- set
- {
- this._alignment = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the margins of the legend column (as a percentage of legend font size).
- /// This is only applicable to items that are automatically generated for the series.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- DefaultValue(typeof(Margins), "0,0,15,15"),
- SRDescription("DescriptionAttributeLegendCellColumn_Margins"),
- SerializationVisibilityAttribute(SerializationVisibility.Attribute),
- DesignerSerializationVisibility(DesignerSerializationVisibility.Content),
- NotifyParentPropertyAttribute(true),
- ]
- public virtual Margins Margins
- {
- get
- {
- return this._margins;
- }
- set
- {
- this._margins = value;
- this.Invalidate();
- CallOnModifing();
- // Set common elements of the new margins class
- if (this.Legend != null)
- {
- this._margins.Common = this.Legend.Common;
- }
- }
- }
- /// <summary>
- /// Returns true if property should be serialized. This is for internal use only.
- /// </summary>
- [EditorBrowsableAttribute(EditorBrowsableState.Never)]
- public bool ShouldSerializeMargins()
- {
- if (this._margins.Top == 0 &&
- this._margins.Bottom == 0 &&
- this._margins.Left == 15 &&
- this._margins.Right == 15)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// Gets or sets the legend column tooltip. This is only applicable to items that are automatically generated for the series.
- /// </summary>
- [
- SRCategory("CategoryAttributeSeriesItems"),
- SRDescription("DescriptionAttributeToolTip"),
- DefaultValue(""),
- #if DESIGNER
- Editor(typeof(KeywordsStringEditor), typeof(UITypeEditor)),
- #endif
- ]
- public virtual string ToolTip
- {
- set
- {
- this._toolTip = value;
- CallOnModifing();
- if (Chart != null &&
- Chart.selection != null)
- {
- Chart.selection.enabledChecked = false;
- }
- }
- get
- {
- return this._toolTip;
- }
- }
- /// <summary>
- /// Gets or sets the legend column header text.
- /// </summary>
- [
- SRCategory("CategoryAttributeHeader"),
- DefaultValue(""),
- SRDescription("DescriptionAttributeLegendCellColumn_HeaderText"),
- ]
- public virtual string HeaderText
- {
- get
- {
- return this._headerText;
- }
- set
- {
- this._headerText = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the color of the legend column header text.
- /// </summary>
- [
- SRCategory("CategoryAttributeHeader"),
- DefaultValue(typeof(Color), "Black"),
- SRDescription("DescriptionAttributeLegendCellColumn_HeaderColor"),
- TypeConverter(typeof(ColorConverter)),
- #if DESIGNER
- Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
- #endif
- ]
- public virtual Color HeaderForeColor
- {
- get
- {
- return this._headerForeColor;
- }
- set
- {
- this._headerForeColor = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the background color of the legend column header.
- /// </summary>
- [
- SRCategory("CategoryAttributeHeader"),
- DefaultValue(typeof(Color), ""),
- SRDescription("DescriptionAttributeHeaderBackColor"),
- TypeConverter(typeof(ColorConverter)),
- #if DESIGNER
- Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
- #endif
- ]
- public virtual Color HeaderBackColor
- {
- get
- {
- return this._headerBackColor;
- }
- set
- {
- this._headerBackColor = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the font of the legend column header.
- /// </summary>
- [
- SRCategory("CategoryAttributeHeader"),
- DefaultValue(typeof(Font), "Microsoft Sans Serif, 8pt, style=Bold"),
- SRDescription("DescriptionAttributeLegendCellColumn_HeaderFont"),
- ]
- public virtual Font HeaderFont
- {
- get
- {
- return this._headerFont;
- }
- set
- {
- this._headerFont = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the horizontal text alignment of the legend column header.
- /// </summary>
- [
- SRCategory("CategoryAttributeHeader"),
- DefaultValue(typeof(StringAlignment), "Center"),
- SRDescription("DescriptionAttributeLegendCellColumn_HeaderTextAlignment"),
- ]
- public StringAlignment HeaderAlignment
- {
- get
- {
- return this._headerAlignment;
- }
- set
- {
- if (value != this._headerAlignment)
- {
- this._headerAlignment = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- }
- /// <summary>
- /// Gets or sets the minimum width (as a percentage of legend font size) of legend column. Set this property to -1 for automatic calculation.
- /// </summary>
- [
- SRCategory("CategoryAttributeSize"),
- DefaultValue(-1),
- TypeConverter(typeof(IntNanValueConverter)),
- SRDescription("DescriptionAttributeLegendCellColumn_MinimumWidth"),
- ]
- public virtual int MinimumWidth
- {
- get
- {
- return this._minimumCellWidth;
- }
- set
- {
- if (value < -1)
- {
- throw (new ArgumentException(SR.ExceptionMinimumCellWidthIsWrong, "value"));
- }
- this._minimumCellWidth = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the maximum width (as a percentage of legend font size) of legend column. Set this property to -1 for automatic calculation.
- /// </summary>
- [
- SRCategory("CategoryAttributeSize"),
- DefaultValue(-1),
- TypeConverter(typeof(IntNanValueConverter)),
- SRDescription("DescriptionAttributeLegendCellColumn_MaximumWidth"),
- ]
- public virtual int MaximumWidth
- {
- get
- {
- return this._maximumCellWidth;
- }
- set
- {
- if (value < -1)
- {
- throw (new ArgumentException(SR.ExceptionMaximumCellWidthIsWrong, "value"));
- }
- this._maximumCellWidth = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- #endregion // Properties
- #region Methods
- /// <summary>
- /// Creates a new LegendCell object and copies all properties from the
- /// current column into the newly created one.
- /// </summary>
- /// <returns>A new copy of the LegendCell</returns>
- internal LegendCell CreateNewCell()
- {
- LegendCell newCell = new LegendCell();
- newCell.CellType = (this.ColumnType == LegendCellColumnType.SeriesSymbol) ? LegendCellType.SeriesSymbol : LegendCellType.Text;
- newCell.Text = this.Text;
- newCell.ToolTip = this.ToolTip;
- newCell.SeriesSymbolSize = this.SeriesSymbolSize;
- newCell.Alignment = this.Alignment;
- newCell.Margins = new Margins(this.Margins.Top, this.Margins.Bottom, this.Margins.Left, this.Margins.Right);
- newCell.Margins.Element = this;
- return newCell;
- }
- #endregion // Methods
- #region IDisposable Members
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (_fontCache != null)
- {
- _fontCache.Dispose();
- _fontCache = null;
- }
- }
- }
- #endregion
- }
- /// <summary>
- /// The LegendCell class represents a single cell in the chart legend.
- /// Legend contains several legend items. Each item contains several
- /// cells which form the vertical columns. This class provides properties
- /// which determine content of the cell and its visual appearance. It
- /// also contains method which determine the size of the cell and draw
- /// cell in the chart.
- /// </summary>
- [
- SRDescription("DescriptionAttributeLegendCell_LegendCell"),
- ]
- public class LegendCell : ChartNamedElement
- {
- #region Fields
- // Legend cell type
- private LegendCellType _cellType = LegendCellType.Text;
- // Legend cell text
- private string _text = string.Empty;
- // Legend cell text color
- private Color _foreColor = Color.Empty;
- // Legend cell back color
- private Color _backColor = Color.Empty;
- // Font cache
- private FontCache _fontCache = new FontCache();
- // Legend cell text font
- private Font _font = null;
- // Legend cell image name
- private string _image = string.Empty;
- // Legend cell image transparent color
- private Color _imageTransparentColor = Color.Empty;
- // Legend cell image size
- private Size _imageSize = Size.Empty;
- // Legend cell series symbol size
- private Size _seriesSymbolSize = new Size(200, 70);
- // Legend cell content allignment
- private ContentAlignment _alignment = ContentAlignment.MiddleCenter;
- // Numer of cells this cell uses to show it's content
- private int _cellSpan = 1;
- // Legend cell tooltip
- private string _toolTip = string.Empty;
- // Legend cell margins
- private Margins _margins = new Margins(0, 0, 15, 15);
- // Cell row index
- private int _rowIndex = -1;
- // Position where cell is drawn in pixel coordinates.
- // Exncludes margins and space required for separators
- internal Rectangle cellPosition = Rectangle.Empty;
- // Position where cell is drawn in pixel coordinates.
- // Includes margins and space required for separators
- internal Rectangle cellPositionWithMargins = Rectangle.Empty;
- // Last cached cell size.
- private Size _cachedCellSize = Size.Empty;
- // Font reduced value used to calculate last cached cell size
- private int _cachedCellSizeFontReducedBy = 0;
- #endregion // Fields
- #region Constructors
- /// <summary>
- /// LegendCell constructor.
- /// </summary>
- public LegendCell()
- {
- this.Intitialize(LegendCellType.Text, string.Empty, ContentAlignment.MiddleCenter);
- }
- /// <summary>
- /// LegendCell constructor.
- /// </summary>
- /// <param name="text">Cell text or image name, depending on the type.</param>
- public LegendCell(string text)
- {
- this.Intitialize(LegendCellType.Text, text, ContentAlignment.MiddleCenter);
- }
- /// <summary>
- /// LegendCell constructor.
- /// </summary>
- /// <param name="cellType">Cell type.</param>
- /// <param name="text">Cell text or image name, depending on the type.</param>
- public LegendCell(LegendCellType cellType, string text)
- {
- this.Intitialize(cellType, text, ContentAlignment.MiddleCenter);
- }
- /// <summary>
- /// LegendCell constructor.
- /// </summary>
- /// <param name="cellType">Cell type.</param>
- /// <param name="text">Cell text or image name, depending on the type.</param>
- /// <param name="alignment">Cell content alignment.</param>
- public LegendCell(LegendCellType cellType, string text, ContentAlignment alignment)
- {
- this.Intitialize(cellType, text, alignment);
- }
- /// <summary>
- /// Initializes newly created object.
- /// </summary>
- /// <param name="cellType">Cell type.</param>
- /// <param name="text">Cell text or image name depending on the type.</param>
- /// <param name="alignment">Cell content alignment.</param>
- private void Intitialize(LegendCellType cellType, string text, ContentAlignment alignment)
- {
- this._cellType = cellType;
- if (this._cellType == LegendCellType.Image)
- {
- this._image = text;
- }
- else
- {
- this._text = text;
- }
- this._alignment = alignment;
- }
- #endregion // Constructors
- #region Properties
-
- /// <summary>
- /// Gets or sets the name of the legend cell.
- /// </summary>
- [
- SRCategory("CategoryAttributeMisc"),
- SRDescription("DescriptionAttributeLegendCell_Name"),
- ]
- public override string Name
- {
- get
- {
- return base.Name;
- }
- set
- {
- base.Name = value;
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the type of the legend cell.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- DefaultValue(LegendCellType.Text),
- SRDescription("DescriptionAttributeLegendCell_CellType"),
- ParenthesizePropertyNameAttribute(true)
- ]
- public virtual LegendCellType CellType
- {
- get
- {
- return this._cellType;
- }
- set
- {
- this._cellType = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets legend this column/cell belongs too.
- /// </summary>
- [
- Browsable(false),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden),
- ]
- public virtual Legend Legend
- {
- get
- {
- LegendItem item = this.LegendItem;
- if (item != null)
- return item.Legend;
- else
- return null;
- }
- }
- /// <summary>
- /// Gets legend item this cell belongs too.
- /// </summary>
- [
- Browsable(false),
- DesignerSerializationVisibilityAttribute(DesignerSerializationVisibility.Hidden),
- SerializationVisibilityAttribute(SerializationVisibility.Hidden),
- ]
- public virtual LegendItem LegendItem
- {
- get
- {
- if (Parent != null)
- return Parent.Parent as LegendItem;
- else
- return null;
- }
- }
- internal override IChartElement Parent
- {
- get { return base.Parent; }
- set
- {
- base.Parent = value;
-
- if (_margins != null)
- _margins.Element = this;
- }
- }
- /// <summary>
- /// Gets or sets the text of the legend cell. Set CellType to text to use this property.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- DefaultValue(""),
- SRDescription("DescriptionAttributeLegendCell_Text"),
- ]
- public virtual string Text
- {
- get
- {
- return this._text;
- }
- set
- {
- this._text = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the text color of the legend cell. Set CellType to text to use this property.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- DefaultValue(typeof(Color), ""),
- SRDescription("DescriptionAttributeForeColor"),
- TypeConverter(typeof(ColorConverter)),
- #if DESIGNER
- Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
- #endif
- ]
- public virtual Color ForeColor
- {
- get
- {
- return this._foreColor;
- }
- set
- {
- this._foreColor = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the background color of the legend cell.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- DefaultValue(typeof(Color), ""),
- SRDescription("DescriptionAttributeBackColor"),
- TypeConverter(typeof(ColorConverter)),
- #if DESIGNER
- Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
- #endif
- ]
- public virtual Color BackColor
- {
- get
- {
- return this._backColor;
- }
- set
- {
- this._backColor = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the font of the legend cell. Set CellType to text to use this property.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- DefaultValue(null),
- SRDescription("DescriptionAttributeLegendCell_Font"),
- ]
- public virtual Font Font
- {
- get
- {
- return this._font;
- }
- set
- {
- this._font = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the URL of the image of the legend cell. Set CellType to image to use this property.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- DefaultValue(""),
- SRDescription("DescriptionAttributeLegendCell_Image"),
- #if DESIGNER
- Editor(typeof(ImageValueEditor), typeof(UITypeEditor)),
- #endif
- ]
- public virtual string Image
- {
- get
- {
- return this._image;
- }
- set
- {
- this._image = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// 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.
- /// </summary>
- [
- SRCategory("CategoryAttributeAppearance"),
- DefaultValue(typeof(Color), ""),
- SRDescription("DescriptionAttributeImageTransparentColor"),
- TypeConverter(typeof(ColorConverter)),
- #if DESIGNER
- Editor(typeof(ChartColorEditor), typeof(UITypeEditor))
- #endif
- ]
- public virtual Color ImageTransparentColor
- {
- get
- {
- return this._imageTransparentColor;
- }
- set
- {
- this._imageTransparentColor = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the image size (as a percentage of legend font size) of the legend cell.
- /// Set CellType to Image to use this property.
- /// </summary>
- /// <remarks>
- /// If property is set to Size.IsEmpty, the original image pixels size is used.
- /// </remarks>
- [
- SRCategory("CategoryAttributeLayout"),
- DefaultValue(typeof(Size), "0, 0"),
- TypeConverter(typeof(SizeEmptyValueConverter)),
- SRDescription("DescriptionAttributeLegendCell_ImageSize"),
- ]
- public virtual Size ImageSize
- {
- get
- {
- return this._imageSize;
- }
- set
- {
- if (value.Width < 0 || value.Height < 0)
- {
- throw (new ArgumentException(SR.ExceptionLegendCellImageSizeIsNegative, "value"));
- }
- this._imageSize = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the series symbol size (as a percentage of legend font size) of the legend cell.
- /// Set CellType to SeriesSymbol to use this property.
- /// </summary>
- [
- SRCategory("CategoryAttributeLayout"),
- DefaultValue(typeof(Size), "200, 70"),
- SRDescription("DescriptionAttributeLegendCell_SeriesSymbolSize"),
- ]
- public virtual Size SeriesSymbolSize
- {
- get
- {
- return this._seriesSymbolSize;
- }
- set
- {
- if (value.Width < 0 || value.Height < 0)
- {
- throw (new ArgumentException(SR.ExceptionLegendCellSeriesSymbolSizeIsNegative, "value"));
- }
- this._seriesSymbolSize = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the content alignment of the legend cell.
- /// </summary>
- [
- SRCategory("CategoryAttributeLayout"),
- DefaultValue(ContentAlignment.MiddleCenter),
- SRDescription("DescriptionAttributeLegendCell_Alignment"),
- ]
- public virtual ContentAlignment Alignment
- {
- get
- {
- return this._alignment;
- }
- set
- {
- this._alignment = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the number of horizontal cells used to draw the content.
- /// </summary>
- [
- SRCategory("CategoryAttributeLayout"),
- DefaultValue(1),
- SRDescription("DescriptionAttributeLegendCell_CellSpan"),
- ]
- public virtual int CellSpan
- {
- get
- {
- return this._cellSpan;
- }
- set
- {
- if (value < 1)
- {
- throw (new ArgumentException(SR.ExceptionLegendCellSpanIsLessThenOne, "value"));
- }
- this._cellSpan = value;
- this.Invalidate();
- CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the legend cell margins (as a percentage of legend font size).
- /// </summary>
- [
- SRCategory("CategoryAttributeLayout"),
- DefaultValue(typeof(Margins), "0,0,15,15"),
- SRDescription("DescriptionAttributeLegendCell_Margins"),
- SerializationVisibilityAttribute(SerializationVisibility.Attribute),
- NotifyParentPropertyAttribute(true),
- ]
- public virtual Margins Margins
- {
- get
- {
- return this._margins;
- }
- set
- {
- this._margins = value;
- this.Invalidate();
- CallOnModifing();
- // Set common elements of the new margins class
- if (this.Legend != null)
- {
- this._margins.Common = this.Common;
- }
- }
- }
- /// <summary>
- /// Returns true if property should be serialized. This method is for internal use only.
- /// </summary>
- [EditorBrowsableAttribute(EditorBrowsableState.Never)]
- internal bool ShouldSerializeMargins()
- {
- if (this._margins.Top == 0 &&
- this._margins.Bottom == 0 &&
- this._margins.Left == 15 &&
- this._margins.Right == 15)
- {
- return false;
- }
- return true;
- }
- /// <summary>
- /// Gets or sets the tooltip of the legend cell.
- /// </summary>
- [
- SRCategory("CategoryAttributeMapArea"),
- SRDescription("DescriptionAttributeToolTip"),
- DefaultValue(""),
- ]
- public virtual string ToolTip
- {
- set
- {
- this._toolTip = value;
- CallOnModifing();
- if (this.Chart != null &&
- this.Chart.selection != null)
- {
- this.Chart.selection.enabledChecked = false;
- }
- }
- get
- {
- return this._toolTip;
- }
- }
- #endregion // Properties
- #region Methods
- /// <summary>
- /// Resets cached cell values.
- /// </summary>
- internal void ResetCache()
- {
- this._cachedCellSize = Size.Empty;
- this._cachedCellSizeFontReducedBy = 0;
- }
- /// <summary>
- /// Sets cell position in relative coordinates.
- /// </summary>
- /// <param name="rowIndex">Cell row index.</param>
- /// <param name="position">Cell position.</param>
- /// <param name="singleWCharacterSize">Size of the 'W' character used to calculate elements.</param>
- internal void SetCellPosition(
- int rowIndex,
- Rectangle position,
- Size singleWCharacterSize)
- {
- // Set cell position
- this.cellPosition = position;
- this.cellPositionWithMargins = position;
- this._rowIndex = rowIndex;
- // Adjust cell position by specified margin
- this.cellPosition.X += (int)(this.Margins.Left * singleWCharacterSize.Width / 100f);
- this.cellPosition.Y += (int)(this.Margins.Top * singleWCharacterSize.Height / 100f);
- this.cellPosition.Width -= (int)(this.Margins.Left * singleWCharacterSize.Width / 100f)
- + (int)(this.Margins.Right * singleWCharacterSize.Width / 100f);
- this.cellPosition.Height -= (int)(this.Margins.Top * singleWCharacterSize.Height / 100f)
- + (int)(this.Margins.Bottom * singleWCharacterSize.Height / 100f);
- // Adjust cell position by space required for the separatorType
- if (LegendItem != null &&
- LegendItem.SeparatorType != LegendSeparatorStyle.None)
- {
- this.cellPosition.Height -= this.Legend.GetSeparatorSize(LegendItem.SeparatorType).Height;
- }
- }
- /// <summary>
- /// Measures legend cell size in chart relative coordinates.
- /// </summary>
- /// <param name="graph">
- /// Chart graphics.
- /// </param>
- /// <param name="fontSizeReducedBy">
- /// A positive or negative integer value that determines the how standard cell font size
- /// should be adjusted. As a result smaller or larger font can be used.
- /// </param>
- /// <param name="legendAutoFont">
- /// Auto fit font used in the legend.
- /// </param>
- /// <param name="singleWCharacterSize">
- /// Size of the 'W' character used to calculate elements.
- /// </param>
- /// <returns>Legend cell size.</returns>
- internal Size MeasureCell(
- ChartGraphics graph,
- int fontSizeReducedBy,
- Font legendAutoFont,
- Size singleWCharacterSize)
- {
- // Check if cached size may be reused
- if (this._cachedCellSizeFontReducedBy == fontSizeReducedBy &&
- !this._cachedCellSize.IsEmpty)
- {
- return this._cachedCellSize;
- }
- // Get cell font
- Size cellSize = Size.Empty;
- bool disposeFont = false;
- Font cellFont = this.GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont);
- // Measure cell content size based on the type
- if (this.CellType == LegendCellType.SeriesSymbol)
- {
- cellSize.Width = (int)(Math.Abs(this.SeriesSymbolSize.Width) * singleWCharacterSize.Width / 100f);
- cellSize.Height = (int)(Math.Abs(this.SeriesSymbolSize.Height) * singleWCharacterSize.Height / 100f);
- }
- else if (this.CellType == LegendCellType.Image)
- {
- if (this.ImageSize.IsEmpty && this.Image.Length > 0)
- {
- SizeF imageSize = new SizeF();
- // Use original image size
- if (this.Common.ImageLoader.GetAdjustedImageSize(this.Image, graph.Graphics, ref imageSize))
- {
- cellSize.Width = (int)imageSize.Width;
- cellSize.Height = (int)imageSize.Height;
- }
- }
- else
- {
- cellSize.Width = (int)(Math.Abs(this.ImageSize.Width) * singleWCharacterSize.Width / 100f);
- cellSize.Height = (int)(Math.Abs(this.ImageSize.Height) * singleWCharacterSize.Height / 100f);
- }
- }
- else if (this.CellType == LegendCellType.Text)
- {
- // Get current cell text taking in consideration keywords
- // and automatic text wrapping.
- string cellText = this.GetCellText();
- // Measure text size.
- // Note that extra "I" character added to add more horizontal spacing
- cellSize = graph.MeasureStringAbs(cellText + "I", cellFont);
- }
- else
- {
- throw (new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(this.CellType.ToString())));
- }
- // Add cell margins
- cellSize.Width += (int)((this.Margins.Left + this.Margins.Right) * singleWCharacterSize.Width / 100f);
- cellSize.Height += (int)((this.Margins.Top + this.Margins.Bottom) * singleWCharacterSize.Height / 100f);
- // Add space required for the separatorType
- if (LegendItem != null &&
- LegendItem.SeparatorType != LegendSeparatorStyle.None)
- {
- cellSize.Height += this.Legend.GetSeparatorSize(LegendItem.SeparatorType).Height;
- }
- // Dispose created font object
- if (disposeFont)
- {
- cellFont.Dispose();
- cellFont = null;
- }
- // Save calculated size
- this._cachedCellSize = cellSize;
- this._cachedCellSizeFontReducedBy = fontSizeReducedBy;
- return cellSize;
- }
- /// <summary>
- /// Gets cell background color.
- /// </summary>
- /// <returns></returns>
- private Color GetCellBackColor()
- {
- Color resultColor = this.BackColor;
- if (this.BackColor.IsEmpty && this.Legend != null)
- {
- // Try getting back color from the associated column
- if (this.LegendItem != null)
- {
- // Get index of this cell
- int cellIndex = this.LegendItem.Cells.IndexOf(this);
- if (cellIndex >= 0)
- {
- // Check if associated column exsists
- if (cellIndex < this.Legend.CellColumns.Count &&
- !this.Legend.CellColumns[cellIndex].BackColor.IsEmpty)
- {
- resultColor = this.Legend.CellColumns[cellIndex].BackColor;
- }
- }
- }
- // Get font from the legend isInterlaced
- if (resultColor.IsEmpty &&
- this.Legend.InterlacedRows &&
- this._rowIndex % 2 != 0)
- {
- if (this.Legend.InterlacedRowsColor.IsEmpty)
- {
- // Automatically determine background color
- // If isInterlaced strips color is not set - use darker color of the area
- if (this.Legend.BackColor == Color.Empty)
- {
- resultColor = Color.LightGray;
- }
- else if (this.Legend.BackColor == Color.Transparent)
- {
- if (Chart.BackColor != Color.Transparent &&
- Chart.BackColor != Color.Black)
- {
- resultColor = ChartGraphics.GetGradientColor(Chart.BackColor, Color.Black, 0.2);
- }
- else
- {
- resultColor = Color.LightGray;
- }
- }
- else
- {
- resultColor = ChartGraphics.GetGradientColor(this.Legend.BackColor, Color.Black, 0.2);
- }
- }
- else
- {
- resultColor = this.Legend.InterlacedRowsColor;
- }
- }
- }
- return resultColor;
- }
- /// <summary>
- /// Gets default cell font. Font can be specified in the cell, column or in the legend.
- /// </summary>
- /// <param name="legendAutoFont">Auto fit font used in the legend.</param>
- /// <param name="fontSizeReducedBy">Number of points legend auto-font reduced by.</param>
- /// <param name="disposeFont">Returns a flag if result font object should be disposed.</param>
- /// <returns>Default cell font.</returns>
- private Font GetCellFont(Font legendAutoFont, int fontSizeReducedBy, out bool disposeFont)
- {
- Font cellFont = this.Font;
- disposeFont = false;
- // Check if font is not set in the cell and legend object reference is valid
- if (cellFont == null &&
- this.Legend != null)
- {
- // Try getting font from the associated column
- if (this.LegendItem != null)
- {
- // Get index of this cell
- int cellIndex = this.LegendItem.Cells.IndexOf(this);
- if (cellIndex >= 0)
- {
- // Check if associated column exsists
- if (cellIndex < this.Legend.CellColumns.Count &&
- this.Legend.CellColumns[cellIndex].Font != null)
- {
- cellFont = this.Legend.CellColumns[cellIndex].Font;
- }
- }
- }
- // Get font from the legend
- if (cellFont == null)
- {
- cellFont = legendAutoFont;
- // No further processing required.
- // Font is already reduced.
- return cellFont;
- }
- }
- // Check if font size should be adjusted
- if (cellFont != null && fontSizeReducedBy != 0)
- {
- // New font is created anf it must be disposed
- disposeFont = true;
- // Calculate new font size
- int newFontSize = (int)Math.Round(cellFont.Size - fontSizeReducedBy);
- if (newFontSize < 1)
- {
- // Font can't be less than size 1
- newFontSize = 1;
- }
- // Create new font
- cellFont = new Font(
- cellFont.FontFamily,
- newFontSize,
- cellFont.Style,
- cellFont.Unit);
- }
- return cellFont;
- }
- /// <summary>
- /// Helper function that returns cell tooltip.
- /// </summary>
- /// <remarks>
- /// Tooltip can be set in the cell or in the legend item. Cell
- /// tooltip always has a higher priority.
- /// </remarks>
- /// <returns>Returns cell text.</returns>
- private string GetCellToolTip()
- {
- // Check if tooltip is set in the cell (highest priority)
- if (this.ToolTip.Length > 0)
- {
- return this.ToolTip;
- }
- // Check if tooltip is set in associated legend item
- if (this.LegendItem != null)
- {
- return this.LegendItem.ToolTip;
- }
- return string.Empty;
- }
- /// <summary>
- /// Helper function that returns cell url.
- /// </summary>
- /// <remarks>
- /// Url can be set in the cell or in the legend item. Cell
- /// tooltip always has a higher priority.
- /// </remarks>
- /// <returns>Returns cell text.</returns>
- private string GetCellUrl()
- {
- return string.Empty;
- }
- /// <summary>
- /// Helper function that returns cell url.
- /// </summary>
- /// <remarks>
- /// Url can be set in the cell or in the legend item. Cell
- /// tooltip always has a higher priority.
- /// </remarks>
- /// <returns>Returns cell text.</returns>
- private string GetCellMapAreaAttributes()
- {
- return string.Empty;
- }
- /// <summary>
- /// Helper function that returns cell url.
- /// </summary>
- /// <remarks>
- /// Url can be set in the cell or in the legend item. Cell
- /// tooltip always has a higher priority.
- /// </remarks>
- /// <returns>Returns cell text.</returns>
- private string GetCellPostBackValue()
- {
- return string.Empty;
- }
- /// <summary>
- /// Helper function that returns the exact text presented in the cell.
- /// </summary>
- /// <remarks>
- /// This method replaces the "\n" substring with the new line character
- /// and automatically wrap text if required.
- /// </remarks>
- /// <returns>Returns cell text.</returns>
- private string GetCellText()
- {
- // Replace all "\n" strings with the new line character
- string resultString = this.Text.Replace("\\n", "\n");
- // Replace the KeywordName.LegendText keyword with legend item Name property
- if (this.LegendItem != null)
- {
- resultString = resultString.Replace(KeywordName.LegendText, this.LegendItem.Name);
- }
- else
- {
- resultString = resultString.Replace(KeywordName.LegendText, "");
- }
- // Check if text width exceeds recomended character length
- if (this.Legend != null)
- {
- int recomendedTextLength = this.Legend.TextWrapThreshold;
- if (recomendedTextLength > 0 &&
- resultString.Length > recomendedTextLength)
- {
- // Iterate through all text characters
- int lineLength = 0;
- for (int charIndex = 0; charIndex < resultString.Length; charIndex++)
- {
- // Reset line length when new line character is found
- if (resultString[charIndex] == '\n')
- {
- lineLength = 0;
- continue;
- }
- // Increase line length counter
- ++lineLength;
- // Check if current character is a white space and
- // current line length exceeds the recomended values.
- if (char.IsWhiteSpace(resultString, charIndex) &&
- lineLength >= recomendedTextLength)
- {
- // Insert new line character in the string
- lineLength = 0;
- resultString = resultString.Substring(0, charIndex) + "\n" +
- resultString.Substring(charIndex + 1).TrimStart();
- }
- }
- }
- }
- return resultString;
- }
- /// <summary>
- /// Helper function that returns cell text color.
- /// </summary>
- /// <returns>Cell text color.</returns>
- private Color GetCellForeColor()
- {
- // Check if cell text color defined in the cell
- if (!this.ForeColor.IsEmpty)
- {
- return this.ForeColor;
- }
- // Check if color from the Column or legend should be used
- if (this.Legend != null)
- {
- // Try getting font from the associated column
- if (this.LegendItem != null)
- {
- // Get index of this cell
- int cellIndex = this.LegendItem.Cells.IndexOf(this);
- if (cellIndex >= 0)
- {
- // Check if associated column exsists
- if (cellIndex < this.Legend.CellColumns.Count &&
- !this.Legend.CellColumns[cellIndex].ForeColor.IsEmpty)
- {
- return this.Legend.CellColumns[cellIndex].ForeColor;
- }
- }
- }
- // Use legend text color
- return this.Legend.ForeColor;
- }
- return Color.Black;
- }
- #endregion // Methods
- #region Cell Painting Methods
- /// <summary>
- /// Paints content of the legend cell.
- /// </summary>
- /// <param name="chartGraph">Chart graphics to draw content on.</param>
- /// <param name="fontSizeReducedBy">Number that determines how much the cell font should be reduced by.</param>
- /// <param name="legendAutoFont">Auto-fit font used in the legend.</param>
- /// <param name="singleWCharacterSize">Size of the 'W' character in auto-fit font.</param>
- internal void Paint(
- ChartGraphics chartGraph,
- int fontSizeReducedBy,
- Font legendAutoFont,
- Size singleWCharacterSize)
- {
- // Check cell size before painting
- if (this.cellPosition.Width <= 0 || this.cellPosition.Height <= 0)
- {
- return;
- }
- // Chart elements painting mode
- if (this.Common.ProcessModePaint)
- {
- // Check if cell background should be painted
- Color cellBackColor = this.GetCellBackColor();
- RectangleF rectRelative = chartGraph.GetRelativeRectangle(this.cellPositionWithMargins);
- if (!cellBackColor.IsEmpty)
- {
- chartGraph.FillRectangleRel(
- rectRelative,
- cellBackColor,
- ChartHatchStyle.None,
- string.Empty,
- ChartImageWrapMode.Tile,
- Color.Empty,
- ChartImageAlignmentStyle.Center,
- GradientStyle.None,
- Color.Empty,
- Color.Empty,
- 0,
- ChartDashStyle.NotSet,
- Color.Empty,
- 0,
- PenAlignment.Inset);
- }
- // Fire an event for custom cell back drawing
- this.Chart.CallOnPrePaint(new ChartPaintEventArgs(this, chartGraph, this.Common, new ElementPosition(rectRelative.X, rectRelative.Y, rectRelative.Width, rectRelative.Height)));
- // Check legend cell type
- switch (this.CellType)
- {
- case (LegendCellType.Text):
- this.PaintCellText(chartGraph, fontSizeReducedBy, legendAutoFont);
- break;
- case (LegendCellType.Image):
- this.PaintCellImage(chartGraph, singleWCharacterSize);
- break;
- case (LegendCellType.SeriesSymbol):
- this.PaintCellSeriesSymbol(chartGraph, singleWCharacterSize);
- break;
- default:
- throw (new InvalidOperationException(SR.ExceptionLegendCellTypeUnknown(this.CellType.ToString())));
- }
- // Fire an event for custom cell drawing
- this.Chart.CallOnPostPaint(new ChartPaintEventArgs(this, chartGraph, this.Common, new ElementPosition(rectRelative.X, rectRelative.Y, rectRelative.Width, rectRelative.Height)));
- }
- #if DEBUG
- // Draw bounding rectangle for debug purpose
- // RectangleF absRectangle = this.cellPosition;
- // chartGraph.DrawRectangle(Pens.Red, absRectangle.X, absRectangle.Y, absRectangle.Width, absRectangle.Height);
- #endif // DEBUG
- // Legend cell selection mode
- if (this.Common.ProcessModeRegions)
- {
- // Add hot region.
- // Note that legend cell is passed as sub-object of legend item
- this.Common.HotRegionsList.AddHotRegion(
- chartGraph.GetRelativeRectangle(this.cellPositionWithMargins),
- this.GetCellToolTip(),
- this.GetCellUrl(),
- this.GetCellMapAreaAttributes(),
- this.GetCellPostBackValue(),
- this.LegendItem,
- this,
- ChartElementType.LegendItem,
- this.LegendItem.SeriesName);
- }
- }
- /// <summary>
- /// Draw legend cell text.
- /// </summary>
- /// <param name="chartGraph">Chart graphics to draw the text on.</param>
- /// <param name="fontSizeReducedBy">Number that determines how much the cell font should be reduced by.</param>
- /// <param name="legendAutoFont">Auto-fit font used in the legend.</param>
- private void PaintCellText(
- ChartGraphics chartGraph,
- int fontSizeReducedBy,
- Font legendAutoFont)
- {
- // Get cell font
- bool disposeFont = false;
- Font cellFont = this.GetCellFont(legendAutoFont, fontSizeReducedBy, out disposeFont);
- // Start Svg Selection mode
- chartGraph.StartHotRegion(this.GetCellUrl(), this.GetCellToolTip());
- // Create font brush
- using (SolidBrush fontBrush = new SolidBrush(this.GetCellForeColor()))
- {
- // Create cell text format
- using (StringFormat format = new StringFormat(StringFormat.GenericDefault))
- {
- format.FormatFlags = StringFormatFlags.LineLimit;
- format.Trimming = StringTrimming.EllipsisCharacter;
- format.Alignment = StringAlignment.Center;
- if (this.Alignment == ContentAlignment.BottomLeft ||
- this.Alignment == ContentAlignment.MiddleLeft ||
- this.Alignment == ContentAlignment.TopLeft)
- {
- format.Alignment = StringAlignment.Near;
- }
- else if (this.Alignment == ContentAlignment.BottomRight ||
- this.Alignment == ContentAlignment.MiddleRight ||
- this.Alignment == ContentAlignment.TopRight)
- {
- format.Alignment = StringAlignment.Far;
- }
- format.LineAlignment = StringAlignment.Center;
- if (this.Alignment == ContentAlignment.BottomCenter ||
- this.Alignment == ContentAlignment.BottomLeft ||
- this.Alignment == ContentAlignment.BottomRight)
- {
- format.LineAlignment = StringAlignment.Far;
- }
- else if (this.Alignment == ContentAlignment.TopCenter ||
- this.Alignment == ContentAlignment.TopLeft ||
- this.Alignment == ContentAlignment.TopRight)
- {
- format.LineAlignment = StringAlignment.Near;
- }
- // Measure string height out of one character
- SizeF charSize = chartGraph.MeasureStringAbs(this.GetCellText(), cellFont, new SizeF(10000f, 10000f), format);
- // If height of one characte is more than rectangle heigjt - remove LineLimit flag
- if (charSize.Height > this.cellPosition.Height && (format.FormatFlags & StringFormatFlags.LineLimit) != 0)
- {
- format.FormatFlags ^= StringFormatFlags.LineLimit;
- }
- else if (charSize.Height < this.cellPosition.Height && (format.FormatFlags & StringFormatFlags.LineLimit) == 0)
- {
- format.FormatFlags |= StringFormatFlags.LineLimit;
- }
- // Draw text
- chartGraph.DrawStringRel(
- this.GetCellText(),
- cellFont,
- fontBrush,
- chartGraph.GetRelativeRectangle(this.cellPosition),
- format);
- }
- }
- // End Svg Selection mode
- chartGraph.EndHotRegion();
- // Dispose created cell font object
- if (disposeFont)
- {
- cellFont.Dispose();
- cellFont = null;
- }
- }
- /// <summary>
- /// Paints cell image.
- /// </summary>
- /// <param name="chartGraph">Graphics used to draw cell image.</param>
- /// <param name="singleWCharacterSize">Size of the 'W' character in auto-fit font.</param>
- private void PaintCellImage(
- ChartGraphics chartGraph,
- Size singleWCharacterSize)
- {
- if (this.Image.Length > 0)
- {
- // Get image size in relative coordinates
- Rectangle imagePosition = Rectangle.Empty;
- System.Drawing.Image image = this.Common.ImageLoader.LoadImage(this.Image);
- SizeF imageSize = new SizeF();
- ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref imageSize);
- imagePosition.Width = (int)imageSize.Width;
- imagePosition.Height = (int)imageSize.Height;
- // Calculate cell position
- Rectangle imageCellPosition = this.cellPosition;
- imageCellPosition.Width = imagePosition.Width;
- imageCellPosition.Height = imagePosition.Height;
- if (!this.ImageSize.IsEmpty)
- {
- // Adjust cell size using image symbol size specified
- if (this.ImageSize.Width > 0)
- {
- int newWidth = (int)(this.ImageSize.Width * singleWCharacterSize.Width / 100f);
- if (newWidth > this.cellPosition.Width)
- {
- newWidth = this.cellPosition.Width;
- }
- imageCellPosition.Width = newWidth;
- }
- if (this.ImageSize.Height > 0)
- {
- int newHeight = (int)(this.ImageSize.Height * singleWCharacterSize.Height / 100f);
- if (newHeight > this.cellPosition.Height)
- {
- newHeight = this.cellPosition.Height;
- }
- imageCellPosition.Height = newHeight;
- }
- }
- // Make sure image size fits into the cell drawing rectangle
- float scaleValue = 1f;
- if (imagePosition.Height > imageCellPosition.Height)
- {
- scaleValue = (float)imagePosition.Height / (float)imageCellPosition.Height;
- }
- if (imagePosition.Width > imageCellPosition.Width)
- {
- scaleValue = Math.Max(scaleValue, (float)imagePosition.Width / (float)imageCellPosition.Width);
- }
- // Scale image size
- imagePosition.Height = (int)(imagePosition.Height / scaleValue);
- imagePosition.Width = (int)(imagePosition.Width / scaleValue);
- // Get image location
- imagePosition.X = (int)((this.cellPosition.X + this.cellPosition.Width / 2f) - imagePosition.Width / 2f);
- imagePosition.Y = (int)((this.cellPosition.Y + this.cellPosition.Height / 2f) - imagePosition.Height / 2f);
- // Adjust image location based on the cell content alignment
- if (this.Alignment == ContentAlignment.BottomLeft ||
- this.Alignment == ContentAlignment.MiddleLeft ||
- this.Alignment == ContentAlignment.TopLeft)
- {
- imagePosition.X = this.cellPosition.X;
- }
- else if (this.Alignment == ContentAlignment.BottomRight ||
- this.Alignment == ContentAlignment.MiddleRight ||
- this.Alignment == ContentAlignment.TopRight)
- {
- imagePosition.X = this.cellPosition.Right - imagePosition.Width;
- }
- if (this.Alignment == ContentAlignment.BottomCenter ||
- this.Alignment == ContentAlignment.BottomLeft ||
- this.Alignment == ContentAlignment.BottomRight)
- {
- imagePosition.Y = this.cellPosition.Bottom - imagePosition.Height;
- }
- else if (this.Alignment == ContentAlignment.TopCenter ||
- this.Alignment == ContentAlignment.TopLeft ||
- this.Alignment == ContentAlignment.TopRight)
- {
- imagePosition.Y = this.cellPosition.Y;
- }
- // Set image transparent color
- System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
- if (this.ImageTransparentColor != Color.Empty)
- {
- imageAttributes.SetColorKey(this.ImageTransparentColor, this.ImageTransparentColor, System.Drawing.Imaging.ColorAdjustType.Default);
- }
- // Increase quality of image scaling
- SmoothingMode oldSmoothingMode = chartGraph.SmoothingMode;
- CompositingQuality oldCompositingQuality = chartGraph.Graphics.CompositingQuality;
- InterpolationMode oldInterpolationMode = chartGraph.Graphics.InterpolationMode;
- chartGraph.SmoothingMode = SmoothingMode.AntiAlias;
- chartGraph.Graphics.CompositingQuality = CompositingQuality.HighQuality;
- chartGraph.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
- // Draw image
- chartGraph.DrawImage(
- image,
- imagePosition,
- 0,
- 0,
- image.Width,
- image.Height,
- GraphicsUnit.Pixel,
- imageAttributes);
- // Restore graphics settings
- chartGraph.SmoothingMode = oldSmoothingMode;
- chartGraph.Graphics.CompositingQuality = oldCompositingQuality;
- chartGraph.Graphics.InterpolationMode = oldInterpolationMode;
- }
- }
- /// <summary>
- /// Paint a series symbol in the cell.
- /// </summary>
- /// <param name="chartGraph">Chart graphics</param>
- /// <param name="singleWCharacterSize">Size of the 'W' character in auto-fit font.</param>
- private void PaintCellSeriesSymbol(
- ChartGraphics chartGraph,
- SizeF singleWCharacterSize)
- {
- //Cache legend item
- LegendItem legendItem = this.LegendItem;
- // Calculate cell position
- Rectangle seriesMarkerPosition = this.cellPosition;
- // Adjust cell size using image symbol size specified
- if (this.SeriesSymbolSize.Width >= 0)
- {
- int newWidth = (int)(this.SeriesSymbolSize.Width * singleWCharacterSize.Width / 100f);
- if (newWidth > this.cellPosition.Width)
- {
- newWidth = this.cellPosition.Width;
- }
- seriesMarkerPosition.Width = newWidth;
- }
- if (this.SeriesSymbolSize.Height >= 0)
- {
- int newHeight = (int)(this.SeriesSymbolSize.Height * singleWCharacterSize.Height / 100f);
- if (newHeight > this.cellPosition.Height)
- {
- newHeight = this.cellPosition.Height;
- }
- seriesMarkerPosition.Height = newHeight;
- }
- // Check for empty size
- if (seriesMarkerPosition.Height <= 0 || seriesMarkerPosition.Width <= 0)
- {
- return;
- }
- // Get symbol location
- seriesMarkerPosition.X = (int)((this.cellPosition.X + this.cellPosition.Width / 2f) - seriesMarkerPosition.Width / 2f);
- seriesMarkerPosition.Y = (int)((this.cellPosition.Y + this.cellPosition.Height / 2f) - seriesMarkerPosition.Height / 2f);
- // Adjust image location based on the cell content alignment
- if (this.Alignment == ContentAlignment.BottomLeft ||
- this.Alignment == ContentAlignment.MiddleLeft ||
- this.Alignment == ContentAlignment.TopLeft)
- {
- seriesMarkerPosition.X = this.cellPosition.X;
- }
- else if (this.Alignment == ContentAlignment.BottomRight ||
- this.Alignment == ContentAlignment.MiddleRight ||
- this.Alignment == ContentAlignment.TopRight)
- {
- seriesMarkerPosition.X = this.cellPosition.Right - seriesMarkerPosition.Width;
- }
- if (this.Alignment == ContentAlignment.BottomCenter ||
- this.Alignment == ContentAlignment.BottomLeft ||
- this.Alignment == ContentAlignment.BottomRight)
- {
- seriesMarkerPosition.Y = this.cellPosition.Bottom - seriesMarkerPosition.Height;
- }
- else if (this.Alignment == ContentAlignment.TopCenter ||
- this.Alignment == ContentAlignment.TopLeft ||
- this.Alignment == ContentAlignment.TopRight)
- {
- seriesMarkerPosition.Y = this.cellPosition.Y;
- }
- // Start Svg Selection mode
- chartGraph.StartHotRegion(this.GetCellUrl(), this.GetCellToolTip());
- // Draw legend item image
- if (legendItem.Image.Length > 0)
- {
- // Get image size
- Rectangle imageScale = Rectangle.Empty;
- System.Drawing.Image image = this.Common.ImageLoader.LoadImage(legendItem.Image);
- if (image != null)
- {
- SizeF imageSize = new SizeF();
- ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref imageSize);
- imageScale.Width = (int)imageSize.Width;
- imageScale.Height = (int)imageSize.Height;
- // Make sure image size fits into the drawing rectangle
- float scaleValue = 1f;
- if (imageScale.Height > seriesMarkerPosition.Height)
- {
- scaleValue = (float)imageScale.Height / (float)seriesMarkerPosition.Height;
- }
- if (imageScale.Width > seriesMarkerPosition.Width)
- {
- scaleValue = Math.Max(scaleValue, (float)imageScale.Width / (float)seriesMarkerPosition.Width);
- }
- // Scale image size
- imageScale.Height = (int)(imageScale.Height / scaleValue);
- imageScale.Width = (int)(imageScale.Width / scaleValue);
- imageScale.X = (int)((seriesMarkerPosition.X + seriesMarkerPosition.Width / 2f) - imageScale.Width / 2f);
- imageScale.Y = (int)((seriesMarkerPosition.Y + seriesMarkerPosition.Height / 2f) - imageScale.Height / 2f);
- // Set image transparent color
- System.Drawing.Imaging.ImageAttributes imageAttributes = new System.Drawing.Imaging.ImageAttributes();
- if (legendItem.BackImageTransparentColor != Color.Empty)
- {
- imageAttributes.SetColorKey(legendItem.BackImageTransparentColor, legendItem.BackImageTransparentColor, System.Drawing.Imaging.ColorAdjustType.Default);
- }
- // Draw image
- chartGraph.DrawImage(
- image,
- imageScale,
- 0,
- 0,
- image.Width,
- image.Height,
- GraphicsUnit.Pixel,
- imageAttributes);
- }
- }
- else
- {
- int maxShadowOffset = (int)Math.Round((3 * chartGraph.Graphics.DpiX) / 96);
- int maxBorderWidth = (int)Math.Round((3 * chartGraph.Graphics.DpiX) / 96);
- if (legendItem.ImageStyle == LegendImageStyle.Rectangle)
- {
- int maxBorderWidthRect = (int)Math.Round((2 * chartGraph.Graphics.DpiX) / 96);
- // Draw series rectangle
- chartGraph.FillRectangleRel(
- chartGraph.GetRelativeRectangle(seriesMarkerPosition),
- legendItem.Color,
- legendItem.BackHatchStyle,
- legendItem.Image,
- legendItem.backImageWrapMode,
- legendItem.BackImageTransparentColor,
- legendItem.backImageAlign,
- legendItem.backGradientStyle,
- legendItem.backSecondaryColor,
- legendItem.borderColor,
- (legendItem.BorderWidth > maxBorderWidthRect) ? maxBorderWidthRect : legendItem.BorderWidth,
- legendItem.BorderDashStyle,
- legendItem.ShadowColor,
- (legendItem.ShadowOffset > maxShadowOffset) ? maxShadowOffset : legendItem.ShadowOffset,
- PenAlignment.Inset);
- }
- if (legendItem.ImageStyle == LegendImageStyle.Line)
- {
- // Prepare line coordinates
- Point point1 = new Point();
- point1.X = seriesMarkerPosition.X;
- point1.Y = (int)(seriesMarkerPosition.Y + seriesMarkerPosition.Height / 2F);
- Point point2 = new Point();
- point2.Y = point1.Y;
- point2.X = seriesMarkerPosition.Right;
- // Disable antialiasing
- SmoothingMode oldMode = chartGraph.SmoothingMode;
- chartGraph.SmoothingMode = SmoothingMode.None;
- // Draw line
- chartGraph.DrawLineRel(
- legendItem.Color,
- (legendItem.borderWidth > maxBorderWidth) ? maxBorderWidth : legendItem.borderWidth,
- legendItem.borderDashStyle,
- chartGraph.GetRelativePoint(point1),
- chartGraph.GetRelativePoint(point2),
- legendItem.shadowColor,
- (legendItem.shadowOffset > maxShadowOffset) ? maxShadowOffset : legendItem.shadowOffset);
- // Restore antialiasing mode
- chartGraph.SmoothingMode = oldMode;
- }
- // Draw symbol (for line also)
- if (legendItem.ImageStyle == LegendImageStyle.Marker ||
- legendItem.ImageStyle == LegendImageStyle.Line)
- {
- MarkerStyle markerStyle = legendItem.markerStyle;
- if (legendItem.style == LegendImageStyle.Marker)
- {
- markerStyle = (legendItem.markerStyle == MarkerStyle.None) ?
- MarkerStyle.Circle : legendItem.markerStyle;
- }
- if (markerStyle != MarkerStyle.None ||
- legendItem.markerImage.Length > 0)
- {
- // Calculate marker size
- int markerSize = (int)Math.Min(seriesMarkerPosition.Width, seriesMarkerPosition.Height);
- markerSize = (int)Math.Min(legendItem.markerSize, (legendItem.style == LegendImageStyle.Line) ? 2f * (markerSize / 3f) : markerSize);
- // Reduce marker size to fit border
- int markerBorderWidth = (legendItem.MarkerBorderWidth > maxBorderWidth) ? maxBorderWidth : legendItem.MarkerBorderWidth;
- if (markerBorderWidth > 0)
- {
- markerSize -= markerBorderWidth;
- if (markerSize < 1)
- {
- markerSize = 1;
- }
- }
- // Draw marker
- Point point = new Point();
- point.X = (int)(seriesMarkerPosition.X + seriesMarkerPosition.Width / 2f);
- point.Y = (int)(seriesMarkerPosition.Y + seriesMarkerPosition.Height / 2f);
- // Calculate image scale
- Rectangle imageScale = Rectangle.Empty;
- if (legendItem.markerImage.Length > 0)
- {
- // Get image size
- System.Drawing.Image image = this.Common.ImageLoader.LoadImage(legendItem.markerImage);
- SizeF imageSize = new SizeF();
- ImageLoader.GetAdjustedImageSize(image, chartGraph.Graphics, ref imageSize);
- imageScale.Width = (int)imageSize.Width;
- imageScale.Height = (int)imageSize.Height;
- // Make sure image size fits into the drawing rectangle
- float scaleValue = 1f;
- if (imageScale.Height > seriesMarkerPosition.Height)
- {
- scaleValue = (float)imageScale.Height / (float)seriesMarkerPosition.Height;
- }
- if (imageScale.Width > seriesMarkerPosition.Width)
- {
- scaleValue = Math.Max(scaleValue, (float)imageScale.Width / (float)seriesMarkerPosition.Width);
- }
- // Scale image size
- imageScale.Height = (int)(imageScale.Height / scaleValue);
- imageScale.Width = (int)(imageScale.Width / scaleValue);
- }
- // Adjust marker position so that it always drawn on pixel
- // boundary.
- PointF pointF = new PointF(point.X, point.Y);
- if ((markerSize % 2) != 0.0)
- {
- pointF.X -= 0.5f;
- pointF.Y -= 0.5f;
- }
- // Draw marker if it's not image
- chartGraph.DrawMarkerRel(
- chartGraph.GetRelativePoint(pointF),
- markerStyle,
- markerSize,
- (legendItem.markerColor == Color.Empty) ? legendItem.Color : legendItem.markerColor,
- (legendItem.markerBorderColor == Color.Empty) ? legendItem.borderColor : legendItem.markerBorderColor,
- markerBorderWidth,
- legendItem.markerImage,
- legendItem.markerImageTransparentColor,
- (legendItem.shadowOffset > maxShadowOffset) ? maxShadowOffset : legendItem.shadowOffset,
- legendItem.shadowColor,
- imageScale);
- }
- }
- }
- // End Svg Selection mode
- chartGraph.EndHotRegion();
- }
- #endregion // Cell Painting Methods
- #region IDisposable Members
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- if (_fontCache != null)
- {
- _fontCache.Dispose();
- _fontCache = null;
- }
- }
- base.Dispose(disposing);
- }
- #endregion
- }
- /// <summary>
- /// The Margins class represents the margins for various chart elements.
- /// </summary>
- [
- SRDescription("DescriptionAttributeMargins_Margins"),
- TypeConverter(typeof(MarginExpandableObjectConverter)),
- ]
- public class Margins
- {
- #region Fields
- // Top margin
- private int _top = 0;
- // Bottom margin
- private int _bottom = 0;
- // Left margin
- private int _left = 0;
- // Right margin
- private int _right = 0;
- // Reference to common chart elements which allows to invalidate
- // chart when one of the properties is changed.
- internal CommonElements Common = null;
- internal ChartElement Element;
- #endregion // Fields
- #region Constructor
- /// <summary>
- /// Margins constructor.
- /// </summary>
- public Margins()
- {
- Element = null;
- }
- /// <summary>
- /// Margins constructor.
- /// </summary>
- /// <param name="top">Top margin.</param>
- /// <param name="bottom">Bottom margin.</param>
- /// <param name="left">Left margin.</param>
- /// <param name="right">Right margin.</param>
- public Margins(int top, int bottom, int left, int right)
- {
- this._top = top;
- this._bottom = bottom;
- this._left = left;
- this._right = right;
- Element = null;
- }
- #endregion // Constructor
- #region Properties
- /// <summary>
- /// Gets or sets the top margin.
- /// </summary>
- [
- SRCategory("CategoryAttributeMisc"),
- DefaultValue(0),
- SRDescription("DescriptionAttributeMargins_Top"),
- RefreshPropertiesAttribute(RefreshProperties.All),
- NotifyParentPropertyAttribute(true),
- ]
- public int Top
- {
- get
- {
- return this._top;
- }
- set
- {
- if (value < 0)
- {
- throw (new ArgumentException(SR.ExceptionMarginTopIsNegative, "value"));
- }
- this._top = value;
- this.Invalidate();
- if (Element != null)
- Element.CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the bottom margin.
- /// </summary>
- [
- SRCategory("CategoryAttributeMisc"),
- DefaultValue(0),
- SRDescription("DescriptionAttributeMargins_Bottom"),
- RefreshPropertiesAttribute(RefreshProperties.All),
- NotifyParentPropertyAttribute(true),
- ]
- public int Bottom
- {
- get
- {
- return this._bottom;
- }
- set
- {
- if (value < 0)
- {
- throw (new ArgumentException(SR.ExceptionMarginBottomIsNegative, "value"));
- }
- this._bottom = value;
- this.Invalidate();
- if (Element != null)
- Element.CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the left margin.
- /// </summary>
- [
- SRCategory("CategoryAttributeMisc"),
- DefaultValue(0),
- RefreshPropertiesAttribute(RefreshProperties.All),
- SRDescription("DescriptionAttributeMargins_Left"),
- NotifyParentPropertyAttribute(true),
- ]
- public int Left
- {
- get
- {
- return this._left;
- }
- set
- {
- if (value < 0)
- {
- throw (new ArgumentException(SR.ExceptionMarginLeftIsNegative, "value"));
- }
- this._left = value;
- this.Invalidate();
- if (Element != null)
- Element.CallOnModifing();
- }
- }
- /// <summary>
- /// Gets or sets the right margin.
- /// </summary>
- [
- SRCategory("CategoryAttributeMisc"),
- DefaultValue(0),
- SRDescription("DescriptionAttributeMargins_Right"),
- RefreshPropertiesAttribute(RefreshProperties.All),
- NotifyParentPropertyAttribute(true),
- ]
- public int Right
- {
- get
- {
- return this._right;
- }
- set
- {
- if (value < 0)
- {
- throw (new ArgumentException(SR.ExceptionMarginRightIsNegative, "value"));
- }
- this._right = value;
- this.Invalidate();
- if (Element != null)
- Element.CallOnModifing();
- }
- }
- #endregion // Properties
- #region Methods
- /// <summary>
- /// Convert margins object to string.
- /// </summary>
- /// <returns>A string that represents the margins object.</returns>
- [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
- public override string ToString()
- {
- return string.Format(
- CultureInfo.InvariantCulture,
- "{0:D}, {1:D}, {2:D}, {3:D}",
- this.Top,
- this.Bottom,
- this.Left,
- this.Right);
- }
- /// <summary>
- /// Determines whether the specified Object is equal to the current Object.
- /// </summary>
- /// <param name="obj">
- /// The Object to compare with the current Object.
- /// </param>
- /// <returns>
- /// True if the specified Object is equal to the current Object; otherwise, false.
- /// </returns>
- [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
- public override bool Equals(object obj)
- {
- Margins margins = obj as Margins;
- if (margins != null)
- {
- if (this.Top == margins.Top &&
- this.Bottom == margins.Bottom &&
- this.Left == margins.Left &&
- this.Right == margins.Right)
- {
- return true;
- }
- }
- return false;
- }
- /// <summary>
- /// Gets object hash code.
- /// </summary>
- /// <returns>Margins object hash value.</returns>
- [SuppressMessage("Microsoft.Security", "CA2123:OverrideLinkDemandsShouldBeIdenticalToBase")]
- public override int GetHashCode()
- {
- return this.Top.GetHashCode() + this.Bottom.GetHashCode() + this.Left.GetHashCode() + this.Right.GetHashCode();
- }
- /// <summary>
- /// Checks if there is no margin.
- /// </summary>
- /// <returns>
- /// <b>True</b> if all margins values are zeros.
- /// </returns>
- public bool IsEmpty()
- {
- return (this.Top == 0 && this.Bottom == 0 && this.Left == 0 && this.Right == 0);
- }
- /// <summary>
- /// Converts Margins class to RectangleF class.
- /// </summary>
- /// <returns>A RectangleF class that contains the values of the margins.</returns>
- public RectangleF ToRectangleF()
- {
- return new RectangleF(this.Left, this.Top, this.Right, this.Bottom);
- }
- /// <summary>
- /// Invalidates chart.
- /// </summary>
- private void Invalidate()
- {
- if (this.Common != null && this.Common.Chart != null)
- {
- this.Common.Chart.Invalidate();
- }
- }
- #endregion // Methods
- }
- /// <summary>
- /// <b>LegendCellCollection</b> is a strongly typed collection of LegendCell objects.
- /// </summary>
- [
- SRDescription("DescriptionAttributeLegendCellCollection_LegendCellCollection"),
- ]
- public class LegendCellCollection : ChartNamedElementCollection<LegendCell>
- {
- #region Constructors
- /// <summary>
- /// LegendCellCollection constructor.
- /// </summary>
- /// <remarks>
- /// This constructor is for internal use and should not be part of documentation.
- /// </remarks>
- /// <param name="parent">Legend item this collection belongs to.</param>
- internal LegendCellCollection(LegendItem parent) : base(parent)
- {
- }
- #endregion
- #region Methods
- /// <summary>
- /// Adds a cell to the end of the collection.
- /// </summary>
- /// <param name="cellType">
- /// A <see cref="LegendCellType"/> value representing the cell type.
- /// </param>
- /// <param name="text">
- /// A <b>string</b> value representing cell text or image name depending
- /// on the <b>cellType</b> parameter.
- /// </param>
- /// <param name="alignment">
- /// A <see cref="ContentAlignment"/> value representing cell content alignment.
- /// </param>
- /// <returns>
- /// Index of the newly added object.
- /// </returns>
- public int Add(LegendCellType cellType, string text, ContentAlignment alignment)
- {
- Add(new LegendCell(cellType, text, alignment));
- return Count - 1;
- }
- /// <summary>
- /// Inserts a cell into the collection.
- /// </summary>
- /// <param name="index">
- /// Index to insert the object at.
- /// </param>
- /// <param name="cellType">
- /// A <see cref="LegendCellType"/> value representing the cell type.
- /// </param>
- /// <param name="text">
- /// A <b>string</b> value representing cell text or image name depending
- /// on the <b>cellType</b> parameter.
- /// </param>
- /// <param name="alignment">
- /// A <see cref="ContentAlignment"/> value representing cell content alignment.
- /// </param>
- public void Insert(int index, LegendCellType cellType, string text, ContentAlignment alignment)
- {
- this.Insert(index, new LegendCell(cellType, text, alignment));
- }
- #endregion
- }
- /// <summary>
- /// The <b>LegendCellColumnCollection</b> class is a strongly typed collection
- /// of LegendCellColumn objects.
- /// </summary>
- [
- SRDescription("DescriptionAttributeLegendCellColumnCollection_LegendCellColumnCollection"),
- ]
- public class LegendCellColumnCollection : ChartNamedElementCollection<LegendCellColumn>
- {
- #region Construction and Initialization
- /// <summary>
- /// LegendCellColumnCollection constructor.
- /// </summary>
- /// <remarks>
- /// This constructor is for internal use and should not be part of documentation.
- /// </remarks>
- /// <param name="legend">
- /// Chart legend which this collection belongs to.
- /// </param>
- internal LegendCellColumnCollection(Legend legend)
- : base(legend)
- {
- }
- #endregion // Construction and Initialization
- #region IDisposable Members
- /// <summary>
- /// Releases unmanaged and - optionally - managed resources
- /// </summary>
- /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected override void Dispose(bool disposing)
- {
- if (disposing)
- {
- //Free managed resources
- foreach (LegendCellColumn item in this)
- {
- item.Dispose();
- }
- this.ClearItems();
- }
- base.Dispose(disposing);
- }
- #endregion
- }
- }
|