@@ -9,7 +9,7 @@ import type { RefObject } from "react";
9
9
import { useEffect , useRef , useCallback } from "react" ;
10
10
import { z } from "zod" ;
11
11
12
- import theme from "./theme .module.scss" ;
12
+ import styles from "./chart .module.scss" ;
13
13
import { useLivePriceData } from "../../hooks/use-live-price-data" ;
14
14
import { Cluster } from "../../services/pyth" ;
15
15
@@ -22,14 +22,18 @@ export const Chart = ({ symbol, feedId }: Props) => {
22
22
const chartContainerRef = useChart ( symbol , feedId ) ;
23
23
24
24
return (
25
- < div style = { { width : "100%" , height : "100%" } } ref = { chartContainerRef } />
25
+ < div
26
+ style = { { width : "100%" , height : "100%" } }
27
+ className = { styles . chart }
28
+ ref = { chartContainerRef }
29
+ />
26
30
) ;
27
31
} ;
28
32
29
33
const useChart = ( symbol : string , feedId : string ) => {
30
34
const { chartContainerRef, chartRef } = useChartElem ( symbol , feedId ) ;
31
35
useChartResize ( chartContainerRef , chartRef ) ;
32
- useChartColors ( chartRef ) ;
36
+ useChartColors ( chartContainerRef , chartRef ) ;
33
37
return chartContainerRef ;
34
38
} ;
35
39
@@ -217,17 +221,24 @@ const useChartResize = (
217
221
} ) ;
218
222
} ;
219
223
220
- const useChartColors = ( chartRef : RefObject < ChartRefContents | undefined > ) => {
224
+ const useChartColors = (
225
+ chartContainerRef : RefObject < HTMLDivElement | null > ,
226
+ chartRef : RefObject < ChartRefContents | undefined > ,
227
+ ) => {
221
228
const { resolvedTheme } = useTheme ( ) ;
222
229
useEffect ( ( ) => {
223
- if ( chartRef . current && resolvedTheme ) {
224
- applyColors ( chartRef . current , resolvedTheme ) ;
230
+ if ( chartRef . current && chartContainerRef . current && resolvedTheme ) {
231
+ applyColors ( chartRef . current , chartContainerRef . current , resolvedTheme ) ;
225
232
}
226
- } , [ resolvedTheme , chartRef ] ) ;
233
+ } , [ resolvedTheme , chartRef , chartContainerRef ] ) ;
227
234
} ;
228
235
229
- const applyColors = ( { chart, ...series } : ChartRefContents , theme : string ) => {
230
- const colors = getColors ( theme ) ;
236
+ const applyColors = (
237
+ { chart, ...series } : ChartRefContents ,
238
+ container : HTMLDivElement ,
239
+ theme : string ,
240
+ ) => {
241
+ const colors = getColors ( container , theme ) ;
231
242
chart . applyOptions ( {
232
243
grid : {
233
244
horzLines : {
@@ -260,12 +271,20 @@ const applyColors = ({ chart, ...series }: ChartRefContents, theme: string) => {
260
271
}
261
272
} ;
262
273
263
- const getColors = ( resolvedTheme : string ) => ( {
264
- border : theme [ `border-${ resolvedTheme } ` ] ?? "red" ,
265
- muted : theme [ `muted-${ resolvedTheme } ` ] ?? "" ,
266
- chartNeutral : theme [ `chart-series-neutral-${ resolvedTheme } ` ] ?? "" ,
267
- chartPrimary : theme [ `chart-series-primary-${ resolvedTheme } ` ] ?? "" ,
268
- } ) ;
274
+ const getColors = ( container : HTMLDivElement , resolvedTheme : string ) => {
275
+ const style = getComputedStyle ( container ) ;
276
+
277
+ return {
278
+ border : style . getPropertyValue ( `--border-${ resolvedTheme } ` ) ,
279
+ muted : style . getPropertyValue ( `--muted-${ resolvedTheme } ` ) ,
280
+ chartNeutral : style . getPropertyValue (
281
+ `--chart-series-neutral-${ resolvedTheme } ` ,
282
+ ) ,
283
+ chartPrimary : style . getPropertyValue (
284
+ `--chart-series-primary-${ resolvedTheme } ` ,
285
+ ) ,
286
+ } ;
287
+ } ;
269
288
270
289
const getLocalTimestamp = ( date : Date ) : UTCTimestamp =>
271
290
( Date . UTC (
0 commit comments