aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/PPC/Tango.PPC.Common/Converters/SegmentsToPieConverter.cs
blob: 82f9bb7444039af935c7926cb212fc6e8d1ba549 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
using Tango.BL.Entities;
using Tango.PPC.Common.Controls;

namespace Tango.PPC.Common.Converters
{
    public class SegmentsToPieConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ObservableCollection<Segment> segments = value as ObservableCollection<Segment>;

            if (segments != null)
            {
                MultiPieChart pie = new MultiPieChart();

                pie.DataList = new List<Double>();

                if (segments.Count > 0)
                {
                    foreach (var segment in segments)
                    {
                        pie.DataList.Add(segment.Length);
                        pie.DataBrushes.Add(segment.GetSegmentBrush());
                    }
                }
                else
                {
                    pie.DataList.Add(10);
                    pie.DataBrushes.Add(new SolidColorBrush(Colors.Gainsboro));
                }

                return pie;
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}