Skip to content

Commit df6e788

Browse files
committed
feat(insights): made the chart responsive
1 parent 43c6f69 commit df6e788

File tree

1 file changed

+21
-0
lines changed
  • apps/insights/src/components/PythProDemoPriceChart

1 file changed

+21
-0
lines changed

apps/insights/src/components/PythProDemoPriceChart/index.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function PythProDemoPriceChartImpl({
3333
const chartRef = useRef<IChartApi>(undefined);
3434
const seriesMapRef = useRef<Record<string, ISeriesApi<"Line">>>({});
3535

36+
/** effects */
3637
useLayoutEffect(() => {
3738
if (!containerRef.current) return;
3839

@@ -70,6 +71,26 @@ export function PythProDemoPriceChartImpl({
7071
};
7172
}, []);
7273

74+
useLayoutEffect(() => {
75+
if (!chartRef.current || !containerRef.current) return;
76+
const { current: chartApi } = chartRef;
77+
78+
const o = new ResizeObserver(([entry]) => {
79+
if (!entry) return;
80+
81+
const {
82+
contentRect: { height, width },
83+
} = entry;
84+
chartApi.resize(width, height);
85+
});
86+
87+
o.observe(containerRef.current);
88+
89+
return () => {
90+
o.disconnect();
91+
};
92+
}, []);
93+
7394
useEffect(() => {
7495
if (!chartRef.current || !isAllowedSymbol(selectedSource)) return;
7596

0 commit comments

Comments
 (0)