From 34823fa1e88510eeb8b4a5556703757e1939f08f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yann=20Brid=C3=A9?= Date: Wed, 29 Mar 2023 15:50:18 +0200 Subject: [PATCH 1/5] =?UTF-8?q?=E2=9C=A8Adding=20column=20plotter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserControls/DataVisualizerUC.Designer.cs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs b/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs index a2bb30ae5..367b5cb37 100644 --- a/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs +++ b/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs @@ -46,6 +46,8 @@ private void InitializeComponent() this.xtraTabControl1 = new DevExpress.XtraTab.XtraTabControl(); this.xtpMessagesText = new DevExpress.XtraTab.XtraTabPage(); this.xtpPieChart = new DevExpress.XtraTab.XtraTabPage(); + this.xtpColumnPlotter = new DevExpress.XtraTab.XtraTabPage(); + this.logStatisticsUC1 = new Analogy.CommonControls.UserControls.LogStatisticsUC(); this.tmrPlotting = new System.Windows.Forms.Timer(this.components); ((System.ComponentModel.ISupportInitialize)(this.splitContainerControl1)).BeginInit(); @@ -70,6 +72,7 @@ private void InitializeComponent() this.xtraTabControl1.SuspendLayout(); this.xtpMessagesText.SuspendLayout(); this.xtpPieChart.SuspendLayout(); + this.xtpColumnPlotter.SuspendLayout(); this.SuspendLayout(); // // splitContainerControl1 @@ -248,7 +251,7 @@ private void InitializeComponent() this.xtraTabControl1.TabIndex = 2; this.xtraTabControl1.TabPages.AddRange(new DevExpress.XtraTab.XtraTabPage[] { this.xtpMessagesText, - this.xtpPieChart}); + this.xtpPieChart, this.xtpColumnPlotter}); // // xtpMessagesText // @@ -264,6 +267,13 @@ private void InitializeComponent() this.xtpPieChart.Size = new System.Drawing.Size(1013, 541); this.xtpPieChart.Text = "Pies"; // + // xtpColumnPlotter + // + this.xtpColumnPlotter.Controls.Add(this.logStatisticsUC1); + this.xtpColumnPlotter.Name = "xtpColumnPlotter"; + this.xtpColumnPlotter.Size = new System.Drawing.Size(1013, 541); + this.xtpColumnPlotter.Text = "Values"; + // // logStatisticsUC1 // this.logStatisticsUC1.Dock = System.Windows.Forms.DockStyle.Fill; @@ -311,6 +321,7 @@ private void InitializeComponent() this.xtraTabControl1.ResumeLayout(false); this.xtpMessagesText.ResumeLayout(false); this.xtpPieChart.ResumeLayout(false); + this.xtpColumnPlotter.ResumeLayout(false); this.ResumeLayout(false); } @@ -329,6 +340,7 @@ private void InitializeComponent() private DevExpress.XtraTab.XtraTabControl xtraTabControl1; private DevExpress.XtraTab.XtraTabPage xtpMessagesText; private DevExpress.XtraTab.XtraTabPage xtpPieChart; + private DevExpress.XtraTab.XtraTabPage xtpColumnPlotter; private LogStatisticsUC logStatisticsUC1; private System.Windows.Forms.Timer tmrPlotting; private DevExpress.XtraEditors.SpinEdit seRefreshInterval; From c7b048da317a0009cbbcb38e76fb0773f81ebcd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yann=20Brid=C3=A9?= Date: Thu, 30 Mar 2023 15:43:07 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=A7Adding=20values=20plotter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/DataVisualizerForm.cs | 8 +- Analogy.CommonControls/Plotting/PlottingUC.cs | 9 +- .../UserControls/DataVisualizerUC.Designer.cs | 37 +++-- .../UserControls/DataVisualizerUC.cs | 6 +- .../UserControls/LogMessagesUC.cs | 2 +- .../UserControls/ServerSideLogMessagesUC.cs | 2 +- .../UserControls/ValuesPlotterUC.Designer.cs | 157 ++++++++++++++++++ .../UserControls/ValuesPlotterUC.cs | 144 ++++++++++++++++ .../UserControls/ValuesPlotterUC.resx | 120 +++++++++++++ 9 files changed, 462 insertions(+), 23 deletions(-) create mode 100644 Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs create mode 100644 Analogy.CommonControls/UserControls/ValuesPlotterUC.cs create mode 100644 Analogy.CommonControls/UserControls/ValuesPlotterUC.resx diff --git a/Analogy.CommonControls/Forms/DataVisualizerForm.cs b/Analogy.CommonControls/Forms/DataVisualizerForm.cs index cb9e402d1..f5c3c2c4b 100644 --- a/Analogy.CommonControls/Forms/DataVisualizerForm.cs +++ b/Analogy.CommonControls/Forms/DataVisualizerForm.cs @@ -16,16 +16,16 @@ public DataVisualizerForm() { InitializeComponent(); } - public DataVisualizerForm(IUserSettingsManager settingsManager, Func> messages) : this() + public DataVisualizerForm(IUserSettingsManager settingsManager, Func> messages, IAnalogyLogger analogyLogger) : this() { _settingsManager = settingsManager; - DataVisualizerUC uc = new DataVisualizerUC(_settingsManager, messages); + DataVisualizerUC uc = new DataVisualizerUC(_settingsManager, messages, analogyLogger); this.Controls.Add(uc); uc.Dock = DockStyle.Fill; } - public DataVisualizerForm(List messages) : this() + public DataVisualizerForm(List messages, IAnalogyLogger analogyLogger) : this() { - DataVisualizerUC uc = new DataVisualizerUC(_settingsManager, messages); + DataVisualizerUC uc = new DataVisualizerUC(_settingsManager, messages, analogyLogger); this.Controls.Add(uc); uc.Dock = DockStyle.Fill; } diff --git a/Analogy.CommonControls/Plotting/PlottingUC.cs b/Analogy.CommonControls/Plotting/PlottingUC.cs index bf51f0507..d768ecbe5 100644 --- a/Analogy.CommonControls/Plotting/PlottingUC.cs +++ b/Analogy.CommonControls/Plotting/PlottingUC.cs @@ -17,8 +17,8 @@ namespace Analogy.CommonControls.Plotting public partial class PlottingUC : XtraUserControl { public event EventHandler<(string name, bool isChecked)> LegendItemChecked; - public IAnalogyPlotting Plotter { get; } - public AnalogyPlottingInteractor Interactor { get; } + public IAnalogyPlotting Plotter { get; private set; } + public AnalogyPlottingInteractor Interactor { get; private set; } private PlottingDataManager Manager { get; set; } public PlotState PlotState { get; private set; } private Color SingleColor { get; set; } @@ -35,6 +35,11 @@ public PlottingUC() } public PlottingUC(IAnalogyPlotting plotter, AnalogyPlottingInteractor interactor) : this() + { + Init(plotter, interactor); + } + + public void Init(IAnalogyPlotting plotter, AnalogyPlottingInteractor interactor) { Plotter = plotter; Interactor = interactor; diff --git a/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs b/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs index 367b5cb37..1ce24db2d 100644 --- a/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs +++ b/Analogy.CommonControls/UserControls/DataVisualizerUC.Designer.cs @@ -1,4 +1,6 @@ -namespace Analogy.CommonControls.UserControls +using System.Windows.Forms; + +namespace Analogy.CommonControls.UserControls { partial class DataVisualizerUC { @@ -46,9 +48,10 @@ private void InitializeComponent() this.xtraTabControl1 = new DevExpress.XtraTab.XtraTabControl(); this.xtpMessagesText = new DevExpress.XtraTab.XtraTabPage(); this.xtpPieChart = new DevExpress.XtraTab.XtraTabPage(); - this.xtpColumnPlotter = new DevExpress.XtraTab.XtraTabPage(); + this.xtpValuesPlotter = new DevExpress.XtraTab.XtraTabPage(); this.logStatisticsUC1 = new Analogy.CommonControls.UserControls.LogStatisticsUC(); + this.valuesPlotterUC = new ValuesPlotterUC(); this.tmrPlotting = new System.Windows.Forms.Timer(this.components); ((System.ComponentModel.ISupportInitialize)(this.splitContainerControl1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.splitContainerControl1.Panel1)).BeginInit(); @@ -72,7 +75,7 @@ private void InitializeComponent() this.xtraTabControl1.SuspendLayout(); this.xtpMessagesText.SuspendLayout(); this.xtpPieChart.SuspendLayout(); - this.xtpColumnPlotter.SuspendLayout(); + this.xtpValuesPlotter.SuspendLayout(); this.SuspendLayout(); // // splitContainerControl1 @@ -251,7 +254,7 @@ private void InitializeComponent() this.xtraTabControl1.TabIndex = 2; this.xtraTabControl1.TabPages.AddRange(new DevExpress.XtraTab.XtraTabPage[] { this.xtpMessagesText, - this.xtpPieChart, this.xtpColumnPlotter}); + this.xtpPieChart, this.xtpValuesPlotter}); // // xtpMessagesText // @@ -266,13 +269,7 @@ private void InitializeComponent() this.xtpPieChart.Name = "xtpPieChart"; this.xtpPieChart.Size = new System.Drawing.Size(1013, 541); this.xtpPieChart.Text = "Pies"; - // - // xtpColumnPlotter - // - this.xtpColumnPlotter.Controls.Add(this.logStatisticsUC1); - this.xtpColumnPlotter.Name = "xtpColumnPlotter"; - this.xtpColumnPlotter.Size = new System.Drawing.Size(1013, 541); - this.xtpColumnPlotter.Text = "Values"; + // // logStatisticsUC1 // @@ -284,6 +281,19 @@ private void InitializeComponent() this.logStatisticsUC1.Statistics = null; this.logStatisticsUC1.TabIndex = 0; // + // xtpValuesPlotter + // + this.xtpValuesPlotter.Controls.Add(this.valuesPlotterUC); + this.xtpValuesPlotter.Name = "xtpValuesPlotter"; + this.xtpValuesPlotter.Size = new System.Drawing.Size(1013, 541); + this.xtpValuesPlotter.Text = "Values"; + // + // valuesPlotterUC + // + this.valuesPlotterUC.Name = "valuesPlotterUC"; + this.valuesPlotterUC.Size = new System.Drawing.Size(1000, 520); + this.valuesPlotterUC.Dock = System.Windows.Forms.DockStyle.Fill; + // // tmrPlotting // this.tmrPlotting.Interval = 5000; @@ -321,7 +331,7 @@ private void InitializeComponent() this.xtraTabControl1.ResumeLayout(false); this.xtpMessagesText.ResumeLayout(false); this.xtpPieChart.ResumeLayout(false); - this.xtpColumnPlotter.ResumeLayout(false); + this.xtpValuesPlotter.ResumeLayout(false); this.ResumeLayout(false); } @@ -340,7 +350,8 @@ private void InitializeComponent() private DevExpress.XtraTab.XtraTabControl xtraTabControl1; private DevExpress.XtraTab.XtraTabPage xtpMessagesText; private DevExpress.XtraTab.XtraTabPage xtpPieChart; - private DevExpress.XtraTab.XtraTabPage xtpColumnPlotter; + private DevExpress.XtraTab.XtraTabPage xtpValuesPlotter; + private ValuesPlotterUC valuesPlotterUC; private LogStatisticsUC logStatisticsUC1; private System.Windows.Forms.Timer tmrPlotting; private DevExpress.XtraEditors.SpinEdit seRefreshInterval; diff --git a/Analogy.CommonControls/UserControls/DataVisualizerUC.cs b/Analogy.CommonControls/UserControls/DataVisualizerUC.cs index f8d03bb95..ca1890abb 100644 --- a/Analogy.CommonControls/UserControls/DataVisualizerUC.cs +++ b/Analogy.CommonControls/UserControls/DataVisualizerUC.cs @@ -27,17 +27,19 @@ public DataVisualizerUC() InitializeComponent(); } - public DataVisualizerUC(IUserSettingsManager settings, Func> messagesFunc) : this() + public DataVisualizerUC(IUserSettingsManager settings, Func> messagesFunc, IAnalogyLogger analogyLogger) : this() { _settings = settings; Messages = messagesFunc; logStatisticsUC1.Statistics = new LogStatistics(messagesFunc.Invoke()); + valuesPlotterUC.Init(messagesFunc, analogyLogger); } - public DataVisualizerUC(IUserSettingsManager settings, List messages) : this() + public DataVisualizerUC(IUserSettingsManager settings, List messages, IAnalogyLogger analogyLogger) : this() { _settings = settings; Messages = () => messages; logStatisticsUC1.Statistics = new LogStatistics(messages); + valuesPlotterUC.Init(Messages, analogyLogger); } private void DataVisualizerUC_Load(object sender, EventArgs e) diff --git a/Analogy.CommonControls/UserControls/LogMessagesUC.cs b/Analogy.CommonControls/UserControls/LogMessagesUC.cs index 52e3d3df3..0a481552e 100644 --- a/Analogy.CommonControls/UserControls/LogMessagesUC.cs +++ b/Analogy.CommonControls/UserControls/LogMessagesUC.cs @@ -3347,7 +3347,7 @@ private void tsmiREmoveAllPreviousMessages_Click(object sender, EventArgs e) private void bBtnDataVisualizer_ItemClick(object sender, ItemClickEventArgs e) { - DataVisualizerForm sv = new DataVisualizerForm(Settings, () => Messages); + DataVisualizerForm sv = new DataVisualizerForm(Settings, () => Messages, Logger); sv.Show(this); } diff --git a/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs b/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs index 4c3ea6d3b..d32143e01 100644 --- a/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs +++ b/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs @@ -3116,7 +3116,7 @@ private void tsmiREmoveAllPreviousMessages_Click(object sender, EventArgs e) private void bBtnDataVisualizer_ItemClick(object sender, ItemClickEventArgs e) { - DataVisualizerForm sv = new DataVisualizerForm(Settings, () => Messages); + DataVisualizerForm sv = new DataVisualizerForm(Settings, () => Messages, Logger); sv.Show(this); } diff --git a/Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs b/Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs new file mode 100644 index 000000000..76ac66a7a --- /dev/null +++ b/Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs @@ -0,0 +1,157 @@ +namespace Analogy.CommonControls.UserControls +{ + partial class ValuesPlotterUC + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Component Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.PnlToolbar = new System.Windows.Forms.Panel(); + this.CmbColumns = new System.Windows.Forms.ComboBox(); + this.BtnAdd = new System.Windows.Forms.Button(); + this.BtnRefreshColumns = new System.Windows.Forms.Button(); + this.label1 = new System.Windows.Forms.Label(); + this.LstPlotted = new System.Windows.Forms.ListBox(); + this.label2 = new System.Windows.Forms.Label(); + this.BtnDelete = new System.Windows.Forms.Button(); + this.PnlPlot = new System.Windows.Forms.Panel(); + this.PnlToolbar.SuspendLayout(); + this.SuspendLayout(); + // + // PnlToolbar + // + this.PnlToolbar.Controls.Add(this.BtnDelete); + this.PnlToolbar.Controls.Add(this.label2); + this.PnlToolbar.Controls.Add(this.LstPlotted); + this.PnlToolbar.Controls.Add(this.label1); + this.PnlToolbar.Controls.Add(this.BtnRefreshColumns); + this.PnlToolbar.Controls.Add(this.BtnAdd); + this.PnlToolbar.Controls.Add(this.CmbColumns); + this.PnlToolbar.Dock = System.Windows.Forms.DockStyle.Top; + this.PnlToolbar.Location = new System.Drawing.Point(0, 0); + this.PnlToolbar.Name = "PnlToolbar"; + this.PnlToolbar.Size = new System.Drawing.Size(1163, 100); + this.PnlToolbar.TabIndex = 0; + // + // CmbColumns + // + this.CmbColumns.FormattingEnabled = true; + this.CmbColumns.Location = new System.Drawing.Point(89, 13); + this.CmbColumns.Name = "CmbColumns"; + this.CmbColumns.Size = new System.Drawing.Size(232, 21); + this.CmbColumns.TabIndex = 0; + // + // BtnAdd + // + this.BtnAdd.Location = new System.Drawing.Point(327, 11); + this.BtnAdd.Name = "BtnAdd"; + this.BtnAdd.Size = new System.Drawing.Size(75, 23); + this.BtnAdd.TabIndex = 1; + this.BtnAdd.Text = "Add"; + this.BtnAdd.UseVisualStyleBackColor = true; + this.BtnAdd.Click += new System.EventHandler(this.BtnAdd_Click); + // + // BtnRefreshColumns + // + this.BtnRefreshColumns.Location = new System.Drawing.Point(438, 11); + this.BtnRefreshColumns.Name = "BtnRefreshColumns"; + this.BtnRefreshColumns.Size = new System.Drawing.Size(75, 23); + this.BtnRefreshColumns.TabIndex = 2; + this.BtnRefreshColumns.Text = "Refresh list"; + this.BtnRefreshColumns.UseVisualStyleBackColor = true; + this.BtnRefreshColumns.Click += new System.EventHandler(this.BtnRefreshColumns_Click); + // + // label1 + // + this.label1.AutoSize = true; + this.label1.Location = new System.Drawing.Point(9, 16); + this.label1.Name = "label1"; + this.label1.Size = new System.Drawing.Size(74, 13); + this.label1.TabIndex = 3; + this.label1.Text = "Select column"; + // + // LstPlotted + // + this.LstPlotted.FormattingEnabled = true; + this.LstPlotted.Location = new System.Drawing.Point(629, 13); + this.LstPlotted.Name = "LstPlotted"; + this.LstPlotted.Size = new System.Drawing.Size(363, 69); + this.LstPlotted.TabIndex = 4; + // + // label2 + // + this.label2.AutoSize = true; + this.label2.Location = new System.Drawing.Point(583, 16); + this.label2.Name = "label2"; + this.label2.Size = new System.Drawing.Size(40, 13); + this.label2.TabIndex = 5; + this.label2.Text = "Plotted"; + // + // BtnDelete + // + this.BtnDelete.Location = new System.Drawing.Point(998, 11); + this.BtnDelete.Name = "BtnDelete"; + this.BtnDelete.Size = new System.Drawing.Size(75, 23); + this.BtnDelete.TabIndex = 6; + this.BtnDelete.Text = "Delete"; + this.BtnDelete.UseVisualStyleBackColor = true; + this.BtnDelete.Click += new System.EventHandler(this.BtnDelete_Click); + // + // PnlPlot + // + this.PnlPlot.Dock = System.Windows.Forms.DockStyle.Fill; + this.PnlPlot.Location = new System.Drawing.Point(0, 100); + this.PnlPlot.Name = "PnlPlot"; + this.PnlPlot.Size = new System.Drawing.Size(1163, 367); + this.PnlPlot.TabIndex = 1; + // + // ValuesPlotterUC + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.AutoSize = true; + this.Controls.Add(this.PnlPlot); + this.Controls.Add(this.PnlToolbar); + this.Name = "ValuesPlotterUC"; + this.Size = new System.Drawing.Size(1163, 467); + this.PnlToolbar.ResumeLayout(false); + this.PnlToolbar.PerformLayout(); + this.ResumeLayout(false); + + } + + #endregion + + private System.Windows.Forms.Panel PnlToolbar; + private System.Windows.Forms.Label label1; + private System.Windows.Forms.Button BtnRefreshColumns; + private System.Windows.Forms.Button BtnAdd; + private System.Windows.Forms.ComboBox CmbColumns; + private System.Windows.Forms.Label label2; + private System.Windows.Forms.ListBox LstPlotted; + private System.Windows.Forms.Button BtnDelete; + private System.Windows.Forms.Panel PnlPlot; + } +} diff --git a/Analogy.CommonControls/UserControls/ValuesPlotterUC.cs b/Analogy.CommonControls/UserControls/ValuesPlotterUC.cs new file mode 100644 index 000000000..d5991ecf8 --- /dev/null +++ b/Analogy.CommonControls/UserControls/ValuesPlotterUC.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; +using Analogy.CommonControls.DataTypes; +using Analogy.CommonControls.Plotting; +using Analogy.Interfaces; +using Analogy.Interfaces.DataTypes; + +namespace Analogy.CommonControls.UserControls +{ + public partial class ValuesPlotterUC : UserControl, IAnalogyPlotting + { + private readonly AnalogyPlottingInteractor _interactor; + private readonly List<(string SeriesName, AnalogyPlottingSeriesType SeriesViewType)> _series; + private Func> _messages; + private PlottingUC _plottingUC; + + public ValuesPlotterUC() + { + _interactor = new AnalogyPlottingInteractor(); + InitializeComponent(); + ActiveColumns = new BindingList(); + ColumnNames = new BindingList(); + CmbColumns.DataSource = ColumnNames; + LstPlotted.DataSource = ActiveColumns; + _series = new List<(string SeriesName, AnalogyPlottingSeriesType SeriesViewType)>(); + } + + public BindingList ColumnNames { get; set; } + public BindingList ActiveColumns { get; set; } + + public IEnumerable<(string SeriesName, AnalogyPlottingSeriesType SeriesViewType)> GetChartSeries() + { + return _series; + } + + public Task InitializePlotting(IAnalogyPlottingInteractor uiInteractor, IAnalogyLogger logger) + { + return Task.CompletedTask; + ; + } + + public Task StartPlotting() + { + _plottingUC = new PlottingUC(this, _interactor); + PnlPlot.Controls.Add(_plottingUC); + _plottingUC.Dock = DockStyle.Fill; + _plottingUC.Start(); + foreach ((string SeriesName, AnalogyPlottingSeriesType SeriesViewType) series in _series) + { + List messages = _messages.Invoke().Where(i => i.AdditionalProperties != null && i.AdditionalProperties.ContainsKey(series.SeriesName)).OrderBy(i => i.Date) + .ToList(); + List points = new(messages.Count); + foreach (IAnalogyLogMessage message in messages) + { + if (Double.TryParse(message.AdditionalProperties![series.SeriesName], out double val)) + { + AnalogyPlottingPointData data = new(series.SeriesName, val, message.Date); + points.Add(data); + } + } + OnNewPointsData?.Invoke(this, points); + } + return Task.CompletedTask; + ; + } + + public Task StopPlotting() + { + if (_plottingUC != null) + { + _plottingUC.Stop(); + PnlPlot.Controls.Remove(_plottingUC); + _plottingUC.Dispose(); + } + return Task.CompletedTask; + ; + } + + public Guid Id { get; set; } + public Guid FactoryId { get; set; } + public string Title { get; set; } + public event EventHandler? OnNewPointData; + public event EventHandler>? OnNewPointsData; + + public void Init(Func> messagesFunc, IAnalogyLogger analogyLogger) + { + InitializePlotting(_interactor, analogyLogger); + _messages = messagesFunc; + RefreshColumnList(); + } + + private void RefreshColumnList() + { + List m = _messages.Invoke(); + IOrderedEnumerable columns = m.Where(i => i.AdditionalProperties != null).SelectMany(i => i.AdditionalProperties!.Keys).Distinct().OrderBy(i => i); + foreach (string column in columns) + ColumnNames.Add(column); + + } + + private void BtnAdd_Click(object sender, EventArgs e) + { + string column = CmbColumns.SelectedItem as string; + if (column == null) + return; + if (!ActiveColumns.Contains(column)) + AddSeries(column); + } + + private void AddSeries(string column) + { + ActiveColumns.Add(column); + StopPlotting(); + _series.Add((column, AnalogyPlottingSeriesType.Line)); + StartPlotting(); + } + + private void RemoveSeries(string column) + { + ActiveColumns.Remove(column); + StopPlotting(); + _series.Remove((column, AnalogyPlottingSeriesType.Line)); + StartPlotting(); + } + + private void BtnRefreshColumns_Click(object sender, EventArgs e) + { + RefreshColumnList(); + } + + private void BtnDelete_Click(object sender, EventArgs e) + { + string? column = LstPlotted.SelectedItem as string; + if (column != null) + { + RemoveSeries(column); + } + } + } +} \ No newline at end of file diff --git a/Analogy.CommonControls/UserControls/ValuesPlotterUC.resx b/Analogy.CommonControls/UserControls/ValuesPlotterUC.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/Analogy.CommonControls/UserControls/ValuesPlotterUC.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file From bfd0214342376bf62c5ebe779fb4367b640cea74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yann=20Brid=C3=A9?= Date: Thu, 30 Mar 2023 17:57:01 +0200 Subject: [PATCH 3/5] =?UTF-8?q?=E2=8F=AA=EF=B8=8F=20Revert=20change?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Analogy.CommonControls/Plotting/PlottingUC.cs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Analogy.CommonControls/Plotting/PlottingUC.cs b/Analogy.CommonControls/Plotting/PlottingUC.cs index d768ecbe5..bf51f0507 100644 --- a/Analogy.CommonControls/Plotting/PlottingUC.cs +++ b/Analogy.CommonControls/Plotting/PlottingUC.cs @@ -17,8 +17,8 @@ namespace Analogy.CommonControls.Plotting public partial class PlottingUC : XtraUserControl { public event EventHandler<(string name, bool isChecked)> LegendItemChecked; - public IAnalogyPlotting Plotter { get; private set; } - public AnalogyPlottingInteractor Interactor { get; private set; } + public IAnalogyPlotting Plotter { get; } + public AnalogyPlottingInteractor Interactor { get; } private PlottingDataManager Manager { get; set; } public PlotState PlotState { get; private set; } private Color SingleColor { get; set; } @@ -35,11 +35,6 @@ public PlottingUC() } public PlottingUC(IAnalogyPlotting plotter, AnalogyPlottingInteractor interactor) : this() - { - Init(plotter, interactor); - } - - public void Init(IAnalogyPlotting plotter, AnalogyPlottingInteractor interactor) { Plotter = plotter; Interactor = interactor; From 9d2c265ee602696199d05acb0e26e19169a36312 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yann=20Brid=C3=A9?= Date: Fri, 31 Mar 2023 10:10:13 +0200 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=92=84Using=20DevExpress=20controls?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../UserControls/ValuesPlotterUC.Designer.cs | 66 +++++++++---------- 1 file changed, 32 insertions(+), 34 deletions(-) diff --git a/Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs b/Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs index 76ac66a7a..b2efeab61 100644 --- a/Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs +++ b/Analogy.CommonControls/UserControls/ValuesPlotterUC.Designer.cs @@ -1,4 +1,6 @@ -namespace Analogy.CommonControls.UserControls +using DevExpress.XtraEditors; + +namespace Analogy.CommonControls.UserControls { partial class ValuesPlotterUC { @@ -30,12 +32,12 @@ private void InitializeComponent() { this.PnlToolbar = new System.Windows.Forms.Panel(); this.CmbColumns = new System.Windows.Forms.ComboBox(); - this.BtnAdd = new System.Windows.Forms.Button(); - this.BtnRefreshColumns = new System.Windows.Forms.Button(); - this.label1 = new System.Windows.Forms.Label(); - this.LstPlotted = new System.Windows.Forms.ListBox(); - this.label2 = new System.Windows.Forms.Label(); - this.BtnDelete = new System.Windows.Forms.Button(); + this.BtnAdd = new DevExpress.XtraEditors.SimpleButton(); + this.BtnRefreshColumns = new DevExpress.XtraEditors.SimpleButton(); + this.LblSelect = new System.Windows.Forms.Label(); + this.LstPlotted = new ListBoxControl(); + this.LblPlotted = new System.Windows.Forms.Label(); + this.BtnDelete = new DevExpress.XtraEditors.SimpleButton(); this.PnlPlot = new System.Windows.Forms.Panel(); this.PnlToolbar.SuspendLayout(); this.SuspendLayout(); @@ -43,9 +45,9 @@ private void InitializeComponent() // PnlToolbar // this.PnlToolbar.Controls.Add(this.BtnDelete); - this.PnlToolbar.Controls.Add(this.label2); + this.PnlToolbar.Controls.Add(this.LblPlotted); this.PnlToolbar.Controls.Add(this.LstPlotted); - this.PnlToolbar.Controls.Add(this.label1); + this.PnlToolbar.Controls.Add(this.LblSelect); this.PnlToolbar.Controls.Add(this.BtnRefreshColumns); this.PnlToolbar.Controls.Add(this.BtnAdd); this.PnlToolbar.Controls.Add(this.CmbColumns); @@ -70,7 +72,6 @@ private void InitializeComponent() this.BtnAdd.Size = new System.Drawing.Size(75, 23); this.BtnAdd.TabIndex = 1; this.BtnAdd.Text = "Add"; - this.BtnAdd.UseVisualStyleBackColor = true; this.BtnAdd.Click += new System.EventHandler(this.BtnAdd_Click); // // BtnRefreshColumns @@ -80,34 +81,32 @@ private void InitializeComponent() this.BtnRefreshColumns.Size = new System.Drawing.Size(75, 23); this.BtnRefreshColumns.TabIndex = 2; this.BtnRefreshColumns.Text = "Refresh list"; - this.BtnRefreshColumns.UseVisualStyleBackColor = true; this.BtnRefreshColumns.Click += new System.EventHandler(this.BtnRefreshColumns_Click); // - // label1 + // LblSelect // - this.label1.AutoSize = true; - this.label1.Location = new System.Drawing.Point(9, 16); - this.label1.Name = "label1"; - this.label1.Size = new System.Drawing.Size(74, 13); - this.label1.TabIndex = 3; - this.label1.Text = "Select column"; + this.LblSelect.AutoSize = true; + this.LblSelect.Location = new System.Drawing.Point(9, 16); + this.LblSelect.Name = "LblSelect"; + this.LblSelect.Size = new System.Drawing.Size(74, 13); + this.LblSelect.TabIndex = 3; + this.LblSelect.Text = "Select column"; // // LstPlotted // - this.LstPlotted.FormattingEnabled = true; this.LstPlotted.Location = new System.Drawing.Point(629, 13); this.LstPlotted.Name = "LstPlotted"; this.LstPlotted.Size = new System.Drawing.Size(363, 69); this.LstPlotted.TabIndex = 4; // - // label2 + // LblPlotted // - this.label2.AutoSize = true; - this.label2.Location = new System.Drawing.Point(583, 16); - this.label2.Name = "label2"; - this.label2.Size = new System.Drawing.Size(40, 13); - this.label2.TabIndex = 5; - this.label2.Text = "Plotted"; + this.LblPlotted.AutoSize = true; + this.LblPlotted.Location = new System.Drawing.Point(583, 16); + this.LblPlotted.Name = "LblPlotted"; + this.LblPlotted.Size = new System.Drawing.Size(40, 13); + this.LblPlotted.TabIndex = 5; + this.LblPlotted.Text = "Plotted"; // // BtnDelete // @@ -116,7 +115,6 @@ private void InitializeComponent() this.BtnDelete.Size = new System.Drawing.Size(75, 23); this.BtnDelete.TabIndex = 6; this.BtnDelete.Text = "Delete"; - this.BtnDelete.UseVisualStyleBackColor = true; this.BtnDelete.Click += new System.EventHandler(this.BtnDelete_Click); // // PnlPlot @@ -145,13 +143,13 @@ private void InitializeComponent() #endregion private System.Windows.Forms.Panel PnlToolbar; - private System.Windows.Forms.Label label1; - private System.Windows.Forms.Button BtnRefreshColumns; - private System.Windows.Forms.Button BtnAdd; - private System.Windows.Forms.ComboBox CmbColumns; - private System.Windows.Forms.Label label2; - private System.Windows.Forms.ListBox LstPlotted; - private System.Windows.Forms.Button BtnDelete; + private System.Windows.Forms.Label LblSelect; + private DevExpress.XtraEditors.SimpleButton BtnRefreshColumns; + private DevExpress.XtraEditors.SimpleButton BtnAdd; + private System.Windows.Forms.ComboBox CmbColumns; + private System.Windows.Forms.Label LblPlotted; + private ListBoxControl LstPlotted; + private DevExpress.XtraEditors.SimpleButton BtnDelete; private System.Windows.Forms.Panel PnlPlot; } } From fc2083c62d177705bda46ab175c4109c604614dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-Yann=20Brid=C3=A9?= Date: Fri, 31 Mar 2023 11:18:06 +0200 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=A8Add=20"live"=20update=20for=20file?= =?UTF-8?q?=20pooling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Forms/DataVisualizerForm.cs | 25 +++++++------ .../UserControls/DataVisualizerUC.cs | 17 +++++---- .../UserControls/LogMessagesUC.Designer.cs | 2 ++ .../UserControls/LogMessagesUC.cs | 12 +++++-- .../ServerSideLogMessagesUC.Designer.cs | 2 ++ .../UserControls/ServerSideLogMessagesUC.cs | 11 ++++-- .../UserControls/ValuesPlotterUC.cs | 35 +++++++++++++++++++ 7 files changed, 83 insertions(+), 21 deletions(-) diff --git a/Analogy.CommonControls/Forms/DataVisualizerForm.cs b/Analogy.CommonControls/Forms/DataVisualizerForm.cs index f5c3c2c4b..34695138c 100644 --- a/Analogy.CommonControls/Forms/DataVisualizerForm.cs +++ b/Analogy.CommonControls/Forms/DataVisualizerForm.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Windows.Forms; using Analogy.Common.Interfaces; -using Analogy.CommonControls.Interfaces; using Analogy.CommonControls.UserControls; using Analogy.Interfaces; @@ -11,6 +10,7 @@ namespace Analogy.CommonControls.Forms public partial class DataVisualizerForm : DevExpress.XtraEditors.XtraForm { private readonly IUserSettingsManager _settingsManager; + private readonly DataVisualizerUC dataVisualizerUC; public DataVisualizerForm() { @@ -19,19 +19,24 @@ public DataVisualizerForm() public DataVisualizerForm(IUserSettingsManager settingsManager, Func> messages, IAnalogyLogger analogyLogger) : this() { _settingsManager = settingsManager; - DataVisualizerUC uc = new DataVisualizerUC(_settingsManager, messages, analogyLogger); - this.Controls.Add(uc); - uc.Dock = DockStyle.Fill; - } - public DataVisualizerForm(List messages, IAnalogyLogger analogyLogger) : this() - { - DataVisualizerUC uc = new DataVisualizerUC(_settingsManager, messages, analogyLogger); - this.Controls.Add(uc); - uc.Dock = DockStyle.Fill; + dataVisualizerUC = new DataVisualizerUC(_settingsManager, messages, analogyLogger); + Controls.Add(dataVisualizerUC); + dataVisualizerUC.Dock = DockStyle.Fill; } + private void DataVisualizerUCForm_Load(object sender, EventArgs e) { Icon = _settingsManager.GetIcon(); } + + public void AppendMessage(IAnalogyLogMessage message, string dataSource) + { + dataVisualizerUC?.AppendMessage(message, dataSource); + } + + public void AppendMessages(List messages, string dataSource) + { + dataVisualizerUC?.AppendMessages(messages, dataSource); + } } } \ No newline at end of file diff --git a/Analogy.CommonControls/UserControls/DataVisualizerUC.cs b/Analogy.CommonControls/UserControls/DataVisualizerUC.cs index ca1890abb..21ff74511 100644 --- a/Analogy.CommonControls/UserControls/DataVisualizerUC.cs +++ b/Analogy.CommonControls/UserControls/DataVisualizerUC.cs @@ -34,13 +34,6 @@ public DataVisualizerUC(IUserSettingsManager settings, Func messages, IAnalogyLogger analogyLogger) : this() - { - _settings = settings; - Messages = () => messages; - logStatisticsUC1.Statistics = new LogStatistics(messages); - valuesPlotterUC.Init(Messages, analogyLogger); - } private void DataVisualizerUC_Load(object sender, EventArgs e) { @@ -221,5 +214,15 @@ private void tmrPlotting_Tick(object sender, EventArgs e) Plot(); tmrPlotting.Enabled = true; } + + public void AppendMessage(IAnalogyLogMessage message, string dataSource) + { + valuesPlotterUC?.AppendMessage(message, dataSource); + } + + public void AppendMessages(List messages, string dataSource) + { + valuesPlotterUC?.AppendMessages(messages, dataSource); + } } } \ No newline at end of file diff --git a/Analogy.CommonControls/UserControls/LogMessagesUC.Designer.cs b/Analogy.CommonControls/UserControls/LogMessagesUC.Designer.cs index b19b9536c..daac36305 100644 --- a/Analogy.CommonControls/UserControls/LogMessagesUC.Designer.cs +++ b/Analogy.CommonControls/UserControls/LogMessagesUC.Designer.cs @@ -27,6 +27,8 @@ protected override void Dispose(bool disposing) components.Dispose(); } + if (frmDataVisualizer != null && !frmDataVisualizer.IsDisposed) + frmDataVisualizer.Dispose(); } base.Dispose(disposing); } diff --git a/Analogy.CommonControls/UserControls/LogMessagesUC.cs b/Analogy.CommonControls/UserControls/LogMessagesUC.cs index 0a481552e..074598f57 100644 --- a/Analogy.CommonControls/UserControls/LogMessagesUC.cs +++ b/Analogy.CommonControls/UserControls/LogMessagesUC.cs @@ -188,6 +188,8 @@ public bool RealTimeMode #region fields private bool useSpecificColumnForJson; private string jsonColumnForInlineJsonViewer; + private DataVisualizerForm frmDataVisualizer; + #endregion fields private JsonTreeUC JsonTreeView { get; set; } @@ -1740,6 +1742,9 @@ public void AppendMessage(IAnalogyLogMessage message, string dataSource) return; } + if (frmDataVisualizer != null) + frmDataVisualizer.AppendMessage(message, dataSource); + if (ExternalWindowsCount > 0) { foreach (XtraFormLogGrid grid in ExternalWindows) @@ -1871,6 +1876,9 @@ public void AppendMessages(List messages, string dataSource) } } + if (frmDataVisualizer != null) + frmDataVisualizer.AppendMessages(messages, dataSource); + foreach (var (dtr, message) in PagingManager.AppendMessages(messages, dataSource)) { if (diffStartTime > DateTime.MinValue) @@ -3347,8 +3355,8 @@ private void tsmiREmoveAllPreviousMessages_Click(object sender, EventArgs e) private void bBtnDataVisualizer_ItemClick(object sender, ItemClickEventArgs e) { - DataVisualizerForm sv = new DataVisualizerForm(Settings, () => Messages, Logger); - sv.Show(this); + frmDataVisualizer = new DataVisualizerForm(Settings, () => Messages, Logger); + frmDataVisualizer.Show(this); } private void bbiScreenshot_ItemClick(object sender, ItemClickEventArgs e) diff --git a/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.Designer.cs b/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.Designer.cs index 3f11c64f3..bce91f42a 100644 --- a/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.Designer.cs +++ b/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.Designer.cs @@ -27,6 +27,8 @@ protected override void Dispose(bool disposing) components.Dispose(); } + if (frmDataVisualizer != null && !frmDataVisualizer.IsDisposed) + frmDataVisualizer.Dispose(); } base.Dispose(disposing); } diff --git a/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs b/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs index d32143e01..367af06a6 100644 --- a/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs +++ b/Analogy.CommonControls/UserControls/ServerSideLogMessagesUC.cs @@ -139,6 +139,8 @@ public GridView LogGrid } private bool _realTimeMode; + private DataVisualizerForm frmDataVisualizer; + public bool RealTimeMode { set @@ -1606,6 +1608,9 @@ public void AppendMessage(IAnalogyLogMessage message, string dataSource) return; } + if (frmDataVisualizer != null) + frmDataVisualizer.AppendMessage(message, dataSource); + if (ExternalWindowsCount > 0) { foreach (XtraFormLogGrid grid in ExternalWindows) @@ -1724,6 +1729,8 @@ public void AppendMessages(List messages, string dataSource) grid.AppendMessages(messages, dataSource); } } + if (frmDataVisualizer != null) + frmDataVisualizer.AppendMessages(messages, dataSource); foreach (var (dtr, message) in PagingManager.AppendMessages(messages, dataSource)) { @@ -3116,8 +3123,8 @@ private void tsmiREmoveAllPreviousMessages_Click(object sender, EventArgs e) private void bBtnDataVisualizer_ItemClick(object sender, ItemClickEventArgs e) { - DataVisualizerForm sv = new DataVisualizerForm(Settings, () => Messages, Logger); - sv.Show(this); + frmDataVisualizer = new DataVisualizerForm(Settings, () => Messages, Logger); + frmDataVisualizer.Show(this); } private void bbiScreenshot_ItemClick(object sender, ItemClickEventArgs e) diff --git a/Analogy.CommonControls/UserControls/ValuesPlotterUC.cs b/Analogy.CommonControls/UserControls/ValuesPlotterUC.cs index d5991ecf8..9be85cb81 100644 --- a/Analogy.CommonControls/UserControls/ValuesPlotterUC.cs +++ b/Analogy.CommonControls/UserControls/ValuesPlotterUC.cs @@ -96,6 +96,7 @@ public void Init(Func> messagesFunc, IAnalogyLogger ana private void RefreshColumnList() { List m = _messages.Invoke(); + ColumnNames.Clear(); IOrderedEnumerable columns = m.Where(i => i.AdditionalProperties != null).SelectMany(i => i.AdditionalProperties!.Keys).Distinct().OrderBy(i => i); foreach (string column in columns) ColumnNames.Add(column); @@ -140,5 +141,39 @@ private void BtnDelete_Click(object sender, EventArgs e) RemoveSeries(column); } } + + public void AppendMessage(IAnalogyLogMessage message, string dataSource) + { + foreach ((string SeriesName, AnalogyPlottingSeriesType SeriesViewType) series in _series) + { + if (message.AdditionalProperties != null && message.AdditionalProperties.ContainsKey(series.SeriesName)) + { + if (Double.TryParse(message.AdditionalProperties![series.SeriesName], out double val)) + { + AnalogyPlottingPointData data = new(series.SeriesName, val, message.Date); + OnNewPointData?.Invoke(this, data); + } + } + } + } + + public void AppendMessages(List messages, string dataSource) + { + foreach ((string SeriesName, AnalogyPlottingSeriesType SeriesViewType) series in _series) + { + List messagesFiltered = messages.Where(i => i.AdditionalProperties != null && i.AdditionalProperties.ContainsKey(series.SeriesName)).OrderBy(i => i.Date) + .ToList(); + List points = new(messagesFiltered.Count); + foreach (IAnalogyLogMessage message in messagesFiltered) + { + if (Double.TryParse(message.AdditionalProperties![series.SeriesName], out double val)) + { + AnalogyPlottingPointData data = new(series.SeriesName, val, message.Date); + points.Add(data); + } + } + OnNewPointsData?.Invoke(this, points); + } + } } } \ No newline at end of file