11import type { UsageStat } from '$lib/types/dashboard' ;
22import 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+
436export 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 : {
0 commit comments