Update app.py
Browse files
app.py
CHANGED
|
@@ -48,74 +48,37 @@ def label_from_score(score: int) -> str:
|
|
| 48 |
return "Low Trust"
|
| 49 |
|
| 50 |
def make_gauge(score: int):
|
| 51 |
-
# clamp score
|
| 52 |
score = max(0, min(100, score))
|
| 53 |
|
| 54 |
-
# 0 -> -90° (left), 100 -> +90° (right)
|
| 55 |
-
angle_deg = (score / 100.0) * 180.0 - 90.0
|
| 56 |
-
angle_rad = angle_deg * np.pi / 180.0
|
| 57 |
-
|
| 58 |
-
# centre of gauge (slightly above the number)
|
| 59 |
-
cx, cy = 0.5, 0.32
|
| 60 |
-
|
| 61 |
-
# SHORTER needle so it stays inside the arc
|
| 62 |
-
r = 0.20 # <- this was larger before; smaller = shorter needle
|
| 63 |
-
|
| 64 |
-
x_tip = cx + r * np.cos(angle_rad)
|
| 65 |
-
y_tip = cy + r * np.sin(angle_rad)
|
| 66 |
-
|
| 67 |
fig = go.Figure(
|
| 68 |
go.Indicator(
|
| 69 |
mode="gauge+number",
|
| 70 |
value=score,
|
| 71 |
-
number={"suffix": "%", "font": {"size":
|
| 72 |
gauge={
|
| 73 |
"shape": "angular",
|
| 74 |
"axis": {"range": [0, 100], "visible": False},
|
| 75 |
"bar": {
|
| 76 |
-
"color": "
|
| 77 |
-
"thickness": 0.
|
| 78 |
},
|
| 79 |
"bgcolor": "white",
|
| 80 |
"borderwidth": 0,
|
|
|
|
|
|
|
| 81 |
"steps": [
|
| 82 |
-
{"range": [0, 33], "color": "#c7d2fe"},
|
| 83 |
-
{"range": [33, 66], "color": "#60a5fa"},
|
| 84 |
-
{"range": [66, 100], "color": "#1d4ed8"}
|
| 85 |
],
|
| 86 |
},
|
| 87 |
domain={"x": [0, 1], "y": [0, 1]},
|
| 88 |
)
|
| 89 |
)
|
| 90 |
|
| 91 |
-
# needle line (shorter & centred)
|
| 92 |
-
fig.add_shape(
|
| 93 |
-
type="line",
|
| 94 |
-
x0=cx,
|
| 95 |
-
y0=cy,
|
| 96 |
-
x1=x_tip,
|
| 97 |
-
y1=y_tip,
|
| 98 |
-
xref="paper",
|
| 99 |
-
yref="paper",
|
| 100 |
-
line=dict(color="black", width=3),
|
| 101 |
-
)
|
| 102 |
-
|
| 103 |
-
# centre hub
|
| 104 |
-
hub_r = 0.012
|
| 105 |
-
fig.add_shape(
|
| 106 |
-
type="circle",
|
| 107 |
-
x0=cx - hub_r,
|
| 108 |
-
y0=cy - hub_r,
|
| 109 |
-
x1=cx + hub_r,
|
| 110 |
-
y1=cy + hub_r,
|
| 111 |
-
xref="paper",
|
| 112 |
-
yref="paper",
|
| 113 |
-
fillcolor="black",
|
| 114 |
-
line=dict(color="black"),
|
| 115 |
-
)
|
| 116 |
-
|
| 117 |
fig.update_layout(
|
| 118 |
-
margin=dict(t=30, b=
|
| 119 |
height=220,
|
| 120 |
)
|
| 121 |
|
|
|
|
| 48 |
return "Low Trust"
|
| 49 |
|
| 50 |
def make_gauge(score: int):
|
| 51 |
+
# clamp score between 0–100
|
| 52 |
score = max(0, min(100, score))
|
| 53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
fig = go.Figure(
|
| 55 |
go.Indicator(
|
| 56 |
mode="gauge+number",
|
| 57 |
value=score,
|
| 58 |
+
number={"suffix": "%", "font": {"size": 34}},
|
| 59 |
gauge={
|
| 60 |
"shape": "angular",
|
| 61 |
"axis": {"range": [0, 100], "visible": False},
|
| 62 |
"bar": {
|
| 63 |
+
"color": "#2563eb", # solid blue fill for the active progress
|
| 64 |
+
"thickness": 0.35
|
| 65 |
},
|
| 66 |
"bgcolor": "white",
|
| 67 |
"borderwidth": 0,
|
| 68 |
+
|
| 69 |
+
# Three blue segments (background arc)
|
| 70 |
"steps": [
|
| 71 |
+
{"range": [0, 33], "color": "#c7d2fe"}, # light blue
|
| 72 |
+
{"range": [33, 66], "color": "#60a5fa"}, # medium blue
|
| 73 |
+
{"range": [66, 100], "color": "#1d4ed8"} # dark blue
|
| 74 |
],
|
| 75 |
},
|
| 76 |
domain={"x": [0, 1], "y": [0, 1]},
|
| 77 |
)
|
| 78 |
)
|
| 79 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
fig.update_layout(
|
| 81 |
+
margin=dict(t=30, b=0, l=20, r=20),
|
| 82 |
height=220,
|
| 83 |
)
|
| 84 |
|