Skip to content

Commit

Permalink
fix selection
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-vorobiov committed Sep 24, 2024
1 parent b72e3d8 commit 39ce57f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion evolve_analytics.meta.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name Evolve Analytics
// @namespace http://tampermonkey.net/
// @version 0.5.0
// @version 0.5.1
// @description Track and see detailed information about your runs
// @author Sneed
// @match https://pmotschmann.github.io/Evolve/
Expand Down
26 changes: 13 additions & 13 deletions src/ui/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function* linePointerMarks(plotPoints: PlotPoint[], key: "day" | "segment", hist
}));
}

function* rectPointerMarks(plotPoints: PlotPoint[], history: HistoryEntry[]) {
function* rectPointerMarks(plotPoints: PlotPoint[], key: "dayDiff" | "segment", history: HistoryEntry[]) {
plotPoints = plotPoints.filter((entry: PlotPoint) => entry.dayDiff !== undefined);

// Transform pointer position from the point to the segment
Expand All @@ -131,15 +131,15 @@ function* rectPointerMarks(plotPoints: PlotPoint[], history: HistoryEntry[]) {

yield Plot.text(plotPoints, Plot.pointerX(toSegment({
x: "run",
y: "segment",
y: key,
dy: -17,
frameAnchor: "top-left",
text: (p: PlotPoint) => `Run #${history[p.run].run}: ${p.milestone} in ${p.day} day(s)`
})));

yield Plot.barY(plotPoints, Plot.pointerX(Plot.stackY({
x: "run",
y: "segment",
y: key,
fill: "milestone",
fillOpacity: 0.5
})));
Expand All @@ -159,13 +159,13 @@ export function makeGraph(history: HistoryManager, view: View, onSelect: (run: H
case "bars":
marks.push(...barMarks(plotPoints, "dayDiff"));
marks.push(...timestamps(plotPoints, "day"));
marks.push(...rectPointerMarks(plotPoints, filteredRuns));
marks.push(...rectPointerMarks(plotPoints, "dayDiff", filteredRuns));
break;

// Vertical bars composed of individual segments stacked on top of each other
case "barsSegmented":
marks.push(...barMarks(plotPoints, "segment"));
marks.push(...rectPointerMarks(plotPoints, filteredRuns));
marks.push(...rectPointerMarks(plotPoints, "segment", filteredRuns));
break;

// Same as "total" but with the areas between the lines filled
Expand Down Expand Up @@ -202,24 +202,24 @@ export function makeGraph(history: HistoryManager, view: View, onSelect: (run: H

const yScale = calculateYScale(plotPoints, view);

const node = Plot.plot({
const plot = Plot.plot({
width: 800,
x: { axis: null },
y: { grid: true, domain: yScale },
color: { legend: true, domain: generateMilestoneNames(milestones) },
marks
});

node.addEventListener("mousedown", () => {
if (node.value) {
onSelect(filteredRuns[node.value.run]);
plot.addEventListener("mousedown", () => {
if (plot.value) {
onSelect(filteredRuns[plot.value.run]);
}
else {
onSelect(null);
}
});

const legendMilestones = $(node).find("> div > span");
const legendMilestones = $(plot).find("> div > span");

legendMilestones
.css("cursor", "pointer")
Expand All @@ -237,9 +237,9 @@ export function makeGraph(history: HistoryManager, view: View, onSelect: (run: H
view.toggleMilestone(milestone);
});

$(node).find("> svg").attr("width", "100%");
$(plot).find("> svg").attr("width", "100%");

$(node).css("margin", "0");
$(plot).css("margin", "0");

return node;
return plot;
}

0 comments on commit 39ce57f

Please sign in to comment.