Skip to content

Commit 4d42242

Browse files
committed
better graph colors
1 parent e7b5b6c commit 4d42242

File tree

4 files changed

+68
-11
lines changed

4 files changed

+68
-11
lines changed

frontend/package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/src/lib/utils/charts.ts

Lines changed: 56 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,53 @@
11
import type { UsageStat } from '$lib/types/dashboard';
22
import type { ApexOptions } from 'apexcharts';
33

4+
const FALLBACK_COLORS: Record<'light' | 'dark', string[]> = {
5+
dark: [
6+
'#f5c2e7',
7+
'#cba6f7',
8+
'#f38ba8',
9+
'#fab387',
10+
'#f9e2af',
11+
'#a6e3a1',
12+
'#94e2d5',
13+
'#89dceb',
14+
'#74c7ec',
15+
'#89b4fa',
16+
'#b4befe'
17+
],
18+
light: [
19+
'#ea76cb',
20+
'#8839ef',
21+
'#d20f39',
22+
'#fe640b',
23+
'#df8e1d',
24+
'#40a02b',
25+
'#179299',
26+
'#04a5e5',
27+
'#209fb5',
28+
'#1e66f5',
29+
'#7287fd'
30+
]
31+
};
32+
33+
const resolveColors = (colors: string[], theme: 'light' | 'dark') =>
34+
colors.length > 0 ? colors : FALLBACK_COLORS[theme];
35+
436
export function createPieChartOptions(
537
data: UsageStat[],
638
colors: string[],
739
theme: 'light' | 'dark' = 'dark'
840
): ApexOptions {
941
const textColor = theme === 'dark' ? '#E6EEF3' : '#111827';
1042
const gridBorderColor = theme === 'dark' ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.08)';
43+
const resolvedColors = resolveColors(colors, theme);
1144
return {
1245
series: data.map((item) => item.total_seconds),
1346
chart: {
1447
foreColor: textColor,
1548
type: 'pie',
1649
height: 350,
50+
background: 'transparent',
1751
animations: {
1852
enabled: true,
1953
speed: 800
@@ -23,7 +57,12 @@ export function createPieChartOptions(
2357
dataLabels: {
2458
enabled: false
2559
},
26-
colors: colors,
60+
colors: resolvedColors,
61+
fill: {
62+
type: 'solid',
63+
colors: resolvedColors,
64+
opacity: 1
65+
},
2766
legend: {
2867
position: 'right',
2968
offsetY: 0,
@@ -71,6 +110,7 @@ export function createBarChartOptions(
71110
const textColor = theme === 'dark' ? '#E6EEF3' : '#111827';
72111
const gridBorderColor = theme === 'dark' ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.08)';
73112
const strokeColor = theme === 'dark' ? '#ffffff' : '#000000';
113+
const resolvedColors = resolveColors(colors, theme);
74114
return {
75115
series: [
76116
{
@@ -85,6 +125,7 @@ export function createBarChartOptions(
85125
foreColor: textColor,
86126
type: 'bar',
87127
height: 350,
128+
background: 'transparent',
88129
animations: {
89130
enabled: true,
90131
speed: 800
@@ -100,14 +141,19 @@ export function createBarChartOptions(
100141
distributed: true
101142
}
102143
},
103-
colors: colors,
144+
colors: resolvedColors,
104145
dataLabels: {
105146
enabled: false
106147
},
107148
stroke: {
108149
width: 1,
109150
colors: [strokeColor]
110151
},
152+
fill: {
153+
type: 'solid',
154+
colors: resolvedColors,
155+
opacity: 1
156+
},
111157
xaxis: {
112158
categories: data.map((item) => item.name),
113159
labels: {
@@ -166,6 +212,7 @@ export function createDateBarChartOptions(
166212
const textColor = theme === 'dark' ? '#E6EEF3' : '#111827';
167213
const gridBorderColor = theme === 'dark' ? 'rgba(255,255,255,0.06)' : 'rgba(0,0,0,0.08)';
168214
const strokeColor = theme === 'dark' ? '#ffffff' : '#000000';
215+
const resolvedColors = resolveColors(colors, theme);
169216
return {
170217
series: [
171218
{
@@ -180,6 +227,7 @@ export function createDateBarChartOptions(
180227
foreColor: textColor,
181228
type: 'bar',
182229
height: 350,
230+
background: 'transparent',
183231
animations: {
184232
enabled: true,
185233
speed: 800
@@ -195,14 +243,19 @@ export function createDateBarChartOptions(
195243
distributed: true
196244
}
197245
},
198-
colors: colors,
246+
colors: resolvedColors,
199247
dataLabels: {
200248
enabled: false
201249
},
202250
stroke: {
203251
width: 1,
204252
colors: [strokeColor]
205253
},
254+
fill: {
255+
type: 'solid',
256+
colors: resolvedColors,
257+
opacity: 1
258+
},
206259
xaxis: {
207260
categories: data.map((item) => item.date),
208261
labels: {

frontend/src/routes/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777
<div class="flex text-text items-center justify-center gap-3 mb-4">
7878
<h1 class="text-5xl font-bold">rustytime</h1>
7979
</div>
80-
<p class="text-xl text-subtext0 px-1">Blazingly fast time tracking for developers.</p>
80+
<p class="text-xl text-ctp-subtext1 dark:text-subtext0 px-1">Blazingly fast time tracking for developers.</p>
8181
</header>
8282

8383
<!-- Main Content -->
@@ -136,7 +136,7 @@
136136
<div class="text-center">
137137
<button
138138
onclick={auth.login}
139-
class="cursor-pointer bg-ctp-surface1 text-ctp-text hover:bg-ctp-surface0 font-semibold py-4 px-8 rounded-lg flex items-center gap-3 mx-auto"
139+
class="cursor-pointer bg-ctp-surface2 text-ctp-text hover:bg-ctp-surface1 font-semibold py-4 px-8 rounded-lg flex items-center gap-3 mx-auto"
140140
>
141141
<LucideGithub class="min-w-6 min-h-6" />
142142
Sign in with GitHub

rustytime/src/schema.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,8 @@ diesel::table! {
6161
diesel::joinable!(heartbeats -> users (user_id));
6262
diesel::joinable!(sessions -> users (user_id));
6363

64-
diesel::allow_tables_to_appear_in_same_query!(heartbeats, sessions, users,);
64+
diesel::allow_tables_to_appear_in_same_query!(
65+
heartbeats,
66+
sessions,
67+
users,
68+
);

0 commit comments

Comments
 (0)