mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-05 08:46:34 +08:00
项目结构调整
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using LiveCharts.Defaults;
|
||||
|
||||
namespace Wpf.CartesianChart.UIElements
|
||||
{
|
||||
public static class DataProvider
|
||||
{
|
||||
public static IEnumerable<DateTimePoint> Points
|
||||
{
|
||||
get
|
||||
{
|
||||
var r = new Random();
|
||||
var timeStamp = DateTime.Now;
|
||||
var trend = 0;
|
||||
|
||||
for (var i = 0; i < 50; i++)
|
||||
{
|
||||
timeStamp = timeStamp.AddDays(1);
|
||||
yield return new DateTimePoint(timeStamp, trend += r.Next(-20, 100));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.UIElements.EventAControl"
|
||||
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.CartesianChart.UIElements"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<WrapPanel Orientation="Vertical" Height="55" Width="55">
|
||||
<TextBlock Margin="0 0 0 10" FontSize="16" Foreground="#388E3C">Event A</TextBlock>
|
||||
<Path Height="20" Width="20" Fill="#388E3C" Stretch="Fill"
|
||||
Data="F1 M 46.5,19C 47.8807,19 49,20.1193 49,21.5C 49,22.8807 47.8807,24 46.5,24L 45.8641,23.9184L 43.5566,26.8718C 45.1489,28.0176 46.5309,29.6405 47.6023,31.6025C 44.8701,32.4842 41.563,33 38,33C 34.4369,33 31.1299,32.4842 28.3977,31.6025C 29.4333,29.7061 30.7591,28.1265 32.2844,26.9882L 29.9221,23.9646C 29.7849,23.9879 29.6438,24 29.5,24C 28.1193,24 27,22.8808 27,21.5C 27,20.1193 28.1193,19 29.5,19C 30.8807,19 32,20.1193 32,21.5C 32,22.0018 31.8521,22.4691 31.5976,22.8607L 34.0019,25.938C 35.2525,25.3305 36.5982,25 38,25C 39.3339,25 40.617,25.2993 41.8156,25.8516L 44.2947,22.6786C 44.1066,22.3274 44,21.9262 44,21.5C 44,20.1193 45.1193,19 46.5,19 Z M 54.5,40C 55.3284,40 56,40.6716 56,41.5C 56,42.3284 55.3284,43 54.5,43L 49.9511,43C 49.88,44.0847 49.7325,45.1391 49.5162,46.1531L 54.8059,48.6197C 55.5567,48.9698 55.8815,49.8623 55.5314,50.6131C 55.1813,51.3639 54.2889,51.6887 53.5381,51.3386L 48.6665,49.067C 46.8161,53.9883 43.2172,57.4651 39,57.9435L 39,34.9864C 42.541,34.8897 45.7913,34.283 48.4239,33.3201L 48.6187,33.8074L 53.73,31.8454C 54.5034,31.5485 55.371,31.9348 55.6679,32.7082C 55.9648,33.4816 55.5785,34.3492 54.8051,34.6461L 49.482,36.6895C 49.717,37.7515 49.8763,38.859 49.9511,40L 54.5,40 Z M 21.5,40L 26.0489,40C 26.1237,38.859 26.2829,37.7516 26.518,36.6895L 21.1949,34.6461C 20.4215,34.3492 20.0352,33.4816 20.332,32.7082C 20.6289,31.9348 21.4966,31.5485 22.27,31.8454L 27.3812,33.8074L 27.5761,33.3201C 30.2087,34.283 33.4589,34.8897 37,34.9864L 37,57.9435C 32.7827,57.4651 29.1838,53.9883 27.3335,49.067L 22.4618,51.3387C 21.711,51.6888 20.8186,51.3639 20.4685,50.6131C 20.1184,49.8623 20.4432,48.9699 21.194,48.6198L 26.4838,46.1531C 26.2674,45.1392 26.12,44.0847 26.0489,43L 21.5,43C 20.6716,43 20,42.3285 20,41.5C 20,40.6716 20.6716,40 21.5,40 Z "/>
|
||||
</WrapPanel>
|
||||
</UserControl>
|
||||
@@ -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.CartesianChart.UIElements
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for EventAControl.xaml
|
||||
/// </summary>
|
||||
public partial class EventAControl : UserControl
|
||||
{
|
||||
public EventAControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.UIElements.EventBControl"
|
||||
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.CartesianChart.UIElements"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Grid>
|
||||
<WrapPanel Orientation="Vertical" Height="55" Width="55">
|
||||
<TextBlock Margin="0 0 0 10" FontSize="16" Foreground="#F44336">Event B</TextBlock>
|
||||
<Path Height="20" Width="20" Fill="#F44336" Stretch="Fill"
|
||||
Data="F1 M 24.9015,43.0378L 25.0963,43.4298C 26.1685,49.5853 31.5377,54.2651 38,54.2651C 44.4623,54.2651 49.8315,49.5854 50.9037,43.4299L 51.0985,43.0379C 51.0985,40.7643 52.6921,39.2955 54.9656,39.2955C 56.9428,39.2955 58.1863,41.1792 58.5833,43.0379C 57.6384,52.7654 47.9756,61.75 38,61.75C 28.0244,61.75 18.3616,52.7654 17.4167,43.0378C 17.8137,41.1792 19.0572,39.2954 21.0344,39.2954C 23.3079,39.2954 24.9015,40.7643 24.9015,43.0378 Z M 26.7727,20.5833C 29.8731,20.5833 32.3864,23.0966 32.3864,26.197C 32.3864,29.2973 29.8731,31.8106 26.7727,31.8106C 23.6724,31.8106 21.1591,29.2973 21.1591,26.197C 21.1591,23.0966 23.6724,20.5833 26.7727,20.5833 Z M 49.2273,20.5833C 52.3276,20.5833 54.8409,23.0966 54.8409,26.197C 54.8409,29.2973 52.3276,31.8106 49.2273,31.8106C 46.127,31.8106 43.6136,29.2973 43.6136,26.197C 43.6136,23.0966 46.127,20.5833 49.2273,20.5833 Z "/>
|
||||
</WrapPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -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.CartesianChart.UIElements
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for EventBControl.xaml
|
||||
/// </summary>
|
||||
public partial class EventBControl : UserControl
|
||||
{
|
||||
public EventBControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.UIElements.SelectedItemControl"
|
||||
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.CartesianChart.UIElements"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<Path Height="30" Width="20" Stretch="Fill" Fill="#0D47A1"
|
||||
Data="F1 M 34,57L 42,57L 42,32.25L 52,42.25L 52,31.75L 38,17.75L 24,31.75L 24,42.25L 34,32.25L 34,57 Z "/>
|
||||
</UserControl>
|
||||
@@ -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.CartesianChart.UIElements
|
||||
{
|
||||
/// <summary>
|
||||
/// Interaction logic for SelectedItemControl.xaml
|
||||
/// </summary>
|
||||
public partial class SelectedItemControl : UserControl
|
||||
{
|
||||
public SelectedItemControl()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace Wpf.CartesianChart.UIElements
|
||||
{
|
||||
public partial class UiElementsAndEventsExample : UserControl
|
||||
{
|
||||
public UiElementsAndEventsExample()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<UserControl x:Class="Wpf.CartesianChart.UIElements.UiElementsAndEventsExample"
|
||||
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:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
|
||||
xmlns:uiElements="clr-namespace:Wpf.CartesianChart.UIElements"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="300" d:DesignWidth="300">
|
||||
<UserControl.DataContext>
|
||||
<uiElements:UiElementsViewModel></uiElements:UiElementsViewModel>
|
||||
</UserControl.DataContext>
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"></ColumnDefinition>
|
||||
<ColumnDefinition Width="*"></ColumnDefinition>
|
||||
</Grid.ColumnDefinitions>
|
||||
<ListBox Width="120" Margin="10" ItemsSource="{Binding Values}"
|
||||
SelectedItem="{Binding SelectedPoint, Mode=TwoWay}">
|
||||
<ListBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding DateTime, StringFormat={}{0:dd MMM}}"/>
|
||||
</DataTemplate>
|
||||
</ListBox.ItemTemplate>
|
||||
</ListBox>
|
||||
<lvc:CartesianChart Grid.Column="1" VisualElements="{Binding Visuals}">
|
||||
<lvc:CartesianChart.Series>
|
||||
<lvc:LineSeries Values="{Binding Values}" PointGeometry="{x:Null}" Fill="Transparent"></lvc:LineSeries>
|
||||
</lvc:CartesianChart.Series>
|
||||
<lvc:CartesianChart.AxisX>
|
||||
<lvc:Axis LabelFormatter="{Binding Formatter}" LabelsRotation="-90">
|
||||
<lvc:Axis.Separator>
|
||||
<lvc:Separator Step="{Binding Step}"/>
|
||||
</lvc:Axis.Separator>
|
||||
</lvc:Axis>
|
||||
</lvc:CartesianChart.AxisX>
|
||||
</lvc:CartesianChart>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using LiveCharts;
|
||||
using LiveCharts.Defaults;
|
||||
using LiveCharts.Helpers;
|
||||
using LiveCharts.Wpf;
|
||||
|
||||
namespace Wpf.CartesianChart.UIElements
|
||||
{
|
||||
public class UiElementsViewModel
|
||||
{
|
||||
private DateTimePoint _selectedPoint;
|
||||
|
||||
public UiElementsViewModel()
|
||||
{
|
||||
Values = DataProvider.Points.AsChartValues();
|
||||
Formatter = x => new DateTime((long) x).ToString("dd MMM");
|
||||
Step = TimeSpan.FromDays(1).Ticks * 2;
|
||||
|
||||
//lets get some random points to add an even in the chart.
|
||||
var e1 = Values.Skip(15).Take(1).First();
|
||||
var e2 = Values.Skip(35).Take(1).First();
|
||||
|
||||
SelectedVisualElement = new VisualElement
|
||||
{
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Bottom,
|
||||
UIElement = new SelectedItemControl()
|
||||
};
|
||||
|
||||
Visuals = new VisualElementsCollection
|
||||
{
|
||||
new VisualElement
|
||||
{
|
||||
X = e1.DateTime.Ticks,
|
||||
Y = e1.Value,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
UIElement = new EventAControl()
|
||||
},
|
||||
new VisualElement
|
||||
{
|
||||
X = e2.DateTime.Ticks,
|
||||
Y = e2.Value,
|
||||
HorizontalAlignment = HorizontalAlignment.Center,
|
||||
VerticalAlignment = VerticalAlignment.Top,
|
||||
UIElement = new EventBControl()
|
||||
},
|
||||
SelectedVisualElement
|
||||
};
|
||||
}
|
||||
|
||||
public ChartValues<DateTimePoint> Values { get; set; }
|
||||
public VisualElementsCollection Visuals { get; set; }
|
||||
public VisualElement EventA { get; set; }
|
||||
public VisualElement EventB { get; set; }
|
||||
public VisualElement SelectedVisualElement { get; set; }
|
||||
public Func<double, string> Formatter { get; set; }
|
||||
public double Step { get; set; }
|
||||
public DateTimePoint SelectedPoint
|
||||
{
|
||||
get { return _selectedPoint; }
|
||||
set
|
||||
{
|
||||
_selectedPoint = value;
|
||||
UpdateSelectedVisual();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateSelectedVisual()
|
||||
{
|
||||
SelectedVisualElement.X = SelectedPoint.DateTime.Ticks;
|
||||
SelectedVisualElement.Y = SelectedPoint.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user