Skip to content

Commit 4853fb1

Browse files
fix(bokeh): address review feedback for ecdf-basic
Attempt 1/3 - fixes based on AI review
1 parent 2d87535 commit 4853fb1

1 file changed

Lines changed: 23 additions & 5 deletions

File tree

  • plots/ecdf-basic/implementations/python

plots/ecdf-basic/implementations/python/bokeh.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
""" anyplot.ai
1+
"""anyplot.ai
22
ecdf-basic: Basic ECDF Plot
33
Library: bokeh 3.9.1 | Python 3.13.14
44
Quality: 89/100 | Updated: 2026-06-25
@@ -16,7 +16,7 @@
1616

1717
import numpy as np
1818
from bokeh.io import output_file, save
19-
from bokeh.models import BoxAnnotation, ColumnDataSource, CrosshairTool, HoverTool, Label, Span
19+
from bokeh.models import BoxAnnotation, ColumnDataSource, CrosshairTool, CustomJSHover, HoverTool, Label, Span
2020
from bokeh.plotting import figure
2121
from PIL import Image
2222
from selenium import webdriver
@@ -93,17 +93,35 @@
9393
x=q_val,
9494
y=y_pos,
9595
text=f"{q_lbl}: {q_val:.0f} min",
96-
text_font_size="26pt",
97-
text_color=INK_SOFT,
96+
text_font_size="30pt",
97+
text_color=INK,
9898
text_font_style="italic",
9999
x_offset=14,
100+
background_fill_color=ELEVATED_BG,
101+
background_fill_alpha=0.88,
102+
border_line_color=INK_SOFT,
103+
border_line_alpha=0.35,
104+
padding=10,
100105
)
101106
)
102107

108+
# Custom JS hover formatters — distinctively Bokeh: show runner count alongside percentage
109+
fmt_time = CustomJSHover(code="return value.toFixed(0) + ' min'")
110+
fmt_pct = CustomJSHover(
111+
code=f"""
112+
const pct = (value * 100).toFixed(1);
113+
const runners = Math.round(value * {n_runners});
114+
return pct + '% — ' + runners + '/{n_runners} runners';
115+
"""
116+
)
117+
103118
# Interactive tools — Bokeh strengths
104119
p.add_tools(
105120
HoverTool(
106-
renderers=[step_renderer], tooltips=[("Finish Time", "@x{0.0} min"), ("Cumulative", "@y{0.0%}")], mode="vline"
121+
renderers=[step_renderer],
122+
tooltips=[("Finish Time", "@x{custom}"), ("Cumulative", "@y{custom}")],
123+
formatters={"@x": fmt_time, "@y": fmt_pct},
124+
mode="vline",
107125
)
108126
)
109127
p.add_tools(CrosshairTool(dimensions="both", line_color=INK_SOFT, line_alpha=0.45))

0 commit comments

Comments
 (0)