Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions RsyncUI/Model/Storage/Actors/ActorLogChartsData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ actor ActorLogChartsData {
} else {
result[dayKey] = record
}
}.values.sorted { $0.date < $1.date }
}.values.sorted { $0.date > $1.date }
}

// By number of files
Expand All @@ -97,7 +97,7 @@ actor ActorLogChartsData {
records
.sorted { $0.files > $1.files } // Sort by value descending
.prefix(count) // Take first N items
.sorted { $0.date < $1.date } // Optional: sort by date for display
.sorted { $0.date > $1.date } // Optional: sort by date for display
}

// By number of files
Expand All @@ -115,7 +115,7 @@ actor ActorLogChartsData {
records
.sorted { $0.transferredMB > $1.transferredMB } // Sort by value descending
.prefix(count) // Take first N items
.sorted { $0.date < $1.date } // Optional: sort by date for display
.sorted { $0.date > $1.date } // Optional: sort by date for display
}

// By transferredMB
Expand Down Expand Up @@ -145,6 +145,6 @@ actor ActorLogChartsData {
} else {
result[dayKey] = record
}
}.values.sorted { $0.date < $1.date }
}.values.sorted { $0.date > $1.date }
}
}
83 changes: 52 additions & 31 deletions RsyncUI/Views/Tasks/LogStatsChartView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ struct LogStatsChartView: View {

@State private var numberofdatabool: Bool = false
@State private var numberofdata: String = ""


@State private var selectedDataPoint: LogEntry.ID?

var body: some View {
VStack {
Text("Statistics: number of records in chart \(logentries?.count ?? 0) for \(synchronizeid)")
Expand Down Expand Up @@ -80,9 +82,9 @@ struct LogStatsChartView: View {
.toggleStyle(.switch)
}

if typeofchart == .linemarkchart {
Chart {
ForEach(logentries ?? []) { entry in
HStack {
if typeofchart == .linemarkchart {
Chart(logentries ?? []) { entry in
switch datainchart {
case .numberoffiles:
LineMark(
Expand All @@ -91,32 +93,29 @@ struct LogStatsChartView: View {
)
.foregroundStyle(.blue)
.symbol(by: .value("Type", "Files"))

case .transferreddata:
LineMark(
x: .value("Date", entry.date),
y: .value("Size (MB)", entry.transferredMB)
)
.foregroundStyle(.green)
.foregroundStyle(.blue)
.symbol(by: .value("Type", "Size"))
}
}
}
.chartXAxis {
AxisMarks(preset: .aligned, position: .bottom) { value in
AxisValueLabel()
AxisTick()
.chartXAxis {
AxisMarks(preset: .aligned, position: .bottom) { _ in
AxisValueLabel()
AxisTick()
}
}
}
.chartYAxis {
AxisMarks(position: .leading) { value in
AxisValueLabel()
.chartYAxis {
AxisMarks(position: .leading) { _ in
AxisValueLabel()
}
}
}
.padding()
} else {
Chart {
ForEach(logentries ?? []) { entry in
.padding()
} else {
Chart(logentries ?? []) { entry in
switch datainchart {
case .numberoffiles:
BarMark(
Expand All @@ -125,6 +124,8 @@ struct LogStatsChartView: View {
)
.foregroundStyle(.blue)
.symbol(by: .value("Type", "Files"))
.foregroundStyle(selectedDataPoint == entry.id ? .red : .blue)
.opacity(selectedDataPoint == nil || selectedDataPoint == entry.id ? 1.0 : 0.5)

case .transferreddata:
BarMark(
Expand All @@ -133,21 +134,42 @@ struct LogStatsChartView: View {
)
.foregroundStyle(.green)
.symbol(by: .value("Type", "Size"))
.foregroundStyle(selectedDataPoint == entry.id ? .red : .green)
.opacity(selectedDataPoint == nil || selectedDataPoint == entry.id ? 1.0 : 0.5)
}
}
}
.chartXAxis {
AxisMarks(preset: .aligned, position: .bottom) { value in
AxisValueLabel()
AxisTick()
.chartXAxis {
AxisMarks(preset: .aligned, position: .bottom) { _ in
AxisValueLabel()
AxisTick()
}
}
.chartYAxis {
AxisMarks(position: .leading) { _ in
AxisValueLabel()
}
}
.padding()
}
.chartYAxis {
AxisMarks(position: .leading) { value in
AxisValueLabel()

if let logentries {
Table(logentries, selection: $selectedDataPoint) {
TableColumn("Date") { item in
Text(item.date, style: .date)
}
.alignment(.leading)
TableColumn("Size (MB)") { item in
Text(String(format: "%.2f", item.transferredMB))
}
.alignment(.trailing)
TableColumn("Files") { item in
Text(String(item.files))
}
.alignment(.trailing)
}
.padding()
.frame(width: 400)
}
.padding()
}
}
.padding()
Expand All @@ -156,13 +178,12 @@ struct LogStatsChartView: View {
logentries = await readandsortlogdata(hiddenID, validhiddenIDs)
}
}

.onChange(of: numberofdatabool) {
Task {
logentries = await readandsortlogdata(hiddenID, validhiddenIDs)
}
}

var synchronizeid: String {
if let configurations = rsyncUIdata.configurations {
if let index = configurations.firstIndex(where: { $0.id == selecteduuids.first }) {
Expand Down