|
| 1 | +using Syncfusion.Maui.TreeMap; |
| 2 | + |
| 3 | +namespace TreeMapChart |
| 4 | +{ |
| 5 | + public partial class MainPage : ContentPage |
| 6 | + { |
| 7 | + private readonly ViewModel _viewModel; |
| 8 | + |
| 9 | + public MainPage() |
| 10 | + { |
| 11 | + InitializeComponent(); |
| 12 | + _viewModel = new ViewModel(); |
| 13 | + this.BindingContext = _viewModel; |
| 14 | + |
| 15 | + treeMapChart.LeafItemBrushSettings = new TreeMapPaletteBrushSettings() |
| 16 | + { |
| 17 | + Brushes = new List<Brush>() |
| 18 | + { |
| 19 | + new SolidColorBrush(Color.FromArgb("#FFB100")), |
| 20 | + new SolidColorBrush(Color.FromArgb("#1E90FF")), |
| 21 | + new SolidColorBrush(Color.FromArgb("#800000")), |
| 22 | + new SolidColorBrush(Color.FromArgb("#006600")), |
| 23 | + new SolidColorBrush(Color.FromArgb("#35CAFE")), |
| 24 | + new SolidColorBrush(Color.FromArgb("#0033A0")), |
| 25 | + new SolidColorBrush(Color.FromArgb("#2F4F4F")), |
| 26 | + new SolidColorBrush(Color.FromArgb("#228B22")), |
| 27 | + } |
| 28 | + }; |
| 29 | + } |
| 30 | + |
| 31 | + private void TreeMapChart_SelectionChanged(object sender, TreeMapSelectionChangedEventArgs e) |
| 32 | + { |
| 33 | + if (sender is SfTreeMap treeMap) |
| 34 | + { |
| 35 | + // Retrieve the selected item's country name |
| 36 | + string? selectedCountry = treeMap.SelectedItems.FirstOrDefault()?.PrimaryValueText; |
| 37 | + |
| 38 | + if (selectedCountry != null) |
| 39 | + { |
| 40 | + // Update data based on the selected country |
| 41 | + UpdateDataBasedOnSelection(selectedCountry); |
| 42 | + _viewModel.SelectedCountry = selectedCountry; |
| 43 | + |
| 44 | + // Navigate to DrillDownPage with updated data |
| 45 | + Navigation.PushAsync(new TitleBreakDownPage(_viewModel)); |
| 46 | + } |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + /// <summary> |
| 51 | + /// Updates the ViewModel's data based on the selected country. |
| 52 | + /// </summary> |
| 53 | + /// <param name="country">The selected country.</param> |
| 54 | + private void UpdateDataBasedOnSelection(string country) |
| 55 | + { |
| 56 | + _viewModel.SelectedCountryTotalTitles = country switch |
| 57 | + { |
| 58 | + "Australia" => 10, |
| 59 | + "India" => 7, |
| 60 | + "England" => 3, |
| 61 | + "West Indies" => 5, |
| 62 | + "Pakistan" => 3, |
| 63 | + "Sri Lanka" => 3, |
| 64 | + "South Africa" => 2, |
| 65 | + "New Zealand" => 2, |
| 66 | + _ => 0 |
| 67 | + }; |
| 68 | + |
| 69 | + _viewModel.SelectedCountryDetails = country switch |
| 70 | + { |
| 71 | + "Australia" => |
| 72 | + [ |
| 73 | + new() { Category = "ODI World Cups", Titles = 6 }, |
| 74 | + new() { Category = "Champions Trophies", Titles = 2 }, |
| 75 | + new() { Category = "T20 World Cups", Titles = 1 }, |
| 76 | + new() { Category = "WTC", Titles = 1 } |
| 77 | + ], |
| 78 | + "India" => |
| 79 | + [ |
| 80 | + new() { Category = "Champions Trophies", Titles = 3 }, |
| 81 | + new() { Category = "ODI World Cups", Titles = 2 }, |
| 82 | + new() { Category = "T20 World Cups", Titles = 2 }, |
| 83 | + ], |
| 84 | + "England" => |
| 85 | + [ |
| 86 | + new() { Category = "T20 World Cups", Titles = 2 }, |
| 87 | + new() { Category = "ODI World Cups", Titles = 1 }, |
| 88 | + ], |
| 89 | + "West Indies" => |
| 90 | + [ |
| 91 | + new() { Category = "ODI World Cups", Titles = 2 }, |
| 92 | + new() { Category = "T20 World Cups", Titles = 2 }, |
| 93 | + new() { Category = "Champions Trophies", Titles = 1 }, |
| 94 | + ], |
| 95 | + "Pakistan" => |
| 96 | + [ |
| 97 | + new() { Category = "ODI World Cups", Titles = 1 }, |
| 98 | + new() { Category = "T20 World Cups", Titles = 1 }, |
| 99 | + new() { Category = "Champions Trophies", Titles = 1 }, |
| 100 | + ], |
| 101 | + "Sri Lanka" => |
| 102 | + [ |
| 103 | + new() { Category = "ODI World Cups", Titles = 1 }, |
| 104 | + new() { Category = "T20 World Cups", Titles = 1 }, |
| 105 | + new() { Category = "Champions Trophies", Titles = 1 }, |
| 106 | + ], |
| 107 | + "South Africa" => |
| 108 | + [ |
| 109 | + new() { Category = "Champions Trophies", Titles = 1 }, |
| 110 | + new() { Category = "WTC", Titles = 1 } |
| 111 | + ], |
| 112 | + "New Zealand" => |
| 113 | + [ |
| 114 | + new() { Category = "Champions Trophies", Titles = 1 }, |
| 115 | + new() { Category = "WTC", Titles = 1 } |
| 116 | + ], |
| 117 | + _ => throw new NotImplementedException() |
| 118 | + }; |
| 119 | + } |
| 120 | + } |
| 121 | +} |
0 commit comments