2026-03-30 17:09:29 +09:00

164 lines
5.3 KiB
C#

/*
* Copyright (c) 2022 LG Electronics Inc.
* SPDX-License-Identifier: LicenseRef-LGE-Proprietary
*/
using Aurora;
using Aurora.View;
using OxyPlot;
using OxyPlot.Axes;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
namespace AuroraUIComponent.Chart
{
public class UCLineChartViewModel : NotifyPropertyChangedBase
{
public PlotModel Sample1 { get; set; }
private OxyPlot.Series.LineSeries _LineGraph;
public string _sChartTitleX { get; set; }
public int _nChartTitleFontSizeX { get; set; }
public string _sChartTitleY { get; set; }
public int _nChartTitleFontSizeY { get; set; }
public double _dChartSizeMinX { get; set; }
public double _dChartSizeMaxX { get; set; }
public double _dChartSizeMinY { get; set; }
public double _dChartSizeMaxY { get; set; }
public string _sLineTitle { get; set; }
public int _nLineFontSize { get; set; }
private const int _nNumMaxPoints = 100;
public UCLineChartViewModel(IAuroraEnvironment aurora)
{
_LineGraph = new OxyPlot.Series.LineSeries();
}
public void InitChart()
{
_LineGraph.Title = _sLineTitle;
_LineGraph.Color = OxyPlot.OxyColors.Blue;
_LineGraph.StrokeThickness = 1;
// create the model and add the lines to it
var model = new OxyPlot.PlotModel {
SubtitleFontSize = 6,
TitleFontSize = 8,
DefaultFontSize = 6,
TitlePadding = 0,
Padding = new OxyThickness(0),
PlotAreaBackground = OxyColors.Transparent,
Background = OxyColors.Transparent,
TextColor = OxyColors.WhiteSmoke
//PlotMargins = new OxyThickness(5)
};
model.Series.Add(_LineGraph);
model.Axes.Add(new OxyPlot.Axes.LinearAxis {
Position = OxyPlot.Axes.AxisPosition.Bottom,
Title = _sChartTitleX,
FontSize = _nChartTitleFontSizeX,
MinorTickSize = 0,
TickStyle = OxyPlot.Axes.TickStyle.None,
MinimumPadding = 0.1,
MaximumPadding = 0.1,
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot,
AxislineColor = OxyColors.WhiteSmoke
}) ;
model.Axes.Add(new OxyPlot.Axes.LinearAxis
{
Position = OxyPlot.Axes.AxisPosition.Left,
Title = _sChartTitleY,
FontSize = _nChartTitleFontSizeY,
MinorTickSize = 0,
TickStyle = OxyPlot.Axes.TickStyle.None,
MinimumPadding = 0.1,
MaximumPadding = 0.1,
MajorGridlineStyle = LineStyle.Solid,
MinorGridlineStyle = LineStyle.Dot,
AxislineColor = OxyColors.WhiteSmoke,
Minimum = _dChartSizeMinY,
Maximum = _dChartSizeMaxY
});
// load the model into the user control
Sample1 = model;
}
public void SetChart(string sTitleX = "", string sTitleY = "", int nSizeX = 0, int nSizeY = 0)
{
_sChartTitleX = sTitleX;
_sChartTitleY = sTitleY;
_nChartTitleFontSizeX = nSizeX;
_nChartTitleFontSizeY = nSizeY;
}
public void SetChartLine(string sTitle = "", int nSize = 0)
{
_sLineTitle = sTitle;
_nLineFontSize = nSize;
SetChartLineRange(false, 0);
SetChartLineRange(false, 1);
}
public void SetChartLineRange(bool bOn, int nAxis = 0, double dSizeMin = 0, double dSizeMax = 0)
{
switch(nAxis)
{
case 0: //X
if(bOn)
{
_dChartSizeMinX = dSizeMin;
_dChartSizeMaxX = dSizeMax;
}
else
{
_dChartSizeMinX = double.MinValue; //-999999999;
_dChartSizeMaxX = double.MaxValue; //999999999;
}
break;
case 1: //Y
if (bOn)
{
_dChartSizeMinY = dSizeMin;
_dChartSizeMaxY = dSizeMax;
}
else
{
_dChartSizeMinY = double.MinValue; //-999999999;
_dChartSizeMaxY = double.MaxValue; //999999999;
}
break;
default:
break;
}
}
public void AddPoint(double _value)
{
if (_LineGraph.Points.Count > _nNumMaxPoints)
{
_LineGraph.Points.Clear();
}
_LineGraph.Points.Add(new OxyPlot.DataPoint(_LineGraph.Points.Count, _value));
Sample1.InvalidatePlot(true);
}
}
}