|
65 | 65 | navigator.clipboard.writeText(newUrl); |
66 | 66 | window.open(newUrl, "_blank").focus(); |
67 | 67 | } |
| 68 | +
|
| 69 | + let graph: Graph; |
| 70 | +
|
| 71 | + function downloadString(text: string, fileType: string, fileName: string) { |
| 72 | + var blob = new Blob([text], { type: fileType }); |
| 73 | +
|
| 74 | + var a = document.createElement("a"); |
| 75 | + a.download = fileName; |
| 76 | + a.href = URL.createObjectURL(blob); |
| 77 | + a.dataset.downloadurl = [fileType, a.download, a.href].join(":"); |
| 78 | + a.style.display = "none"; |
| 79 | + document.body.appendChild(a); |
| 80 | + a.click(); |
| 81 | + document.body.removeChild(a); |
| 82 | + setTimeout(function () { |
| 83 | + URL.revokeObjectURL(a.href); |
| 84 | + }, 1500); |
| 85 | + } |
| 86 | +
|
| 87 | + function saveSVG() { |
| 88 | + const svg = graph.getSVG(); |
| 89 | + downloadString(svg, "image/svg+xml", "function-graph-overview.svg"); |
| 90 | + } |
68 | 91 | </script> |
69 | 92 |
|
70 | 93 | <main> |
|
115 | 138 | </div> |
116 | 139 | </div> |
117 | 140 | <div class="graph"> |
118 | | - <div class="controls"> |
119 | | - <input type="checkbox" id="simplify" bind:checked={simplify} /> |
120 | | - <label for="simplify">Simplify</label> |
| 141 | + <div class="graph-controls"> |
| 142 | + <div class="settings"> |
| 143 | + <input type="checkbox" id="simplify" bind:checked={simplify} /> |
| 144 | + <label for="simplify">Simplify</label> |
121 | 145 |
|
122 | | - <input type="checkbox" id="flatSwitch" bind:checked={flatSwitch} /> |
123 | | - <label for="flatSwitch">Flat Switch</label> |
| 146 | + <input type="checkbox" id="flatSwitch" bind:checked={flatSwitch} /> |
| 147 | + <label for="flatSwitch">Flat Switch</label> |
| 148 | + </div> |
| 149 | + <div class="download"> |
| 150 | + <button on:click={saveSVG}>Save SVG</button> |
| 151 | + </div> |
124 | 152 | </div> |
125 | | - <Graph {code} language={selection.language} {simplify} {flatSwitch} /> |
| 153 | + <Graph |
| 154 | + {code} |
| 155 | + language={selection.language} |
| 156 | + {simplify} |
| 157 | + {flatSwitch} |
| 158 | + bind:this={graph} |
| 159 | + /> |
126 | 160 | </div> |
127 | 161 | </main> |
128 | 162 |
|
|
150 | 184 | margin-top: 1rem; |
151 | 185 | margin-left: 1rem; |
152 | 186 | } |
| 187 | + .graph-controls { |
| 188 | + font-family: Arial, Helvetica, sans-serif; |
| 189 | + margin-top: 1rem; |
| 190 | + margin-left: 1rem; |
| 191 | + margin-right: 1rem; |
| 192 | +
|
| 193 | + display: flex; |
| 194 | + justify-content: space-between; |
| 195 | + } |
153 | 196 |
|
154 | 197 | .codemirror { |
155 | 198 | padding-top: 1rem; |
|
0 commit comments