File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -63,25 +63,36 @@ const ViolinChart = ({
6363 } ;
6464 } ) ;
6565
66+ // Set minimum width for the plot to ensure readability
67+ const minWidth = 600 ; // Minimum width in pixels
68+ const effectiveWidth = Math . max ( containerWidth , minWidth ) ;
69+
6670 // Clear previous content
6771 d3 . select ( svgRef . current ) . selectAll ( '*' ) . remove ( ) ;
6872
69- // Create SVG
73+ // Create SVG with minimum width
7074 const svg = d3
7175 . select ( svgRef . current )
72- . attr ( 'width' , containerWidth )
76+ . attr ( 'width' , effectiveWidth )
7377 . attr ( 'height' , height + margin . top + margin . bottom )
7478 . append ( 'g' )
7579 . attr ( 'transform' , `translate(${ margin . left } ,${ margin . top } )` ) ;
7680
77- // Reserve space for legend (120px width + 20px padding)
81+ // Reserve space for legend and use effective width
7882 const legendWidth = 140 ;
7983 const plotWidth =
80- containerWidth -
84+ effectiveWidth -
8185 margin . left -
8286 margin . right -
8387 ( comparison ? legendWidth : 0 ) ;
8488
89+ // Update container styles to enable horizontal scrolling
90+ if ( containerRef . current ) {
91+ containerRef . current . style . overflowX =
92+ effectiveWidth > containerWidth ? 'auto' : 'hidden' ;
93+ containerRef . current . style . maxWidth = '100%' ;
94+ }
95+
8596 // Create scales
8697 const xScale = d3
8798 . scaleBand ( )
You can’t perform that action at this time.
0 commit comments