Skip to content

Commit da9a3aa

Browse files
shrutipatel31facebook-github-bot
authored andcommitted
Update subtitle rendering in notebook Analysis Cards (facebook#5112)
Summary: Matches the web UI change from D97406631 for notebook (Jupyter/Bento) rendering of Ax analysis cards. **Before**: Subtitles were hidden behind a clickable <details>/<summary> element with an info icon -- users had to click to reveal the subtitle text. **After**: Subtitles are now shown as visible, secondary-styled text directly beneath the title, truncated to a single line via an ellipsis. A "See more"/"See less" toggle appears automatically when the subtitle overflows. Differential Revision: D98690381
1 parent 3712dd6 commit da9a3aa

1 file changed

Lines changed: 52 additions & 18 deletions

File tree

ax/core/analysis_card.py

Lines changed: 52 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@
1919
from plotly.offline import get_plotlyjs
2020

2121
# Simple HTML template for rendering a card with a title, subtitle, and body with
22-
# scrollable overflow.
22+
# scrollable overflow. Subtitles are rendered in a <div> with max-height overflow
23+
# so that any HTML content (tables, lists, etc.) is valid and clipped correctly
24+
# in the collapsed state. A "See more"/"See less" toggle appears when content
25+
# overflows (matching the web UI pattern).
2326
html_card_template = """
2427
<style>
2528
.card {{
@@ -30,34 +33,65 @@
3033
border-radius: 0.5em;
3134
padding: 10px;
3235
}}
33-
.card-header:hover {{
34-
cursor: pointer;
35-
}}
36-
.card-header details summary {{
37-
list-style: none;
38-
display: inline-flex;
39-
align-items: center;
40-
gap: 0.5em;
36+
.card-subtitle {{
37+
color: gray;
38+
font-size: 0.9em;
39+
margin: 4px 0 0 0;
40+
line-height: 1.4em;
41+
max-height: 1.4em;
42+
overflow: hidden;
43+
white-space: nowrap;
44+
text-overflow: ellipsis;
4145
}}
42-
.card-header details summary::-webkit-details-marker {{
46+
.card-subtitle-toggle {{
47+
color: #1877F2;
48+
cursor: pointer;
49+
font-size: 0.85em;
50+
background: none;
51+
border: none;
52+
padding: 0;
53+
margin-top: 2px;
4354
display: none;
4455
}}
45-
.card-header details summary::after {{
46-
content: "ℹ️";
47-
font-size: 0.9em;
48-
}}
4956
</style>
5057
<div class="card">
5158
<div class="card-header">
52-
<details>
53-
<summary><b>{title_str}</b></summary>
54-
<p>{subtitle_str}</p>
55-
</details>
59+
<b>{title_str}</b>
60+
<div class="card-subtitle">{subtitle_str}</div>
61+
<button class="card-subtitle-toggle">See more</button>
5662
</div>
5763
<div class="card-body">
5864
{body_html}
5965
</div>
6066
</div>
67+
<script>
68+
(function() {{
69+
var card = document.currentScript.previousElementSibling;
70+
var subtitle = card.querySelector('.card-subtitle');
71+
var toggle = card.querySelector('.card-subtitle-toggle');
72+
if (subtitle && toggle) {{
73+
requestAnimationFrame(function() {{
74+
if (subtitle.scrollHeight > subtitle.clientHeight
75+
|| subtitle.scrollWidth > subtitle.clientWidth) {{
76+
toggle.style.display = 'inline';
77+
}}
78+
}});
79+
toggle.onclick = function() {{
80+
if (subtitle.style.maxHeight === 'none') {{
81+
subtitle.style.maxHeight = '1.4em';
82+
subtitle.style.whiteSpace = 'nowrap';
83+
subtitle.style.textOverflow = 'ellipsis';
84+
toggle.textContent = 'See more';
85+
}} else {{
86+
subtitle.style.maxHeight = 'none';
87+
subtitle.style.whiteSpace = 'normal';
88+
subtitle.style.textOverflow = 'clip';
89+
toggle.textContent = 'See less';
90+
}}
91+
}};
92+
}}
93+
}})();
94+
</script>
6195
"""
6296

6397
# Simple HTML template for rendering a *group* card with a title, subtitle, and

0 commit comments

Comments
 (0)