using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

using C1.Silverlight.Chart;
using C1.Silverlight.Chart.Extended;

namespace ChartExtended.Samples
{
  public partial class Functions : UserControl
  {
    YFunctionSeries ds;
    
    public Functions()
    {
      InitializeComponent();

      chart.ChartType = ChartType.Line;
      tbCode.Text = "Math.sin(4*val)*Math.cos(3*val)";
      chart.Data.Children.Add(new YFunctionSeries() 
      {
        FunctionCode = tbCode.Text,
        Min = -10,
        Max = 10,
        SampleCount=300,
      });

      tbCode.TextChanged += (s, e) =>
        {
          error.Visibility = Visibility.Collapsed;
        };
    }

    private void btnApply_Click(object sender, RoutedEventArgs e)
    {
      chart.Data.Children.Clear();

      ds = new YFunctionSeries()
      {
        Min = -10,
        Max = 10,
        FunctionCode = tbCode.Text,
        SampleCount=300
      };

      if (!string.IsNullOrEmpty(ds.FunctionCodeError))
      {
        error.Visibility = Visibility.Visible;
        ToolTipService.SetToolTip(error, ds.FunctionCodeError);
      }

      chart.Data.Children.Add(ds);
    }

    private void btnSample1_Click(object sender, RoutedEventArgs e)
    {
      tbCode.Text = "Math.sin(val)";
    }

    private void btnSample2_Click(object sender, RoutedEventArgs e)
    {
      tbCode.Text = "if (val > 0) return val * val; else return -val * val;";
    }
  }
}
