Skip to content

Commit 40fc86c

Browse files
committed
add download svg graph
1 parent c0694a2 commit 40fc86c

3 files changed

Lines changed: 29 additions & 0 deletions

File tree

docs/src/introduction.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<script src="https://unpkg.com/elkjs@0.9.3/lib/elk.bundled.js"></script>
88
<script src="https://unpkg.com/cytoscape-elk@2.2.0/dist/cytoscape-elk.js"></script>
9+
<script src="https://unpkg.com/cytoscape-svg@0.4.0/cytoscape-svg.js"></script>
910

1011
<div id="cy-search">
1112
<input id="search-input" type="text" placeholder="Search problems...">
@@ -23,6 +24,7 @@
2324
<div>
2425
<span id="instructions">Click a node to start path selection</span>
2526
<button id="clear-btn">Clear</button>
27+
<button id="download-svg-btn">Download SVG</button>
2628
</div>
2729
</div>
2830
<div id="cy-help">

docs/src/static/reduction-graph.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@
6363
font-size: 12px;
6464
}
6565

66+
#download-svg-btn {
67+
margin-left: 8px;
68+
padding: 3px 10px;
69+
cursor: pointer;
70+
font-size: 12px;
71+
}
72+
6673
#cy-search {
6774
margin-bottom: 8px;
6875
}

docs/src/static/reduction-graph.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ document.addEventListener('DOMContentLoaded', function() {
1313
try { cytoscape({ headless: true, elements: [] }).layout({ name: 'elk' }); elkAvailable = true; } catch(e) {}
1414
}
1515

16+
// Register cytoscape-svg extension if available
17+
if (typeof cytoscapeSvg !== 'undefined') {
18+
cytoscape.use(cytoscapeSvg);
19+
}
20+
1621
var categoryColors = {
1722
graph: '#c8f0c8', set: '#f0c8c8', algebraic: '#f0f0a0',
1823
formula: '#c8c8f0', misc: '#f0c8e0'
@@ -552,6 +557,21 @@ document.addEventListener('DOMContentLoaded', function() {
552557
}
553558
});
554559

560+
// Download SVG handler
561+
var downloadBtn = document.getElementById('download-svg-btn');
562+
if (downloadBtn) {
563+
downloadBtn.addEventListener('click', function() {
564+
var svgContent = cy.svg({ scale: 1, full: true, bg: getComputedStyle(document.documentElement).getPropertyValue('--bg').trim() || '#ffffff' });
565+
var blob = new Blob([svgContent], { type: 'image/svg+xml;charset=utf-8' });
566+
var url = URL.createObjectURL(blob);
567+
var a = document.createElement('a');
568+
a.href = url;
569+
a.download = 'reduction-graph.svg';
570+
a.click();
571+
URL.revokeObjectURL(url);
572+
});
573+
}
574+
555575
// Search bar handler
556576
var searchInput = document.getElementById('search-input');
557577
if (searchInput) {

0 commit comments

Comments
 (0)