Inheritance: System.Windows.Controls.UserControl
Ejemplo n.º 1
0
        internal bool ComputeScale(SimpleLineChart trigger)
        {
            bool           changed  = false;
            ChartScaleInfo combined = null;

            int index = this.scaleIndex;

            // make sure they are all up to date.
            foreach (var ptr in FindCharts())
            {
                ChartScaleInfo info = ptr.ComputeScaleSelf(index);
                if (combined == null)
                {
                    combined = info;
                }
                else
                {
                    combined.Combine(info);
                }
            }

            foreach (var ptr in FindCharts())
            {
                if (ptr.ApplyScale(combined))
                {
                    if (ptr != trigger)
                    {
                        ptr.DelayedUpdate();
                    }
                    changed = true;
                }
            }
            return(changed);
        }
Ejemplo n.º 2
0
        private static void FixNextPointers(Grid group)
        {
            // fix up the "next" pointers for removed chart.
            SimpleLineChart first    = null;
            SimpleLineChart previous = null;

            foreach (UIElement f in group.Children)
            {
                SimpleLineChart chart = f as SimpleLineChart;
                if (chart != null)
                {
                    if (first == null)
                    {
                        first      = chart;
                        chart.Next = null;
                    }
                    else
                    {
                        previous.Next = chart;
                        chart.Next    = first;
                    }
                    previous = chart;
                }
            }
            foreach (UIElement f in group.Children)
            {
                SimpleLineChart chart = f as SimpleLineChart;
                if (chart != null)
                {
                    chart.InvalidateArrange();
                }
            }
        }
Ejemplo n.º 3
0
 public void RemoveChart(SimpleLineChart e)
 {
     if (e.Parent == theStack)
     {
         theStack.Children.Remove(e);
     }
     else if (e.Parent is Grid)
     {
         // it's a chart group then.
         Grid group = (Grid)e.Parent;
         group.Children.Remove(e);
         SimpleLineChart chart = e as SimpleLineChart;
         if (chart != null)
         {
             chart.Next = null;
         }
         if (group.Children.Count == 0)
         {
             theStack.Children.Remove(group);
         }
         else
         {
             FixNextPointers(group);
         }
     }
 }
Ejemplo n.º 4
0
        public IEnumerable <SimpleLineChart> FindCharts()
        {
            List <SimpleLineChart> result = new List <SimpleLineChart>();

            foreach (UIElement f in this.Children)
            {
                SimpleLineChart chart = f as SimpleLineChart;
                if (chart != null)
                {
                    result.Add(chart);
                }
            }
            return(result);
        }
Ejemplo n.º 5
0
 public IEnumerable <SimpleLineChart> FindCharts()
 {
     foreach (UIElement e in Snapshot(theStack.Children))
     {
         SimpleLineChart chart = e as SimpleLineChart;
         if (chart != null)
         {
             yield return(chart);
         }
         ChartGroup group = e as ChartGroup;
         if (group != null)
         {
             foreach (SimpleLineChart child in group.FindCharts())
             {
                 yield return(child);
             }
         }
     }
 }
Ejemplo n.º 6
0
 public void RemoveChart(SimpleLineChart e)
 {
     if (e.Parent == theStack)
     {
         theStack.Children.Remove(e);
     }
     else if (e.Parent is ChartGroup)
     {
         // it's a chart group then.
         ChartGroup group = (ChartGroup)e.Parent;
         group.Children.Remove(e);
         SimpleLineChart chart = e as SimpleLineChart;
         if (chart != null)
         {
             chart.Group = null;
         }
         if (group.Children.Count == 0)
         {
             theStack.Children.Remove(group);
         }
         group.InvalidateCharts();
     }
 }
Ejemplo n.º 7
0
 public IEnumerable <SimpleLineChart> FindCharts()
 {
     foreach (UIElement e in Snapshot(theStack.Children))
     {
         SimpleLineChart chart = e as SimpleLineChart;
         if (chart != null)
         {
             yield return(chart);
         }
         Grid group = e as Grid;
         if (group != null)
         {
             foreach (UIElement f in Snapshot(group.Children))
             {
                 chart = f as SimpleLineChart;
                 if (chart != null)
                 {
                     yield return(chart);
                 }
             }
         }
     }
 }
