Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 41 additions & 5 deletions src/dynomanager.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { AppState, DOM } from './config.js';

Check warning on line 1 in src/dynomanager.js

View workflow job for this annotation

GitHub Actions / validate_and_build

'DOM' is defined but never used

Check warning on line 1 in src/dynomanager.js

View workflow job for this annotation

GitHub Actions / validate_and_build

'DOM' is defined but never used
import { Chart } from 'chart.js';
import { PaletteManager } from './palettemanager.js';
import { ChartManager } from './chartmanager.js';

export const DynoManager = {
chartInstance: null,
Expand Down Expand Up @@ -141,24 +142,59 @@
}
}

if (!document.getElementById('btn-export-dyno')) {
if (!document.getElementById('dyno-action-group')) {
const closeBtn = modal.querySelector('.btn-close');
if (closeBtn && closeBtn.parentElement) {
const mainHeader = closeBtn.parentElement;

const actionGroup = document.createElement('div');
actionGroup.id = 'dyno-action-group';
actionGroup.style.display = 'flex';
actionGroup.style.gap = '10px';
actionGroup.style.marginRight = 'auto';
actionGroup.style.marginLeft = '15px';

const highlightBtn = document.createElement('button');
highlightBtn.className = 'btn btn-sm';
highlightBtn.style.backgroundColor = 'var(--brand-blue, #1c3d72)';
highlightBtn.style.color = '#fff';
highlightBtn.style.border = 'none';
highlightBtn.innerHTML =
'<i class="fas fa-search-plus"></i> View on Chart';
highlightBtn.onclick = () => this.highlightCurrentPull();

const exportBtn = document.createElement('button');
exportBtn.id = 'btn-export-dyno';
exportBtn.className = 'btn btn-sm btn-primary';
exportBtn.innerHTML = '<i class="fas fa-camera"></i> Save PNG';
exportBtn.style.marginRight = 'auto';
exportBtn.style.marginLeft = '15px';
exportBtn.onclick = () => this.exportChart();

mainHeader.insertBefore(exportBtn, closeBtn);
actionGroup.appendChild(highlightBtn);
actionGroup.appendChild(exportBtn);

mainHeader.insertBefore(actionGroup, closeBtn);
}
}
},

highlightCurrentPull() {
if (this.currentPulls.length === 0) return;

const activePull = this.currentPulls[this.selectedPullIndex];
const file = AppState.files[0];

if (activePull.time && activePull.time.length > 0) {
const startTimeMs = activePull.time[0];
const endTimeMs = activePull.time[activePull.time.length - 1];

const startSec = (startTimeMs - file.startTime) / 1000;
const endSec = (endTimeMs - file.startTime) / 1000;

this.closeModal();

ChartManager.zoomTo(startSec, endSec, 0);
}
},

exportChart() {
const canvas = document.getElementById('dynoCanvas');
if (!canvas) return;
Expand Down
6 changes: 6 additions & 0 deletions tests/dynomanager.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const mockChartInstance = {
options: { plugins: {}, scales: {} },
};

await jest.unstable_mockModule('../src/chartmanager.js', () => ({
ChartManager: {
zoomTo: jest.fn(),
},
}));

await jest.unstable_mockModule('chart.js', () => {
const MockChart = jest.fn((ctx, config) => {
if (config && config.options) mockChartInstance.options = config.options;
Expand Down
Loading