SVashishta1 commited on
Commit
13057ee
·
1 Parent(s): b0db292
Files changed (1) hide show
  1. app.py +24 -10
app.py CHANGED
@@ -627,8 +627,8 @@ def generate_visualization(result_df, query):
627
  print("Visualization requested, attempting to create plot...")
628
 
629
  # Set common figure parameters
630
- fig_width = 1000
631
- fig_height = 700
632
 
633
  # Determine visualization type from query
634
  viz_type = 'bar' # Default
@@ -695,7 +695,14 @@ def generate_visualization(result_df, query):
695
 
696
  if y_cols:
697
  fig = px.line(result_df, x=x_col, y=y_cols[0])
698
- fig.update_layout(title_text=f'Line Chart of {y_cols[0]} over {x_col}')
 
 
 
 
 
 
 
699
  else:
700
  # Fallback to bar chart
701
  viz_type = 'bar'
@@ -707,24 +714,31 @@ def generate_visualization(result_df, query):
707
  y_col = numeric_cols[0] if numeric_cols else result_df.columns[1] if len(result_df.columns) > 1 else None
708
 
709
  if y_col:
710
- fig = px.bar(result_df, x=x_col, y=y_col)
711
- fig.update_layout(title_text=f'Bar Chart of {y_col} by {x_col}')
 
 
 
712
  else:
713
- fig = px.bar(result_df, x=x_col)
714
- fig.update_layout(title_text=f'Bar Chart of {x_col}')
 
 
 
715
 
716
  # Set common layout properties
717
  fig.update_layout(
718
  width=fig_width,
719
  height=fig_height,
720
- template="plotly_white"
 
 
721
  )
722
 
723
  print(f"Created figure with width={fig_width}, height={fig_height}")
724
 
725
  # Convert to image
726
  print("Converting figure to image...")
727
- import plotly.io as pio
728
  img_bytes = pio.to_image(fig, format="png", width=fig_width, height=fig_height, scale=2)
729
  print("Image conversion successful")
730
 
@@ -736,7 +750,7 @@ def generate_visualization(result_df, query):
736
  print("HTML conversion successful")
737
 
738
  # Return the HTML img tag
739
- return f"<img src='{img_src}' width='100%' style='min-height:700px;' />"
740
 
741
  except Exception as e:
742
  import traceback
 
627
  print("Visualization requested, attempting to create plot...")
628
 
629
  # Set common figure parameters
630
+ fig_width = 1200
631
+ fig_height = 650
632
 
633
  # Determine visualization type from query
634
  viz_type = 'bar' # Default
 
695
 
696
  if y_cols:
697
  fig = px.line(result_df, x=x_col, y=y_cols[0])
698
+ fig.update_layout(
699
+ title_text=f'Line Chart of {y_cols[0]} over {x_col}',
700
+ xaxis=dict(
701
+ tickangle=-45,
702
+ tickmode='auto',
703
+ nticks=20
704
+ )
705
+ )
706
  else:
707
  # Fallback to bar chart
708
  viz_type = 'bar'
 
714
  y_col = numeric_cols[0] if numeric_cols else result_df.columns[1] if len(result_df.columns) > 1 else None
715
 
716
  if y_col:
717
+ fig = px.bar(result_df, x=x_col, y=y_col, width=900)
718
+ fig.update_layout(
719
+ title_text=f'Bar Chart of {y_col} by {x_col}',
720
+ bargap=0.2
721
+ )
722
  else:
723
+ fig = px.bar(result_df, x=x_col, width=900)
724
+ fig.update_layout(
725
+ title_text=f'Bar Chart of {x_col}',
726
+ bargap=0.2
727
+ )
728
 
729
  # Set common layout properties
730
  fig.update_layout(
731
  width=fig_width,
732
  height=fig_height,
733
+ template="plotly_white",
734
+ margin=dict(l=40, r=40, t=80, b=80, pad=4),
735
+ autosize=True
736
  )
737
 
738
  print(f"Created figure with width={fig_width}, height={fig_height}")
739
 
740
  # Convert to image
741
  print("Converting figure to image...")
 
742
  img_bytes = pio.to_image(fig, format="png", width=fig_width, height=fig_height, scale=2)
743
  print("Image conversion successful")
744
 
 
750
  print("HTML conversion successful")
751
 
752
  # Return the HTML img tag
753
+ return f"<img src='{img_src}' width='100%' style='max-width:1200px; min-height:650px; display:block; margin:0 auto;' />"
754
 
755
  except Exception as e:
756
  import traceback