Skip to content

Commit 6bc2077

Browse files
committed
Fixed an issue wherer the backgroud fill and the series fill didn't match frequently
1 parent 976bc19 commit 6bc2077

File tree

2 files changed

+120
-58
lines changed

2 files changed

+120
-58
lines changed

src/Files.App/UserControls/StatusCenter.xaml

Lines changed: 33 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
</Style>
6969
</ListView.ItemContainerStyle>
7070

71+
<!-- Item Template -->
7172
<ListView.ItemTemplate>
7273
<DataTemplate x:DataType="statuscenter:StatusCenterItem">
7374
<Grid
@@ -139,7 +140,7 @@
139140
Text="{x:Bind Header, Mode=OneWay}"
140141
TextTrimming="CharacterEllipsis"
141142
TextWrapping="NoWrap"
142-
ToolTipService.ToolTip="{x:Bind SubHeader, Mode=OneWay}" />
143+
ToolTipService.ToolTip="{x:Bind Header, Mode=OneWay}" />
143144

144145
</StackPanel>
145146

@@ -197,7 +198,7 @@
197198

198199
</Grid>
199200

200-
<!-- Progress & Footer -->
201+
<!-- Graph & Footer -->
201202
<Grid
202203
x:Name="StatusCenterItemRichProgressDisplayPanel"
203204
Grid.Row="1"
@@ -213,7 +214,7 @@
213214
<ColumnDefinition Width="Auto" />
214215
</Grid.ColumnDefinitions>
215216

216-
<!-- Extended ProgressBar -->
217+
<!-- Main ProgressBar -->
217218
<ProgressBar
218219
x:Name="MainProgressBar"
219220
Margin="4,4,4,4"
@@ -224,7 +225,7 @@
224225
Value="{x:Bind ProgressPercentage, Mode=OneWay}" />
225226

226227
<!-- Graph -->
227-
<Border
228+
<Grid
228229
x:Name="MainGraphCartesianChartClipGrid"
229230
Height="72"
230231
Margin="4,4,4,12"
@@ -234,53 +235,42 @@
234235
CornerRadius="4"
235236
Visibility="{x:Bind IsExpanded, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}">
236237

237-
<Grid>
238-
<ProgressBar
239-
x:Name="SecondaryProgressBar"
240-
Height="70"
241-
MinHeight="70"
242-
VerticalAlignment="Stretch"
243-
CornerRadius="4,0,0,4"
244-
Foreground="{ThemeResource AppThemeFillColorAttentionBrush}"
245-
IsIndeterminate="False"
246-
Style="{StaticResource CustomProgressBarStyle}"
247-
Visibility="{x:Bind IsExpanded, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneWay}"
248-
Value="{x:Bind ProgressPercentage, Mode=OneWay}" />
249-
238+
<!-- NOTE: The Graph Control Somehow Includes Slight Padding, Which Is Removed By Setting Negative Margin -->
239+
<Grid Margin="-2,0,0,-2">
250240
<livecharts2:CartesianChart
251241
x:Name="MainCartesianChart"
252-
Height="48"
253-
Margin="0,-2"
242+
Height="72"
254243
VerticalAlignment="Bottom"
255244
AnimationsSpeed="00:00:00.001"
256245
Series="{x:Bind SpeedGraphSeries, Mode=OneWay}"
257246
TooltipPosition="Hidden"
258-
XAxes="{x:Bind SpeedGraphXAxes}"
259-
YAxes="{x:Bind SpeedGraphYAxes}" />
260-
261-
<StackPanel Margin="8,4">
262-
263-
<TextBlock
264-
x:Name="OperationSpeedStringTextBlock"
265-
HorizontalAlignment="Right"
266-
VerticalAlignment="Top"
267-
FontSize="10"
268-
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
269-
Style="{StaticResource CaptionTextBlockStyle}"
270-
Text="{helpers:ResourceString Name=SpeedWithColon}" />
271-
272-
<TextBlock
273-
x:Name="OperationSpeedPerSecTextBlock"
274-
HorizontalAlignment="Right"
275-
VerticalAlignment="Top"
276-
FontSize="13"
277-
Style="{StaticResource BodyStrongTextBlockStyle}"
278-
Text="{x:Bind SpeedText, Mode=OneWay}" />
279-
280-
</StackPanel>
247+
XAxes="{x:Bind SpeedGraphXAxes, Mode=OneWay}"
248+
YAxes="{x:Bind SpeedGraphYAxes, Mode=OneWay}" />
281249
</Grid>
282250

