refactor: 그래프 종류 string -> enum

hhsung_work
HyungJune Kim 10 months ago
parent 11bbf7922f
commit 3ac0255008

@ -0,0 +1,66 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static SmartAquaViewer.Model.Enums;
namespace SmartAquaViewer.Classes
{
public interface IChartSettings
{
GraphType Kind { get; }
}
public sealed class AvailableFields
{
public IReadOnlyList<string> Numeric { get; init; } = new List<string>();
public IReadOnlyList<string> Categorical { get; init; } = new List<string>();
}
public class LineSettings : IChartSettings
{
public GraphType Kind => GraphType.LINE;
[Required] public string XField { get; set; } = ""; // 보통 시간
[MinLength(1)] public List<string> YFields { get; set; } = new();
public bool ShowLegend { get; set; } = true;
}
public class BoxPlotSettings : IChartSettings
{
public GraphType Kind => GraphType.BOX;
[Required] public string GroupField { get; set; } = ""; // 수조/장비 등 카테고리
[Required] public string ValueField { get; set; } = ""; // DO, pH, 압력 등 숫자
public bool ShowOutliers { get; set; } = true;
}
public class ScatterSettings : IChartSettings
{
public GraphType Kind => GraphType.SCATTER;
[Required] public string XField { get; set; } = ""; // 숫자
[Required] public string YField { get; set; } = ""; // 숫자
public string? ColorBy { get; set; } // 카테고리(수조/장비/상태)
public string? SizeBy { get; set; } // 숫자(버블 크기)
}
public class StepSettings : IChartSettings
{
public GraphType Kind => GraphType.STEP;
[Required] public string XField { get; set; } = ""; // 보통 시간
// 장비별 상태 필드 매핑
public ObservableCollection<StateSeriesMap> Series { get; } = new();
public double OnValue { get; set; } = 1;
public double OffValue { get; set; } = 0;
}
public class StateSeriesMap
{
public string SeriesName { get; set; } = ""; // 예: "오존용해장치"
public string Field { get; set; } = ""; // 예: "오존용해장치(상태)"
public string OnToken { get; set; } = "ON";
public string OffToken { get; set; } = "OFF";
}
}

@ -0,0 +1,49 @@
<UserControl x:Class="SmartAquaViewer.Controls.GraphControl"
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:SmartAquaViewer.Controls"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="1080">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="550"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Border Margin="20"
Background="#384659" BorderBrush="#404F63" BorderThickness="1" CornerRadius="10">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="그래프" FontSize="24" FontFamily="{StaticResource SCDream4}" Foreground="White"
Margin="15 15 15 5"/>
<TextBlock Grid.Row="2" Text="X축" FontSize="24" FontFamily="{StaticResource SCDream4}" Foreground="White"
Margin="15 15 15 5"/>
<TextBlock Grid.Row="4" Text="Y축" FontSize="24" FontFamily="{StaticResource SCDream4}" Foreground="White"
Margin="15 15 15 5"/>
<ComboBox Grid.Row="1" Margin="15 0" Height="50"
Style="{StaticResource ComboBoxStyle}"
ItemsSource="{Binding GraphTypes}"
SelectedItem="{Binding SelectedGraphType}"/>
<ComboBox Grid.Row="3" Margin="15 0" Height="50"
Style="{StaticResource ComboBoxStyle}"></ComboBox>
<ListBox Grid.Row="5" Margin="15 0" Height="50" SelectionMode="Extended"/>
</Grid>
</Border>
<Border Grid.Column="1" Margin="0 20 20 20"
Background="#384659" BorderBrush="#404F63" BorderThickness="1" CornerRadius="10">
</Border>
</Grid>
</UserControl>

@ -0,0 +1,33 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 SmartAquaViewer.Controls
{
/// <summary>
/// GraphControl.xaml에 대한 상호 작용 논리
/// </summary>
public partial class GraphControl : UserControl
{
public GraphControl()
{
InitializeComponent();
}
private void ComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
}
}
}

@ -14,5 +14,13 @@ namespace SmartAquaViewer.Model
Filter, Filter,
Sterilizer Sterilizer
} }
public enum GraphType
{
LINE,
BOX,
SCATTER,
STEP
}
} }
} }

