mirror of
https://github.com/olehomelchenko/astrolabe-nvc.git
synced 2025-12-21 21:22:23 +00:00
fix: various small fixes
This commit is contained in:
@@ -165,8 +165,8 @@
|
||||
<span class="view-label">Fit:</span>
|
||||
<div class="view-toggle-group">
|
||||
<button class="btn btn-toggle active" id="preview-fit-default" title="Display at original spec dimensions">Original</button>
|
||||
<button class="btn btn-toggle" id="preview-fit-width" title="Scale to fit preview pane width">Width</button>
|
||||
<button class="btn btn-toggle" id="preview-fit-full" title="Scale to fit entire preview pane">Full</button>
|
||||
<button class="btn btn-toggle" id="preview-fit-width" title="Scale to fit preview pane width (⚠️ for faceted specs, applies to each facet)">Width</button>
|
||||
<button class="btn btn-toggle" id="preview-fit-full" title="Scale to fit entire preview pane (⚠️ for faceted specs, applies to each facet)">Full</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -116,7 +116,7 @@ document.addEventListener('DOMContentLoaded', function () {
|
||||
});
|
||||
|
||||
// Toggle panel buttons
|
||||
document.querySelectorAll('.toggle-btn').forEach(button => {
|
||||
document.querySelectorAll('[id^="toggle-"][id$="-panel"]').forEach(button => {
|
||||
button.addEventListener('click', function () {
|
||||
const panelId = this.id.replace('toggle-', '');
|
||||
togglePanel(panelId);
|
||||
|
||||
@@ -8,20 +8,46 @@ function applyPreviewFitMode(spec, fitMode) {
|
||||
// Clone to avoid mutation
|
||||
const modifiedSpec = JSON.parse(JSON.stringify(spec));
|
||||
|
||||
if (fitMode === 'width' || fitMode === 'full') {
|
||||
const previewPane = document.getElementById('vega-preview');
|
||||
if (previewPane) {
|
||||
const containerWidth = previewPane.offsetWidth - 10; // 10px padding for scroll
|
||||
const containerHeight = previewPane.offsetHeight - 10; // 10px padding
|
||||
|
||||
// Apply dimensions recursively to handle nested specs
|
||||
function applyDimensions(s) {
|
||||
if (!s || typeof s !== 'object') return;
|
||||
|
||||
// Set dimensions at current level if this is a unit spec or has width/height
|
||||
if (fitMode === 'width') {
|
||||
// Fit to width - get preview pane width
|
||||
const previewPane = document.getElementById('vega-preview');
|
||||
if (previewPane) {
|
||||
const containerWidth = previewPane.offsetWidth;
|
||||
modifiedSpec.width = containerWidth - 10; // 10px padding for scroll
|
||||
// Keep original aspect ratio by not setting height
|
||||
}
|
||||
s.width = containerWidth;
|
||||
delete s.height; // Remove height to preserve aspect ratio
|
||||
} else if (fitMode === 'full') {
|
||||
// Fit to full pane - get both dimensions
|
||||
const previewPane = document.getElementById('vega-preview');
|
||||
if (previewPane) {
|
||||
modifiedSpec.width = previewPane.offsetWidth - 10; // 10px padding
|
||||
modifiedSpec.height = previewPane.offsetHeight - 10; // 10px padding
|
||||
s.width = containerWidth;
|
||||
s.height = containerHeight;
|
||||
}
|
||||
|
||||
// Recursively apply to nested specs
|
||||
// For facet specs
|
||||
if (s.spec) {
|
||||
applyDimensions(s.spec);
|
||||
}
|
||||
// For layer, concat, hconcat, vconcat
|
||||
if (Array.isArray(s.layer)) {
|
||||
s.layer.forEach(applyDimensions);
|
||||
}
|
||||
if (Array.isArray(s.concat)) {
|
||||
s.concat.forEach(applyDimensions);
|
||||
}
|
||||
if (Array.isArray(s.hconcat)) {
|
||||
s.hconcat.forEach(applyDimensions);
|
||||
}
|
||||
if (Array.isArray(s.vconcat)) {
|
||||
s.vconcat.forEach(applyDimensions);
|
||||
}
|
||||
}
|
||||
|
||||
applyDimensions(modifiedSpec);
|
||||
}
|
||||
}
|
||||
// 'default' mode leaves original dimensions untouched
|
||||
|
||||
@@ -815,6 +815,7 @@ function duplicateSnippet(snippetId) {
|
||||
const newSnippet = createSnippet(duplicateSpec, duplicateName);
|
||||
newSnippet.comment = originalSnippet.comment;
|
||||
newSnippet.tags = [...originalSnippet.tags];
|
||||
newSnippet.datasetRefs = extractDatasetRefs(duplicateSpec);
|
||||
|
||||
SnippetStorage.saveSnippet(newSnippet);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user