Skip to content

Commit bea8c9d

Browse files
Restores tooltips to line plots and fixes the call to uses TTL instead of OAuth (#470)
Co-authored-by: gradio-pr-bot <gradio-pr-bot@users.noreply.github.com>
1 parent 915d170 commit bea8c9d

4 files changed

Lines changed: 58 additions & 4 deletions

File tree

.changeset/mighty-owls-feel.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"trackio": minor
3+
---
4+
5+
feat:Restores tooltips to line plots and fixes the call to uses TTL instead of OAuth

trackio/frontend/src/App.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@
181181
if (mutationPollTimer) clearInterval(mutationPollTimer);
182182
mutationPollTimer = setInterval(() => {
183183
refreshMutationAccess();
184-
}, 15000);
184+
}, 120000);
185185
}
186186
187187
$effect(() => {

trackio/frontend/src/components/LinePlot.svelte

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,35 @@
115115
...extra,
116116
});
117117
118+
const yTitle = y.includes("/") ? y.split("/").pop() : y;
119+
const tooltipEnc = [
120+
{ field: colorField, type: "nominal", title: "Run" },
121+
{ field: x, type: "quantitative", title: x },
122+
{ field: y, type: "quantitative", title: yTitle },
123+
];
124+
125+
const hoverParams = [{
126+
name: "hover",
127+
select: { type: "point", on: "pointerover", nearest: true, clear: "pointerout" },
128+
}];
129+
130+
const hoverPointLayer = (dataSpec, layerName) => ({
131+
...dataSpec,
132+
mark: { type: "circle", clip: true, size: 60, opacity: 0 },
133+
encoding: {
134+
x: xEnc,
135+
y: yEnc,
136+
...colorEnc,
137+
tooltip: tooltipEnc,
138+
opacity: {
139+
condition: { param: "hover", empty: false, value: 1 },
140+
value: 0,
141+
},
142+
},
143+
params: hoverParams,
144+
name: layerName,
145+
});
146+
118147
if (hasSmoothed) {
119148
layers.push({
120149
data: { name: "data_original", values: originalData },
@@ -128,17 +157,21 @@
128157
encoding: { x: xEnc, y: yEnc, ...colorEnc },
129158
name: "plot",
130159
});
160+
layers.push(
161+
hoverPointLayer({ data: { name: "data_smoothed", values: smoothedData } }, "hover_points"),
162+
);
131163
} else {
132164
layers.push({
133165
data: { name: "data_plot", values: data },
134166
mark: lineMark(),
135167
encoding: { x: xEnc, y: yEnc, ...colorEnc },
136168
name: "plot",
137169
});
170+
layers.push(
171+
hoverPointLayer({ data: { name: "data_plot", values: data } }, "hover_points"),
172+
);
138173
}
139174
140-
const yTitle = y.includes("/") ? y.split("/").pop() : y;
141-
142175
return {
143176
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
144177
title: {

trackio/server.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,38 @@ def check_hf_token_has_write_access(hf_token: str | None) -> None:
279279
)
280280

281281

282-
@lru_cache(maxsize=32)
282+
_oauth_write_cache: dict[str, tuple[bool, float]] = {}
283+
_OAUTH_WRITE_CACHE_TTL = 300
284+
285+
283286
def check_oauth_token_has_write_access(oauth_token: str | None) -> None:
284287
if not os.getenv("SYSTEM") == "spaces":
285288
return
286289
if oauth_token is None:
287290
raise PermissionError(
288291
"Expected an oauth to be provided when logging to a Space"
289292
)
293+
now = time.monotonic()
294+
cached = _oauth_write_cache.get(oauth_token)
295+
if cached is not None:
296+
allowed, ts = cached
297+
if now - ts < _OAUTH_WRITE_CACHE_TTL:
298+
if not allowed:
299+
raise PermissionError(
300+
"Expected the oauth token to be the user owner of the space, or be a member of the org owner of the space"
301+
)
302+
return
290303
who = HfApi.whoami(oauth_token)
291304
user_name = who["name"]
292305
owner_name = os.getenv("SPACE_AUTHOR_NAME")
293306
if user_name == owner_name:
307+
_oauth_write_cache[oauth_token] = (True, now)
294308
return
295309
for org in who["orgs"]:
296310
if org["name"] == owner_name and org["roleInOrg"] == "write":
311+
_oauth_write_cache[oauth_token] = (True, now)
297312
return
313+
_oauth_write_cache[oauth_token] = (False, now)
298314
raise PermissionError(
299315
"Expected the oauth token to be the user owner of the space, or be a member of the org owner of the space"
300316
)

0 commit comments

Comments
 (0)