283-
</Border>
251+
<!-- Speed Text -->
252+
<StackPanel Margin="8,4">
253+
254+
<TextBlock
255+
x:Name="OperationSpeedStringTextBlock"
256+
HorizontalAlignment="Right"
257+
VerticalAlignment="Top"
258+
FontSize="10"
259+
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
260+
Style="{StaticResource CaptionTextBlockStyle}"
261+
Text="{helpers:ResourceString Name=SpeedWithColon}" />
262+
263+
<TextBlock
264+
x:Name="OperationSpeedPerSecTextBlock"
265+
HorizontalAlignment="Right"
266+
VerticalAlignment="Top"
267+
FontSize="13"
268+
Style="{StaticResource BodyStrongTextBlockStyle}"
269+
Text="{x:Bind SpeedText, Mode=OneWay}" />
270+
271+
</StackPanel>
272+
273+
</Grid>
284274

285275
<!-- Footer -->
286276
<Grid

src/Files.App/Utils/StatusCenter/StatusCenterItem.cs

Lines changed: 87 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,14 +163,18 @@ public StatusCenterItemProgressModel Progress
163163

164164
public ObservableCollection<ObservablePoint>? SpeedGraphValues { get; private set; }
165165

166+
public ObservableCollection<ObservablePoint>? SpeedGraphBackgroundValues { get; private set; }
167+
166168
public ObservableCollection<ISeries>? SpeedGraphSeries { get; private set; }
167169

168-
public IList<ICartesianAxis>? SpeedGraphXAxes { get; private set; }
170+
public ObservableCollection<ICartesianAxis>? SpeedGraphXAxes { get; private set; }
169171

170-
public IList<ICartesianAxis>? SpeedGraphYAxes { get; private set; }
172+
public ObservableCollection<ICartesianAxis>? SpeedGraphYAxes { get; private set; }
171173

172174
public double IconBackgroundCircleBorderOpacity { get; private set; }
173175

176+
public double? CurrentHighestPointValue { get; private set; }
177+
174178
public CancellationToken CancellationToken
175179
=> _operationCancellationToken?.Token ?? default;
176180

@@ -207,18 +211,17 @@ public StatusCenterItem(
207211
IconBackgroundCircleBorderOpacity = 1;
208212
AnimatedIconState = "NormalOff";
209213
SpeedGraphValues = new();
214+
SpeedGraphBackgroundValues = new();
210215
CancelCommand = new RelayCommand(ExecuteCancelCommand);
211216
Message = "ProcessingItems".GetLocalizedResource();
217+
Source = source;
218+
Destination = destination;
212219

213-
if (source is not null)
214-
Source = source;
215-
216-
if (destination is not null)
217-
Destination = destination;
218-
220+
// Get the graph color
219221
if (App.Current.Resources["AppThemeFillColorAttentionBrush"] is not SolidColorBrush accentBrush)
220222
return;
221223

224+
// Initialize graph series
222225
SpeedGraphSeries = new()
223226
{
224227
new LineSeries<ObservablePoint>
@@ -231,21 +234,42 @@ public StatusCenterItem(
231234
// Stroke
232235
Stroke = new SolidColorPaint(
233236
new(accentBrush.Color.R, accentBrush.Color.G, accentBrush.Color.B),
234-
1),
237+
1f),
235238

236239
// Fill under the stroke
237240
Fill = new LinearGradientPaint(
238241
new SKColor[] {
239242
new(accentBrush.Color.R, accentBrush.Color.G, accentBrush.Color.B, 50),
240243
new(accentBrush.Color.R, accentBrush.Color.G, accentBrush.Color.B, 10)
241244
},
242-
new(0.5f, 0f),
243-
new(0.5f, 1.0f),
244-
new[] { 0.2f, 1.3f }),
245+
new(0f, 0f),
246+
new(0f, 0f),
247+
new[] { 0.1f, 1.0f }),
248+
},
249+
new LineSeries<ObservablePoint>
250+
{
251+
Values = SpeedGraphBackgroundValues,
252+
GeometrySize = 0d,
253+
DataPadding = new(0, 0),
254+
IsHoverable = false,
255+
256+
// Stroke
257+
Stroke = new SolidColorPaint(
258+
new(accentBrush.Color.R, accentBrush.Color.G, accentBrush.Color.B, 40),
259+
0.1f),
260+
261+
// Fill under the stroke
262+
Fill = new LinearGradientPaint(
263+
new SKColor[] {
264+
new(accentBrush.Color.R, accentBrush.Color.G, accentBrush.Color.B, 40)
265+
},
266+
new(0f, 0f),
267+
new(0f, 0f)),
245268
}
246269
};
247270

