Skip to content

Commit 3acbc64

Browse files
committed
fix: Align pie chart data with table data in dashboard
This commit fixes the discrepancy between the pie chart and table data in the dashboard view. The changes ensure that: 1. The pie chart now uses the same today's data as shown in the table 2. The pie chart legend now correctly displays today's usage time for each site 3. Added a helper function getTodaySummaryTime() to consistently extract today's data This ensures consistency across all dashboard visualizations and improves the accuracy of the data representation.
1 parent 0c62354 commit 3acbc64

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/components/TopSitesPieChart.vue

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<div class="site-color" :style="{ backgroundColor: chartColors[index] }"></div>
1111
<div class="site-info">
1212
<div class="site-url">{{ site.url }}</div>
13-
<div class="site-time">{{ convertSummaryTimeToString(site.summaryTime) }}</div>
13+
<div class="site-time">{{ convertSummaryTimeToString(getTodaySummaryTime(site)) }}</div>
1414
</div>
1515
</div>
1616
</div>
@@ -35,6 +35,7 @@ import { DARK_MODE_DEFAULT, StorageParams } from '../storage/storage-params';
3535
import { useTodayTabListSummary } from '../functions/useTodayTabListSummary';
3636
import { SortingBy } from '../utils/enums';
3737
import { Tab } from '../entity/tab';
38+
import { todayLocalDate } from '../utils/date';
3839
3940
const settingsStorage = injectStorage();
4041
const darkMode = ref(false);
@@ -51,29 +52,33 @@ const chartColors = [
5152
'#e256ae',
5253
];
5354
54-
// Process tabs to get top 4 sites and combine the rest as "Others"
55+
// Process tabs to get top 4 sites for the pie chart using TODAY's data
5556
async function processTabsData() {
5657
isLoading.value = true;
5758
58-
// Get today's tab list summary
59+
// Get today's tab list summary - same data source as used in TabList.vue
5960
const tabSummary = await useTodayTabListSummary(SortingBy.UsageTime);
6061
6162
if (!tabSummary || !tabSummary.tabs || tabSummary.tabs.length === 0) {
6263
isLoading.value = false;
6364
return;
6465
}
6566
67+
// Get the tabs data
6668
const tabs = tabSummary.tabs;
67-
const summaryTime = tabSummary.summaryTime || 0;
6869
6970
// Extract top 4 sites
7071
const top4Sites = tabs.slice(0, 4);
7172
72-
// Prepare data for chart - only top 4 sites
73+
// Get TODAY's data for each site - this is what's shown in the table
7374
const labels = top4Sites.map(tab => tab.url);
74-
const timeValues = top4Sites.map(tab => tab.summaryTime);
75+
const timeValues = top4Sites.map(tab => {
76+
// Get today's summary time for this tab - exactly as shown in the table
77+
const todayData = tab.days.find(day => day.date === todayLocalDate());
78+
return todayData ? todayData.summary : 0;
79+
});
7580
76-
// Save top sites for the list
81+
// Save top sites for the list - keep the original Tab objects
7782
topSites.value = top4Sites;
7883
7984
// Set chart data
@@ -132,6 +137,12 @@ function setupChartData(labels: string[], timeValues: number[]) {
132137
};
133138
}
134139
140+
// Get today's summary time for a tab
141+
function getTodaySummaryTime(tab: Tab): number {
142+
const todayData = tab.days.find(day => day.date === todayLocalDate());
143+
return todayData ? todayData.summary : 0;
144+
}
145+
135146
// Handler for refresh events
136147
function handleRefresh() {
137148
processTabsData();

0 commit comments

Comments
 (0)