summaryrefslogtreecommitdiff
path: root/Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs
diff options
context:
space:
mode:
authorLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
committerLucas Faria Mendes <lucas.fariamo08@gmail.com>2026-03-30 13:38:18 +0000
commit1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1 (patch)
treee1c3b20ea08f0cf71122a1e73f0d395f8fd83874 /Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs
parent674ca83ba9243a9e95a7568c797668dab6aee26a (diff)
downloadgestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.tar.gz
gestor-1f4e14b2e973ee7de337fd4866d9a5ceff5cb6d1.zip
chore: location
Diffstat (limited to 'Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs')
-rw-r--r--Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs140
1 files changed, 140 insertions, 0 deletions
diff --git a/Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs b/Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs
new file mode 100644
index 0000000..ddbff3c
--- /dev/null
+++ b/Codemerx/Gestor.Application/Componentes/CustomLegendChart.cs
@@ -0,0 +1,140 @@
+using LiveCharts.Definitions.Series;
+using LiveCharts.Wpf;
+using LiveCharts.Wpf.Charts.Base;
+using System;
+using System.CodeDom.Compiler;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.Linq;
+using System.Runtime.CompilerServices;
+using System.Threading;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Markup;
+using System.Windows.Media;
+
+namespace Gestor.Application.Componentes
+{
+ public class CustomLegendChart : UserControl, IChartLegend, INotifyPropertyChanged, IComponentConnector
+ {
+ public readonly static DependencyProperty OrientationProperty;
+
+ internal ItemsControl itemsControl;
+
+ private bool _contentLoaded;
+
+ public ObservableCollection<CustomSeriesViewModel> LegendEntries { get; } = new ObservableCollection<CustomSeriesViewModel>();
+
+ public System.Windows.Controls.Orientation Orientation
+ {
+ get
+ {
+ return (System.Windows.Controls.Orientation)base.GetValue(CustomLegendChart.OrientationProperty);
+ }
+ set
+ {
+ base.SetValue(CustomLegendChart.OrientationProperty, value);
+ }
+ }
+
+ public List<SeriesViewModel> Series
+ {
+ get
+ {
+ return (
+ from x in this.LegendEntries
+ select x.SeriesViewModel).ToList<SeriesViewModel>();
+ }
+ set
+ {
+ Chart ownerChart = this.GetOwnerChart();
+ foreach (CustomSeriesViewModel list in (
+ from x in this.LegendEntries
+ where !ownerChart.get_Series().Any<ISeriesView>((ISeriesView s) => (object)s == (object)x.View)
+ select x).ToList<CustomSeriesViewModel>())
+ {
+ this.LegendEntries.Remove(list);
+ }
+ foreach (SeriesViewModel seriesViewModel in value)
+ {
+ if (!this.LegendEntries.All<CustomSeriesViewModel>((CustomSeriesViewModel x) => x.Title != seriesViewModel.get_Title()))
+ {
+ continue;
+ }
+ ISeriesView seriesView = ownerChart.get_Series().FirstOrDefault<ISeriesView>((ISeriesView x) => x.get_Title() == seriesViewModel.get_Title());
+ this.LegendEntries.Add(new CustomSeriesViewModel(seriesViewModel, seriesView));
+ }
+ this.OnPropertyChanged("Series");
+ }
+ }
+
+ static CustomLegendChart()
+ {
+ CustomLegendChart.OrientationProperty = DependencyProperty.Register("Orientation", typeof(System.Windows.Controls.Orientation), typeof(CustomLegendChart), new PropertyMetadata((object)System.Windows.Controls.Orientation.Horizontal));
+ }
+
+ public CustomLegendChart()
+ {
+ this.InitializeComponent();
+ this.itemsControl.DataContext = this;
+ }
+
+ public static T FindParent<T>(DependencyObject child)
+ where T : DependencyObject
+ {
+ DependencyObject parent = VisualTreeHelper.GetParent(child);
+ if (parent == null)
+ {
+ return default(T);
+ }
+ T t = (T)(parent as T);
+ if (t != null)
+ {
+ return t;
+ }
+ return CustomLegendChart.FindParent<T>(parent);
+ }
+
+ private Chart GetOwnerChart()
+ {
+ return CustomLegendChart.FindParent<Chart>(this);
+ }
+
+ [DebuggerNonUserCode]
+ [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
+ public void InitializeComponent()
+ {
+ if (this._contentLoaded)
+ {
+ return;
+ }
+ this._contentLoaded = true;
+ System.Windows.Application.LoadComponent(this, new Uri("/Gestor.Application;component/componentes/customlegendchart.xaml", UriKind.Relative));
+ }
+
+ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = "")
+ {
+ if (this.PropertyChanged != null)
+ {
+ this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
+ }
+ }
+
+ [DebuggerNonUserCode]
+ [EditorBrowsable(EditorBrowsableState.Never)]
+ [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
+ void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
+ {
+ if (connectionId != 1)
+ {
+ this._contentLoaded = true;
+ return;
+ }
+ this.itemsControl = (ItemsControl)target;
+ }
+
+ public event PropertyChangedEventHandler PropertyChanged;
+ }
+} \ No newline at end of file