Ejemplo n.º 8
0
 internal void AddChart(SimpleLineChart chart)
 {
     this.Children.Add(chart);
     chart.Group = this;
     InvalidateCharts();
 }
Ejemplo n.º 9
0
        private void LiveUpdate(SimpleLineChart chart, MavlinkLog currentFlightLog, LogItemSchema schema)
        {
            // this method is running on a background task and it's job is to read an infinite stream of
            // data values from the log and show them in the live scrolling chart.

            CancellationTokenSource canceller = new CancellationTokenSource();

            chart.Closed += (s,e) =>
            {
                canceller.Cancel();
            };

            var query = currentFlightLog.LiveQuery(schema, canceller.Token);
            foreach (DataValue item in query)
            {
                if (item == null)
                {
                    return;
                }
                chart.SetCurrentValue(item);
            }
        }
Ejemplo n.º 10
0
        // bugbug: should concatenate data from selected logs - then sort by X...
        // bugbug: give them unique X values that are smooth over time.  Alternatively we could
        // give the entry Timestamp, but that seems to bunch up the values, so timeclock is not
        // updating smoothly for some reason...

        private void InitializeChartData(LogItemSchema schema, SimpleLineChart chart, List<DataValue> values)
        {
            int x = 0;
            foreach (var d in values)
            {
                d.X = x++;
            }
            chart.SetData(new Model.DataSeries()
            {
                Name = schema.Name,
                Values = values
            });
        }
Ejemplo n.º 11
0
        private void GraphItem(LogItemSchema schema)
        {
            if (schema.IsNumeric)
            {
                ChartStack.Visibility = Visibility.Visible;
                ChartStack.UpdateLayout();
                SimpleLineChart chart = new SimpleLineChart();
                chart.Margin = defaultChartMargin;
                chart.Focusable = false;
                chart.Closed += OnChartClosed;
                chart.LineColor = HlsColor.GetRandomColor();
                chart.StrokeThickness = 1;
                chart.Tag = schema;

                if (currentFlightLog != null && schema.Root == currentFlightLog.Schema)
                {
                    List<DataValue> values = new List<DataValue>(currentFlightLog.GetDataValues(schema, DateTime.MinValue, TimeSpan.MaxValue)); 
                    InitializeChartData(schema, chart, values);

                    // now turn on live scrolling...
                    chart.LiveScrolling = true;

                    // now start watching the live update for new values that need to be added to this chart.
                    Task.Run(() =>
                    {
                        LiveUpdate(chart, currentFlightLog, schema);
                    });

                }
                else
                {
                    List<DataValue> values = new List<DataValue>(GetSelectedDataValues(schema));
                    InitializeChartData(schema, chart, values);
                }

                if (chartGroup != null)
                {
                    SimpleLineChart last = null;
                    if (chartGroup.Children.Count > 0)
                    {
                        last = chartGroup.Children[chartGroup.Children.Count - 1] as SimpleLineChart;
                    }
                    chartGroup.Children.Add(chart);
                    if (chartGroup.Parent == null)
                    {
                        ChartStack.AddChart(chartGroup);
                    }
                    if (last != null)
                    {
                        last.Next = chart;
                    }
                }
                else
                {
                    ChartStack.AddChart(chart);
                }
                LayoutCharts();

                Messages.Visibility = Visibility.Collapsed;
            }
            else
            {
                Paragraph p = new Paragraph();
                foreach (var value in GetSelectedDataValues(schema))
                {
                    p.Inlines.Add(new Run(value.Label));
                    p.Inlines.Add(new LineBreak());
                }
                var doc = Messages.Document;
                doc.Blocks.Add(p);

                Messages.Visibility = Visibility.Visible;
                Messages.Focus();
            }
        }
Ejemplo n.º 12
0
 public void AddChart(SimpleLineChart chart)
 {
     theStack.Children.Add(chart);
 }