Skip to content

Instantly share code, notes, and snippets.

@davidlav
Last active October 27, 2016 22:48
Show Gist options
  • Save davidlav/0a2e9d0ff056a032f3c74336c5edebc5 to your computer and use it in GitHub Desktop.
Save davidlav/0a2e9d0ff056a032f3c74336c5edebc5 to your computer and use it in GitHub Desktop.
SVG Dimensions in Aurelia (doesn't work)
<template>
<link rel="stylesheet" href="style.css">
<div class="place-holder" id="splash-banner"></div>
<div id="under-splash-banner">
<div class="place-holder" id="news-feed"></div>
<div id="resizable-panels">
<div id="patient-info">
<div class="place-holder" id="order-history"></div>
<div class="place-holder" id="health-status"></div>
<div class="place-holder" id="to-do"></div>
</div>
<div id="timeline">
<!--How do I find the size of this SVG element (the white box)?-->
<svg id="timeline-svg" ref="svgElement"></svg>
</div>
</div>
</div>
</template>
// What are the dimensions of <svg id="timeline-svg" ref="svgElement"></svg> in app.html?
export class App {
attached() {
const w = parseInt(d3.select('#timeline-svg').style('width'), 10);
const h = parseInt(d3.select('#timeline-svg').style('height'), 10);
document.getElementById('news-feed').innerHTML = "Empty SVG dimensions are: " + w + " x " + h + "<br>No matter how much you resize it and reload the page, the above will always report<br>'300 x 150'";
}
}
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/jspm_packages/system.js"></script>
<script src="https://cdn.rawgit.com/jdanyow/aurelia-bundle/v1.0.3/config.js"></script>
<script src="https://d3js.org/d3.v3.min.js"></script>
<script>
System.import('aurelia-bootstrapper');
</script>
</body>
</html>
html {
box-sizing: border-box;
}
/* line 7, D:/Webstorm Projects/EDIS/css/style.sass */
*, *::before, *::after {
box-sizing: inherit;
}
/* line 10, D:/Webstorm Projects/EDIS/css/style.sass */
body {
display: flex;
flex-direction: column;
margin: 0;
height: 100vh;
font-family: 'Roboto', 'Open Sans', sans-serif;
text-align: center;
}
/* line 17, D:/Webstorm Projects/EDIS/css/style.sass */
.place-holder {
display: flex;
font-size: 18pt;
justify-content: center;
align-items: center;
}
/* line 23, D:/Webstorm Projects/EDIS/css/style.sass */
#splash-banner {
height: 100px;
background-color: rgba(255, 0, 0, 0.2);
}
/* line 27, D:/Webstorm Projects/EDIS/css/style.sass */
#under-splash-banner {
display: flex;
flex-direction: row-reverse;
flex: 1;
width: 100vw;
}
/* line 33, D:/Webstorm Projects/EDIS/css/style.sass */
#news-feed {
width: 400px;
background-color: rgba(0, 255, 0, 0.2);
}
/* line 37, D:/Webstorm Projects/EDIS/css/style.sass */
#resizable-panels {
display: flex;
flex-direction: column;
width: 100%;
}
/* line 42, D:/Webstorm Projects/EDIS/css/style.sass */
#patient-info {
display: flex;
flex: 1;
}
/* line 46, D:/Webstorm Projects/EDIS/css/style.sass */
#order-history {
flex: 1;
background-color: rgba(0, 0, 255, 0.1);
}
/* line 50, D:/Webstorm Projects/EDIS/css/style.sass */
#health-status {
flex: 1;
background-color: rgba(0, 0, 255, 0.2);
}
/* line 54, D:/Webstorm Projects/EDIS/css/style.sass */
#to-do {
flex: 1;
background-color: rgba(0, 0, 255, 0.3);
}
/* line 58, D:/Webstorm Projects/EDIS/css/style.sass */
#timeline {
display: flex;
flex: 1;
}
/* line 63, D:/Webstorm Projects/EDIS/css/style.sass */
#timeline-svg {
flex: 1;
border: 1px solid gray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment