Skip to content

Commit e7e1008

Browse files
committed
FP value tooltips
1 parent 7cecd61 commit e7e1008

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/herbie/LocalError/newLocalError.css

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
border-radius: 4px;
1212
} */
1313

14-
.high-error .accuracy-col {
14+
.high-error .accuracy-col span {
1515
font-weight: 500;
1616
color: #b91c1c; /* Keep the red tone */
1717
background-color: #fdf2f2; /* Very subtle pink background */
@@ -29,10 +29,11 @@
2929

3030
.local-error td:not(.program-col), th:not(.program-col) {
3131
text-align: right;
32+
padding-left: 10px;
3233
}
3334

3435
.local-error table {
35-
border-spacing: 10px 0px;
36+
border-spacing: 0px 0px;
3637
}
3738

3839
.local-error td {
@@ -46,4 +47,11 @@
4647

4748
.no-explanations .explanation {
4849
display: none;
49-
}
50+
}
51+
52+
/* slightly darken the hovered row */
53+
.local-error tbody tr:hover {
54+
background-color: #f3f4f6; /* Light gray background on hover */
55+
border-radius: 5px;
56+
transition: background-color 0.2s ease;
57+
}

src/herbie/LocalError/newLocalError.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ function shouldExpand(currentPath: number[], allErrorPaths: number[][]): boolean
6565

6666
type LocalErrorTreeWithExplanation = LocalErrorTree & { explanation?: string, path?: number[] };
6767

68+
let valueId = 0;
6869

6970
function TreeRow({
7071
node,
@@ -82,13 +83,25 @@ function TreeRow({
8283
);
8384
const collapsedExpression = formatExpression(node);
8485

86+
87+
8588
function renderValue(value: any) {
8689
if (value === "true" || value === "false") {
8790
return value;
8891
}
92+
valueId += 1;
8993
const num = parseFloat(value);
9094
if (isNaN(num)) {return value;}
91-
return herbiejs.displayNumber(num);
95+
return <>
96+
<span className="number-value"
97+
data-tooltip-id= {`value-tooltip-${valueId}`}
98+
>
99+
{herbiejs.displayNumber(num)}
100+
</span>
101+
<Tooltip id={`value-tooltip-${valueId}`}>
102+
{num.toString()}
103+
</Tooltip>
104+
</>
92105
}
93106

94107
const isHighError = parseFloat(node["percent-accuracy"]) < 50;
@@ -142,11 +155,13 @@ function TreeRow({
142155
</div>
143156
</span>
144157
</td>
145-
<td>{renderValue(node["actual-value"])}</td>
146158
<td>{renderValue(node["exact-value"])}</td>
159+
<td>{renderValue(node["actual-value"])}</td>
147160
<td>{renderValue(node["abs-error-difference"])}</td>
148161
<td className="accuracy-col">
162+
<span>
149163
{parseFloat(node["percent-accuracy"]).toFixed(1)}%
164+
</span>
150165
</td>
151166
<td className="explanation">
152167
{node.explanation ?
@@ -272,7 +287,7 @@ function NewLocalError({ expressionId }: { expressionId: number }) {
272287
>
273288
<svg width="10" height="10" viewBox="0 0 24 24" fill="currentColor">
274289
<circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="2" fill="none"/>
275-
<text x="12" y="16" textAnchor="middle" fontSize="12" fontWeight="bold">?</text>
290+
<text x="12" y="16" textAnchor="middle" fontSize="12" fontWeight="bold">i</text>
276291
</svg>
277292
</span>
278293
<Tooltip id={tooltipId} />

0 commit comments

Comments
 (0)