项目结构调整

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,258 @@
//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using LiveCharts.Charts;
using LiveCharts.Definitions.Charts;
using LiveCharts.Dtos;
using LiveCharts.Wpf.Charts.Base;
namespace LiveCharts.Wpf.Components
{
/// <summary>
///
/// </summary>
/// <seealso cref="LiveCharts.Definitions.Charts.ISeparatorElementView" />
public class AxisSeparatorElement : ISeparatorElementView
{
private readonly SeparatorElementCore _model;
/// <summary>
/// Initializes a new instance of the <see cref="AxisSeparatorElement"/> class.
/// </summary>
/// <param name="model">The model.</param>
public AxisSeparatorElement(SeparatorElementCore model)
{
_model = model;
}
internal TextBlock TextBlock { get; set; }
internal Line Line { get; set; }
/// <summary>
/// Gets the label model.
/// </summary>
/// <value>
/// The label model.
/// </value>
public LabelEvaluation LabelModel { get; private set; }
/// <summary>
/// Gets the model.
/// </summary>
/// <value>
/// The model.
/// </value>
public SeparatorElementCore Model
{
get { return _model; }
}
/// <summary>
/// Updates the label.
/// </summary>
/// <param name="text">The text.</param>
/// <param name="axis">The axis.</param>
/// <param name="source">The source.</param>
/// <returns></returns>
public LabelEvaluation UpdateLabel(string text, AxisCore axis, AxisOrientation source)
{
TextBlock.Text = text;
var formattedText = new FormattedText(
TextBlock.Text,
CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight,
new Typeface(TextBlock.FontFamily, TextBlock.FontStyle, TextBlock.FontWeight, TextBlock.FontStretch),
TextBlock.FontSize, Brushes.Black);
var transform = new LabelEvaluation(axis.View.LabelsRotation,
formattedText.Width, formattedText.Height, axis, source);
TextBlock.RenderTransform = Math.Abs(transform.LabelAngle) > 1
? new RotateTransform(transform.LabelAngle)
: null;
LabelModel = transform;
return transform;
}
/// <summary>
/// Clears the specified chart.
/// </summary>
/// <param name="chart">The chart.</param>
public void Clear(IChartView chart)
{
chart.RemoveFromView(TextBlock);
chart.RemoveFromView(Line);
TextBlock = null;
Line = null;
}
/// <summary>
/// Places the specified chart.
/// </summary>
/// <param name="chart">The chart.</param>
/// <param name="axis">The axis.</param>
/// <param name="direction">The direction.</param>
/// <param name="axisIndex">Index of the axis.</param>
/// <param name="toLabel">To label.</param>
/// <param name="toLine">To line.</param>
/// <param name="tab">The tab.</param>
public void Place(ChartCore chart, AxisCore axis, AxisOrientation direction, int axisIndex,
double toLabel, double toLine, double tab)
{
if (direction == AxisOrientation.Y)
{
Line.X1 = chart.DrawMargin.Left;
Line.X2 = chart.DrawMargin.Left + chart.DrawMargin.Width;
Line.Y1 = toLine;
Line.Y2 = toLine;
Canvas.SetLeft(TextBlock, tab);
Canvas.SetTop(TextBlock, toLabel);
}
else
{
Line.X1 = toLine;
Line.X2 = toLine;
Line.Y1 = chart.DrawMargin.Top;
Line.Y2 = chart.DrawMargin.Top + chart.DrawMargin.Height;
Canvas.SetLeft(TextBlock, toLabel);
Canvas.SetTop(TextBlock, tab);
}
}
/// <summary>
/// Removes the specified chart.
/// </summary>
/// <param name="chart">The chart.</param>
public void Remove(ChartCore chart)
{
chart.View.RemoveFromView(TextBlock);
chart.View.RemoveFromView(Line);
TextBlock = null;
Line = null;
}
/// <summary>
/// Moves the specified chart.
/// </summary>
/// <param name="chart">The chart.</param>
/// <param name="axis">The axis.</param>
/// <param name="direction">The direction.</param>
/// <param name="axisIndex">Index of the axis.</param>
/// <param name="toLabel">To label.</param>
/// <param name="toLine">To line.</param>
/// <param name="tab">The tab.</param>
public void Move(ChartCore chart, AxisCore axis, AxisOrientation direction, int axisIndex, double toLabel, double toLine, double tab)
{
if (direction == AxisOrientation.Y)
{
Line.BeginAnimation(Line.X1Property,
new DoubleAnimation(chart.DrawMargin.Left, chart.View.AnimationsSpeed));
Line.BeginAnimation(Line.X2Property,
new DoubleAnimation(chart.DrawMargin.Left + chart.DrawMargin.Width, chart.View.AnimationsSpeed));
Line.BeginAnimation(Line.Y1Property,
new DoubleAnimation(toLine, chart.View.AnimationsSpeed));
Line.BeginAnimation(Line.Y2Property,
new DoubleAnimation(toLine, chart.View.AnimationsSpeed));
TextBlock.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(toLabel, chart.View.AnimationsSpeed));
TextBlock.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(tab, chart.View.AnimationsSpeed));
}
else
{
Line.BeginAnimation(Line.X1Property,
new DoubleAnimation(toLine, chart.View.AnimationsSpeed));
Line.BeginAnimation(Line.X2Property,
new DoubleAnimation(toLine, chart.View.AnimationsSpeed));
Line.BeginAnimation(Line.Y1Property,
new DoubleAnimation(chart.DrawMargin.Top, chart.View.AnimationsSpeed));
Line.BeginAnimation(Line.Y2Property,
new DoubleAnimation(chart.DrawMargin.Top + chart.DrawMargin.Height, chart.View.AnimationsSpeed));
TextBlock.BeginAnimation(Canvas.LeftProperty,
new DoubleAnimation(toLabel, chart.View.AnimationsSpeed));
TextBlock.BeginAnimation(Canvas.TopProperty,
new DoubleAnimation(tab, chart.View.AnimationsSpeed));
}
}
/// <summary>
/// Fades the in.
/// </summary>
/// <param name="axis">The axis.</param>
/// <param name="chart">The chart.</param>
public void FadeIn(AxisCore axis, ChartCore chart)
{
if (TextBlock.Visibility != Visibility.Collapsed)
TextBlock.BeginAnimation(UIElement.OpacityProperty,
new DoubleAnimation(0, 1, chart.View.AnimationsSpeed));
if (Line.Visibility != Visibility.Collapsed)
Line.BeginAnimation(UIElement.OpacityProperty,
new DoubleAnimation(0, 1, chart.View.AnimationsSpeed));
}
/// <summary>
/// Fades the out and remove.
/// </summary>
/// <param name="chart">The chart.</param>
public void FadeOutAndRemove(ChartCore chart)
{
if (TextBlock.Visibility == Visibility.Collapsed &&
Line.Visibility == Visibility.Collapsed) return;
var anim = new DoubleAnimation
{
From = 1,
To = 0,
Duration = chart.View.AnimationsSpeed
};
var dispatcher = ((Chart) chart.View).Dispatcher;
anim.Completed += (sender, args) =>
{
dispatcher.Invoke(new Action(() =>
{
chart.View.RemoveFromView(TextBlock);
chart.View.RemoveFromView(Line);
}));
};
TextBlock.BeginAnimation(UIElement.OpacityProperty, anim);
Line.BeginAnimation(UIElement.OpacityProperty,
new DoubleAnimation(1, 0, chart.View.AnimationsSpeed));
}
}
}

