|
1 | | -<!doctype html> |
2 | | -<meta charset="utf-8" /> |
3 | | -<title>Bar Chart using the EplusM scale</title> |
4 | | -<link rel="preconnect" href="https://fonts.googleapis.com"> |
5 | | -<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> |
6 | | -<link href="https://fonts.googleapis.com/css2?family=Inter:wght@500&family=Manrope:wght@200..800&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet"> |
7 | | - |
8 | | -<style> |
9 | | - body, svg { |
10 | | - font-family: 'Rubik', serif; |
11 | | - margin: 0; |
12 | | - padding: 0; |
13 | | - overflow: hidden; |
14 | | - } |
15 | | - |
16 | | - .grid { |
17 | | - color: black; |
18 | | - opacity: 0.5; |
19 | | - stroke-width: 0.5px; |
20 | | - } |
21 | | - |
22 | | - .grid-strong { |
23 | | - color: rgb(20, 22, 76); |
24 | | - stroke-width: 1px; |
25 | | - } |
26 | | - |
27 | | - .strongText { |
28 | | - font-size: 16px; |
29 | | - font-weight: bold; |
30 | | - color: rgb(20, 22, 76); |
31 | | - } |
32 | | - |
33 | | - .strongSSBText { |
34 | | - font-size: 16px; |
35 | | - font-weight: bold; |
36 | | - } |
37 | | - |
38 | | - .lightText { |
39 | | - font-size: 16px; |
40 | | - color: grey; |
41 | | - } |
42 | | - |
43 | | - .dashed-line { |
44 | | - stroke: grey; |
45 | | - stroke-width: 2; |
46 | | - stroke-dasharray: 4; |
47 | | - } |
48 | | -</style> |
49 | | -<div id="container"></div> |
50 | | -<svg id="mainsvg" xmlns="http://www.w3.org/2000/svg"></svg> |
51 | | - |
| 1 | +<!DOCTYPE html> |
| 2 | +<html lang="en"> |
| 3 | + <head> |
| 4 | + <meta charset="utf-8" /> |
| 5 | + <title>Bar Chart using the EplusM scale</title> |
| 6 | + <link rel="preconnect" href="https://fonts.googleapis.com"> |
| 7 | + <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> |
| 8 | + <link href="https://fonts.googleapis.com/css2?family=Inter:wght@500&family=Manrope:wght@200..800&family=Montserrat:ital,wght@0,100..900;1,100..900&family=Rubik:ital,wght@0,300..900;1,300..900&display=swap" rel="stylesheet"> |
52 | 9 | <script type="module"> |
53 | 10 | import * as d3 from 'https://cdn.jsdelivr.net/npm/d3@7/+esm'; |
54 | 11 | import { scaleEplusM, bricksEplusM } from 'd3-eplusm'; |
|
91 | 48 |
|
92 | 49 | // Create the SVG container. |
93 | 50 | const svg = d3 |
94 | | - .select('#mainsvg') |
| 51 | + .select('#brickssvg') |
95 | 52 | .attr('width', width) |
96 | 53 | .attr('height', height) |
97 | 54 | .attr('viewBox', [0, 0, width, height]) |
|
249 | 206 | // Append the SVG element. |
250 | 207 | window['container'].append(svg.node()); |
251 | 208 | </script> |
| 209 | +</head> |
| 210 | + <body> |
| 211 | + <div id="container"> |
| 212 | + <svg id="brickssvg" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"> |
| 213 | + <style> |
| 214 | + svg { |
| 215 | + font-family: 'Rubik', serif; |
| 216 | + margin: 0; |
| 217 | + padding: 0; |
| 218 | + overflow: hidden; |
| 219 | + } |
| 220 | + |
| 221 | + .grid { |
| 222 | + color: black; |
| 223 | + opacity: 0.5; |
| 224 | + stroke-width: 0.5px; |
| 225 | + } |
| 226 | + |
| 227 | + .grid-strong { |
| 228 | + color: rgb(20, 22, 76); |
| 229 | + stroke-width: 1px; |
| 230 | + } |
| 231 | + |
| 232 | + .strongText { |
| 233 | + font-size: 16px; |
| 234 | + font-weight: bold; |
| 235 | + color: rgb(20, 22, 76); |
| 236 | + } |
| 237 | + |
| 238 | + .strongSSBText { |
| 239 | + font-size: 16px; |
| 240 | + font-weight: bold; |
| 241 | + } |
| 242 | + |
| 243 | + .lightText { |
| 244 | + font-size: 16px; |
| 245 | + color: grey; |
| 246 | + } |
| 247 | + |
| 248 | + .dashed-line { |
| 249 | + stroke: grey; |
| 250 | + stroke-width: 2; |
| 251 | + stroke-dasharray: 4; |
| 252 | + } |
| 253 | +</style> |
| 254 | + </svg> |
| 255 | + <script> |
| 256 | +function saveSvg(id, name) { |
| 257 | +const svgEl = document.getElementById(id); |
| 258 | + svgEl.setAttribute("xmlns", "http://www.w3.org/2000/svg"); |
| 259 | + var svgData = svgEl.outerHTML; |
| 260 | + var preface = '<?xml version="1.0" standalone="no"?>\r\n'; |
| 261 | + var svgBlob = new Blob([preface, svgData], {type:"image/svg+xml;charset=utf-8"}); |
| 262 | + var svgUrl = URL.createObjectURL(svgBlob); |
| 263 | + var downloadLink = document.createElement("a"); |
| 264 | + downloadLink.href = svgUrl; |
| 265 | + downloadLink.download = name; |
| 266 | + document.body.appendChild(downloadLink); |
| 267 | + downloadLink.click(); |
| 268 | + document.body.removeChild(downloadLink); |
| 269 | +} |
| 270 | + |
| 271 | +window.addEventListener( |
| 272 | + 'keypress', |
| 273 | + function (evt) { |
| 274 | + if (evt.code == "KeyS") |
| 275 | + saveSvg('brickssvg', 'bricks.svg') |
| 276 | +}); |
| 277 | + </script> |
| 278 | +</div> |
| 279 | +</body> |
| 280 | +</html> |
0 commit comments