fix svg examples

pull/2421/head
Richard Harris 7 years ago
parent d1b5d5bf45
commit db57b2c110

@ -34,6 +34,10 @@
</script> </script>
<style> <style>
h2 {
text-align: center;
}
.chart { .chart {
width: 100%; width: 100%;
max-width: 500px; max-width: 500px;
@ -77,9 +81,10 @@
} }
</style> </style>
<div class="chart"> <h2>US birthrate by year</h2>
<h2>US birthrate by year</h2>
<svg bind:clientWidth={width} bind:clientHeight={height}> <div class="chart" bind:clientWidth={width} bind:clientHeight={height}>
<svg>
<!-- y axis --> <!-- y axis -->
<g class="axis y-axis" transform="translate(0,{padding.top})"> <g class="axis y-axis" transform="translate(0,{padding.top})">
{#each yTicks as tick} {#each yTicks as tick}

@ -1,5 +1,4 @@
<script> <script>
import { onMount } from 'svelte';
import { scaleLinear } from 'd3-scale'; import { scaleLinear } from 'd3-scale';
import points from './data.js'; import points from './data.js';
@ -26,21 +25,12 @@
function formatMobile (tick) { function formatMobile (tick) {
return "'" + tick % 100; return "'" + tick % 100;
} }
let svg;
function resize() {
({ width, height } = svg.getBoundingClientRect());
}
onMount(resize);
</script> </script>
<svelte:window on:resize='{resize}'/> <h2>Arctic sea ice minimum</h2>
<div class="chart"> <div class="chart" bind:clientWidth={width} bind:clientHeight={height}>
<h2>Arctic sea ice minimum</h2> <svg>
<svg bind:this={svg}>
<!-- y axis --> <!-- y axis -->
<g class="axis y-axis" transform="translate(0, {padding.top})"> <g class="axis y-axis" transform="translate(0, {padding.top})">
{#each yTicks as tick} {#each yTicks as tick}
@ -65,21 +55,23 @@
<path class="path-area" d={area}></path> <path class="path-area" d={area}></path>
<path class="path-line" d={path}></path> <path class="path-line" d={path}></path>
</svg> </svg>
<p>Average September extent. Source: <a href='https://climate.nasa.gov/vital-signs/arctic-sea-ice/'>NSIDC/NASA</a>
</div> </div>
<p>Average September extent. Source: <a href='https://climate.nasa.gov/vital-signs/arctic-sea-ice/'>NSIDC/NASA</a></p>
<style> <style>
.chart { .chart, h2, p {
width: 100%; width: 100%;
max-width: 500px; max-width: 500px;
margin: 0 auto; margin-left: auto;
margin-right: auto;
} }
svg { svg {
position: relative; position: relative;
width: 100%; width: 100%;
height: 200px; height: 200px;
overflow: visible;
} }
.tick { .tick {

Loading…
Cancel
Save