Spaces:
Running
Running
thibaud frere
commited on
Commit
·
0e04b08
1
Parent(s):
73c8635
update
Browse files
app/src/content/embeds/d3-line.html
CHANGED
|
@@ -318,19 +318,34 @@
|
|
| 318 |
const runs = runOrder;
|
| 319 |
// Domain
|
| 320 |
let minStep = Infinity, maxStep = -Infinity, maxVal = 0, minVal = Infinity;
|
|
|
|
|
|
|
|
|
|
| 321 |
runs.forEach(r => {
|
| 322 |
const arr = map[r] || [];
|
| 323 |
-
arr.forEach(pt => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 324 |
});
|
| 325 |
if (!isFinite(minStep) || !isFinite(maxStep)) { return; }
|
| 326 |
xScale.domain([minStep, maxStep]);
|
| 327 |
-
const isRank = /rank/i.test(metricKey);
|
| 328 |
yScale.domain(isRank ? [Math.max(maxVal, 1), Math.min(minVal, 0)] : [0, Math.max(1, maxVal)]).nice();
|
| 329 |
|
| 330 |
const { innerWidth, innerHeight } = updateScales();
|
| 331 |
|
| 332 |
// Bind lines
|
| 333 |
-
const series = runs.map((r, i) => ({
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 334 |
const paths = gLines.selectAll('path.run-line').data(series, d=>d.run);
|
| 335 |
const gen = isRank ? lineGenStep : lineGenSmooth;
|
| 336 |
paths.enter().append('path').attr('class','run-line').attr('fill','none').attr('stroke-width',2)
|
|
@@ -363,7 +378,7 @@
|
|
| 363 |
const m = new Map(s.values.map(v=>[v.step, v.value]));
|
| 364 |
const val = m.has(nearest) ? m.get(nearest) : null;
|
| 365 |
if (val != null) {
|
| 366 |
-
const formatVal = (vv) => (
|
| 367 |
html += `<div><span style=\"display:inline-block;width:10px;height:10px;background:${s.color};border-radius:50%;margin-right:6px;\"></span><strong>${s.run}</strong> ${formatVal(val)}</div>`;
|
| 368 |
}
|
| 369 |
});
|
|
|
|
| 318 |
const runs = runOrder;
|
| 319 |
// Domain
|
| 320 |
let minStep = Infinity, maxStep = -Infinity, maxVal = 0, minVal = Infinity;
|
| 321 |
+
const isRank = /rank/i.test(metricKey);
|
| 322 |
+
const isAverage = /average/i.test(metricKey);
|
| 323 |
+
const isRankStrict = isRank && !isAverage;
|
| 324 |
runs.forEach(r => {
|
| 325 |
const arr = map[r] || [];
|
| 326 |
+
arr.forEach(pt => {
|
| 327 |
+
const val = isRankStrict ? Math.round(pt.value) : pt.value;
|
| 328 |
+
minStep = Math.min(minStep, pt.step);
|
| 329 |
+
maxStep = Math.max(maxStep, pt.step);
|
| 330 |
+
maxVal = Math.max(maxVal, val);
|
| 331 |
+
minVal = Math.min(minVal, val);
|
| 332 |
+
});
|
| 333 |
});
|
| 334 |
if (!isFinite(minStep) || !isFinite(maxStep)) { return; }
|
| 335 |
xScale.domain([minStep, maxStep]);
|
|
|
|
| 336 |
yScale.domain(isRank ? [Math.max(maxVal, 1), Math.min(minVal, 0)] : [0, Math.max(1, maxVal)]).nice();
|
| 337 |
|
| 338 |
const { innerWidth, innerHeight } = updateScales();
|
| 339 |
|
| 340 |
// Bind lines
|
| 341 |
+
const series = runs.map((r, i) => ({
|
| 342 |
+
run: r,
|
| 343 |
+
color: pool[i % pool.length],
|
| 344 |
+
values: (map[r]||[])
|
| 345 |
+
.slice()
|
| 346 |
+
.sort((a,b)=>a.step-b.step)
|
| 347 |
+
.map(pt => isRankStrict ? { step: pt.step, value: Math.round(pt.value) } : pt)
|
| 348 |
+
}));
|
| 349 |
const paths = gLines.selectAll('path.run-line').data(series, d=>d.run);
|
| 350 |
const gen = isRank ? lineGenStep : lineGenSmooth;
|
| 351 |
paths.enter().append('path').attr('class','run-line').attr('fill','none').attr('stroke-width',2)
|
|
|
|
| 378 |
const m = new Map(s.values.map(v=>[v.step, v.value]));
|
| 379 |
const val = m.has(nearest) ? m.get(nearest) : null;
|
| 380 |
if (val != null) {
|
| 381 |
+
const formatVal = (vv) => (isRankStrict ? d3.format('d')(vv) : (+vv).toFixed(4));
|
| 382 |
html += `<div><span style=\"display:inline-block;width:10px;height:10px;background:${s.color};border-radius:50%;margin-right:6px;\"></span><strong>${s.run}</strong> ${formatVal(val)}</div>`;
|
| 383 |
}
|
| 384 |
});
|