alidenewade commited on
Commit
d6b4465
·
verified ·
1 Parent(s): 782b2ef

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -268,11 +268,11 @@ def plot_properties_dashboard(df: pd.DataFrame):
268
  ("Category", "@Category")
269
  ])
270
 
271
- # Common plot configuration
272
  plot_config = {
273
- 'height': 400, 'tools': [hover, 'pan,wheel_zoom,box_zoom,reset,save'],
274
- 'sizing_mode': 'stretch_width', 'background_fill_color': '#0F0F0F',
275
- 'border_fill_color': '#0F0F0F', 'outline_line_color': '#333333'
276
  }
277
 
278
  def style_plot(p, x_label, y_label, title):
@@ -340,7 +340,7 @@ def plot_properties_dashboard(df: pd.DataFrame):
340
 
341
  # Plot 4: Enhanced Donut Chart
342
  p4_config = plot_config.copy()
343
- p4_config.update({'tools': "hover", 'x_range': (-1.2, 1.2), 'y_range': (-1.2, 1.2)})
344
  p4 = figure(title="Drug-Likeness Distribution", **p4_config)
345
 
346
  # Calculate percentages and create donut chart
@@ -365,16 +365,29 @@ def plot_properties_dashboard(df: pd.DataFrame):
365
 
366
  donut_source = ColumnDataSource(data)
367
 
368
- # Create donut using annular wedges (outer ring)
369
- p4.annular_wedge(x=0, y=0, inner_radius=0.35, outer_radius=0.6,
370
  start_angle='start_angle', end_angle='end_angle',
371
  line_color="white", line_width=3, fill_color='color',
372
  legend_field='category', source=donut_source)
373
 
 
 
 
 
 
 
 
 
 
 
 
 
 
374
  # Add center text
375
  p4.text([0], [0], text=[f"{len(df)}\nCompounds"],
376
  text_align="center", text_baseline="middle",
377
- text_color="white", text_font_size="16pt", text_font_style="bold")
378
 
379
  # Custom hover for donut
380
  p4.add_tools(HoverTool(tooltips=[("Category", "@category"),
@@ -384,9 +397,9 @@ def plot_properties_dashboard(df: pd.DataFrame):
384
  style_plot(p4, "", "", "Compound Classification")
385
  p4.axis.visible = False
386
  p4.grid.visible = False
387
-
388
  # Create responsive grid layout
389
- grid = gridplot([[p1, p2], [p3, p4]], sizing_mode='stretch_width',
390
  toolbar_location='right', merge_tools=True)
391
 
392
  return grid, "✅ Generated enhanced molecular properties dashboard."
 
268
  ("Category", "@Category")
269
  ])
270
 
271
+ # Common plot configuration - square plots with no background fill
272
  plot_config = {
273
+ 'width': 400, 'height': 400, 'tools': [hover, 'pan,wheel_zoom,box_zoom,reset,save'],
274
+ 'sizing_mode': 'fixed', 'background_fill_color': None,
275
+ 'border_fill_color': None, 'outline_line_color': '#333333'
276
  }
277
 
278
  def style_plot(p, x_label, y_label, title):
 
340
 
341
  # Plot 4: Enhanced Donut Chart
342
  p4_config = plot_config.copy()
343
+ p4_config.update({'tools': "hover", 'x_range': (-1.0, 1.0), 'y_range': (-1.0, 1.0)})
344
  p4 = figure(title="Drug-Likeness Distribution", **p4_config)
345
 
346
  # Calculate percentages and create donut chart
 
365
 
366
  donut_source = ColumnDataSource(data)
367
 
368
+ # Create donut using annular wedges (outer ring) - sized to fit within boundaries
369
+ p4.annular_wedge(x=0, y=0, inner_radius=0.25, outer_radius=0.45,
370
  start_angle='start_angle', end_angle='end_angle',
371
  line_color="white", line_width=3, fill_color='color',
372
  legend_field='category', source=donut_source)
373
 
374
+ # Add percentage text to each slice
375
+ for i, row in data.iterrows():
376
+ # Calculate middle angle for text positioning
377
+ mid_angle = (row['start_angle'] + row['end_angle']) / 2
378
+ # Position text at middle radius of the annular wedge
379
+ text_radius = 0.35
380
+ x_pos = text_radius * cos(mid_angle)
381
+ y_pos = text_radius * sin(mid_angle)
382
+
383
+ p4.text([x_pos], [y_pos], text=[f"{row['percentage']:.1f}%"],
384
+ text_align="center", text_baseline="middle",
385
+ text_color="white", text_font_size="11pt", text_font_style="bold")
386
+
387
  # Add center text
388
  p4.text([0], [0], text=[f"{len(df)}\nCompounds"],
389
  text_align="center", text_baseline="middle",
390
+ text_color="white", text_font_size="14pt", text_font_style="bold")
391
 
392
  # Custom hover for donut
393
  p4.add_tools(HoverTool(tooltips=[("Category", "@category"),
 
397
  style_plot(p4, "", "", "Compound Classification")
398
  p4.axis.visible = False
399
  p4.grid.visible = False
400
+
401
  # Create responsive grid layout
402
+ grid = gridplot([[p1, p2], [p3, p4]], sizing_mode='fixed',
403
  toolbar_location='right', merge_tools=True)
404
 
405
  return grid, "✅ Generated enhanced molecular properties dashboard."