private void FillChart(string titleSeries, string titleY, ISeriesView series, IList <string> label, int step) { this.chart.Series.Clear(); this.chart.AxisX.Clear(); this.chart.AxisY.Clear(); this.chart.Series = new SeriesCollection { series }; this.chart.AxisX.Add(new Axis { Labels = label, LabelsRotation = 15, Separator = new Separator { Step = step, IsEnabled = true //disable it to make it invisible. } }); this.chart.AxisY.Add(new Axis { Title = titleY, LabelFormatter = value => value.ToString("N0"), MinValue = 0 }); this.chart.LegendLocation = LegendLocation.Top; this.chart.Zoom = ZoomingOptions.X; }
/// <summary>Attach the model and view to this presenter.</summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.series = model as Series; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; intellisense = new IntellisensePresenter(seriesView as ViewBase); intellisense.ItemSelected += OnIntellisenseItemSelected; Graph parentGraph = series.FindAncestor <Graph>(); if (parentGraph != null) { try { GraphPresenter = new GraphPresenter(); explorerPresenter.ApsimXFile.Links.Resolve(GraphPresenter); GraphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } } try { PopulateView(); } catch (Exception err) { explorerPresenter.MainPresenter.ShowError(err); } ConnectViewEvents(); }
/// <summary> /// Возвращает индекс ближайшего по времени элемента(меньшего чем заданный в graphpt) /// </summary> /// <param name="series">Где искать</param> /// <param name="graphpt">Время в Graph</param> /// <returns></returns> private int findClosestFitInSeries(ISeriesView series, long ticks) { IEnumerable <DateModel> arr = series.Values.Cast <DateModel>(); int end = arr.Count() - 1; int beg = 0; int currMid = (end + beg) / 2; while (true) { long currTick = arr.ElementAt(currMid).DateTime.Ticks; if (currTick == ticks) { return(currMid); } else if (end - beg == 1) // максимальное приближение сейчас { if (currTick > ticks) { return(currMid - 1); } return(currMid); } else if (currTick > ticks) { end = currMid; currMid = (end + beg) / 2; } else { beg = currMid; currMid = (end + beg) / 2; } } }
/// <summary> /// Initializes a new instance of the <see cref="StackedAreaAlgorithm"/> class. /// </summary> /// <param name="view">The view.</param> public StackedAreaAlgorithm(ISeriesView view) : base(view) { SeriesOrientation = SeriesOrientation.Horizontal; _stackModelable = (IStackModelableSeriesView)view; PreferredSelectionMode = TooltipSelectionMode.SharedXValues; }
/// <summary> /// Initializes a new instance of the <see cref="StackedRowAlgorithm"/> class. /// </summary> /// <param name="view">The view.</param> public StackedRowAlgorithm(ISeriesView view) : base(view) { SeriesOrientation = SeriesOrientation.Vertical; _stackModelable = (IStackModelableSeriesView) view; PreferredSelectionMode = TooltipSelectionMode.SharedYValues; }
/// <summary> /// Collects the unnecessary values /// </summary> public void CollectGarbage(ISeriesView seriesView) { #if NET40 var isclass = typeof(T).IsClass; #endif #if NET45 var isclass = typeof(T).GetTypeInfo().IsClass; #endif var tracker = GetTracker(seriesView); foreach (var garbage in GetGarbagePoints(seriesView).ToList()) { if (garbage.View != null) //yes null, double.Nan Values, will generate null views. { garbage.View.RemoveFromView(seriesView.Model.Chart); } if (!isclass) { tracker.Indexed.Remove(garbage.Key); } else { tracker.Referenced.Remove(garbage.Instance); } } }
private IEnumerable <ChartPoint> GetGarbagePoints(ISeriesView view) { var tracker = GetTracker(view); return(tracker.Indexed.Values.Where(x => IsGarbage(x, tracker)).Concat( tracker.Referenced.Values.Where(x => IsGarbage(x, tracker)))); }
private IEnumerable <ISeriesView> BuildDetailsPieSeries(ReportUnit parentReportUnit, ISeriesView parentSeries, int valueIndex, int valuesCount) { var result = new List <ISeriesView>(); foreach (var reportUnit in parentReportUnit.Detailing) { ISeriesView series = null; // if detailing report unit category is different create new series else continue parent series if (reportUnit.CategoryId != parentReportUnit.CategoryId) { series = BuildSeries <MCPieSeries>(reportUnit, valueIndex, valuesCount); result.Add(series); } else { series = parentSeries; series.Values[valueIndex] = reportUnit; } // build series for every detailed report unit as new level (next value index) if (reportUnit.Detailing.Count > 0) { result.AddRange(BuildDetailsPieSeries(reportUnit, series, valueIndex + 1, valuesCount)); } } return(result); }
public void Autoscale(ISeriesView series) { //AxisX.MinValue = series.ActualValues.GetPoints(series).Select(x => x.X).Min(); //AxisX.MaxValue = series.ActualValues.GetPoints(series).Select(x => x.X).Max(); AxisY.MinValue = series.ActualValues.GetPoints(series).Select(x => x.Y).Min() - 1; AxisY.MaxValue = series.ActualValues.GetPoints(series).Select(x => x.Y).Max() + 1; }
private void InitializeSeriesParams(ISeriesView seriesView) { Chart.View.EnsureElementBelongsToCurrentView(seriesView); seriesView.Model.Chart = Chart; seriesView.Values.Series = seriesView.Model; seriesView.Model.SeriesCollection = Chart.View.Series; seriesView.Model.SeriesCollection.Chart = Chart; }
private void ChartOnDataClick(object sender, ChartPoint point) { if (point == null) { return; } _selectedSeries = SeriesCollection.First(x => x.Title == point.SeriesView.Title); _selectedPointIndex = ((ServoPoint)point.Instance).Index; }
/// <summary> /// Gets the current chart points in the view, the view is required as an argument, because an instance of IChartValues could hold many ISeriesView instances. /// </summary> /// <param name="seriesView">The series view</param> /// <returns></returns> public IEnumerable <ChartPoint> GetPoints(ISeriesView seriesView) { if (seriesView == null) { yield break; } var config = GetConfig(seriesView); var isClass = typeof(T).GetTypeInfo().IsClass; var isObservable = isClass && typeof(IObservableChartPoint).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()); var notifies = isClass && typeof(INotifyPropertyChanged).GetTypeInfo() .IsAssignableFrom(typeof(T).GetTypeInfo()); var tracker = GetTracker(seriesView); var gci = tracker.Gci; var index = 0; foreach (var value in this) { if (isObservable) { var observable = (IObservableChartPoint)value; if (observable != null) { observable.PointChanged -= ObservableOnPointChanged; observable.PointChanged += ObservableOnPointChanged; } } if (notifies) { var notify = (INotifyPropertyChanged)value; if (notify != null) { notify.PropertyChanged -= NotifyOnPropertyChanged; notify.PropertyChanged += NotifyOnPropertyChanged; } } var cp = GetChartPoint(isClass, tracker, index, value); cp.Gci = gci; cp.Instance = value; cp.Key = index; cp.SeriesView = seriesView; config.Evaluate(index, value, cp); index++; yield return(cp); } }
/// <summary> /// Maps a series view to a collection of series. /// </summary> /// <param name="series">The series view to map to a collection of series.</param> /// <returns>The collection of series mapped from the series view.</returns> /// <exception cref="ArgumentNullException">Thrown when series is null.</exception> public static SeriesCollection AsSeriesCollection(this ISeriesView series) { if (series == null) { throw new ArgumentNullException(nameof(series)); } return(new SeriesCollection { series }); }
private void InitializeSeriesParams(ISeriesView seriesView) { if (!seriesView.IsInVisualTree) { Chart.View.AddToView(seriesView); } seriesView.Model.Chart = Chart; seriesView.Values.Series = seriesView.Model; seriesView.Model.SeriesCollection = Chart.View.Series; seriesView.Model.SeriesCollection.Chart = Chart; }
/// <summary> /// Attach the model and view to this presenter. /// </summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.graph = model as Graph; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; this.dataStore = graph.DataStore; // Populate the series names. PopulateSeriesNames(); this.explorerPresenter.CommandHistory.ModelChanged += this.OnGraphModelChanged2; }
/// <summary> /// Gets series that owns the values /// </summary> /// <param name="view"></param> /// <returns></returns> public PointTracker GetTracker(ISeriesView view) { PointTracker tracker; if (Trackers.TryGetValue(view, out tracker)) { return(tracker); } tracker = new PointTracker(); Trackers[view] = tracker; return(tracker); }
/// <summary> /// Gets the current chart points in the view, the view is required as an argument, because an instance of IChartValues could hold many ISeriesView instances. /// </summary> /// <param name="seriesView">The series view</param> /// <returns></returns> public IEnumerable <ChartPoint> GetPoints(ISeriesView seriesView) { if (seriesView == null) { yield break; } var config = GetConfig(seriesView); #if NET40 var isClass = typeof(T).IsClass; var isObservable = isClass && typeof(IObservableChartPoint).IsAssignableFrom(typeof(T)); #endif #if NET45 var isClass = typeof(T).GetTypeInfo().IsClass; var isObservable = isClass && typeof(IObservableChartPoint).GetTypeInfo().IsAssignableFrom(typeof(T).GetTypeInfo()); #endif var tracker = GetTracker(seriesView); var gci = tracker.Gci; var source = this.ToList(); //copy it, to prevent async issues for (var index = 0; index < source.Count; index++) { var value = source[index]; if (isObservable) { var observable = (IObservableChartPoint)value; if (observable != null) { observable.PointChanged -= ObservableOnPointChanged; observable.PointChanged += ObservableOnPointChanged; } } var cp = GetChartPoint(isClass, tracker, index, value); cp.Gci = gci; cp.Instance = value; cp.Key = index; cp.SeriesView = seriesView; config.Evaluate(index, value, cp); yield return(cp); } }
private void ValidateGarbageCollector(ISeriesView view) { var tracker = GetTracker(view); if (tracker.Gci != int.MaxValue) { return; } tracker.Gci = 0; foreach (var point in tracker.Indexed.Values.Concat(tracker.Referenced.Values)) { point.Gci = 0; } }
public void UpdateSeries(ISeriesView targetSeries, SeriesDefinition sourceSeries) { // Detect the data resolution of the source series. // Use it as chart resolution if needed. var detectedResolution = DetectResolution(sourceSeries); if (_view.Resolution > detectedResolution) { _view.Resolution = detectedResolution; } // QuantChart series are unix timestamp switch (sourceSeries.SeriesType) { case SeriesType.Scatter: case SeriesType.Bar: case SeriesType.Line: var existingCommonValues = (GearedValues <InstantChartPoint>)(targetSeries.Values ?? (targetSeries.Values = new GearedValues <InstantChartPoint>())); existingCommonValues.AddRange(sourceSeries.Values); break; case SeriesType.Candle: // Build daily candles var existingCandleValues = (ChartValues <OhlcInstantChartPoint>)(targetSeries.Values ?? (targetSeries.Values = new ChartValues <OhlcInstantChartPoint>())); var newValues = sourceSeries.Values.GroupBy(cp => Instant.MaxValue.Minus(cp.X).Days).Select( g => { return(new OhlcInstantChartPoint { X = g.First().X, Open = (double)g.First().Y, Close = (double)g.Last().Y, Low = (double)g.Min(z => z.Y), High = (double)g.Max(z => z.Y) }); }).ToList(); // Update existing ohlc points. UpdateExistingOhlcPoints(existingCandleValues, newValues, Resolution.Daily); existingCandleValues.AddRange(newValues); break; default: throw new Exception($"SeriesType {sourceSeries.SeriesType} is not supported."); } }
/// <summary> /// Attach the model and view to this presenter. /// </summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.series = model as Series; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; Graph parentGraph = Apsim.Parent(series, typeof(Graph)) as Graph; if (parentGraph != null) { graphPresenter = new GraphPresenter(); graphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter); } PopulateView(); ConnectViewEvents(); }
private void UpdateSeries(ISeriesView series, QuantChartSeries qSeries) { var detectedResolution = DetectResolution(qSeries); if (Resolution > detectedResolution) { Resolution = detectedResolution; } // QuantChart series are unix timestamp switch (qSeries.SeriesType) { case SeriesType.Line: var existingLineValues = (GearedValues <TimeStampChartPoint>)(series.Values ?? (series.Values = new GearedValues <TimeStampChartPoint>())); existingLineValues.AddRange(qSeries.Values.Select(cp => cp.ToTimeStampChartPoint())); // Update range break; case SeriesType.Bar: var existingBarValues = (GearedValues <TimeStampChartPoint>)(series.Values ?? (series.Values = new GearedValues <TimeStampChartPoint>())); existingBarValues.AddRange(qSeries.Values.Select(cp => cp.ToTimeStampChartPoint())); break; case SeriesType.Candle: // Build daily candles // TODO: Candle allows for custom resolution var existingCandleValues = (GearedValues <TimeStampOhlcChartPoint>)(series.Values ?? (series.Values = new GearedValues <TimeStampOhlcChartPoint>())); var newValues = qSeries.Values.Select(cp => cp.ToTimeStampChartPoint()).GroupBy(cp => cp.X).Select( g => { return(new TimeStampOhlcChartPoint { X = g.First().X, Open = (double)g.First().Y, Close = (double)g.Last().Y, Low = (double)g.Min(z => z.Y), High = (double)g.Max(z => z.Y) }); }); existingCandleValues.AddRange(newValues); break; } }
/// <summary> /// Attach the model and view to this presenter. /// </summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.series = model as Series; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; Graph parentGraph = Apsim.Parent(series, typeof(Graph)) as Graph; if (parentGraph != null) { graphPresenter = new GraphPresenter(); graphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter); } PopulateView(); ConnectViewEvents(); }
private void ChartMouseMove(object sender, MouseEventArgs e) { if (e.LeftButton != MouseButtonState.Pressed) { _selectedSeries = null; _selectedPointIndex = -1; Mouse.OverrideCursor = null; return; } Mouse.OverrideCursor = Cursors.Hand; Point point = Chart.ConvertToChartValues(e.GetPosition(Chart)); if (_selectedSeries != null) { SetNewValue(point); } }
/// <summary> /// Gets the closest chart point with a given value. /// </summary> /// <param name="series">The target series.</param> /// <param name="value">The value.</param> /// <param name="orientation">the axis orientation</param> /// <returns></returns> public static ChartPoint ClosestPointTo(this ISeriesView series, double value, AxisOrientation orientation) { ChartPoint t = null; var delta = double.PositiveInfinity; foreach (var point in series.Values.GetPoints(series)) { var i = orientation == AxisOrientation.X ? point.X : point.Y; var di = Math.Abs(i - value); if (di < delta) { t = point; delta = di; } } return(t); }
/// <summary>Attach the model and view to this presenter.</summary> /// <param name="model">The graph model to work with</param> /// <param name="view">The series view to work with</param> /// <param name="explorerPresenter">The parent explorer presenter</param> public void Attach(object model, object view, ExplorerPresenter explorerPresenter) { this.series = model as Series; this.seriesView = view as SeriesView; this.explorerPresenter = explorerPresenter; intellisense = new IntellisensePresenter(seriesView as ViewBase); intellisense.ItemSelected += OnIntellisenseItemSelected; Graph parentGraph = Apsim.Parent(series, typeof(Graph)) as Graph; if (parentGraph != null) { graphPresenter = new GraphPresenter(); explorerPresenter.ApsimXFile.Links.Resolve(graphPresenter); graphPresenter.Attach(parentGraph, seriesView.GraphView, explorerPresenter); } PopulateView(); ConnectViewEvents(); }
private IPointEvaluator <T> GetConfig(ISeriesView view) { //Trying to get the user defined configuration... //series == null means that chart values are null, and LiveCharts //could not set the Series Instance tho the current chart values... if (view == null || view.Model.SeriesCollection == null) { return(null); } var config = (view.Configuration ?? view.Model.SeriesCollection.Configuration) as IPointEvaluator <T>; if (config != null) { return(config); } return(DefaultConfiguration ?? (DefaultConfiguration = ChartCore.Configurations.GetConfig <T>(view.Model.SeriesOrientation) as IPointEvaluator <T>)); }
public RowAlgorithm(ISeriesView view) : base(view) { SeriesOrientation = SeriesOrientation.Vertical; PreferredSelectionMode = TooltipSelectionMode.SharedYInSeries; }
private void InitializeSeriesView(ISeriesView seriesView) { Chart.View.EnsureElementBelongsToCurrentView(seriesView); }
public BubbleAlgorithm(ISeriesView view) : base(view) { PreferredSelectionMode = TooltipSelectionMode.OnlySender; }
public PieAlgorithm(ISeriesView view) : base(view) { }
/// <summary> /// Initializes the garbage collector /// </summary> public void InitializeStep(ISeriesView series) { ValidateGarbageCollector(series); GetTracker(series).Gci++; }
/// <summary> /// Initializes a new instance of the <see cref="RowAlgorithm"/> class. /// </summary> /// <param name="view">The view.</param> public RowAlgorithm(ISeriesView view) : base(view) { SeriesOrientation = SeriesOrientation.Vertical; PreferredSelectionMode = TooltipSelectionMode.SharedYInSeries; }
public HeatAlgorithm(ISeriesView view) : base(view) { PreferredSelectionMode = TooltipSelectionMode.OnlySender; }
/// <summary> /// Initializes a new instance of the <see cref="SeriesAlgorithm"/> class. /// </summary> /// <param name="view">The view.</param> protected SeriesAlgorithm(ISeriesView view) { View = view; }
/// <summary> /// Initializes a new instance of the <see cref="PieAlgorithm"/> class. /// </summary> /// <param name="view">The view.</param> public PieAlgorithm(ISeriesView view) : base(view) { PreferredSelectionMode= TooltipSelectionMode.SharedXValues; }
/// <summary> /// Evaluates the limits in the chart values /// </summary> public void Initialize(ISeriesView seriesView) { var config = GetConfig(seriesView); if (config == null) { return; } var xMin = double.PositiveInfinity; var xMax = double.NegativeInfinity; var yMin = double.PositiveInfinity; var yMax = double.NegativeInfinity; var wMin = double.PositiveInfinity; var wMax = double.NegativeInfinity; var tracker = GetTracker(seriesView); var cp = new ChartPoint(); var ax = seriesView.Model.Chart.AxisX[seriesView.ScalesXAt]; var ay = seriesView.Model.Chart.AxisY[seriesView.ScalesYAt]; double fx = double.IsNaN(ax.MinValue) ? double.NegativeInfinity : ax.MinValue, tx = double.IsNaN(ax.MaxValue) ? double.PositiveInfinity : ax.MaxValue, fy = double.IsNaN(ay.MinValue) ? double.NegativeInfinity : ay.MinValue, ty = double.IsNaN(ay.MaxValue) ? double.PositiveInfinity : ay.MaxValue; var isHorizontal = seriesView.Model.SeriesOrientation == SeriesOrientation.Horizontal; var index = 0; foreach (var item in this) { config.Evaluate(index, item, cp); index++; if (isHorizontal) { if (cp.X < fx || cp.X > tx) { continue; } } else { if (cp.Y < fy || cp.Y > ty) { continue; } } if (seriesView is IFinancialSeriesView) { if (cp.X < xMin) { xMin = cp.X; } if (cp.X > xMax) { xMax = cp.X; } if (cp.Low < yMin) { yMin = cp.Low; } if (cp.High > yMax) { yMax = cp.High; } if (cp.Weight < wMin) { wMin = cp.Weight; } if (cp.Weight > wMax) { wMax = cp.Weight; } } else if (seriesView is IScatterSeriesView || seriesView is IHeatSeriesView) { if (cp.X < xMin) { xMin = cp.X; } if (cp.X > xMax) { xMax = cp.X; } if (cp.Y < yMin) { yMin = cp.Y; } if (cp.Y > yMax) { yMax = cp.Y; } if (cp.Weight < wMin) { wMin = cp.Weight; } if (cp.Weight > wMax) { wMax = cp.Weight; } } else { if (cp.X < xMin) { xMin = cp.X; } if (cp.X > xMax) { xMax = cp.X; } if (cp.Y < yMin) { yMin = cp.Y; } if (cp.Y > yMax) { yMax = cp.Y; } } } tracker.XLimit = new CoreLimit(double.IsInfinity(xMin) ? 0 : xMin, double.IsInfinity(yMin) ? 1 : xMax); tracker.YLimit = new CoreLimit(double.IsInfinity(yMin) ? 0 : yMin, double.IsInfinity(yMax) ? 1 : yMax); tracker.WLimit = new CoreLimit(double.IsInfinity(wMin) ? 0 : wMin, double.IsInfinity(wMax) ? 1 : wMax); }
public ColumnAlgorithm(ISeriesView view) : base(view) { SeriesOrientation = SeriesOrientation.Horizontal; PreferredSelectionMode = TooltipSelectionMode.SharedXValues; }
private void InitializeSeriesParams(ISeriesView seriesView) { Chart.View.EnsureElementBelongsToCurrentView(seriesView); seriesView.Model.Chart = Chart; if (seriesView.Values != null) seriesView.Values.Series = seriesView.Model; seriesView.Model.SeriesCollection = Chart.View.Series; seriesView.Model.SeriesCollection.Chart = Chart; }
public StackedRowAlgorithm(ISeriesView view) : base(view) { SeriesOrientation = SeriesOrientation.Vertical; _stackModelable = (IStackModelableSeriesView)view; PreferredSelectionMode = TooltipSelectionMode.SharedYValues; }
public ColumnAlgorithm(ISeriesView view) : base(view) { SeriesOrientation = SeriesOrientation.Horizontal; PreferredSelectionMode = TooltipSelectionMode.SharedXValues; }