Skip to content

Commit

Permalink
removed functions from buttons when no file loaded (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnaliam authored Apr 14, 2024
1 parent d6a74a2 commit 1cf6bc6
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions ts/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,32 @@ import * as d3 from "d3";
import { degreesToRadians, clamp } from './funcs';
import { parse } from 'csv-parse/browser/esm/sync';

const playPause: HTMLButtonElement = document.getElementById("playPause") as HTMLButtonElement;
const stepLeft: HTMLButtonElement = document.getElementById("stepLeft") as HTMLButtonElement;
const stepRight: HTMLButtonElement = document.getElementById("stepRight") as HTMLButtonElement;
const timeSlider = document.getElementById("timeSlider");
const changeFile = document.getElementById("changedFile");
const buttonsToDisable: HTMLButtonElement[] = [ playPause, stepLeft, stepRight ];

let playing: boolean = false;
let i: number = 0;
let endIndex: number = 0;
let startIndex: number = 0;
let fileLoaded: boolean = false;

let draw;
let indexToSliderScale;
let sliderToIndexScale;
let onSliderChange;

function initialize(data: object[]) {
// adding function to the buttons
buttonsToDisable.forEach((button) => {button.disabled = false});
playPause.addEventListener("click", () => { playing = !playing; });
stepLeft.addEventListener("click", () => { stepLogging(true) });
stepRight.addEventListener("click", () => { stepLogging(false) });
timeSlider.addEventListener("input", () => { onSliderChange() });

// Constants and helpers
const canvas = document.getElementById("canvas") as HTMLCanvasElement;
const ctx = canvas.getContext("2d");
Expand Down Expand Up @@ -209,12 +224,12 @@ async function changedFile(event) {
const file = event.target.files.item(0);
const text = await file.text();
const jsonFromCSV = parse(text, {columns: true, skip_empty_lines: true});
fileLoaded = true;

initialize(jsonFromCSV);
}

document.getElementById("playPause").addEventListener("click", () => { playing = !playing; });
document.getElementById("stepLeft").addEventListener("click", () => { stepLogging(true) });
document.getElementById("stepRight").addEventListener("click", () => { stepLogging(false) });
document.getElementById("timeSlider").addEventListener("input", () => { onSliderChange() });
document.getElementById("changedFile").addEventListener("change", () => { changedFile(event) });

changeFile.addEventListener("change", () => { changedFile(event) });

buttonsToDisable.forEach((button) => { button.disabled = true; });

0 comments on commit 1cf6bc6

Please sign in to comment.