Skip to content

Commit

Permalink
Added CustomersTooltip.
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgy Levchenko committed Mar 30, 2021
1 parent f9dd31e commit 35df592
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 5 deletions.
24 changes: 24 additions & 0 deletions src/DataAccess/SmartThermo.DataAccess.Sqlite/Context.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
using Microsoft.EntityFrameworkCore;
using SmartThermo.DataAccess.Sqlite.Models;
using System;
using System.Collections.Generic;

namespace SmartThermo.DataAccess.Sqlite
{
Expand All @@ -11,6 +13,28 @@ public class Context : DbContext

public DbSet<SensorInformation> SensorInformations { get; set; }

public DbSet<Setting> Settings { get; set; }

public DbSet<SelectMode> SelectModes { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Setting>().HasData(new Setting
{
Id = 1,
});

modelBuilder.Entity<SelectMode>().HasData(new SelectMode[]
{
new SelectMode { Id = 1, SettingId = 1, Stage = false },
new SelectMode { Id = 2, SettingId = 1, Stage = false },
new SelectMode { Id = 3, SettingId = 1, Stage = false },
new SelectMode { Id = 4, SettingId = 1, Stage = false },
new SelectMode { Id = 5, SettingId = 1, Stage = false },
new SelectMode { Id = 6, SettingId = 1, Stage = false }
});
}

protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseSqlite(@"Data Source=app.db");
}
Expand Down
13 changes: 13 additions & 0 deletions src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/SelectMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace SmartThermo.DataAccess.Sqlite.Models
{
public class SelectMode
{
public int Id { get; set; }

public bool Stage { get; set; }

public int SettingId { get; set; }

public Setting Setting { get; set; }
}
}
11 changes: 11 additions & 0 deletions src/DataAccess/SmartThermo.DataAccess.Sqlite/Models/Setting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Collections.Generic;

namespace SmartThermo.DataAccess.Sqlite.Models
{
public class Setting
{
public int Id { get; set; }

public List<SelectMode> SelectModes { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@ public LoadDataViewerWindowViewModel(IDeviceConnector deviceConnector, INotifica

SelectMode[(int)i - 1] = !SelectMode[(int)i - 1];
RaisePropertyChanged(nameof(SelectMode));

using var context = new Context();
var selectMode = context.SelectModes
.Where(x => x.Id == i)
.FirstOrDefault();
selectMode.Stage = _selectMode[(int)i - 1];
context.SaveChanges();
});
}

Expand Down Expand Up @@ -251,12 +258,13 @@ private void InitCharts()
ChartValues.AddRange(Enumerable.Range(0, 36)
.Select(x => new ChartValues<MeasureData>())
.ToList());
Temperature.AddRange(Enumerable.Range(0,36)
.Select(x => 0)
.ToList());
LimitRelayItems.AddRange(Enumerable.Range(0, 6)
.Select(x => new LimitRelay())
.ToList());
SelectMode.AddRange(Enumerable.Range(0, 6)
.Select(x => false)
.ToList());
GetSelectMode();

XFormatter = value => new DateTime((long)value).ToString("mm:ss");
YFormatter = value => Math.Round(value, 1).ToString(CultureInfo.InvariantCulture);
Expand All @@ -267,6 +275,12 @@ private void InitCharts()
SetRelayLimits();
}

private void GetSelectMode()
{
using var context = new Context();
SelectMode.AddRange(context.SelectModes.Select(x => x.Stage).ToList());
}

private void SetRelayLimits()
{
var data = _deviceConnector.SettingDevice;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<UserControl
x:Class="SmartThermo.Modules.DataViewer.Views.Charts.CustomersTooltip"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:charts="clr-namespace:SmartThermo.Modules.DataViewer.Views.Charts"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:wpf="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
Padding="8"
d:DataContext="{d:DesignInstance charts:CustomersTooltip}"
d:DesignHeight="450"
d:DesignWidth="800"
Background="#E4555555"
BorderBrush="#555555"
BorderThickness="2"
mc:Ignorable="d">

<StackPanel>
<TextBlock
HorizontalAlignment="Center"
Style="{DynamicResource BodyTextBlockStyle}"
Text="{Binding Data.Points[0].ChartPoint.Instance.DateTime, StringFormat=HH:mm:ss}" />

<Separator Margin="0,8" />
<ItemsControl
HorizontalAlignment="Center"
Grid.IsSharedSizeScope="True"
ItemsSource="{Binding Data.Points}">

<ItemsControl.ItemTemplate>
<DataTemplate DataType="{x:Type wpf:DataPointViewModel}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" SharedSizeGroup="Title" />
<ColumnDefinition Width="Auto" SharedSizeGroup="Value" />
<ColumnDefinition Width="Auto" SharedSizeGroup="Percent" />
</Grid.ColumnDefinitions>
<Ellipse
Grid.Column="0"
Width="10"
Height="10"
Fill="{Binding Series.Stroke}"
Stroke="{Binding Series.Stroke}" />
<TextBlock
Grid.Column="1"
Margin="4,0,0,0"
VerticalAlignment="Center"
Foreground="White"
Style="{DynamicResource CaptionTextBlockStyle}"
Text="{Binding Series.Title}" />
<TextBlock
Grid.Column="2"
Margin="8,0,0,0"
VerticalAlignment="Center"
Foreground="White"
Style="{DynamicResource CaptionTextBlockStyle}"
Text="{Binding ChartPoint.Instance.Value, StringFormat={}{0}°C}" />
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</StackPanel>
</UserControl>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using LiveCharts;
using LiveCharts.Wpf;
using System.ComponentModel;

namespace SmartThermo.Modules.DataViewer.Views.Charts
{
/// <summary>
/// Interaction logic for CustomersTooltip.xaml
/// </summary>
public partial class CustomersTooltip : IChartTooltip
{
public event PropertyChangedEventHandler PropertyChanged;

private TooltipData _data;

public CustomersTooltip()
{
InitializeComponent();
DataContext = this;
}

public TooltipData Data
{
get { return _data; }
set
{
_data = value;
OnPropertyChanged("Data");
}
}

public TooltipSelectionMode? SelectionMode { get; set; }

protected virtual void OnPropertyChanged(string propertyName = null)
{
if (PropertyChanged != null)
PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SmartThermo.Modules.DataViewer.Views.Represent"
xmlns:local="clr-namespace:SmartThermo.Modules.DataViewer.Views.Charts"
xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:prism="http://prismlibrary.com/"
Expand Down Expand Up @@ -145,7 +145,7 @@
</Style>
</lvc:CartesianChart.Style>
<lvc:CartesianChart.DataTooltip>
<lvc:DefaultTooltip Background="{DynamicResource SystemControlPageBackgroundChromeMediumLowBrush}" />
<local:CustomersTooltip />
</lvc:CartesianChart.DataTooltip>
</lvc:CartesianChart>
</Grid>
Expand Down

0 comments on commit 35df592

Please sign in to comment.