-
Notifications
You must be signed in to change notification settings - Fork 65
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue #1 WIP Stacked to Bar Example #5
Open
MichaelAdamBerry
wants to merge
3
commits into
Rich-Harris:master
Choose a base branch
from
MichaelAdamBerry:example-stacked-to-grouped
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
<script> | ||
import * as Pancake from "@sveltejs/pancake"; | ||
import { fly, scale } from "svelte/transition"; | ||
import { quintOut } from "svelte/easing"; | ||
import { crossfade } from "svelte/transition"; | ||
import { flip } from "svelte/animate"; | ||
import data from "./data.js"; | ||
|
||
const [send, receive] = crossfade({ | ||
duration: d => Math.sqrt(d * 200), | ||
|
||
fallback(node, params) { | ||
const style = getComputedStyle(node); | ||
const transform = style.transform === "none" ? "" : style.transform; | ||
|
||
return { | ||
duration: 600, | ||
easing: quintOut, | ||
css: t => ` | ||
transform: ${transform} scale(${t}); | ||
opacity: ${t} | ||
` | ||
}; | ||
} | ||
}); | ||
|
||
const fruits = ["apples", "bananas", "cherries", "dates"]; | ||
const colors = ["#00e047", "#7ceb68", "#b7f486", "#ecfda5"]; | ||
|
||
let shiftX = 1 / fruits.length; | ||
let isFlattened = false; | ||
|
||
const stacks = Pancake.stacks(data, fruits, "year"); | ||
|
||
const max = stacks.reduce( | ||
(max, stack) => Math.max(max, ...stack.values.map(v => v.end)), | ||
0 | ||
); | ||
|
||
const years = { | ||
min: data[data.length - 1].year, | ||
max: data[0].year | ||
}; | ||
</script> | ||
|
||
<style> | ||
.chart { | ||
height: 200px; | ||
padding: 3em 0 2em 2em; | ||
margin: 0 0 36px 0; | ||
} | ||
|
||
.grid-line { | ||
position: relative; | ||
display: block; | ||
} | ||
|
||
.grid-line.horizontal { | ||
width: calc(100% + 2em); | ||
left: -2em; | ||
} | ||
|
||
.grid-line span { | ||
position: absolute; | ||
left: 0; | ||
bottom: 0; | ||
font-family: sans-serif; | ||
font-size: 14px; | ||
color: #999; | ||
line-height: 1; | ||
} | ||
|
||
.year-label { | ||
position: absolute; | ||
width: 4em; | ||
left: -2em; | ||
bottom: -22px; | ||
font-family: sans-serif; | ||
font-size: 14px; | ||
color: #999; | ||
text-align: center; | ||
} | ||
|
||
.box { | ||
position: absolute; | ||
left: 2px; | ||
top: 0; | ||
width: calc(100% - 4px); | ||
height: 100%; | ||
border-radius: 2px; | ||
} | ||
.radio-inputs { | ||
display: flex; | ||
} | ||
|
||
label { | ||
margin: 0 1rem; | ||
} | ||
</style> | ||
|
||
<div class="radio-inputs"> | ||
<label> | ||
<input type="radio" bind:group={isFlattened} value={false} /> | ||
Stacked | ||
</label> | ||
<label> | ||
<input type="radio" bind:group={isFlattened} value={true} /> | ||
Grouped | ||
</label> | ||
</div> | ||
|
||
<div class="chart"> | ||
|
||
<Pancake.Chart x1={years.max + 0.5} x2={years.min - 0.5} y1={0} y2={max}> | ||
<Pancake.Grid horizontal count={5} let:value let:first> | ||
<div class="grid-line horizontal"> | ||
<span>{value}</span> | ||
</div> | ||
</Pancake.Grid> | ||
|
||
<Pancake.Grid vertical count={10} let:value> | ||
<span class="year-label">{value}</span> | ||
</Pancake.Grid> | ||
|
||
{#each stacks as stack, i} | ||
{#if !isFlattened} | ||
{#each stack.values as d, vi} | ||
<Pancake.Box x1={d.i + 0.5} x2={d.i - 0.5} y1={d.start} y2={d.end}> | ||
<div | ||
in:receive={{ key: (i + 1) * vi }} | ||
out:send={{ key: (i + 1) * vi }} | ||
class="box" | ||
style="background-color: {colors[i]}" /> | ||
</Pancake.Box> | ||
{/each} | ||
{:else} | ||
{#each stack.values as d, vi} | ||
<Pancake.Box | ||
x1={d.i + 0.5 - i * shiftX} | ||
x2={d.i + 0.5 - i * shiftX - shiftX} | ||
y1={d.value} | ||
y2={0}> | ||
<div | ||
in:receive={{ key: (i + 1) * vi }} | ||
out:send={{ key: (i + 1) * vi }} | ||
class="box" | ||
style="background-color: {colors[i]}" /> | ||
</Pancake.Box> | ||
{/each} | ||
{/if} | ||
{/each} | ||
</Pancake.Chart> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export default [ | ||
{ year: 2019, apples: 3840, bananas: 1920, cherries: 960, dates: 400 }, | ||
{ year: 2018, apples: 1600, bananas: 1440, cherries: 960, dates: 400 }, | ||
{ year: 2017, apples: 820, bananas: 1000, cherries: 640, dates: 400 }, | ||
{ year: 2016, apples: 820, bananas: 560, cherries: 720, dates: 400 }, | ||
{ year: 2015, apples: 3840, bananas: 1020, cherries: 960, dates: 400 }, | ||
{ year: 2014, apples: 1600, bananas: 1240, cherries: 960, dates: 400 }, | ||
{ year: 2013, apples: 820, bananas: 1200, cherries: 640, dates: 400 }, | ||
{ year: 2012, apples: 820, bananas: 860, cherries: 720, dates: 400 }, | ||
{ year: 2011, apples: 840, bananas: 1920, cherries: 960, dates: 400 }, | ||
{ year: 2010, apples: 1600, bananas: 1440, cherries: 960, dates: 400 }, | ||
{ year: 2009, apples: 820, bananas: 1000, cherries: 640, dates: 400 }, | ||
{ year: 2008, apples: 820, bananas: 560, cherries: 720, dates: 400 } | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"name": "Pancake • Stacked to Grouped Bar"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,88 @@ | ||
<script> | ||
import Chart1 from './1/App.svelte'; | ||
import Chart2 from './2/App.svelte'; | ||
import Chart3 from './3/App.svelte'; | ||
import Chart1 from "./1/App.svelte"; | ||
import Chart2 from "./2/App.svelte"; | ||
import Chart3 from "./3/App.svelte"; | ||
import Chart4 from "./4/App.svelte"; | ||
</script> | ||
|
||
<div class="chart-preview"> | ||
<header> | ||
<h3>Population pyramid</h3> | ||
<p><a href="https://svelte.dev/repl/8686ac654dff448eafbe7cb396b8a058">Edit</a></p> | ||
</header> | ||
<Chart1/> | ||
</div> | ||
<style> | ||
header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: baseline; | ||
border-bottom: 1px solid rgba(255, 62, 0, 0.2); | ||
margin: 0 0 1em 0; | ||
padding: 0 0 3px 0px; | ||
overflow: hidden; | ||
} | ||
|
||
h3 { | ||
/*border-bottom: 3px solid #ddd;*/ | ||
margin: 0; | ||
line-height: 1; | ||
} | ||
|
||
<div class="chart-preview"> | ||
<header> | ||
<h3>Life expectancy</h3> | ||
<p><a href="https://svelte.dev/repl/3eaa39931e8045cf87da8b482e502c29">Edit</a></p> | ||
</header> | ||
<Chart2/> | ||
</div> | ||
.chart-preview { | ||
margin: 2em 0 6em 0; | ||
} | ||
|
||
p { | ||
margin: 0; | ||
line-height: 1; | ||
} | ||
|
||
a { | ||
font-size: 14px; | ||
color: #ff3e00; | ||
border-bottom: 6px solid rgba(255, 62, 0, 0.2); | ||
text-decoration: none; | ||
} | ||
</style> | ||
|
||
<div class="chart-preview"> | ||
<header> | ||
<h3>Treemap</h3> | ||
<p><a href="https://svelte.dev/repl/2a8acd2328ff4a5398def8b8c8252904">Edit</a></p> | ||
</header> | ||
<Chart3/> | ||
<header> | ||
<h3>Population pyramid</h3> | ||
<p> | ||
<a href="https://svelte.dev/repl/8686ac654dff448eafbe7cb396b8a058"> | ||
Edit | ||
</a> | ||
</p> | ||
</header> | ||
<Chart1 /> | ||
</div> | ||
|
||
<style> | ||
header { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: baseline; | ||
border-bottom: 1px solid rgba(255,62,0,0.2); | ||
margin: 0 0 1em 0; | ||
padding: 0 0 3px 0px; | ||
overflow: hidden; | ||
} | ||
|
||
h3 { | ||
/*border-bottom: 3px solid #ddd;*/ | ||
margin: 0; | ||
line-height: 1; | ||
} | ||
|
||
.chart-preview { | ||
margin: 2em 0 6em 0; | ||
} | ||
|
||
p { | ||
margin: 0; | ||
line-height: 1; | ||
} | ||
<div class="chart-preview"> | ||
<header> | ||
<h3>Life expectancy</h3> | ||
<p> | ||
<a href="https://svelte.dev/repl/3eaa39931e8045cf87da8b482e502c29"> | ||
Edit | ||
</a> | ||
</p> | ||
</header> | ||
<Chart2 /> | ||
</div> | ||
|
||
a { | ||
font-size: 14px; | ||
color: #ff3e00; | ||
border-bottom: 6px solid rgba(255,62,0,0.2); | ||
text-decoration: none; | ||
} | ||
</style> | ||
<div class="chart-preview"> | ||
<header> | ||
<h3>Treemap</h3> | ||
<p> | ||
<a href="https://svelte.dev/repl/2a8acd2328ff4a5398def8b8c8252904"> | ||
Edit | ||
</a> | ||
</p> | ||
</header> | ||
<Chart3 /> | ||
</div> | ||
<div class="chart-preview"> | ||
<header> | ||
<h3>Stacked to Grouped Bars</h3> | ||
<p> | ||
<a | ||
href="https://svelte.dev/repl/34bce599eb744d66b80073d21a67bdc2?version=3.18.1"> | ||
Edit | ||
</a> | ||
</p> | ||
</header> | ||
<Chart4 /> | ||
</div> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like you have a mix of tabs and spaces in this file. All the other examples use exclusively tabs