Skip to content

Commit 74e952e

Browse files
committed
changes
1 parent 67d891d commit 74e952e

3 files changed

Lines changed: 23 additions & 19 deletions

File tree

trackio/frontend/src/components/BarPlot.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@
148148
function downloadCSV() {
149149
const barData = getBarData();
150150
if (barData.length === 0) return;
151-
const header = "run," + y;
151+
const yHeader = /[,"]/.test(y) ? `"${y.replace(/"/g, '""')}"` : y;
152+
const header = "run," + yHeader;
152153
const rows = barData.map((row) => {
153154
const run =
154155
typeof row.run === "string" && (row.run.includes(",") || row.run.includes('"'))

trackio/frontend/src/components/LinePlot.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@
199199
if (originals.length === 0) return;
200200
201201
const cols = Object.keys(originals[0]).filter((k) => k !== "data_type");
202-
const header = cols.join(",");
202+
const header = cols.map((c) => /[,"]/.test(c) ? `"${c.replace(/"/g, '""')}"` : c).join(",");
203203
const rows = originals.map((row) =>
204204
cols.map((c) => {
205205
const v = row[c];

trackio/frontend/src/pages/Metrics.svelte

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
let masterData = $state([]);
3333
let xColumn = $state("step");
3434
let metrics = $state([]);
35+
let singlePointMetrics = $state(new Set());
3536
let xLim = $state(null);
3637
let hasLoaded = $state(false);
3738
let metricOrder = $state({});
@@ -115,6 +116,23 @@
115116
(c) => c !== xColumn && c !== "run" && c !== "data_type" && c !== "x_axis",
116117
);
117118
metrics = cols;
119+
120+
const countPerRunMetric = new Map();
121+
for (const r of originals) {
122+
const run = r.run;
123+
for (const col of cols) {
124+
if (r[col] == null) continue;
125+
const key = `${col}\0${run}`;
126+
countPerRunMetric.set(key, (countPerRunMetric.get(key) || 0) + 1);
127+
}
128+
}
129+
const sp = new Set(cols);
130+
for (const [key, count] of countPerRunMetric) {
131+
if (count > 1) {
132+
sp.delete(key.split("\0")[0]);
133+
}
134+
}
135+
singlePointMetrics = sp;
118136
}
119137
120138
async function fetchNewRuns() {
@@ -223,21 +241,6 @@
223241
return result.data;
224242
}
225243
226-
function isSinglePoint(metric) {
227-
const originals = masterData.filter(
228-
(r) => (r.data_type === "original" || !r.data_type) && r[metric] != null,
229-
);
230-
const countPerRun = new Map();
231-
for (const r of originals) {
232-
const run = r.run;
233-
countPerRun.set(run, (countPerRun.get(run) || 0) + 1);
234-
}
235-
if (countPerRun.size === 0) return false;
236-
for (const count of countPerRun.values()) {
237-
if (count > 1) return false;
238-
}
239-
return true;
240-
}
241244
</script>
242245

243246
<div class="metrics-page">
@@ -283,7 +286,7 @@
283286
<div class="plot-grid">
284287
{#each orderedDirect as metric, i}
285288
{@const plotData = getPlotData(metric)}
286-
{@const useBar = isSinglePoint(metric)}
289+
{@const useBar = singlePointMetrics.has(metric)}
287290
{#if plotData.length > 0}
288291
{#if useBar}
289292
<BarPlot
@@ -328,7 +331,7 @@
328331
<div class="plot-grid">
329332
{#each orderedSub as metric, i}
330333
{@const plotData = getPlotData(metric)}
331-
{@const useBar = isSinglePoint(metric)}
334+
{@const useBar = singlePointMetrics.has(metric)}
332335
{#if plotData.length > 0}
333336
{#if useBar}
334337
<BarPlot

0 commit comments

Comments
 (0)