Skip to content

Commit

Permalink
Remove old canvas class and add new class
Browse files Browse the repository at this point in the history
  • Loading branch information
cherriae committed Feb 27, 2025
1 parent 3006e3a commit b19ba03
Show file tree
Hide file tree
Showing 8 changed files with 2,533 additions and 856 deletions.
2,064 changes: 2,064 additions & 0 deletions app/static/js/Canvas.js

Large diffs are not rendered by default.

143 changes: 0 additions & 143 deletions app/static/js/CanvasCoordinateSystem.js

This file was deleted.

121 changes: 0 additions & 121 deletions app/static/js/compare.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,20 +212,6 @@ function updateRawDataTable(data) {
Object.entries(data).forEach(([teamNumber, teamData]) => {
teamData.matches?.forEach(match => {
const row = document.createElement('tr');

// Parse auto path data
let autoPaths = [];
if (match.auto_path) {
try {
if (typeof match.auto_path === 'string') {
autoPaths = JSON.parse(match.auto_path);
} else if (Array.isArray(match.auto_path)) {
autoPaths = match.auto_path;
}
} catch (e) {
console.error('Error parsing auto path:', e);
}
}

const safeAutoPaths = JSON.stringify(autoPaths)
.replace(/'/g, '\\\'')
Expand Down Expand Up @@ -282,117 +268,10 @@ function getTeamColor(index) {
return colors[index] || colors[0];
}

// Auto Path Modal Functions
function showAutoPath(teamNumber, matchNumber, pathData, notes = '') {
// Store the path data
currentPathData = pathData;

// Show the modal
const modal = document.getElementById('autoPathModal');
modal.classList.remove('hidden');

// Initialize canvas if needed
if (!modalCanvas) {
modalCanvas = document.getElementById('modalAutoPathCanvas');
modalCoordSystem = new CanvasCoordinateSystem(modalCanvas);
resizeModalCanvas();
window.addEventListener('resize', resizeModalCanvas);
}

// Draw the paths
redrawPaths();

// Update notes
const notesElement = document.getElementById('modalAutoNotes');
if (notesElement) {
notesElement.textContent = `Team ${teamNumber} - Match ${matchNumber}${notes ? ': ' + notes : ''}`;
}
}

function resizeModalCanvas() {
const container = modalCanvas.parentElement;
modalCanvas.width = container.clientWidth;
modalCanvas.height = container.clientHeight;
modalCoordSystem.updateTransform();
redrawPaths();
}

function redrawPaths() {
if (!modalCoordSystem || !currentPathData) {
return;
}

modalCoordSystem.clear();

let paths = currentPathData;
if (typeof currentPathData === 'string') {
try {
paths = JSON.parse(currentPathData);
} catch (e) {
console.error('Error parsing path data:', e);
return;
}
}

if (Array.isArray(paths)) {
paths.forEach(path => {
if (Array.isArray(path) && path.length > 0) {
const formattedPath = path.map(point => {
if (typeof point === 'object' && 'x' in point && 'y' in point) {
return {
x: (point.x / 1000) * modalCanvas.width,
y: (point.y / 300) * modalCanvas.height
};
}
return null;
}).filter(point => point !== null);

if (formattedPath.length > 0) {
modalCoordSystem.drawPath(formattedPath, '#3b82f6', 3);
}
}
});
}
}

function zoomIn(event) {
if (!modalCoordSystem) {
return;
}
const rect = modalCanvas.getBoundingClientRect();
let mouseX = rect.width / 2;
let mouseY = rect.height / 2;

modalCoordSystem.zoom(mouseX, mouseY, 1.1);
redrawPaths();
}

function zoomOut(event) {
if (!modalCoordSystem) {
return;
}
const rect = modalCanvas.getBoundingClientRect();
let mouseX = rect.width / 2;
let mouseY = rect.height / 2;

modalCoordSystem.zoom(mouseX, mouseY, 0.9);
redrawPaths();
}

function resetZoom() {
if (!modalCoordSystem) {
return;
}
modalCoordSystem.resetView();
redrawPaths();
}

function closeAutoPathModal() {
const modal = document.getElementById('autoPathModal');
modal.classList.add('hidden');
if (modalCoordSystem) {
modalCoordSystem.resetView();
}
}

// Event Listeners
Expand Down
Loading

0 comments on commit b19ba03

Please sign in to comment.