Skip to content

Commit

Permalink
Days scale
Browse files Browse the repository at this point in the history
  • Loading branch information
roman-vorobiov committed Dec 13, 2024
1 parent b8c0c99 commit 2cdcb47
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 40 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.9.1
// @version 0.9.2
// @description Track and see detailed information about your runs
// @author Sneed
// @match https://pmotschmann.github.io/Evolve/
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type ViewConfig = {
showLines: boolean,
fillArea: boolean,
numRuns?: number,
daysScale?: number,
milestones: Record<string, boolean>,
additionalInfo: Array<keyof typeof additionalInformation>
}
Expand Down
6 changes: 1 addition & 5 deletions src/migration/7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,14 @@ export type Config7 = {
}

function migrateView(view: ViewConfig7): ViewConfig8 {
const newView: ViewConfig8 = {
return {
...view,
mode: ["segmented", "barsSegmented"].includes(view.mode) ? "duration" : "timestamp",
smoothness: 0,
showBars: ["bars", "barsSegmented"].includes(view.mode),
showLines: ["total", "filled", "segmented"].includes(view.mode),
fillArea: view.mode === "filled"
};

delete (newView as any).daysScale;

return newView;
}

export function migrate7(config: Config7): Config8 {
Expand Down
15 changes: 11 additions & 4 deletions src/ui/graph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ import type { default as PlotType } from "@observablehq/plot";

declare const Plot: typeof PlotType;

function calculateYScale(plotPoints: PlotPoint[], view: View): [number, number] | undefined {
if (view.daysScale) {
return [0, view.daysScale];
}
else if (plotPoints.length === 0) {
// Default scale with empty history
return [0, 1000];
}
}

function lastRunEntries(plotPoints: PlotPoint[]): PlotPoint[] {
const timestamps: PlotPoint[] = [];

Expand Down Expand Up @@ -234,13 +244,10 @@ export function makeGraph(history: HistoryManager, view: View, onSelect: (run: H
});
}

// Default scale with empty history
const yScale = plotPoints.length === 0 ? [0, 1000] : undefined;

const plot = Plot.plot({
width: 800,
x: { axis: null },
y: { grid: true, domain: yScale },
y: { grid: true, domain: calculateYScale(plotPoints, view) },
color: { legend: true, domain: generateMilestoneNames(milestones) },
marks
});
Expand Down
9 changes: 7 additions & 2 deletions src/ui/viewSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { makeSelect, makeSlider, makeCheckbox, makeToggleableNumberInput } from "./utils";
import { makeSelect, makeSlider, makeCheckbox, makeNumberInput, makeToggleableNumberInput } from "./utils";
import { resets, universes, viewModes } from "../enums";
import type { View, ViewConfig } from "../config";

Expand Down Expand Up @@ -34,7 +34,8 @@ export function makeViewSettings(view: View) {
break;

case "numRuns":
view.numRuns = Number(value) || undefined;
case "daysScale":
view[key] = Number(value) || undefined;
break;

default:
Expand Down Expand Up @@ -72,6 +73,9 @@ export function makeViewSettings(view: View) {

const avgWindowSlider = makeSetting("Smoothness", makeSlider([0, 100], view.smoothness, bind("smoothness")));

const daysScaleInput = makeNumberInput("Auto", view.daysScale)
.on("change", bindThis("daysScale"));

onPropertyChange(["universe"], () => {
const resetName = view.universe === "magic" ? "Vacuum Collapse" : "Black Hole";
resetTypeInput.find(`> option[value="blackhole"]`).text(resetName);
Expand All @@ -92,6 +96,7 @@ export function makeViewSettings(view: View) {

const displaySettings = $(`<div class="flex-container" style="flex-direction: row;"></div>`)
.append(makeSetting("Mode", modeInput))
.append(makeSetting("Days scale", daysScaleInput))
.append(showBarsToggle)
.append(showLinesToggle)
.append(fillAreaToggle)
Expand Down
28 changes: 0 additions & 28 deletions test/migration7.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,33 +127,5 @@ describe("Migration", () => {
]
});
});

it("should discard daysScale field", () => {
const oldConfig = {
version: 7,
views: [
{
...makeView("total"),
daysScale: 123
}
]
};

expect(migrate7(oldConfig as any)).toEqual({
version: 8,
views: [
{
resetType: "ascension",
mode: "timestamp",
showBars: false,
showLines: true,
fillArea: false,
smoothness: 0,
milestones: {},
additionalInfo: []
}
]
});
});
});
});

0 comments on commit 2cdcb47

Please sign in to comment.