Skip to content

Instantly share code, notes, and snippets.

@stalkerg
Created August 6, 2018 06:53
Show Gist options
  • Save stalkerg/15b180aca667f6a53a1477d909451ce3 to your computer and use it in GitHub Desktop.
Save stalkerg/15b180aca667f6a53a1477d909451ce3 to your computer and use it in GitHub Desktop.
Svelte Simple SparkLine Component
<svg viewBox="0 0 {maxWidth} {maxHeight}"
style="width: {width}; height: {height};vertical-align: middle;margin-top: {marginTop};"
preserveAspectRatio="none">
{#each data as value, index}
<path stroke="{ (value/maxHeight) * 100 > 80 ? colorDanger : color}"
stroke-width="{strokeWidth}"
d="M{(strokeWidth + 2) * index + strokeWidth/2} 100 V{ maxHeight - (value/maxHeight) * 100 }"
/>
{/each}
</svg>
<script>
export default {
data() {
return {
data: [],
maxWidth: 100,
maxHeight: 100,
height: '1.25rem',
marginTop: '-0.625rem',
width: '80px',
strokeWidth: 8,
color: '#4caf50',
colorDanger: '#f44336',
};
},
};
</script>
@nickreese
Copy link

Stoked to try this out.

@stalkerg
Copy link
Author

stalkerg commented May 7, 2020

Sorry, it's for Svelt2 but I can port it for Svelte3.

@nickreese
Copy link

No stress. Ended up porting a d3 example to svelte 3. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment