项目结构调整

This commit is contained in:
艾竹
2023-04-16 20:11:40 +08:00
parent cbfbf96033
commit 81f91f3f35
2124 changed files with 218 additions and 5516 deletions

View File

@@ -0,0 +1,21 @@
using System;
using System.Collections.Generic;
namespace Wpf.PieChart.DropDowns
{
public static class DataProvider
{
public static IEnumerable<double> Values
{
get
{
var r = new Random();
for (var i = 0; i < 30; i++)
{
yield return r.NextDouble() * 100;
}
}
}
}
}

View File

@@ -0,0 +1,31 @@
using System;
using System.Windows.Input;
using LiveCharts;
namespace Wpf.PieChart.DropDowns
{
public class DropDownCommand : ICommand
{
private Action<DropDownPoint> _action;
public DropDownCommand(Action<DropDownPoint> action)
{
_action = action;
}
public void Execute(object parameter)
{
var chartPoint = (ChartPoint) parameter;
var dropDownPoint = (DropDownPoint) chartPoint.Instance;
_action(dropDownPoint);
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
}
}

View File

@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Windows.Media;
using LiveCharts;
using LiveCharts.Helpers;
using LiveCharts.Wpf;
namespace Wpf.PieChart.DropDowns
{
public class DropDownViewModel : INotifyPropertyChanged
{
private SeriesCollection _series;
public DropDownViewModel()
{
var navigation = new List<SeriesCollection>();
var initialValues = DataProvider.Values.ToArray();
Series = GroupSeriesByTheshold(content: initialValues, threshold: initialValues.Max() * .7);
SliceClickCommand = new DropDownCommand(dropDownPoint =>
{
//if the point has no content to display...
if (dropDownPoint.Content.Length == 1) return;
navigation.Add(Series.Select(x => new PieSeries
{
Values = x.Values,
Title = x.Title,
Fill = ((Series) x).Fill
}).AsSeriesCollection());
Series = GroupSeriesByTheshold(content: dropDownPoint.Content, threshold: dropDownPoint.Content.Max() * .7);
});
GoBackCommand = new RelayCommand(() =>
{
if (!navigation.Any())return;
var previous = navigation.Last();
if(previous == null) return;
Series = previous;
navigation.Remove(previous);
});
Formatter = x => x.ToString("N1");
}
public SeriesCollection Series
{
get { return _series; }
set
{
_series = value;
OnPropertyChanged("Series");
}
}
public DropDownCommand SliceClickCommand { get; set; }
public RelayCommand GoBackCommand { get; set; }
public Func<double, string> Formatter { get; set; }
private static SeriesCollection GroupSeriesByTheshold(double[] content, double threshold)
{
var series = content
.Where(x => x > threshold)
.Select((value, index) => new PieSeries
{
Values = new ChartValues<DropDownPoint>
{
new DropDownPoint {Content = new[] {value}}
},
Title = "Series " + index
}).AsSeriesCollection();
var thresholdSeries = new PieSeries
{
Values = new ChartValues<DropDownPoint>
{
new DropDownPoint
{
Content = content.Where(x => x < threshold).ToArray()
}
},
Title = "DropDown Slice",
Fill = new SolidColorBrush(Color.FromRgb(30,30,30)),
PushOut = 5
};
series.Add(thresholdSeries);
return series;
}
#region INotifyPropertyChanged implementation
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
var handler = PropertyChanged;
if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}
}

View File

@@ -0,0 +1,38 @@
<UserControl x:Class="Wpf.PieChart.DropDowns.PieDropDownSample"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:Wpf.PieChart.DropDowns"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<UserControl.DataContext>
<local:DropDownViewModel></local:DropDownViewModel>
</UserControl.DataContext>
<UserControl.Resources>
<Style TargetType="lvc:PieSeries">
<Setter Property="StrokeThickness" Value="0"></Setter>
<Setter Property="DataLabels" Value="True"></Setter>
<Setter Property="LabelPosition" Value="OutsideSlice"></Setter>
<Setter Property="Foreground" Value="#303030"></Setter>
<Setter Property="FontSize" Value="16"></Setter>
</Style>
</UserControl.Resources>
<Grid>
<Button VerticalAlignment="Top" HorizontalAlignment="Left"
Command="{Binding GoBackCommand}">
Go Back
</Button>
<TextBlock VerticalAlignment="Bottom" TextWrapping="Wrap">Click in the black slice to open more content, click back to go to the previous state</TextBlock>
<lvc:PieChart Series="{Binding Series}"
DataClickCommand="{Binding SliceClickCommand}"
Margin="40"
DataTooltip="{x:Null}"
AnimationsSpeed="0:0:0.25">
<lvc:PieChart.AxisY>
<lvc:Axis LabelFormatter="{Binding Formatter}"></lvc:Axis>
</lvc:PieChart.AxisY>
</lvc:PieChart>
</Grid>
</UserControl>

View File

@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace Wpf.PieChart.DropDowns
{
/// <summary>
/// Interaction logic for PieDropDownSample.xaml
/// </summary>
public partial class PieDropDownSample : UserControl
{
public PieDropDownSample()
{
InitializeComponent();
}
}
}

View File

@@ -0,0 +1,52 @@
using System.Linq;
using LiveCharts;
using LiveCharts.Configurations;
namespace Wpf.PieChart.DropDowns
{
public class DropDownPoint
{
static DropDownPoint()
{
//In this case we are plotting our own point to have
//more control over the current plot
//configuring a custom type is quite simple
//first we define a mapper
var mapper = Mappers.Pie<DropDownPoint>()
.Value(x => x.Value);//use the value property in the plot
//then we save the mapper globally, there are many ways
//so configure a series, for more info see:
//https://lvcharts.net/App/examples/v1/wpf/Types%20and%20Configuration
Charting.For<DropDownPoint>(mapper);
}
/// <summary>
/// Gets or sets the value to plot
/// </summary>
/// <value>
/// The value.
/// </value>
public double Value
{
get { return Content.Sum(); }
}
/// <summary>
/// Gets or sets the content, all the values that represent this point
/// </summary>
/// <value>
/// The content.
/// </value>
public double[] Content { get; set; }
/// <summary>
/// Gets or sets the title.
/// </summary>
/// <value>
/// The title.
/// </value>
public double Title { get; set; }
}
}

View File

@@ -0,0 +1,27 @@
using System;
using System.Windows.Input;
namespace Wpf.PieChart.DropDowns
{
public class RelayCommand : ICommand
{
private Action _action;
public RelayCommand(Action action)
{
_action = action;
}
public void Execute(object parameter)
{
_action();
}
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
}
}