using System; using System.Net; using System.Windows; using System.Windows.Controls; using System.Windows.Documents; using System.Windows.Ink; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Animation; using System.Windows.Shapes; using C1.Silverlight.Chart; namespace ChartAlarmZones_SL_CS { public class AlarmZone : XYDataSeries { #region "constructor" public AlarmZone() { this.LayoutUpdated += new EventHandler(AlarmZone_LayoutUpdated); this.ChartType = C1.Silverlight.Chart.ChartType.PolygonFilled; UpdateLegend(); Update(); } #endregion #region "members" private C1Chart _chart; public C1Chart Chart { get { return _chart; } set { _chart = value; } } private double? _lowerExtent = null; public double? LowerExtent { get { return _lowerExtent; } set { _lowerExtent = value; Update(); } } private double? _upperExtent = null; public double? UpperExtent { get { return _upperExtent; } set { _upperExtent = value; Update(); } } private double? _near = null; public double? Near { get { return _near; } set { _near = value; Update(); } } private double? _far = null; public double? Far { get { return _far; } set { _far = value; Update(); } } private bool _showInLegend = false; public bool ShowInLegend { get { return _showInLegend; } set { _showInLegend = value; UpdateLegend(); } } #endregion #region "implementation" public void Update() { if (_near != null && _far != null) { this.XValues = new DoubleCollection(); this.XValues.Add((double)_near); this.XValues.Add((double)_far); this.XValues.Add((double)_far); this.XValues.Add((double)_near); } if (_lowerExtent != null && _upperExtent != null) { this.Values = new DoubleCollection(); this.Values.Add((double)_lowerExtent); this.Values.Add((double)_lowerExtent); this.Values.Add((double)_upperExtent); this.Values.Add((double)_upperExtent); } } public void UpdateLegend() { if (_showInLegend) { this.Display = SeriesDisplay.SkipNaN; } else { this.Display = SeriesDisplay.HideLegend; } } private void chart_LayoutUpdated(object sender, EventArgs e) { if (Chart != null) { if (Chart.View != null) { // if extent is null, set to axis bounds if (_near == null) { _near = Chart.View.AxisX.ActualMin; Update(); } if (_far == null) { _far = Chart.View.AxisX.ActualMax; Update(); } if (_upperExtent == null) { _upperExtent = Chart.View.AxisY.ActualMax; Update(); } if (_lowerExtent == null) { _lowerExtent = Chart.View.AxisY.ActualMin; Update(); } } } } #endregion void AlarmZone_LayoutUpdated(object sender, EventArgs e) { if (this.Parent != null && this.Chart == null) { Canvas c = this.Parent as Canvas; if (c != null) { Canvas cv = c.Parent as Canvas; if (cv != null) { C1Chart chart = cv.Parent as C1Chart; if (chart != null) { this.Chart = chart; this.Chart.LayoutUpdated += chart_LayoutUpdated; } } } } } } }