Exemplo n.º 1
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);
            }

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

            Debug.WriteLine("LiveUpdate terminating on schema item " + schema.Name);
        }
Exemplo n.º 2
0
 private void InitializeChartData(LogItemSchema schema, SimpleLineChart chart, List <DataValue> values)
 {
     chart.SetData(new Model.DataSeries()
     {
         Name   = schema.Name,
         Values = values
     });
 }
Exemplo n.º 3
0
        private void OnChartClosed(object sender, EventArgs e)
        {
            SimpleLineChart chart = sender as SimpleLineChart;

            ChartStack.RemoveChart(chart);
            chart.LiveScrolling = false;
            liveScrolling.Remove(chart);
            LayoutCharts();

            LogItemSchema item = (chart.Tag as LogItemSchema);

            if (item != null)
            {
                UnselectCategory(item);
            }
        }
Exemplo n.º 4
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       = 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;
                    // the X values are in microseconds (s0 the numerator is the speed of scrolling).
                    chart.LiveScrollingXScale = 50.0 / 1000000.0;

                    liveScrolling.Add(chart);

                    // 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));
                    if (values.Count > 0)
                    {
                        InitializeChartData(schema, chart, values);
                    }
                    else
                    {
                        chart = null;
                    }
                    ShowStatus(string.Format("Found {0} data values", values.Count));
                }

                if (chart != null)
                {
                    if (chartGroup != null)
                    {
                        chartGroup.AddChart(chart);
                        if (chartGroup.Parent == null)
                        {
                            ChartStack.AddChartGroup(chartGroup);
                        }
                    }
                    else
                    {
                        ChartStack.AddChart(chart);
                    }
                    LayoutCharts();
                }

                ConsoleButton.IsChecked = false;
                SystemConsole.Hide();
            }
            else
            {
                StringBuilder sb = new StringBuilder();
                foreach (var value in GetSelectedDataValues(schema))
                {
                    sb.AppendLine(value.Label);
                }

                SystemConsole.Write(sb.ToString());
                ConsoleButton.IsChecked = true;
                SystemConsole.Show();
            }
        }