mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-04-15 21:56:37 +08:00
项目结构调整
This commit is contained in:
83
Others/Live-Charts-master/UwpView/Extentions.cs
Normal file
83
Others/Live-Charts-master/UwpView/Extentions.cs
Normal file
@@ -0,0 +1,83 @@
|
||||
using System.Linq;
|
||||
using Windows.Foundation;
|
||||
using LiveCharts.Dtos;
|
||||
using LiveCharts.Uwp.Charts.Base;
|
||||
|
||||
namespace LiveCharts.Uwp
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public static class Extentions
|
||||
{
|
||||
/// <summary>
|
||||
/// Converts a point at screen to chart values scale
|
||||
/// </summary>
|
||||
/// <param name="chart">Target chart</param>
|
||||
/// <param name="screenPoint">point in screen</param>
|
||||
/// <param name="axisX">axis x index</param>
|
||||
/// <param name="axisY">axis y index</param>
|
||||
/// <returns></returns>
|
||||
public static Point ConvertToChartValues(this Chart chart, Point screenPoint, int axisX = 0, int axisY = 0)
|
||||
{
|
||||
if (chart.Model == null || chart.AxisX == null || chart.AxisX.Any(x => x.Model == null)) return new Point();
|
||||
|
||||
var uw = new CorePoint(
|
||||
chart.AxisX[axisX].Model.EvaluatesUnitWidth
|
||||
? ChartFunctions.GetUnitWidth(AxisOrientation.X, chart.Model, axisX)/2
|
||||
: 0,
|
||||
chart.AxisY[axisY].Model.EvaluatesUnitWidth
|
||||
? ChartFunctions.GetUnitWidth(AxisOrientation.Y, chart.Model, axisY)/2
|
||||
: 0);
|
||||
|
||||
return new Point(
|
||||
ChartFunctions.FromPlotArea(screenPoint.X - uw.X, AxisOrientation.X, chart.Model, axisX),
|
||||
ChartFunctions.FromPlotArea(screenPoint.Y - uw.Y, AxisOrientation.Y, chart.Model, axisY));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a chart values pair to pixels
|
||||
/// </summary>
|
||||
/// <param name="chart">Target chart</param>
|
||||
/// <param name="chartPoint">point in screen</param>
|
||||
/// <param name="axisX">axis x index</param>
|
||||
/// <param name="axisY">axis y index</param>
|
||||
/// <returns></returns>
|
||||
public static Point ConvertToPixels(this Chart chart, Point chartPoint, int axisX = 0, int axisY = 0)
|
||||
{
|
||||
if (chart.Model == null || chart.AxisX.Any(x => x.Model == null)) return new Point();
|
||||
|
||||
var uw = new CorePoint(
|
||||
chart.AxisX[axisX].Model.EvaluatesUnitWidth
|
||||
? ChartFunctions.GetUnitWidth(AxisOrientation.X, chart.Model, axisX) / 2
|
||||
: 0,
|
||||
chart.AxisY[axisY].Model.EvaluatesUnitWidth
|
||||
? ChartFunctions.GetUnitWidth(AxisOrientation.Y, chart.Model, axisY) / 2
|
||||
: 0);
|
||||
|
||||
return new Point(
|
||||
ChartFunctions.ToPlotArea(chartPoint.X, AxisOrientation.X, chart.Model, axisX) + uw.X,
|
||||
ChartFunctions.ToPlotArea(chartPoint.Y, AxisOrientation.Y, chart.Model, axisY) + uw.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a ChartPoint to Point
|
||||
/// </summary>
|
||||
/// <param name="chartPoint">point to convert</param>
|
||||
/// <returns></returns>
|
||||
public static Point AsPoint(this ChartPoint chartPoint)
|
||||
{
|
||||
return new Point(chartPoint.X, chartPoint.Y);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Converts a CorePoint to Point
|
||||
/// </summary>
|
||||
/// <param name="point">point to convert</param>
|
||||
/// <returns></returns>
|
||||
internal static Point AsPoint(this CorePoint point)
|
||||
{
|
||||
return new Point(point.X, point.Y);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user