DeliveryAdminWindow: add advanced tooltips for weight and gradation
This commit is contained in:
@ -519,6 +519,38 @@ namespace Elwig.Windows {
|
||||
return (filterNames, dpq.Select(p => p.Delivery).Distinct().OrderBy(d => d.DateString).ThenBy(d => d.TimeString), dpq, filter);
|
||||
}
|
||||
|
||||
private static void AddToolTipCell(Grid grid, string text, int row, int col, int colSpan = 1, bool bold = false, bool alignRight = false, bool alignCenter = false) {
|
||||
var tb = new TextBlock() {
|
||||
Text = text,
|
||||
TextAlignment = alignRight ? TextAlignment.Right : alignCenter ? TextAlignment.Center : TextAlignment.Left,
|
||||
Margin = new(0, 12 * row, 0, 0),
|
||||
FontWeight = bold ? FontWeights.Bold : FontWeights.Normal,
|
||||
};
|
||||
tb.SetValue(Grid.ColumnProperty, col);
|
||||
tb.SetValue(Grid.ColumnSpanProperty, colSpan);
|
||||
grid.Children.Add(tb);
|
||||
}
|
||||
|
||||
private void AddWeightToolTipRow(int row, string? h1, string? h2, int weight, int? total1, int total2) {
|
||||
var bold = h2 == null;
|
||||
if (h1 != null) AddToolTipCell(StatusWeightToolTip, h1 + ":", row, 0, (h2 == null) ? 2 : 1, bold);
|
||||
if (h2 != null) AddToolTipCell(StatusWeightToolTip, h2 + ":", row, 1, 1, bold);
|
||||
AddToolTipCell(StatusWeightToolTip, $"{weight:N0} kg", row, 2, 1, bold, true);
|
||||
if (total1 != null && total1 != 0)
|
||||
AddToolTipCell(StatusWeightToolTip, $"{weight * 100.0 / total1:N1} %", row, 3, 1, bold, true);
|
||||
if (total2 != 0)
|
||||
AddToolTipCell(StatusWeightToolTip, $"{weight * 100.0 / total2:N1} %", row, 4, 1, bold, true);
|
||||
}
|
||||
|
||||
private void AddGradationToolTipRow(int row, string? h1, string? h2, double min, double avg, double max) {
|
||||
var bold = h2 == null;
|
||||
if (h1 != null) AddToolTipCell(StatusGradationToolTip, h1 + ":", row, 0, (h2 == null) ? 2 : 1, bold);
|
||||
if (h2 != null) AddToolTipCell(StatusGradationToolTip, h2 + ":", row, 1, 1, bold);
|
||||
AddToolTipCell(StatusGradationToolTip, $"{min:N1}°", row, 2, 1, bold, true);
|
||||
AddToolTipCell(StatusGradationToolTip, $"{avg:N1}°", row, 3, 1, bold, true);
|
||||
AddToolTipCell(StatusGradationToolTip, $"{max:N1}°", row, 4, 1, bold, true);
|
||||
}
|
||||
|
||||
private async Task RefreshDeliveryListQuery(bool updateSort = false) {
|
||||
var (_, deliveryQuery, deliveryPartsQuery, filter) = await GetFilters();
|
||||
var deliveries = await deliveryQuery.ToListAsync();
|
||||
@ -551,29 +583,56 @@ namespace Elwig.Windows {
|
||||
var varieties = await deliveryParts.Select(d => d.SortId).Distinct().ToListAsync();
|
||||
StatusVarieties.Text = $"Sorten: {varieties.Count}" + (varieties.Count > 0 && varieties.Count <= 10 ? $" ({string.Join(", ", varieties)})" : "");
|
||||
|
||||
StatusWeightToolTip.Children.Clear();
|
||||
StatusGradationToolTip.Children.Clear();
|
||||
|
||||
var weight = await deliveryParts.SumAsync(p => p.Weight);
|
||||
StatusWeight.Text = $"Gewicht: {weight:N0} kg";
|
||||
AddWeightToolTipRow(0, "Gewicht", null, weight, null, weight);
|
||||
|
||||
if (n > 0) {
|
||||
var kmwMin = await deliveryParts.MinAsync(p => p.Kmw);
|
||||
var kmwAvg = Utils.AggregateDeliveryPartsKmw(deliveryParts);
|
||||
var kmwMax = await deliveryParts.MaxAsync(p => p.Kmw);
|
||||
StatusGradation.Text = $"Gradation: {kmwMin:N1}° / {kmwAvg:N1}° / {kmwMax:N1}°";
|
||||
AddToolTipCell(StatusGradationToolTip, "min.", 0, 2, 1, false, false, true);
|
||||
AddToolTipCell(StatusGradationToolTip, "⌀", 0, 3, 1, false, false, true);
|
||||
AddToolTipCell(StatusGradationToolTip, "max.", 0, 4, 1, false, false, true);
|
||||
AddGradationToolTipRow(1, "Gradation", null, kmwMin, kmwAvg, kmwMax);
|
||||
} else {
|
||||
StatusGradation.Text = "Gradation: -";
|
||||
}
|
||||
|
||||
if (n > 0 && (n <= 200 || TodayOnlyInput.IsChecked == true)) {
|
||||
var parts = await deliveryParts.ToListAsync();
|
||||
var groups = parts
|
||||
var attrGroups = parts
|
||||
.GroupBy(p => p.Attribute?.Name)
|
||||
.Select(g => (g.Key, g.Sum(p => p.Weight), g.Min(p => p.Kmw), Utils.AggregateDeliveryPartsKmw(g), g.Max(p => p.Kmw)))
|
||||
.OrderByDescending(g => g.Item2)
|
||||
.ThenBy(g => g.Key)
|
||||
.ToList();
|
||||
var groups = parts
|
||||
.GroupBy(p => (p.Attribute?.Name, p.SortId))
|
||||
.Select(g => (g.Key.Name, g.Key.SortId, g.Sum(p => p.Weight), g.Min(p => p.Kmw), Utils.AggregateDeliveryPartsKmw(g), g.Max(p => p.Kmw)))
|
||||
.OrderByDescending(g => g.SortId)
|
||||
.ThenBy(g => g.Name)
|
||||
.ThenBy(g => g.SortId)
|
||||
.ToList();
|
||||
|
||||
if (groups.Count == 1) {
|
||||
var g = groups.First().Key;
|
||||
if (g != "") {
|
||||
int rowNum = 1;
|
||||
foreach (var attrG in attrGroups) {
|
||||
rowNum++;
|
||||
AddWeightToolTipRow(rowNum++, attrG.Key, null, attrG.Item2, attrG.Item2, weight);
|
||||
AddGradationToolTipRow(rowNum, attrG.Key, null, attrG.Item3, attrG.Item4, attrG.Item5);
|
||||
foreach (var g in groups.Where(g => g.Name == attrG.Key).OrderByDescending(g => g.Item3).ThenBy(g => g.SortId)) {
|
||||
AddWeightToolTipRow(rowNum++, null, g.SortId, g.Item3, attrG.Item2, weight);
|
||||
AddGradationToolTipRow(rowNum, null, g.SortId, g.Item4, g.Item5, g.Item6);
|
||||
}
|
||||
}
|
||||
|
||||
if (attrGroups.Count == 1) {
|
||||
var g = attrGroups.First().Key;
|
||||
if (g != null) {
|
||||
StatusWeight.Text += $" [{g}]";
|
||||
StatusGradation.Text += $" [{g}]";
|
||||
}
|
||||
@ -585,12 +644,13 @@ namespace Elwig.Windows {
|
||||
.ToList();
|
||||
|
||||
if (sortGroups.Count > 1 && sortGroups.Count <= 4) {
|
||||
StatusWeight.Text += $" = {string.Join(" + ", sortGroups.Select(g => $"{g.Item2:N0} kg ({(double)g.Item2 / weight:0%})" + (g.Key == "" ? "" : $" [{g.Key}]")))}";
|
||||
StatusGradation.Text += $" = {string.Join(" + ", sortGroups.Select(g => $"{g.Item3:N1}/{g.Item4:N1}/{g.Item5:N1}" + (g.Key == "" ? "" : $" [{g.Key}]")))}";
|
||||
StatusWeight.Text += $" = {string.Join(" + ", sortGroups.Select(g => $"{g.Item2:N0} kg ({(double)g.Item2 / weight:0%})" + (g.Key == null ? "" : $" [{g.Key}]")))}";
|
||||
StatusGradation.Text += $" = {string.Join(" + ", sortGroups.Select(g => $"{g.Item3:N1}/{g.Item4:N1}/{g.Item5:N1}" + (g.Key == null ? "" : $" [{g.Key}]")))}";
|
||||
|
||||
}
|
||||
} else if (groups.Count <= 4) {
|
||||
StatusWeight.Text += $" = {string.Join(" + ", groups.Select(g => $"{g.Item2:N0} kg ({(double)g.Item2 / weight:0%})" + (g.Key == "" ? "" : $" [{g.Key}]")))}";
|
||||
StatusGradation.Text += $" = {string.Join(" + ", groups.Select(g => $"{g.Item3:N1}/{g.Item4:N1}/{g.Item5:N1}" + (g.Key == "" ? "" : $" [{g.Key}]")))}";
|
||||
} else if (attrGroups.Count <= 4) {
|
||||
StatusWeight.Text += $" = {string.Join(" + ", attrGroups.Select(g => $"{g.Item2:N0} kg ({(double)g.Item2 / weight:0%})" + (g.Key == null ? "" : $" [{g.Key}]")))}";
|
||||
StatusGradation.Text += $" = {string.Join(" + ", attrGroups.Select(g => $"{g.Item3:N1}/{g.Item4:N1}/{g.Item5:N1}" + (g.Key == null ? "" : $" [{g.Key}]")))}";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -600,9 +660,6 @@ namespace Elwig.Windows {
|
||||
}
|
||||
|
||||
StatusVarieties.ToolTip = StatusVarieties.Text;
|
||||
// TODO display Weight/Gradation with newlines in ToolTip and grouped by sortid AND attributes
|
||||
StatusWeight.ToolTip = StatusWeight.Text;
|
||||
StatusGradation.ToolTip = StatusGradation.Text;
|
||||
}
|
||||
|
||||
protected override async Task OnRenewContext() {
|
||||
|
Reference in New Issue
Block a user