#if WPF
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Input;
using System.ComponentModel;
using System.Windows.Shapes;
#else
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Input;
using System.Collections.Generic;
using System.Windows.Shapes;
#endif
using System.Windows.Data;
using Visifire.Commons;
namespace Visifire.Charts
{
///
/// Legend of chart
///
#if SL
[System.Windows.Browser.ScriptableType]
#endif
public class Legend : ObservableObject
{
#region Public Methods
///
/// Initializes a new instance of the Visifire.Charts.Legend class
///
public Legend()
{
// Apply default style from generic
#if WPF
if (!_defaultStyleKeyApplied)
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(Legend), new FrameworkPropertyMetadata(typeof(Legend)));
_defaultStyleKeyApplied = true;
}
#else
DefaultStyleKey = typeof(Legend);
#endif
Entries = new List>();
}
public override void Bind()
{
#if SL
Binding b = new Binding("FontSize");
b.Source = this;
this.SetBinding(InternalFontSizeProperty, b);
b = new Binding("FontFamily");
b.Source = this;
this.SetBinding(InternalFontFamilyProperty, b);
b = new Binding("FontStyle");
b.Source = this;
this.SetBinding(InternalFontStyleProperty, b);
b = new Binding("FontWeight");
b.Source = this;
this.SetBinding(InternalFontWeightProperty, b);
b = new Binding("BorderThickness");
b.Source = this;
this.SetBinding(InternalBorderThicknessProperty, b);
b = new Binding("Background");
b.Source = this;
this.SetBinding(InternalBackgroundProperty, b);
b = new Binding("HorizontalAlignment");
b.Source = this;
this.SetBinding(InternalHorizontalAlignmentProperty, b);
b = new Binding("VerticalAlignment");
b.Source = this;
this.SetBinding(InternalVerticalAlignmentProperty, b);
b = new Binding("Padding");
b.Source = this;
this.SetBinding(InternalPaddingProperty, b);
b = new Binding("Opacity");
b.Source = this;
this.SetBinding(InternalOpacityProperty, b);
b = new Binding("MaxWidth");
b.Source = this;
this.SetBinding(InternalMaxWidthProperty, b);
b = new Binding("MaxHeight");
b.Source = this;
this.SetBinding(InternalMaxHeightProperty, b);
#endif
}
#endregion
#region Public Properties
///
/// Identifies the Visifire.Charts.Legend.HrefTarget dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.HrefTarget dependency property.
///
public static readonly DependencyProperty HrefTargetProperty = DependencyProperty.Register
("HrefTarget",
typeof(HrefTargets),
typeof(Legend),
new PropertyMetadata(OnHrefTargetChanged));
///
/// Identifies the Visifire.Charts.Legend.Href dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.Href dependency property.
///
public static readonly DependencyProperty HrefProperty = DependencyProperty.Register
("Href",
typeof(String),
typeof(Legend),
new PropertyMetadata(OnHrefChanged));
///
/// Identifies the Visifire.Charts.Legend.Reversed dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.Reversed dependency property.
///
public static readonly DependencyProperty ReversedProperty = DependencyProperty.Register
("Reversed",
typeof(Boolean),
typeof(Legend),
new PropertyMetadata(OnReversedChanged));
///
/// Identifies the Visifire.Charts.Legend.LabelMargin dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.LabelMargin dependency property.
///
public static readonly DependencyProperty LabelMarginProperty = DependencyProperty.Register
("LabelMargin",
typeof(Double),
typeof(Legend),
new PropertyMetadata(OnLabelMarginPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.BorderColor dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.BorderColor dependency property.
///
public static readonly DependencyProperty BorderColorProperty = DependencyProperty.Register
("BorderColor",
typeof(Brush),
typeof(Legend),
new PropertyMetadata(OnBorderColorPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.LegendFontColor dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleFontColor dependency property.
///
public static readonly DependencyProperty TitleFontColorProperty = DependencyProperty.Register
("TitleFontColor",
typeof(Brush),
typeof(Legend),
new PropertyMetadata(OnTitleFontColorPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.DockInsidePlotArea dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.DockInsidePlotArea dependency property.
///
public static readonly DependencyProperty DockInsidePlotAreaProperty = DependencyProperty.Register
("DockInsidePlotArea",
typeof(Boolean),
typeof(Legend),
new PropertyMetadata(OnDockInsidePlotAreaPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.Enabled dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.Enabled dependency property.
///
public static readonly DependencyProperty EnabledProperty = DependencyProperty.Register
("Enabled",
typeof(Nullable),
typeof(Legend),
new PropertyMetadata(OnEnabledPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.FontColor dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.FontColor dependency property.
///
public static readonly DependencyProperty FontColorProperty = DependencyProperty.Register
("FontColor",
typeof(Brush),
typeof(Legend),
new PropertyMetadata(OnFontColorPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.LightingEnabled dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.LightingEnabled dependency property.
///
public static readonly DependencyProperty LightingEnabledProperty = DependencyProperty.Register
("LightingEnabled",
typeof(Boolean),
typeof(Legend),
new PropertyMetadata(OnLightingEnabledPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.CornerRadius dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.CornerRadius dependency property.
///
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.Register
("CornerRadius",
typeof(CornerRadius),
typeof(Legend),
new PropertyMetadata(new CornerRadius(1), OnCornerRadiusPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.Title dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.Title dependency property.
///
public static readonly DependencyProperty TitleProperty = DependencyProperty.Register
("Title",
typeof(String),
typeof(Legend),
new PropertyMetadata(OnTitlePropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.TitleAlignmentX dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleAlignmentX dependency property.
///
public static readonly DependencyProperty TitleAlignmentXProperty = DependencyProperty.Register
("TitleAlignmentX",
typeof(HorizontalAlignment),
typeof(Legend),
new PropertyMetadata(OnTitleAlignmentXPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.TitleTextAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleTextAlignment dependency property.
///
public static readonly DependencyProperty TitleTextAlignmentProperty = DependencyProperty.Register
("TitleTextAlignment",
typeof(TextAlignment),
typeof(Legend),
new PropertyMetadata(OnTitleTextAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.TitleBackground dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleBackground dependency property.
///
public static readonly DependencyProperty TitleBackgroundProperty = DependencyProperty.Register
("TitleBackground",
typeof(Brush),
typeof(Legend),
new PropertyMetadata(OnTitleBackgroundPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.TitleFontFamily dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleFontFamily dependency property.
///
public static readonly DependencyProperty TitleFontFamilyProperty = DependencyProperty.Register
("TitleFontFamily",
typeof(FontFamily),
typeof(Legend),
new PropertyMetadata(new FontFamily("Arial"), OnTitleFontFamilyPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.TitleFontSize dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleFontSize dependency property.
///
public static readonly DependencyProperty TitleFontSizeProperty = DependencyProperty.Register
("TitleFontSize",
typeof(Double),
typeof(Legend),
new PropertyMetadata(OnTitleFontSizePropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.TitleFontStyle dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleFontStyle dependency property.
///
public static readonly DependencyProperty TitleFontStyleProperty = DependencyProperty.Register
("TitleFontStyle",
typeof(FontStyle),
typeof(Legend),
new PropertyMetadata(OnTitleFontStylePropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.TitleFontWeight dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.TitleFontWeight dependency property.
///
public static readonly DependencyProperty TitleFontWeightProperty = DependencyProperty.Register
("TitleFontWeight",
typeof(FontWeight),
typeof(Legend),
new PropertyMetadata(OnTitleFontWeightPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.EntryMargin dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.EntryMargin dependency property.
///
public static readonly DependencyProperty EntryMarginProperty = DependencyProperty.Register
("EntryMargin",
typeof(Double),
typeof(Legend),
new PropertyMetadata(OnEntryMarginPropertyChanged));
#if SL
///
/// Identifies the Visifire.Charts.Title.FontSize dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontSize dependency property.
///
private static readonly DependencyProperty
InternalFontSizeProperty = DependencyProperty.Register
("InternalFontSize",
typeof(Double),
typeof(Legend), new PropertyMetadata(OnFontSizePropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontFamily dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontFamily dependency property.
///
private static readonly DependencyProperty InternalFontFamilyProperty = DependencyProperty.Register
("InternalFontFamily",
typeof(FontFamily),
typeof(Legend),
new PropertyMetadata(OnFontFamilyPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontStyle dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontStyle dependency property.
///
private static readonly DependencyProperty InternalFontStyleProperty = DependencyProperty.Register
("InternalFontStyle",
typeof(FontStyle),
typeof(Legend),
new PropertyMetadata(OnFontStylePropertyChanged));
///
/// Identifies the Visifire.Charts.Title.FontWeight dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.FontWeight dependency property.
///
private static readonly DependencyProperty InternalFontWeightProperty = DependencyProperty.Register
("InternalFontWeight",
typeof(FontWeight),
typeof(Legend),
new PropertyMetadata(OnFontWeightPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.BorderThickness dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.BorderThickness dependency property.
///
private static readonly DependencyProperty InternalBorderThicknessProperty = DependencyProperty.Register
("InternalBorderThickness",
typeof(Thickness),
typeof(Legend),
new PropertyMetadata(OnBorderThicknessPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Background dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Background dependency property.
///
private static readonly DependencyProperty InternalBackgroundProperty = DependencyProperty.Register
("InternalBackground",
typeof(Brush),
typeof(Legend),
new PropertyMetadata(OnBackgroundPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.HorizontalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.HorizontalAlignment dependency property.
///
private static readonly DependencyProperty InternalHorizontalAlignmentProperty = DependencyProperty.Register
("InternalHorizontalAlignment",
typeof(HorizontalAlignment),
typeof(Legend),
new PropertyMetadata(OnHorizontalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.VerticalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.VerticalAlignment dependency property.
///
private static readonly DependencyProperty InternalVerticalAlignmentProperty = DependencyProperty.Register
("InternalVerticalAlignment",
typeof(VerticalAlignment),
typeof(Legend),
new PropertyMetadata(OnVerticalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Padding dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Padding dependency property.
///
private static readonly DependencyProperty InternalPaddingProperty = DependencyProperty.Register
("InternalPadding",
typeof(Thickness),
typeof(Legend),
new PropertyMetadata(OnPaddingPropertyChanged));
///
/// Identifies the Visifire.Charts.Title.Opacity dependency property.
///
///
/// The identifier for the Visifire.Charts.Title.Opacity dependency property.
///
private static readonly DependencyProperty InternalOpacityProperty = DependencyProperty.Register
("InternalOpacity",
typeof(Double),
typeof(Legend),
new PropertyMetadata(1.0, OnOpacityPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.MaxHeight dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.MaxHeight dependency property.
///
private static readonly DependencyProperty InternalMaxHeightProperty = DependencyProperty.Register
("InternalMaxHeight",
typeof(Double),
typeof(Legend),
new PropertyMetadata(Double.PositiveInfinity, OnMaxHeightPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.MaxWidth dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.MaxWidth dependency property.
///
private static readonly DependencyProperty InternalMaxWidthProperty = DependencyProperty.Register
("InternalMaxWidth",
typeof(Double),
typeof(Legend),
new PropertyMetadata(Double.PositiveInfinity, OnMaxWidthPropertyChanged));
#else
///
/// Identifies the Visifire.Charts.Legend.FontFamily dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.FontFamily dependency property.
///
public new static readonly DependencyProperty FontFamilyProperty = DependencyProperty.Register
("FontFamily",
typeof(FontFamily),
typeof(Legend),
new PropertyMetadata(OnFontFamilyPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.FontSize dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.FontSize dependency property.
///
public new static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register
("FontSize",
typeof(Double),
typeof(Legend),
new PropertyMetadata(OnFontSizePropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.FontStyle dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.FontStyle dependency property.
///
public new static readonly DependencyProperty FontStyleProperty = DependencyProperty.Register
("FontStyle",
typeof(FontStyle),
typeof(Legend),
new PropertyMetadata(OnFontStylePropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.FontWeight dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.FontWeight dependency property.
///
public new static readonly DependencyProperty FontWeightProperty = DependencyProperty.Register
("FontWeight",
typeof(FontWeight),
typeof(Legend),
new PropertyMetadata(OnFontWeightPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.Opacity dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.Opacity dependency property.
///
public new static readonly DependencyProperty OpacityProperty = DependencyProperty.Register
("Opacity",
typeof(Double),
typeof(Legend),
new PropertyMetadata(1.0, OnOpacityPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.BorderThickness dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.BorderThickness dependency property.
///
public new static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register
("BorderThickness",
typeof(Thickness),
typeof(Legend),
new PropertyMetadata(OnBorderThicknessPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.Background dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.Background dependency property.
///
public new static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register
("Background",
typeof(Brush),
typeof(Legend),
new PropertyMetadata(OnBackgroundPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.Padding dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.Padding dependency property.
///
public new static readonly DependencyProperty PaddingProperty = DependencyProperty.Register
("Padding",
typeof(Thickness),
typeof(Legend),
new PropertyMetadata(OnPaddingPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.HorizontalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.HorizontalAlignment dependency property.
///
public new static readonly DependencyProperty HorizontalAlignmentProperty = DependencyProperty.Register
("HorizontalAlignment",
typeof(HorizontalAlignment),
typeof(Legend),
new PropertyMetadata(OnHorizontalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.VerticalAlignment dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.VerticalAlignment dependency property.
///
public new static readonly DependencyProperty VerticalAlignmentProperty = DependencyProperty.Register
("VerticalAlignment",
typeof(VerticalAlignment),
typeof(Legend),
new PropertyMetadata(OnVerticalAlignmentPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.MaxHeight dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.MaxHeight dependency property.
///
public new static readonly DependencyProperty MaxHeightProperty = DependencyProperty.Register
("MaxHeight",
typeof(Double),
typeof(Legend),
new PropertyMetadata(Double.PositiveInfinity, OnMaxHeightPropertyChanged));
///
/// Identifies the Visifire.Charts.Legend.MaxWidth dependency property.
///
///
/// The identifier for the Visifire.Charts.Legend.MaxWidth dependency property.
///
public new static readonly DependencyProperty MaxWidthProperty = DependencyProperty.Register
("MaxWidth",
typeof(Double),
typeof(Legend),
new PropertyMetadata(Double.PositiveInfinity, OnMaxWidthPropertyChanged));
#endif
///
/// Get or set the HrefTarget property
///
public HrefTargets HrefTarget
{
get
{
return (HrefTargets)GetValue(HrefTargetProperty);
}
set
{
SetValue(HrefTargetProperty, value);
}
}
///
/// Get or set the Href porperty
///
public String Href
{
get
{
return (String)GetValue(HrefProperty);
}
set
{
SetValue(HrefProperty, value);
}
}
///
/// Get or set the Href porperty
///
public Boolean Reversed
{
get
{
return (Boolean)GetValue(ReversedProperty);
}
set
{
SetValue(ReversedProperty, value);
}
}
///
/// Get or set the Opacity property
///
public new Double Opacity
{
get
{
return (Double)GetValue(OpacityProperty);
}
set
{
#if SL
if (Opacity != value)
{
InternalOpacity = value;
SetValue(OpacityProperty, value);
FirePropertyChanged("Opacity");
}
#else
SetValue(OpacityProperty, value);
#endif
}
}
///
/// Get or set the Cursor property
///
public new Cursor Cursor
{
get
{
return base.Cursor;
}
set
{
if (base.Cursor != value)
{
base.Cursor = value;
FirePropertyChanged("Cursor");
}
}
}
///
/// Get or set the label margin of the Legend
///
public Double LabelMargin
{
get
{
return (Double)GetValue(LabelMarginProperty);
}
set
{
SetValue(LabelMarginProperty, value);
}
}
///
/// Get or set the padding of the Legend
///
public new Thickness Padding
{
get
{
return (Thickness)GetValue(PaddingProperty);
}
set
{
#if WPF
SetValue(PaddingProperty, value);
#else
InternalPadding = value;
SetValue(PaddingProperty, value);
FirePropertyChanged("Padding");
#endif
}
}
///
/// Get or set the HorizontalAlignment property of the Legend
///
public new HorizontalAlignment HorizontalAlignment
{
get
{
return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
}
set
{
#if SL
if (HorizontalAlignment != value)
{
InternalHorizontalAlignment = value;
SetValue(HorizontalAlignmentProperty, value);
FirePropertyChanged("HorizontalAlignment");
}
#else
SetValue(HorizontalAlignmentProperty, value);
#endif
}
}
///
/// Get or set the VerticalAlignment property of the Legend
///
public new VerticalAlignment VerticalAlignment
{
get
{
return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
}
set
{
#if SL
if (VerticalAlignment != value)
{
InternalVerticalAlignment = value;
SetValue(VerticalAlignmentProperty, value);
FirePropertyChanged("VerticalAlignment");
}
#else
SetValue(VerticalAlignmentProperty, value);
#endif
}
}
///
/// Get or set the BorderColor property of the Legend
///
public Brush BorderColor
{
get
{
return (Brush)GetValue(BorderColorProperty);
}
set
{
SetValue(BorderColorProperty, value);
}
}
///
/// Get or set the BorderThickness property of the Legend
///
public new Thickness BorderThickness
{
get
{
return (Thickness)GetValue(BorderThicknessProperty);
}
set
{
#if SL
if (BorderThickness != value)
{
InternalBorderThickness = value;
SetValue(BorderThicknessProperty, value);
FirePropertyChanged("BorderThickness");
}
#else
SetValue(BorderThicknessProperty, value);
#endif
}
}
///
/// Get or set the Background property of the Legend
///
public new Brush Background
{
get
{
return (Brush)GetValue(BackgroundProperty);
}
set
{
#if SL
if (Background != value)
{
InternalBackground = value;
SetValue(BackgroundProperty, value);
FirePropertyChanged("Background");
}
#else
SetValue(BackgroundProperty, value);
#endif
}
}
///
/// Get or set the DockInsidePlotArea property of the Legend
///
public Boolean DockInsidePlotArea
{
get
{
return (Boolean)GetValue(DockInsidePlotAreaProperty);
}
set
{
SetValue(DockInsidePlotAreaProperty, value);
}
}
///
/// Get or set the Enabled property of the Legend
///
[System.ComponentModel.TypeConverter(typeof(NullableBoolConverter))]
public Nullable Enabled
{
get
{
if ((Nullable)GetValue(EnabledProperty) == null)
return true;
else
return (Nullable)GetValue(EnabledProperty);
}
set
{
SetValue(EnabledProperty, value);
}
}
///
/// Get or set the FontColor property of the Legend
///
public Brush FontColor
{
get
{
//return ((Brush)GetValue(FontColorProperty) == null) ? (new SolidColorBrush(Colors.Black)) : (Brush)GetValue(FontColorProperty);
return (Brush)GetValue(FontColorProperty);
}
set
{
SetValue(FontColorProperty, value);
}
}
///
/// Get or set the FontFamily property of the Legend
///
public new FontFamily FontFamily
{
get
{
if ((FontFamily)GetValue(FontFamilyProperty) == null)
return new FontFamily("Verdana");
else
return (FontFamily)GetValue(FontFamilyProperty);
}
set
{
#if SL
if (FontFamily != value)
{
InternalFontFamily = value;
SetValue(FontFamilyProperty, value);
FirePropertyChanged("FontFamily");
}
#else
SetValue(FontFamilyProperty, value);
#endif
}
}
///
/// Get or set the FontSize property of the Legend
///
public new Double FontSize
{
get
{
return (Double)GetValue(FontSizeProperty);
}
set
{
#if SL
if (FontSize != value)
{
InternalFontSize = value;
SetValue(FontSizeProperty, value);
FirePropertyChanged("FontSize");
}
#else
SetValue(FontSizeProperty, value);
#endif
}
}
///
/// Get or set the FontStyle property of the Legend
///
#if WPF
[TypeConverter(typeof(System.Windows.FontStyleConverter))]
#endif
public new FontStyle FontStyle
{
get
{
return (FontStyle)(GetValue(FontStyleProperty));
}
set
{
#if SL
if (FontStyle != value)
{
InternalFontStyle = value;
SetValue(FontStyleProperty, value);
FirePropertyChanged("FontStyle");
}
#else
SetValue(FontStyleProperty, value);
#endif
}
}
///
/// Get or set the FontWeight property of the Legend
///
#if WPF
[System.ComponentModel.TypeConverter(typeof(System.Windows.FontWeightConverter))]
#endif
public new FontWeight FontWeight
{
get
{
return (FontWeight)(GetValue(FontWeightProperty));
}
set
{
#if SL
if (InternalFontWeight != value)
{
InternalFontWeight = value;
SetValue(FontWeightProperty, value);
FirePropertyChanged("FontWeight");
}
#else
SetValue(FontWeightProperty, value);
#endif
}
}
///
/// Get or set the LightingEnabled property of the Legend
///
public Boolean LightingEnabled
{
get
{
return (Boolean)GetValue(LightingEnabledProperty);
}
set
{
SetValue(LightingEnabledProperty, value);
}
}
#if WPF
[System.ComponentModel.TypeConverter(typeof(System.Windows.CornerRadiusConverter))]
#else
[System.ComponentModel.TypeConverter(typeof(Converters.CornerRadiusConverter))]
#endif
///
/// Get or set the CornerRadius property of the Legend
///
public CornerRadius CornerRadius
{
get
{
return (CornerRadius)GetValue(CornerRadiusProperty);
}
set
{
SetValue(CornerRadiusProperty, value);
}
}
///
/// Get or set the Title property of the Legend
///
public String Title
{
get
{
return (String)GetValue(TitleProperty);
}
set
{
SetValue(TitleProperty, value);
}
}
///
/// Get or set the TitleAlignmentX property of the Legend
///
public HorizontalAlignment TitleAlignmentX
{
get
{
return (HorizontalAlignment)GetValue(TitleAlignmentXProperty);
}
set
{
SetValue(TitleAlignmentXProperty, value);
}
}
///
/// Get or set the TitleTextAlignment property of the Legend
///
public TextAlignment TitleTextAlignment
{
get
{
return (TextAlignment)GetValue(TitleTextAlignmentProperty);
}
set
{
SetValue(TitleTextAlignmentProperty, value);
}
}
///
/// Get or set the TitleBackground property of the Legend
///
public Brush TitleBackground
{
get
{
return (Brush)GetValue(TitleBackgroundProperty);
}
set
{
SetValue(TitleBackgroundProperty, value);
}
}
///
/// Get or set the TitleFontColor property of the Legend
///
public Brush TitleFontColor
{
get
{
return (Brush)GetValue(TitleFontColorProperty);
}
set
{
SetValue(TitleFontColorProperty, value);
}
}
///
/// Get or set the TitleFontFamily property of the Legend
///
public FontFamily TitleFontFamily
{
get
{
return (FontFamily)GetValue(TitleFontFamilyProperty);
}
set
{
SetValue(TitleFontFamilyProperty, value);
}
}
///
/// Get or set the TitleFontSize property of the Legend
///
public Double TitleFontSize
{
get
{
return (Double)GetValue(TitleFontSizeProperty);
}
set
{
SetValue(TitleFontSizeProperty, value);
}
}
///
/// Get or set the TitleFontStyle property of the Legend
///
#if SL
[System.ComponentModel.TypeConverter(typeof(Visifire.Commons.Converters.FontStyleConverter))]
#endif
public FontStyle TitleFontStyle
{
get
{
return (FontStyle)GetValue(TitleFontStyleProperty);
}
set
{
SetValue(TitleFontStyleProperty, value);
}
}
///
/// Get or set the TitleFontWeight property of the Legend
///
public FontWeight TitleFontWeight
{
get
{
return (FontWeight)GetValue(TitleFontWeightProperty);
}
set
{
SetValue(TitleFontWeightProperty, value);
}
}
///
/// Get or set the EntryMargin property of the Legend
///
public Double EntryMargin
{
get
{
return (Double)GetValue(EntryMarginProperty);
}
set
{
SetValue(EntryMarginProperty, value);
}
}
///
/// Get or set the maximum height of the Legend
///
public new Double MaxHeight
{
get
{
return (Double)GetValue(MaxHeightProperty);
}
set
{
#if SL
if (MaxHeight != value)
{
SetValue(MaxHeightProperty, value);
FirePropertyChanged("MaxHeight");
}
#else
SetValue(MaxHeightProperty, value);
#endif
}
}
///
/// Get or set the maximum height of the Legend
///
public new Double MaxWidth
{
get
{
return (Double)GetValue(MaxWidthProperty);
}
set
{
#if SL
if (MaxWidth != value)
{
InternalMaxWidth = value;
SetValue(MaxWidthProperty, value);
FirePropertyChanged("MaxWidth");
}
#else
SetValue(MaxWidthProperty, value);
#endif
}
}
///
/// Get or set the FontFamily property of title
///
internal FontFamily InternalFontFamily
{
get
{
FontFamily retVal;
if (_internalFontFamily == null)
retVal = (FontFamily)GetValue(FontFamilyProperty);
else
retVal = _internalFontFamily;
return (retVal == null) ? new FontFamily("Verdana") : retVal;
}
set
{
_internalFontFamily = value;
}
}
///
/// Get or set the FontSize property of title
///
internal Double InternalFontSize
{
get
{
return (Double)(Double.IsNaN(_internalFontSize) ? GetValue(FontSizeProperty) : _internalFontSize);
}
set
{
_internalFontSize = value;
}
}
///
/// Get or set the FontStyle property of title text
///
#if WPF
[TypeConverter(typeof(System.Windows.FontStyleConverter))]
#endif
internal FontStyle InternalFontStyle
{
get
{
return (FontStyle)((_internalFontStyle == null) ? GetValue(FontStyleProperty) : _internalFontStyle);
}
set
{
_internalFontStyle = value;
}
}
///
/// Get or set the FontWeight property of title text
///
#if WPF
[System.ComponentModel.TypeConverter(typeof(System.Windows.FontWeightConverter))]
#endif
internal FontWeight InternalFontWeight
{
get
{
return (FontWeight)((_internalFontWeight == null) ? GetValue(FontWeightProperty) : _internalFontWeight);
}
set
{
_internalFontWeight = value;
}
}
///
/// Get or set the BorderThickness of title
///
internal Thickness InternalBorderThickness
{
get
{
return (Thickness)((_borderThickness == null) ? GetValue(BorderThicknessProperty) : _borderThickness);
}
set
{
_borderThickness = value;
}
}
///
/// Get or set the Background property of title
///
internal Brush InternalBackground
{
get
{
return (Brush)((_internalBackground == null) ? GetValue(BackgroundProperty) : _internalBackground);
}
set
{
_internalBackground = value;
}
}
///
/// Get or set the HorizontalAlignment property of title
///
internal HorizontalAlignment InternalHorizontalAlignment
{
get
{
return (HorizontalAlignment)((_internalHorizontalAlignment == null) ? GetValue(HorizontalAlignmentProperty) : _internalHorizontalAlignment);
}
set
{
_internalHorizontalAlignment = value;
}
}
///
/// Get or set the VerticalAlignment property of title
///
internal VerticalAlignment InternalVerticalAlignment
{
get
{
return (VerticalAlignment)((_internalVerticalAlignment == null) ? GetValue(VerticalAlignmentProperty) : _internalVerticalAlignment);
}
set
{
_internalVerticalAlignment = value;
}
}
///
/// Get or set the Padding property of title
///
public Thickness InternalPadding
{
get
{
return (Thickness)((_internalPadding == null) ? GetValue(PaddingProperty) : _internalPadding);
}
set
{
_internalPadding = value;
}
}
///
/// Get or set the Opacity property
///
internal Double InternalOpacity
{
get
{
return (Double)(Double.IsNaN(_internalOpacity) ? GetValue(OpacityProperty) : _internalOpacity);
}
set
{
_internalOpacity = value;
}
}
///
/// Get or set the maximum height of the Legend
///
internal Double InternalMaxHeight
{
get
{
return (Double)(Double.IsNaN(_internalMaxheight) ? GetValue(MaxHeightProperty) : _internalMaxheight);
}
set
{
_internalMaxheight = value;
}
}
///
/// Get or set the maximum height of the Legend
///
internal Double InternalMaxWidth
{
get
{
return (Double)(Double.IsNaN(_internalMaxWidth) ? GetValue(MaxWidthProperty) : _internalMaxWidth);
}
set
{
_internalMaxWidth = value;
}
}
#endregion
#region Public Events And Delegates
#endregion
#region Protected Methods
#endregion
#region Internal Properties
///
/// Get or set the maximum height of the Legend
///
internal Double InternalMaximumHeight
{
get;
set;
}
///
/// Get or set the maximum height of the Legend
///
internal Double InternalMaximumWidth
{
get;
set;
}
///
/// Get or set theOrientation of Legend
///
internal Orientation Orientation
{
get;
set;
}
///
/// Get or set the Maximum number of rows in Legend
///
internal Int32 MaxRows
{
get;
set;
}
///
/// Get or set the Maximum number of columns in Legend
///
internal Int32 MaxColumns
{
get;
set;
}
///
/// Legend visual
///
internal Border Visual
{
get;
set;
}
///
/// Layout type of Legend
///
internal Layouts LegendLayout
{
get;
set;
}
///
/// Label text and Marker as symbol
///
internal List> Entries
{
get;
set;
}
#endregion
#region Private Properties
///
/// LegendContainer is the 1st child of the Visual
///
private StackPanel LegendContainer
{
get;
set;
}
///
/// Size of an entry
///
private struct EntrySize
{
///
/// Size of the entry symbol
///
public Size SymbolSize;
///
/// Size of the textSize
///
public Size TextSize;
}
#endregion
#region Private Delegates
#endregion
#region Private Methods
///
/// Event handler attached with HrefTarget property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnHrefTargetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend c = d as Legend;
c.FirePropertyChanged("HrefTarget");
}
///
/// Event handler attached with Href property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnHrefChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend c = d as Legend;
c.FirePropertyChanged("Href");
}
///
/// Event handler attached with Reversed property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnReversedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend c = d as Legend;
c.FirePropertyChanged("Reversed");
}
///
/// Event handler attached with LabelMargin property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnLabelMarginPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("LabelMargin");
}
///
/// Event handler attached with BorderColor property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnBorderColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("BorderColor");
}
///
/// Event handler attached with DockInsidePlotArea property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnDockInsidePlotAreaPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("DockInsidePlotArea");
}
///
/// Event handler attached with Enabled property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("Enabled");
}
///
/// Event handler attached with FontColor property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("FontColor");
}
//------------------------------------------------------------
///
/// Event handler attached with FontFamily property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontFamilyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
if (e.NewValue == null || e.OldValue == null)
{
legend.InternalFontFamily = (FontFamily)e.NewValue;
legend.FirePropertyChanged("FontFamily");
}
else if (e.NewValue.ToString() != e.OldValue.ToString())
{
legend.InternalFontFamily = (FontFamily)e.NewValue;
legend.FirePropertyChanged("FontFamily");
}
//legend.FirePropertyChanged("FontFamily");
}
///
/// Event handler attached with FontSize property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalFontSize = (Double)e.NewValue;
legend.FirePropertyChanged("FontSize");
}
///
/// Event handler attached with FontStyle property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontStylePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalFontStyle = (FontStyle)e.NewValue;
legend.FirePropertyChanged("FontStyle");
}
///
/// Event handler attached with FontWeight property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnFontWeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalFontWeight = (FontWeight)e.NewValue;
legend.FirePropertyChanged("FontWeight");
}
///
/// Event handler attached with BorderThickness property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnBorderThicknessPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalBorderThickness = (Thickness)e.NewValue;
legend.FirePropertyChanged("BorderThickness");
}
///
/// Event handler attached with Background property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalBackground = (Brush)e.NewValue;
legend.FirePropertyChanged("Background");
}
///
/// Event handler attached with Padding property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnPaddingPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalPadding = (Thickness)e.NewValue;
legend.FirePropertyChanged("Padding");
}
///
/// Event handler attached with HorizontalAlignment property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnHorizontalAlignmentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalHorizontalAlignment = (HorizontalAlignment)e.NewValue;
legend.FirePropertyChanged("HorizontalAlignment");
}
///
/// Event handler attached with VerticalAlignment property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnVerticalAlignmentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalVerticalAlignment = (VerticalAlignment)e.NewValue;
legend.FirePropertyChanged("VerticalAlignment");
}
///
/// Event handler attached with Opacity property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnOpacityPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalOpacity = (Double)e.NewValue;
legend.FirePropertyChanged("Opacity");
}
///
/// Event handler attached with MaxHeight property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnMaxHeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalMaxHeight = (Double)e.NewValue;
legend.FirePropertyChanged("MaxHeight");
}
///
/// Event handler attached with MaxWidth property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnMaxWidthPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.InternalMaxWidth = (Double)e.NewValue;
legend.FirePropertyChanged("MaxWidth");
}
//----------------------------------------------
///
/// Event handler attached with LightingEnabled property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnLightingEnabledPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("LightingEnabled");
}
///
/// Event handler attached with CornerRadius property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnCornerRadiusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("CornerRadius");
}
///
/// Event handler attached with Title property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitlePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("Title");
}
///
/// Event handler attached with TitleAlignmentX property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleAlignmentXPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleAlignmentX");
}
///
/// Event handler attached with TitleTextAlignment property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleTextAlignmentPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleTextAlignment");
}
///
/// Event handler attached with TitleBackground property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleBackgroundPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleBackground");
}
///
/// Event handler attached with TitleFontColor property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleFontColorPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleFontColor");
}
///
/// Event handler attached with TitleFontFamily property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleFontFamilyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleFontFamily");
}
///
/// Event handler attached with TitleFontStyle property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleFontStylePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleFontStyle");
}
///
/// Event handler attached with TitleFontSize property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleFontSizePropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleFontSize");
}
///
/// Event handler attached with TitleFontWeight property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnTitleFontWeightPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("TitleFontWeight");
}
///
/// Event handler attached with EntryMargin property changed event of Legend element
///
/// DependencyObject
/// DependencyPropertyChangedEventArgs
private static void OnEntryMarginPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
Legend legend = d as Legend;
legend.FirePropertyChanged("EntryMargin");
}
///
/// Apply font properties of a TextBlock
///
///
private void ApplyFontProperty(TextBlock textBlock)
{
textBlock.FontFamily = InternalFontFamily;
textBlock.FontStyle = InternalFontStyle;
textBlock.FontWeight = InternalFontWeight;
textBlock.FontSize = InternalFontSize;
textBlock.Foreground = Charts.Chart.CalculateFontColor((Chart as Chart), FontColor, this.DockInsidePlotArea);
}
///
/// Apply font properties of a marker
///
/// Marker
private void ApplyFontPropertiesOfMarkerAsSymbol(Marker marker)
{
marker.FontFamily = InternalFontFamily;
marker.FontStyle = InternalFontStyle;
marker.FontWeight = InternalFontWeight;
marker.FontSize = InternalFontSize;
marker.FontColor = Charts.Chart.CalculateFontColor((Chart as Chart), FontColor, this.DockInsidePlotArea);
}
///
/// Apply font properties of the title of Legend
///
///
private void ApplyFontProperty(Title title)
{
if (TitleFontFamily != null)
title.InternalFontFamily = TitleFontFamily;
if (TitleFontSize != 0)
title.InternalFontSize = TitleFontSize;
if (TitleFontStyle != null)
title.InternalFontStyle = TitleFontStyle;
if (TitleFontWeight != null)
title.InternalFontWeight = TitleFontWeight;
if (!String.IsNullOrEmpty(Title))
title.Text = GetFormattedMultilineText(Title);
title.InternalFontColor = Charts.Chart.CalculateFontColor((Chart as Chart), TitleFontColor, this.DockInsidePlotArea);
}
///
/// Apply visual properties
///
private void ApplyVisualProperty()
{
if (Cursor != null)
Visual.Cursor = Cursor;
Visual.BorderBrush = BorderColor;
Visual.BorderThickness = InternalBorderThickness;
Visual.CornerRadius = CornerRadius;
Visual.Background = this.InternalBackground;
Visual.HorizontalAlignment = InternalHorizontalAlignment;
Visual.VerticalAlignment = InternalVerticalAlignment;
Visual.Opacity = this.InternalOpacity;
ApplyLighting();
AttachHref(Chart, Visual, Href, HrefTarget);
AttachToolTip(Chart, this, Visual);
AttachEvents2Visual(this, Visual);
}
///
/// Return actual size of the TextBlock
///
/// TextBlock
/// Size
private Size TextBlockActualSize(TextBlock textBlock)
{
#if WPF
textBlock.Measure(new Size(Double.MaxValue,Double.MaxValue));
return textBlock.DesiredSize;
#else
return new Size(textBlock.ActualWidth, textBlock.ActualHeight);
#endif
}
///
/// Plloy lighting over Legend
///
private void ApplyLighting()
{
if (LightingEnabled)
LegendContainer.Background = Graphics.LightingBrush(LightingEnabled);
else
LegendContainer.Background = new SolidColorBrush(Colors.Transparent);
}
///
/// Returns StackPanel used as a column of the Legend
///
/// StackPanel
private StackPanel StackPanelColumn()
{
StackPanel st = new StackPanel();
st.HorizontalAlignment = HorizontalAlignment.Left;
st.Orientation = Orientation.Vertical;
return st;
}
///
/// Returns StackPanel used as a row of the Legend
///
/// StackPanel
private StackPanel StackPanelRow()
{
StackPanel st = new StackPanel();
st.Orientation = Orientation.Horizontal;
return st;
}
///
/// Returns max entry size of legend
///
/// EntrySize
private EntrySize GetMaxSymbolAndColumnWidth()
{
EntrySize entrySize = new EntrySize();
foreach (KeyValuePair labelAndSymbol in Entries)
{
TextBlock t = new TextBlock();
t.Text = labelAndSymbol.Key;
ApplyFontProperty(t);
Size labelSize = TextBlockActualSize(t);
entrySize.TextSize.Width = (labelSize.Width > entrySize.TextSize.Width) ? labelSize.Width : entrySize.TextSize.Width;
entrySize.TextSize.Height = (labelSize.Height > entrySize.TextSize.Height) ? labelSize.Height : entrySize.TextSize.Height;
(labelAndSymbol.Value as Marker).Margin = EntryMargin;
(labelAndSymbol.Value as Marker).CreateVisual();
entrySize.SymbolSize.Width = ((labelAndSymbol.Value as Marker).MarkerActualSize.Width > entrySize.SymbolSize.Width) ? (labelAndSymbol.Value as Marker).MarkerActualSize.Width : entrySize.SymbolSize.Width;
entrySize.SymbolSize.Height = ((labelAndSymbol.Value as Marker).MarkerActualSize.Height > entrySize.SymbolSize.Height) ? (labelAndSymbol.Value as Marker).MarkerActualSize.Height : entrySize.SymbolSize.Height;
}
return entrySize;
}
///
/// Apply LineStyle to line symbol of a legend entry in Legend
///
///
///
private DoubleCollection ApplyLineStyleForMarkerOfLegendEntry(Line line, String lineStyle)
{
DoubleCollection retVal = null;
switch (lineStyle)
{
case "Solid":
line.StrokeThickness = 3;
retVal = null;
break;
case "Dashed":
line.StrokeThickness = 3;
retVal = new DoubleCollection() { .2, .4, .2, .12 };
break;
case "Dotted":
line.StrokeThickness = 3;
retVal = new DoubleCollection() { .5, .5, .5, .5 };
break;
}
return retVal;
}
///
/// Customize the marker for legend in Line chart
///
///
///
private Canvas GetNewMarkerForLineChart(Marker marker)
{
Canvas lineMarker = new Canvas();
Line line = new Line() { Tag = marker.Tag };
line.Margin = new Thickness(EntryMargin);
line.Stroke = (marker.BorderColor);
Double height = marker.TextBlockSize.Height > marker.MarkerSize.Height ? marker.TextBlockSize.Height : marker.MarkerSize.Height;
lineMarker.Height = marker.MarkerActualSize.Height;
line.X1 = 0;
line.X2 = ENTRY_SYMBOL_LINE_WIDTH;
line.Y1 = 0;
line.Y2 = 0;
line.Width = ENTRY_SYMBOL_LINE_WIDTH;
lineMarker.Width = marker.MarkerActualSize.Width + ENTRY_SYMBOL_LINE_WIDTH / 2;
line.StrokeDashArray = ApplyLineStyleForMarkerOfLegendEntry(line, marker.DataSeriesOfLegendMarker.LineStyle.ToString());
lineMarker.Children.Add(line);
lineMarker.Children.Add(marker.Visual);
if (!(InternalVerticalAlignment == VerticalAlignment.Center && (InternalHorizontalAlignment == HorizontalAlignment.Left || InternalHorizontalAlignment == HorizontalAlignment.Right)))
{
line.Margin = new Thickness(ENTRY_SYMBOL_LINE_WIDTH / 2, marker.Visual.Margin.Top, marker.Visual.Margin.Right, marker.Visual.Margin.Bottom);
marker.Visual.Margin = new Thickness(ENTRY_SYMBOL_LINE_WIDTH / 2, marker.Visual.Margin.Top, marker.Visual.Margin.Right, marker.Visual.Margin.Bottom);
}
#if WPF
line.SetValue(Canvas.TopProperty, height/2 );
#else
line.Height = 8;
line.SetValue(Canvas.TopProperty, (height / 2) + .4876);
#endif
line.SetValue(Canvas.LeftProperty, (Double)(-marker.MarkerSize.Width / 2) - .4876);
return lineMarker;
}
///
/// Draw vertical flow layout for legend
///
/// Legend content referecnce
private void DrawVerticalFlowLayout4Legend(ref Grid legendContent)
{
Int32 currentPanelIndex = 0;
Double currentHeight = 0;
StackPanel legendPanel = new StackPanel();
(legendPanel as StackPanel).Orientation = Orientation.Horizontal;
legendPanel.Children.Add(StackPanelColumn());
legendPanel.Height = 0;
foreach (KeyValuePair labelAndSymbol in Entries)
{
Marker markerAsSymbol = labelAndSymbol.Value;
markerAsSymbol.Margin = EntryMargin;
markerAsSymbol.LabelMargin = LabelMargin;
markerAsSymbol.Text = labelAndSymbol.Key;
markerAsSymbol.TextAlignmentY = AlignmentY.Center;
markerAsSymbol.TextAlignmentX = AlignmentX.Right;
ApplyFontPropertiesOfMarkerAsSymbol(markerAsSymbol);
if (markerAsSymbol.DataSeriesOfLegendMarker.RenderAs == RenderAs.Line
|| markerAsSymbol.DataSeriesOfLegendMarker.RenderAs == RenderAs.Stock
|| markerAsSymbol.DataSeriesOfLegendMarker.RenderAs == RenderAs.CandleStick
)
{
markerAsSymbol.BorderColor = markerAsSymbol.MarkerFillColor;
markerAsSymbol.MarkerFillColor = new SolidColorBrush(Colors.White);
markerAsSymbol.BorderThickness = 0.7;
markerAsSymbol.CreateVisual();
Canvas lineMarker = GetNewMarkerForLineChart(markerAsSymbol);
lineMarker.HorizontalAlignment = HorizontalAlignment.Left;
lineMarker.VerticalAlignment = VerticalAlignment.Center;
if ((currentHeight + lineMarker.Height) <= InternalMaximumHeight)
{
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(lineMarker);
currentHeight += lineMarker.Height;
}
else
{
legendPanel.Children.Add(StackPanelColumn());
currentPanelIndex++;
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(lineMarker);
currentHeight = markerAsSymbol.MarkerActualSize.Height;
}
}
else
{
markerAsSymbol.CreateVisual();
if ((currentHeight + markerAsSymbol.MarkerActualSize.Height) <= InternalMaximumHeight)
{
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(markerAsSymbol.Visual);
currentHeight += markerAsSymbol.MarkerActualSize.Height;
}
else
{
legendPanel.Children.Add(StackPanelColumn());
currentPanelIndex++;
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(markerAsSymbol.Visual);
currentHeight = markerAsSymbol.MarkerActualSize.Height;
}
}
markerAsSymbol.Visual.HorizontalAlignment = HorizontalAlignment.Left;
legendPanel.Height = (legendPanel.Height < currentHeight) ? currentHeight : legendPanel.Height;
}
legendPanel.HorizontalAlignment = HorizontalAlignment.Center;
legendPanel.VerticalAlignment = VerticalAlignment.Center;
legendContent.Children.Add(legendPanel);
}
///
/// Draw vertical grid layout for legend
///
/// Legend content referecnce
private void DrawVerticalGridlayout4Legend(ref Grid legendContent)
{
Int32 row, column;
Grid legendGrid = new Grid();
EntrySize maxEntrySize = GetMaxSymbolAndColumnWidth();
MaxRows = (Int32)(InternalMaximumHeight / (maxEntrySize.SymbolSize.Height + maxEntrySize.TextSize.Height + EntryMargin + LabelMargin));
MaxColumns = (Int32)Math.Ceiling(((Double)Entries.Count / MaxRows));
for (row = 0; row < MaxRows; row++)
legendGrid.RowDefinitions.Add(new RowDefinition());
row = 0;
column = 0;
Double maxRowHeight = 0;
foreach (KeyValuePair labelAndSymbol in Entries)
{
if (row == 0)
{
legendGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(maxEntrySize.SymbolSize.Width + EntryMargin + LabelMargin / 2) });
legendGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(maxEntrySize.TextSize.Width + LabelMargin / 2) });
}
(labelAndSymbol.Value as Marker).Visual.Margin = new Thickness(EntryMargin, EntryMargin, LabelMargin / 2, EntryMargin);
(labelAndSymbol.Value as Marker).Visual.SetValue(Grid.RowProperty, row);
(labelAndSymbol.Value as Marker).Visual.SetValue(Grid.ColumnProperty, column++);
legendGrid.Children.Add((labelAndSymbol.Value as Marker).Visual);
TextBlock label = new TextBlock();
label.Margin = new Thickness(LabelMargin, 0, 0, 0);
label.Text = labelAndSymbol.Key;
ApplyFontProperty(label);
label.SetValue(Grid.RowProperty, row);
label.SetValue(Grid.ColumnProperty, column++);
label.HorizontalAlignment = HorizontalAlignment.Left;
label.VerticalAlignment = VerticalAlignment.Center;
legendGrid.Children.Add(label);
label.Measure(new Size(Double.MaxValue, Double.MaxValue));
Double maxRowHeight1 = (label.DesiredSize.Height > (labelAndSymbol.Value as Marker).Visual.DesiredSize.Height) ? label.DesiredSize.Height : (labelAndSymbol.Value as Marker).Visual.DesiredSize.Height;
if (maxRowHeight1 > maxRowHeight)
{
maxRowHeight = maxRowHeight1;
legendGrid.RowDefinitions[row].Height = new GridLength(maxRowHeight + 2 * EntryMargin);
}
if (column >= MaxColumns * 2)
{
row++;
column = 0;
}
}
legendGrid.ShowGridLines = true;
legendGrid.HorizontalAlignment = HorizontalAlignment.Center;
legendGrid.VerticalAlignment = VerticalAlignment.Center;
legendContent.Children.Add(legendGrid);
}
///
/// Draw horizontal flow layout for legend
///
/// Legend content referecnce
private void DrawHorizontalFlowLayout4Legend(ref Grid legendContent)
{
Int32 currentPanelIndex = 0;
Double currentWidth = 0;
StackPanel legendPanel = new StackPanel();
(legendPanel as StackPanel).Orientation = Orientation.Vertical;
legendPanel.Children.Add(StackPanelRow());
foreach (KeyValuePair labelAndSymbol in Entries)
{
Marker marker = labelAndSymbol.Value;
marker.Margin = EntryMargin;
marker.LabelMargin = LabelMargin;
marker.Text = labelAndSymbol.Key;
ApplyFontPropertiesOfMarkerAsSymbol(marker);
marker.TextAlignmentY = AlignmentY.Center;
marker.TextAlignmentX = AlignmentX.Right;
if (marker.DataSeriesOfLegendMarker.RenderAs == RenderAs.Line
|| marker.DataSeriesOfLegendMarker.RenderAs == RenderAs.Stock
|| marker.DataSeriesOfLegendMarker.RenderAs == RenderAs.CandleStick
)
{
marker.BorderColor = marker.MarkerFillColor;
marker.MarkerFillColor = new SolidColorBrush(Colors.White);
marker.BorderThickness = 0.7;
marker.LabelMargin += ENTRY_SYMBOL_LINE_WIDTH /2;
marker.CreateVisual();
Canvas lineMarker = GetNewMarkerForLineChart(marker);
//if (marker.DataSeriesOfLegendMarker.MarkerEnabled == false)
// marker.MarkerShape.Opacity = 0;
if ((currentWidth + lineMarker.Width) <= InternalMaximumWidth)
{
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(lineMarker);
currentWidth += lineMarker.Width;
}
else
{
legendPanel.Children.Add(StackPanelRow());
currentPanelIndex++;
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(lineMarker);
currentWidth = marker.MarkerActualSize.Width;
}
}
else
{
marker.CreateVisual();
if ((currentWidth + marker.MarkerActualSize.Width) <= InternalMaximumWidth)
{
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(marker.Visual);
currentWidth += marker.MarkerActualSize.Width;
}
else
{
legendPanel.Children.Add(StackPanelRow());
currentPanelIndex++;
(legendPanel.Children[currentPanelIndex] as StackPanel).Children.Add(marker.Visual);
currentWidth = marker.MarkerActualSize.Width;
}
}
marker.Visual.HorizontalAlignment = HorizontalAlignment.Center;
}
legendPanel.HorizontalAlignment = HorizontalAlignment.Center;
legendPanel.VerticalAlignment = VerticalAlignment.Center;
legendContent.Children.Add(legendPanel);
}
///
/// Draw horizontal grid layout for legend
///
/// Legend content referecnce
private void DrawHorizontalGridlayout4Legend(ref Grid legendContent)
{
Int32 row, column;
Grid legendGrid = new Grid();
EntrySize maxEntrySize = GetMaxSymbolAndColumnWidth();
MaxColumns = (Int32)(InternalMaximumWidth / (maxEntrySize.SymbolSize.Width + maxEntrySize.TextSize.Width + EntryMargin + LabelMargin));
MaxRows = (Int32)Math.Ceiling(((Double)Entries.Count / MaxColumns));
for (row = 0; row < MaxRows; row++)
legendGrid.RowDefinitions.Add(new RowDefinition());
row = 0;
column = 0;
Double maxRowHeight = 0;
foreach (KeyValuePair labelAndSymbol in Entries)
{
if (row == 0)
{
legendGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(maxEntrySize.SymbolSize.Width + EntryMargin + LabelMargin / 2) });
legendGrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(maxEntrySize.TextSize.Width + LabelMargin / 2) });
}
(labelAndSymbol.Value as Marker).Visual.Margin = new Thickness(EntryMargin, EntryMargin, LabelMargin / 2, EntryMargin);
(labelAndSymbol.Value as Marker).Visual.SetValue(Grid.RowProperty, row);
(labelAndSymbol.Value as Marker).Visual.SetValue(Grid.ColumnProperty, column++);
legendGrid.Children.Add((labelAndSymbol.Value as Marker).Visual);
TextBlock label = new TextBlock();
label.Margin = new Thickness(LabelMargin, 0, 0, 0);
label.Text = labelAndSymbol.Key;
ApplyFontProperty(label);
label.SetValue(Grid.RowProperty, row);
label.SetValue(Grid.ColumnProperty, column++);
label.HorizontalAlignment = HorizontalAlignment.Left;
label.VerticalAlignment = VerticalAlignment.Center;
legendGrid.Children.Add(label);
label.Measure(new Size(Double.MaxValue, Double.MaxValue));
Double maxRowHeight1 = (label.DesiredSize.Height > (labelAndSymbol.Value as Marker).Visual.DesiredSize.Height) ? label.DesiredSize.Height : (labelAndSymbol.Value as Marker).Visual.DesiredSize.Height;
if (maxRowHeight1 > maxRowHeight)
{
maxRowHeight = maxRowHeight1;
legendGrid.RowDefinitions[row].Height = new GridLength(maxRowHeight + 2 * EntryMargin);
}
if (column >= MaxColumns * 2)
{
row++;
column = 0;
}
}
legendGrid.ShowGridLines = true;
legendGrid.HorizontalAlignment = HorizontalAlignment.Center;
legendGrid.VerticalAlignment = VerticalAlignment.Center;
legendContent.Children.Add(legendGrid);
}
///
/// Create the content of the Legend
///
/// Grid
private Grid CreateLegendContent()
{
Grid legendContent = new Grid();
InternalMaximumWidth -= 2 * InternalPadding.Left;
InternalMaximumHeight -= 2 * InternalPadding.Left;
if (Orientation == Orientation.Vertical)
{
if (LegendLayout == Layouts.FlowLayout)
{
DrawVerticalFlowLayout4Legend(ref legendContent);
}
else if (LegendLayout == Layouts.Gridlayout)// MaxWidth is reqired for GridLayout calculation
{
DrawVerticalGridlayout4Legend(ref legendContent);
}
}
else if (Orientation == Orientation.Horizontal)
{
if (LegendLayout == Layouts.FlowLayout)
{
DrawHorizontalFlowLayout4Legend(ref legendContent);
}
else if (LegendLayout == Layouts.Gridlayout)// MaxWidth is reqired for GridLayout calculation
{
DrawHorizontalGridlayout4Legend(ref legendContent);
}
}
legendContent.Measure(new Size(Double.MaxValue, Double.MaxValue));
legendContent.Height = legendContent.DesiredSize.Height + InternalPadding.Left * 2;
legendContent.Width = legendContent.DesiredSize.Width + InternalPadding.Left * 2;
return legendContent;
}
#endregion
#region Internal Methods
///
/// Create visual object of the Legend
///
internal void CreateVisualObject()
{
if (!(Boolean)Enabled)
{
Visual = null;
return;
}
ElementData tag = new ElementData { Element = this, VisualElementName = "Legend" };
Visual = new Border() { Tag = tag };
Grid innerGrid = new Grid() { Tag = tag };
(Visual as Border).Child = innerGrid;
LegendContainer = new StackPanel() { Tag = tag };
if (!String.IsNullOrEmpty(Title))
{
Title legendTitle = new Title();
ApplyFontProperty(legendTitle);
if (TitleBackground != null)
legendTitle.InternalBackground = TitleBackground;
legendTitle.InternalHorizontalAlignment = TitleAlignmentX;
legendTitle.InternalVerticalAlignment = VerticalAlignment.Top;
legendTitle.TextAlignment = TitleTextAlignment;
legendTitle.CreateVisualObject(tag);
legendTitle.Measure(new Size(Double.MaxValue, Double.MaxValue));
if(legendTitle.DesiredSize.Width > InternalMaxWidth)
legendTitle.Visual.Width = InternalMaxWidth;
LegendContainer.Children.Add(legendTitle.Visual);
}
Grid legendContent = CreateLegendContent();
legendContent.Tag = tag;
LegendContainer.Children.Add(legendContent);
LegendContainer.VerticalAlignment = VerticalAlignment.Center;
LegendContainer.HorizontalAlignment = HorizontalAlignment.Center;
ApplyVisualProperty();
innerGrid.Children.Add(LegendContainer);
Visual.Cursor = this.Cursor;
Visual.Measure(new Size(Double.MaxValue, Double.MaxValue));
if (!Double.IsPositiveInfinity(InternalMaxHeight) && InternalMaxHeight < Visual.DesiredSize.Height)
Visual.Height = InternalMaxHeight;
else
Visual.Height = Visual.DesiredSize.Height;
if (!Double.IsPositiveInfinity(InternalMaxWidth) && InternalMaxWidth < Visual.DesiredSize.Width + InternalPadding.Left)
Visual.Width = InternalMaxWidth;
else
Visual.Width = Visual.DesiredSize.Width + InternalPadding.Left;
}
#endregion
#region Internal Events And Delegates
#endregion
#region Data
private const Double ENTRY_SYMBOL_LINE_WIDTH = 18;
private Double _internalFontSize = Double.NaN;
private FontFamily _internalFontFamily = null;
internal Brush InternalFontColor;
Nullable _internalFontStyle = null;
Nullable _internalFontWeight = null;
Nullable _borderThickness = null;
Brush _internalBackground = null;
Nullable _internalHorizontalAlignment = null;
Nullable _internalVerticalAlignment = null;
Nullable _internalPadding = null;
Double _internalOpacity = Double.NaN;
Double _internalMaxheight = Double.NaN;
Double _internalMaxWidth = Double.NaN;
#if WPF
///
/// Whether the default style is applied
///
private static Boolean _defaultStyleKeyApplied;
#endif
#endregion
}
}