View File

@@ -0,0 +1,97 @@
//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System;
using System.Diagnostics;
using System.Windows.Threading;
using LiveCharts.Dtos;
using LiveCharts.Wpf.Charts.Base;
namespace LiveCharts.Wpf.Components
{
internal class ChartUpdater : LiveCharts.ChartUpdater
{
public ChartUpdater(TimeSpan frequency)
{
Timer = new DispatcherTimer {Interval = frequency};
Timer.Tick += OnTimerOnTick;
Freq = frequency;
}
public DispatcherTimer Timer { get; set; }
private bool RequiresRestart { get; set; }
private TimeSpan Freq { get; set; }
public override void Run(bool restartView = false, bool updateNow = false)
{
if (Timer == null)
{
Timer = new DispatcherTimer {Interval = Freq};
Timer.Tick += OnTimerOnTick;
IsUpdating = false;
}
if (updateNow)
{
UpdaterTick(restartView, true);
return;
}
RequiresRestart = restartView || RequiresRestart;
if (IsUpdating) return;
IsUpdating = true;
Timer.Start();
}
public override void UpdateFrequency(TimeSpan freq)
{
Timer.Interval = freq;
}
public void OnTimerOnTick(object sender, EventArgs args)
{
UpdaterTick(RequiresRestart, false);
}
private void UpdaterTick(bool restartView, bool force)
{
var wpfChart = (Chart) Chart.View;
if (!force && !wpfChart.IsVisible && !wpfChart.IsMocked) return;
Chart.ControlSize = wpfChart.IsMocked
? wpfChart.Model.ControlSize
: new CoreSize(wpfChart.ActualWidth, wpfChart.ActualHeight);
Timer.Stop();
Update(restartView, force);
IsUpdating = false;
RequiresRestart = false;
wpfChart.ChartUpdated();
wpfChart.PrepareScrolBar();
}
}
}

