@@ -49,7 +49,7 @@ public MetricsView(
4949
5050 private void UserControl_Loaded ( object sender , RoutedEventArgs e )
5151 {
52- this . Metrics . AddRange ( this . metricsService . GetMetrics ( ) . Select ( s => new MetricSetViewModel { Instrument = s . Instrument , AggregationType = s . AggregationType , Metrics = new ObservableCollection < Metric > ( s . Metrics ?? new List < Metric > ( ) ) } ) . ToList ( ) ) ;
52+ this . Metrics . AddRange ( [ .. this . metricsService . GetMetrics ( ) . Select ( s => new MetricSetViewModel { Instrument = s . Instrument , AggregationType = s . AggregationType , Metrics = [ .. s . Metrics ?? [ ] ] } ) ] ) ;
5353 this . metricsService . SetRecorded += this . MetricsService_SetRecorded ;
5454 this . metricsService . MetricRecorded += this . MetricsService_MetricRecorded ;
5555 }
@@ -71,7 +71,7 @@ private void MetricsService_SetRecorded(object? sender, MetricSet e)
7171 {
7272 this . Dispatcher . Invoke ( ( ) =>
7373 {
74- this . Metrics . Add ( new MetricSetViewModel { AggregationType = e . AggregationType , Instrument = e . Instrument , Metrics = new ObservableCollection < Metric > ( e . Metrics ?? new List < Metric > ( ) ) } ) ;
74+ this . Metrics . Add ( new MetricSetViewModel { AggregationType = e . AggregationType , Instrument = e . Instrument , Metrics = [ .. e . Metrics ?? [ ] ] } ) ;
7575 } ) ;
7676 }
7777
@@ -114,8 +114,8 @@ metricSet.Metrics is null ||
114114 }
115115
116116 cartesianChart . DrawMargin = new LiveChartsCore . Measure . Margin ( 30 ) ;
117- cartesianChart . XAxes = new Axis [ ]
118- {
117+ cartesianChart . XAxes =
118+ [
119119 new Axis
120120 {
121121 Name = "Time" ,
@@ -133,10 +133,10 @@ metricSet.Metrics is null ||
133133 TicksPaint = this . transparentPaint ,
134134 ZeroPaint = this . transparentPaint ,
135135 }
136- } ;
136+ ] ;
137137
138- cartesianChart . YAxes = new Axis [ ]
139- {
138+ cartesianChart . YAxes =
139+ [
140140 new Axis
141141 {
142142 Name = metricSet . Instrument . Unit ,
@@ -150,18 +150,18 @@ metricSet.Metrics is null ||
150150 TicksPaint = this . transparentPaint ,
151151 ZeroPaint = this . transparentPaint ,
152152 }
153- } ;
153+ ] ;
154154
155- cartesianChart . Series = new ISeries [ ]
156- {
155+ cartesianChart . Series =
156+ [
157157 new LineSeries < Metric >
158158 {
159159 Values = metricSet . AggregationType switch
160160 {
161- AggregationTypes . NoAggregate => this . PlotNoAggregation ( metricSet . Metrics ) ,
162- AggregationTypes . P95 => this . PlotPercentageAggregation ( metricSet . Metrics , 0.95 ) ,
163- AggregationTypes . P98 => this . PlotPercentageAggregation ( metricSet . Metrics , 0.98 ) ,
164- AggregationTypes . P99 => this . PlotPercentageAggregation ( metricSet . Metrics , 0.99 ) ,
161+ AggregationTypes . NoAggregate => PlotNoAggregation ( metricSet . Metrics ) ,
162+ AggregationTypes . P95 => PlotPercentageAggregation ( metricSet . Metrics , 0.95 ) ,
163+ AggregationTypes . P98 => PlotPercentageAggregation ( metricSet . Metrics , 0.98 ) ,
164+ AggregationTypes . P99 => PlotPercentageAggregation ( metricSet . Metrics , 0.99 ) ,
165165 _ => throw new InvalidOperationException ( "Unable to plot metrics. Unknown aggregation" )
166166 } ,
167167 Fill = default ,
@@ -173,7 +173,7 @@ metricSet.Metrics is null ||
173173 GeometrySize = default ,
174174 Name = string . Empty
175175 }
176- } ;
176+ ] ;
177177
178178 cartesianChart . Title = new LabelVisual
179179 {
@@ -183,23 +183,23 @@ metricSet.Metrics is null ||
183183 } ;
184184 }
185185
186- private IEnumerable < Metric > PlotNoAggregation ( IEnumerable < Metric > dataSet )
186+ private void InterceptScroll ( object sender , System . Windows . Input . MouseWheelEventArgs e )
187+ {
188+ e . Handled = true ;
189+ }
190+
191+ private static ObservableCollection < Metric > PlotNoAggregation ( ObservableCollection < Metric > dataSet )
187192 {
188193 return dataSet ;
189194 }
190195
191- private IEnumerable < Metric > PlotPercentageAggregation ( IEnumerable < Metric > dataSet , double percentage )
196+ private static IReadOnlyCollection < Metric > PlotPercentageAggregation ( ObservableCollection < Metric > dataSet , double percentage )
192197 {
193198 var dataSetArray = dataSet . ToArray ( ) ;
194199 var valuesToTake = Math . Round ( dataSetArray . Length * percentage ) . ToInt ( ) ;
195200 var orderedByValueDataSet = dataSetArray . OrderBy ( s => s . Measurement ) ;
196201 var finalDataSet = orderedByValueDataSet . Take ( valuesToTake ) . OrderBy ( s => s . Timestamp ) ;
197202
198- return finalDataSet ;
199- }
200-
201- private void InterceptScroll ( object sender , System . Windows . Input . MouseWheelEventArgs e )
202- {
203- e . Handled = true ;
203+ return [ .. finalDataSet ] ;
204204 }
205205}
0 commit comments