@@ -55,14 +55,14 @@ function useInitial() {
5555
5656 // measure graph style
5757 const el = document . getElementById ( "width-measure" ) ! ;
58+ const { maxWidth : maxValueWidth } = getComputedStyle ( el . querySelector ( ".graph-v" ) ! ) ;
5859
5960 {
6061 const span = el . querySelector ( "span" ) ! ;
6162 const { lineHeight } = getComputedStyle ( span ) ;
6263 const { borderWidth } = getComputedStyle ( el ) ;
6364 const { paddingLeft, paddingRight } = getComputedStyle ( el . querySelector ( ".graph-kv" ) ! ) ;
6465 const { marginRight, maxWidth : maxKeyWidth } = getComputedStyle ( el . querySelector ( ".graph-k" ) ! ) ;
65- const { maxWidth : maxValueWidth } = getComputedStyle ( el . querySelector ( ".graph-v" ) ! ) ;
6666
6767 const measured = {
6868 fontWidth : Math . ceil ( span . offsetWidth / span . textContent ! . length ) ,
@@ -82,12 +82,13 @@ function useInitial() {
8282 {
8383 const span = el . querySelector ( "span" ) ! ;
8484 const { height : rowHeight } = getComputedStyle ( el . querySelector ( ".tbl-row" ) ! ) ;
85- const { maxWidth : maxCellWidth , paddingLeft, paddingRight } = getComputedStyle ( el . querySelector ( ".tbl-cell" ) ! ) ;
85+ const { paddingLeft, paddingRight } = getComputedStyle ( el . querySelector ( ".tbl-cell" ) ! ) ;
8686 const measured = {
8787 fontWidth : Math . ceil ( span . offsetWidth / span . textContent ! . length ) ,
8888 rowHeight : px2num ( rowHeight ) ,
89- maxCellWidth : px2num ( maxCellWidth ) ,
89+ maxCellWidth : px2num ( maxValueWidth ) ,
9090 padding : px2num ( paddingLeft ) + px2num ( paddingRight ) ,
91+ scrollbarWidth : getScrollbarWidth ( ) ,
9192 } ;
9293
9394 setupGlobalTableStyle ( measured ) ;
@@ -96,3 +97,20 @@ function useInitial() {
9697 }
9798 } , [ ] ) ;
9899}
100+
101+ // Calculate the scrollbar width
102+ function getScrollbarWidth ( ) {
103+ const outer = document . createElement ( "div" ) ;
104+ outer . style . width = "100px" ;
105+ outer . style . height = "100px" ;
106+ outer . style . overflow = "scroll" ;
107+ document . body . appendChild ( outer ) ;
108+
109+ const inner = document . createElement ( "div" ) ;
110+ inner . style . width = "100%" ;
111+ outer . appendChild ( inner ) ;
112+
113+ const scrollbarWidth = outer . offsetWidth - inner . offsetWidth ;
114+ document . body . removeChild ( outer ) ;
115+ return scrollbarWidth ;
116+ }
0 commit comments