View File

@@ -0,0 +1,68 @@
//The MIT License(MIT)
//copyright(c) 2016 Greg Dennis & Alberto Rodriguez
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Windows.Data;
using System.Windows.Media;
namespace LiveCharts.Wpf.Components
{
internal class SerieConverter : IValueConverter
{
public static SerieConverter Instance { get; set; }
static SerieConverter()
{
Instance = new SerieConverter();
}
private SerieConverter() { }
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
var series = value as IEnumerable<Series>;
if (series != null)
return series.Select(x => new SeriesViewModel
{
});
var serie = value as Series;
if (serie != null)
return new SeriesViewModel
{
Title = serie.Title,
Stroke = serie.Stroke,
Fill = serie.Fill,
PointGeometry = serie.PointGeometry ?? Geometry.Parse("M 0,0.5 h 1,0.5 Z")
};
return value;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,50 @@
//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System.IO;
using System.Windows;
using System.Windows.Markup;
using System.Xml;
namespace LiveCharts.Wpf.Components
{
/// <summary>
///
/// </summary>
public static class DefaultXamlReader
{
/// <summary>
/// Creates the specified type.
/// </summary>
/// <returns></returns>
public static DataTemplate DataLabelTemplate()
{
var stringReader = new StringReader(
@"<DataTemplate xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"">
<TextBlock Text=""{Binding FormattedText}""></TextBlock>
</DataTemplate>");
var xmlReader = XmlReader.Create(stringReader);
return XamlReader.Load(xmlReader) as DataTemplate;
}
}
}

View File

@@ -0,0 +1,40 @@
//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System.Windows.Media;
namespace LiveCharts.Wpf.Components
{
/// <summary>
///
/// </summary>
public interface IFondeable
{
/// <summary>
/// Gets the point foreground.
/// </summary>
/// <value>
/// The point foreground.
/// </value>
Brush PointForeground { get; }
}
}

View File

@@ -0,0 +1,48 @@
//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System;
using System.Windows;
namespace LiveCharts.Wpf.Components
{
// This is a workaround to prevent a possible threading issue
// LiveChart was designed to be easy to use, the current design
// avoids the usage of DataTemplates, instead we use the same object (UIElement)
// since UI elements are running the UI thread, it is possible that
// when we try to modify a property in a UIElement, i.e. the labels of an axis,
// we can't, well we can but we need to use the UI dispatcher.
internal static class ThreadAccess
{
public static T Resolve<T>(DependencyObject dependencyObject,
DependencyProperty dependencyProperty)
{
if (dependencyObject.Dispatcher.CheckAccess())
return (T) dependencyObject.GetValue(dependencyProperty);
return (T) dependencyObject.Dispatcher.Invoke(
new Func<T>(() => (T) dependencyObject.GetValue(dependencyProperty)));
}
}
}

View File

@@ -0,0 +1,76 @@
//The MIT License(MIT)
//Copyright(c) 2016 Alberto Rodriguez & LiveCharts Contributors
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
using System.Windows.Media;
namespace LiveCharts.Wpf.Components
{
/// <summary>
/// A tooltip element data transfer object
/// </summary>
public class TooltipDto
{
/// <summary>
/// Gets or sets the series.
/// </summary>
/// <value>
/// The series.
/// </value>
public Series Series { get; set; }
/// <summary>
/// Gets or sets the index.
/// </summary>
/// <value>
/// The index.
/// </value>
public int Index { get; set; }
/// <summary>
/// Gets or sets the stroke.
/// </summary>
/// <value>
/// The stroke.
/// </value>
public Brush Stroke { get; set; }
/// <summary>
/// Gets or sets the fill.
/// </summary>
/// <value>
/// The fill.
/// </value>
public Brush Fill { get; set; }
/// <summary>
/// Gets or sets the point.
/// </summary>
/// <value>
/// The point.
/// </value>
public ChartPoint Point { get; set; }
/// <summary>
/// Gets or sets the value.
/// </summary>
/// <value>
/// The value.
/// </value>
public string Value { get; set; }
}
}