@ -1,45 +0,0 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using SmartAquaViewer.DataAnalysis;
namespace SmartAquaViewer.ViewModel
{
public interface IGridSection { string Title { get; } }
public class TankSection : IGridSection
{
public string Title { get; set; } = "수조";
public ObservableCollection<TankRow> Rows { get; } = new();
}
public class FilterSection : IGridSection
{
public string Title { get; set; } = "여과";
public ObservableCollection<FilterRow> Rows { get; } = new();
}
public class SterilizeSection : IGridSection
{
public string Title { get; set; } = "살균";
public ObservableCollection<SterRow> Rows { get; } = new();
}
// 예시 Row들
public class TankRow
{
public DateTime RecordedTime { get; set; }
public WaterTank Tank { get; set; }
}
public class FilterRow
{
public DateTime RecordedTime { get; set; }
public FilteringSystem Filter { get; set; }
}
public class SterRow
{
public DateTime RecordedTime { get; set; }
public SterilizingSystem Sterilizer { get; set; }
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SmartAquaViewer.ViewModel
{
class GraphControlViewModel
{
}
}

@ -21,25 +21,11 @@ namespace SmartAquaViewer.ViewModel
public delegate void SystemChangedEventHandler(MonitorTab selectedTab); public delegate void SystemChangedEventHandler(MonitorTab selectedTab);
public event SystemChangedEventHandler OnSystemChanged; public event SystemChangedEventHandler OnSystemChanged;
public ObservableCollection<string> GraphTypes { get; } public ObservableCollection<GraphType> GraphTypes { get; }
public List<WaterQualityVO> WaterQualityList { get; } public List<WaterQualityVO> WaterQualityList { get; }
public Dictionary<int, ObservableCollection<WaterQualityVO>> TankGroups { get; } public Dictionary<int, ObservableCollection<WaterQualityVO>> TankGroups { get; }
private string _selectedGraphType;
public string SelectedGraphType
{
get => _selectedGraphType;
set
{
if (_selectedGraphType != value)
{
_selectedGraphType = value;
OnPropertyChanged();
}
}
}
private MonitorTab _selectedTab; private MonitorTab _selectedTab;
public MonitorTab SelectedTab public MonitorTab SelectedTab
{ {
@ -52,24 +38,23 @@ namespace SmartAquaViewer.ViewModel
OnPropertyChanged(); OnPropertyChanged();
Debug.WriteLine($"CurrentTab changed to: {_selectedTab}"); Debug.WriteLine($"CurrentTab changed to: {_selectedTab}");
SetGraphType();
SelectedGraphType = GraphTypes.FirstOrDefault();
OnSystemChanged?.Invoke(SelectedTab); OnSystemChanged?.Invoke(SelectedTab);
} }
} }
} }
private string _currentSystem; private GraphType _selectedGraphType;
public string CurrentSystem public GraphType SelectedGraphType
{ {
get => _currentSystem; get => _selectedGraphType;
set set
{ {
if (_currentSystem != value) if (_selectedGraphType != value)
{ {
_currentSystem = value; _selectedGraphType = value;
OnPropertyChanged(); OnPropertyChanged();
SetGraphType();
SelectedGraphType = GraphTypes.FirstOrDefault() ?? string.Empty;
} }
} }
} }
@ -138,11 +123,10 @@ namespace SmartAquaViewer.ViewModel
g.OrderBy(r => r.RecordedTime)) g.OrderBy(r => r.RecordedTime))
); );
GraphTypes = new ObservableCollection<GraphType>();
SelectedTab = MonitorTab.Tank; // Default system
GraphTypes = new ObservableCollection<string>();
CurrentSystem = "Tank"; // Default system
SetGraphType(); SetGraphType();
SelectedGraphType = GraphTypes.FirstOrDefault();
ChangeDrawerStatusCommand = new RelayCommand(_ => IsOpenMode = !IsOpenMode); ChangeDrawerStatusCommand = new RelayCommand(_ => IsOpenMode = !IsOpenMode);
} }
@ -151,28 +135,28 @@ namespace SmartAquaViewer.ViewModel
{ {
GraphTypes.Clear(); GraphTypes.Clear();
switch (CurrentSystem) switch (SelectedTab)
{ {
case "Tank": case MonitorTab.Tank:
GraphTypes.Add("LINE"); GraphTypes.Add(GraphType.LINE);
GraphTypes.Add("BOX"); GraphTypes.Add(GraphType.BOX);
GraphTypes.Add("SCATTER"); GraphTypes.Add(GraphType.SCATTER);
break; break;
case "Filter": case MonitorTab.Filter:
GraphTypes.Add("LINE"); GraphTypes.Add(GraphType.LINE);
GraphTypes.Add("STEP"); GraphTypes.Add(GraphType.STEP);
break; break;
case "Sterilizer": case MonitorTab.Sterilizer:
GraphTypes.Add("LINE"); GraphTypes.Add(GraphType.LINE);
GraphTypes.Add("STEP"); GraphTypes.Add(GraphType.STEP);
break; break;
default: default:
break; break;
} }
string graphTypes = string.Empty; string graphTypes = string.Empty;
foreach (string str in GraphTypes) foreach (GraphType graphType in GraphTypes)
graphTypes += (str + ", "); graphTypes += (graphType.ToString() + ", ");
Debug.WriteLine(graphTypes); Debug.WriteLine(graphTypes);
} }

Loading…
Cancel
Save