/// <summary> /// Fired upon GameObject creation. /// </summary> public void OnDestroy(GameObject obj) { if (obj != null && obj.IsValid) { if (Axes.Any(o => o.Key == obj.NetworkId)) { Axes.Remove(obj.NetworkId); } } }
/// <summary> /// Called when [series source changed]. /// </summary> /// <param name="oldValue">The old value.</param> /// <param name="newValue">The new value.</param> protected virtual void OnSeriesSourceChanged(IEnumerable oldValue, IEnumerable newValue) { object xAxisLabel = null; var xAxes = this.Axes.OfType <CategoryXAxis>().ToList(); if (xAxes.Count > 0) { xAxisLabel = xAxes.First().Label; } DebugManager.Time("DataChartEx.OnSeriesSourceChanged"); Series.Clear(); Axes.Clear(); if (newValue != null) { #region Axes and Series var yAxisTemplate = GetCurentAxisCategoryYTemplate(DataContext); if (yAxisTemplate != null) { // load data template content var yAxis = yAxisTemplate.LoadContent() as NumericYAxis; if (yAxis != null) { yAxis.IsLogarithmic = AxisValueIsLogarithmic; yAxis.DataContext = DataContext; yAxis.LabelSettings.Visibility = this.AxisCategoryYVisibility; Axes.Add(yAxis); } } var axisCategoryXTemplate = GetCurentAxisCategoryXTemplate(DataContext); foreach (var item in newValue) { var dataTemplate = GetCurentSeriesTemplate(item); if (dataTemplate != null) { // load data template content var series = dataTemplate.LoadContent() as Series; // load data template for the axis var axis = axisCategoryXTemplate.LoadContent() as Axis; if (series != null && axis != null) { // set data context series.DataContext = item; axis.DataContext = item; if (xAxisLabel != null) { axis.Label = xAxisLabel; } Series.Add(series); Axes.Add(axis); series.RefreshXAxis <CategoryXAxis>(this); //series.RefreshXAxis<CategoryDateTimeXAxis>(this); series.RefreshYAxis <NumericYAxis>(this); } } } // make only one axis labels pane visible. if (Axes.Any(axis => axis is CategoryXAxis)) { Axes.Last().LabelSettings.Visibility = this.AxisCategoryXVisibility; } //if (Axes.Where(axis => axis is CategoryDateTimeXAxis).Count() > 0) //{ // Axes.Last().LabelSettings.Visibility = Visibility.Visible; //} #endregion } // hover interaction layers if (this.SelectedChartType == StockChartType.Area || this.SelectedChartType == StockChartType.StepArea || this.SelectedChartType == StockChartType.RangeArea || this.SelectedChartType == StockChartType.Line) { var itemHighlightLayer = new CategoryItemHighlightLayer(); itemHighlightLayer.MarkerTemplate = Application.Current.Resources["ItemHighlightMarkerTemplate"] as DataTemplate; itemHighlightLayer.TransitionDuration = TimeSpan.FromMilliseconds(500); itemHighlightLayer.UseInterpolation = false; Canvas.SetZIndex(itemHighlightLayer, 10002); Series.Add(itemHighlightLayer); } var crosshairLayer = new CrosshairLayer(); crosshairLayer.UseInterpolation = false; crosshairLayer.TransitionDuration = TimeSpan.FromMilliseconds(500); Canvas.SetZIndex(crosshairLayer, 10001); Series.Add(crosshairLayer); var itemTooltipLayer = new ItemToolTipLayer() { TransitionDuration = TimeSpan.FromMilliseconds(500), UseInterpolation = false }; itemTooltipLayer.ToolTipStyle = Application.Current.Resources["SeriesToolTipStyle"] as Style; Canvas.SetZIndex(itemTooltipLayer, 10003); Series.Add(itemTooltipLayer); DebugManager.Time("DataChartEx.OnSeriesSourceChanged"); // TODO Listen for INotifyCollectionChanged with a weak event pattern }