248-
SpeedGraphXAxes = new ICartesianAxis[]
271+
// Initialize X axes of the graph
272+
SpeedGraphXAxes = new()
249273
{
250274
new Axis
251275
{
@@ -256,7 +280,8 @@ public StatusCenterItem(
256280
}
257281
};
258282

259-
SpeedGraphYAxes = new ICartesianAxis[]
283+
// Initialize Y axes of the graph
284+
SpeedGraphYAxes = new()
260285
{
261286
new Axis
262287
{
@@ -341,6 +366,7 @@ private void ReportProgress(StatusCenterItemProgressModel value)
341366
if (value.Status is FileSystemStatusCode status)
342367
FileSystemOperationReturnResult = status.ToStatus();
343368

369+
// Update the footer message, percentage, processing item name
344370
if (value.Percentage is double p)
345371
{
346372
if (ProgressPercentage != value.Percentage)
@@ -428,9 +454,41 @@ private void ReportProgress(StatusCenterItemProgressModel value)
428454
break;
429455
}
430456

431-
// Remove the same point
457+
bool isSamePoint = false;
458+
459+
// Remove the point that has the same X position
432460
if (SpeedGraphValues?.FirstOrDefault(v => v.X == point.X) is ObservablePoint existingPoint)
461+
{
433462
SpeedGraphValues.Remove(existingPoint);
463+
isSamePoint = true;
464+
}
465+
466+
CurrentHighestPointValue ??= point.Y;
467+
468+
if (!isSamePoint)
469+
{
470+
// NOTE: -0.4 is the value that is needs to set for the graph drawing
471+
var maxHeight = CurrentHighestPointValue * 1.44d - 0.4;
472+
473+
if (CurrentHighestPointValue < point.Y &&
474+
SpeedGraphYAxes is not null &&
475+
SpeedGraphYAxes.FirstOrDefault() is var item &&
476+
item is not null)
477+
{
478+
// Max height is updated
479+
CurrentHighestPointValue = point.Y;
480+
maxHeight = CurrentHighestPointValue * 1.44d;
481+
item.MaxLimit = maxHeight;
482+
483+
// NOTE: -0.1 is the value that is needs to set for the graph drawing
484+
UpdateGraphBackgroundPoints(point.X, maxHeight - 0.1, true);
485+
}
486+
else
487+
{
488+
// Max height is not updated
489+
UpdateGraphBackgroundPoints(point.X, maxHeight, false);
490+
}
491+
}
434492

435493
// Add a new point
436494
SpeedGraphValues?.Add(point);
@@ -443,6 +501,20 @@ private void ReportProgress(StatusCenterItemProgressModel value)
443501
_viewModel.NotifyChanges();
444502
}
445503

504+
private void UpdateGraphBackgroundPoints(double? x, double? y, bool redraw)
505+
{
506+
if (SpeedGraphBackgroundValues is null)
507+
return;
508+
509+
ObservablePoint newPoint = new(x, y);
510+
SpeedGraphBackgroundValues.Add(newPoint);
511+
512+
if (redraw)
513+
{
514+
SpeedGraphBackgroundValues.ForEach(x => x.Y = CurrentHighestPointValue * 1.44d - 0.1);
515+
}
516+
}
517+
446518
public void ExecuteCancelCommand()
447519
{
448520
if (IsCancelable)

0 commit comments

Comments
 (0)