KevinIsInCoding Claude Opus 4.8 commited on
Commit
06fbefb
·
unverified ·
1 Parent(s): 3b2b5d9

fix(landscape): instant CSS hover for the pipeline wheel (#24)

Browse files

Compound dots and sector wedges carried their label as a native SVG <title>,
which browsers render as an OS tooltip with a built-in ~1s appearance delay —
the "hover is laggy" feedback from physicians. Replace <title> with a pure-CSS
hover: on .wheel-dot:hover the dot pops (scale 1.8, pivoting on its own center)
and shows a dark name chip immediately; wedges show a count chip. No JS, since
Gradio's {@html} won't execute injected scripts.

Also lift all dots into a layer drawn after every wedge so a hovered dot and its
label always sit on top, avoiding z-order coverage between adjacent groups.
No layout change — same wheel geometry, sectors, rings, and dots.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

Files changed (1) hide show
  1. landscape.py +46 -8
landscape.py CHANGED
@@ -161,6 +161,35 @@ _CLASS_TO_GROUP = {
161
 
162
  _DOT_CAP = 12 # max dots drawn per sector×ring cell (real counts live in hover/summary)
163
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
  def _group_of(therapy: dict) -> str:
166
  return _CLASS_TO_GROUP.get(_primary_class(therapy), "Others / Multiple")
@@ -232,8 +261,12 @@ def _cell_dots(cx, cy, r_in, r_out, a0, a1, cells, col) -> str:
232
  a = aa0 + fa * (aa1 - aa0) + ja
233
  x, y = _polar_xy(cx, cy, r, a)
234
  fill = col if active else _INACTIVE_COLOR
235
- out.append(f'<circle cx="{x:.1f}" cy="{y:.1f}" r="5" fill="{fill}" '
236
- f'stroke="#fff" stroke-width="1.3"><title>{html.escape(name)}</title></circle>')
 
 
 
 
237
  return "".join(out)
238
 
239
 
@@ -270,9 +303,11 @@ def build_pipeline_svg(landscape: dict | None, status_filter: str = "All trials"
270
  mx, my_t, my_b = 116, 46, 70 # margins so perimeter labels aren't clipped
271
  svg = [f'<svg viewBox="{-mx} {-my_t} {W + 2 * mx} {W + my_t + my_b}" width="100%" '
272
  f'style="max-width:840px;height:auto;" '
273
- 'font-family="-apple-system,Segoe UI,Roboto,sans-serif">']
 
274
 
275
- labels = [] # perimeter category + exemplar labels, drawn after wedges
 
276
  for gi, g in enumerate(groups):
277
  col = GROUP_COLORS[g]
278
  center = gi * seg # group 0 centered at top
@@ -284,10 +319,12 @@ def build_pipeline_svg(landscape: dict | None, status_filter: str = "All trials"
284
  cnt = len(cells)
285
  path = _annular_sector_path(cx, cy, ri, ro, a0, a1)
286
  fillop = 0.13 + 0.05 * i
287
- svg.append(f'<path d="{path}" fill="{col}" fill-opacity="{fillop:.2f}" '
288
- f'stroke="#fff" stroke-width="2"><title>{html.escape(g)} — {html.escape(ring)}: '
289
- f'{cnt} compound{"s" if cnt != 1 else ""}</title></path>')
290
- svg.append(_cell_dots(cx, cy, ri, ro, a0, a1, cells, col))
 
 
291
 
292
  # perimeter label: category name (wrapped at " / ") + count + top exemplar
293
  exemplar = next((sorted(grid[g][r], key=lambda c: c[0])[0][0]
@@ -315,6 +352,7 @@ def build_pipeline_svg(landscape: dict | None, status_filter: str = "All trials"
315
  f'font-size="10.5" fill="#8a929c">e.g. {html.escape(exemplar[:20])}</text>')
316
  labels.append(lab)
317
 
 
318
  svg.extend(labels)
319
 
320
  # center hub
 
161
 
162
  _DOT_CAP = 12 # max dots drawn per sector×ring cell (real counts live in hover/summary)
163
 
164
+ # Instant CSS hover for the wheel — replaces native SVG <title> (whose OS tooltip has a
165
+ # ~1s appearance delay). On hover a dot pops (scale) and shows its name chip immediately;
166
+ # sector wedges show their count chip. Pure CSS: no JS (Gradio's {@html} won't run scripts).
167
+ # Class names are prefixed `wheel-` so the <style> (document-scoped once embedded) can't
168
+ # collide with other `.dot`/`.lbl` classes on the Gradio page.
169
+ _WHEEL_STYLE = (
170
+ "svg .wheel-dot{cursor:pointer;}"
171
+ "svg .wheel-dot>circle{transition:transform .07s ease;transform-box:fill-box;"
172
+ "transform-origin:center;}"
173
+ "svg .wheel-dot:hover>circle{transform:scale(1.8);stroke-width:1.6;}"
174
+ "svg .wheel-lbl{opacity:0;transition:opacity .07s ease;pointer-events:none;}"
175
+ "svg .wheel-dot:hover .wheel-lbl,svg .wheel-wedge:hover .wheel-lbl{opacity:1;}"
176
+ )
177
+
178
+
179
+ def _hover_chip(x: float, y: float, text: str, *, dy: float, font: float = 11.0) -> str:
180
+ """A hidden dark tooltip chip (rect + white text) centered at x, offset vertically by dy.
181
+
182
+ Shown instantly via CSS when its parent .wheel-dot / .wheel-wedge is hovered. A solid
183
+ dark fill stays legible even if a later translucent wedge paints over it.
184
+ """
185
+ half_w = max(len(text) * font * 0.30 + 7, 14)
186
+ return (f'<g class="wheel-lbl">'
187
+ f'<rect x="{x - half_w:.1f}" y="{y + dy:.1f}" width="{2 * half_w:.1f}" height="17" '
188
+ f'rx="4" fill="#1f2d3a"/>'
189
+ f'<text x="{x:.1f}" y="{y + dy + 12:.1f}" text-anchor="middle" '
190
+ f'font-size="{font}" fill="#fff">{html.escape(text)}</text>'
191
+ f'</g>')
192
+
193
 
194
  def _group_of(therapy: dict) -> str:
195
  return _CLASS_TO_GROUP.get(_primary_class(therapy), "Others / Multiple")
 
261
  a = aa0 + fa * (aa1 - aa0) + ja
262
  x, y = _polar_xy(cx, cy, r, a)
263
  fill = col if active else _INACTIVE_COLOR
264
+ out.append(
265
+ f'<g class="wheel-dot">'
266
+ f'<circle cx="{x:.1f}" cy="{y:.1f}" r="5" fill="{fill}" stroke="#fff" stroke-width="1.3"/>'
267
+ f'{_hover_chip(x, y, name, dy=-27)}'
268
+ f'</g>'
269
+ )
270
  return "".join(out)
271
 
272
 
 
303
  mx, my_t, my_b = 116, 46, 70 # margins so perimeter labels aren't clipped
304
  svg = [f'<svg viewBox="{-mx} {-my_t} {W + 2 * mx} {W + my_t + my_b}" width="100%" '
305
  f'style="max-width:840px;height:auto;" '
306
+ 'font-family="-apple-system,Segoe UI,Roboto,sans-serif">',
307
+ f'<style>{_WHEEL_STYLE}</style>']
308
 
309
+ labels = [] # perimeter category + exemplar labels, drawn after wedges
310
+ dot_layer = [] # all compound dots, drawn after all wedges so every dot sits on top
311
  for gi, g in enumerate(groups):
312
  col = GROUP_COLORS[g]
313
  center = gi * seg # group 0 centered at top
 
319
  cnt = len(cells)
320
  path = _annular_sector_path(cx, cy, ri, ro, a0, a1)
321
  fillop = 0.13 + 0.05 * i
322
+ mrx, mry = _polar_xy(cx, cy, (ri + ro) / 2, (a0 + a1) / 2)
323
+ chip = _hover_chip(mrx, mry, f'{g} — {ring}: {cnt} compound{"s" if cnt != 1 else ""}',
324
+ dy=-8, font=10.5)
325
+ svg.append(f'<g class="wheel-wedge"><path d="{path}" fill="{col}" '
326
+ f'fill-opacity="{fillop:.2f}" stroke="#fff" stroke-width="2"/>{chip}</g>')
327
+ dot_layer.append(_cell_dots(cx, cy, ri, ro, a0, a1, cells, col))
328
 
329
  # perimeter label: category name (wrapped at " / ") + count + top exemplar
330
  exemplar = next((sorted(grid[g][r], key=lambda c: c[0])[0][0]
 
352
  f'font-size="10.5" fill="#8a929c">e.g. {html.escape(exemplar[:20])}</text>')
353
  labels.append(lab)
354
 
355
+ svg.extend(dot_layer) # dots above all wedges
356
  svg.extend(labels)
357
 
358
  # center hub