generated from carbonplan/article-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Rework maple bars and detail charts #31
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
15272a0
maple and bar rework
Shane98c 5180081
mobile, expander attempt, detail charts breakout
Shane98c 3596f7b
handle error/missing
Shane98c 57febb8
add vscode to gitignore
Shane98c bd62c03
Merge branch 'main' of https://github.com/carbonplan/offsets-db-web i…
Shane98c 370757b
fix animation
Shane98c 7a2d789
better math
Shane98c 1c57e67
even better math
Shane98c b35e74b
no math
Shane98c a1635ae
improve maple spacing
Shane98c a6916b1
always mobile
Shane98c 37a4bbb
rework badge/labels arrangement
Shane98c b04ca58
expander => triangle concept
Shane98c b94dcfb
rethinking detail?
Shane98c bd15a5f
details chart concept
Shane98c 0ca9320
clean up messy columns
Shane98c 0cdf94c
rm unused row
Shane98c bf5b34f
improve triangle
Shane98c 0fac217
needed the rows
Shane98c f1f3f0c
wider, attempt to wrap on slash
Shane98c 4ea3e6e
fix label typography
Shane98c 6d066bd
revert to expander
Shane98c 7b8bf04
conditional expander
Shane98c eff5a74
don't stack maple bars
Shane98c a2cf9bb
reorient and hide detail on mobile
Shane98c 557b1d5
rework detail charts, add loading state placeholders
Shane98c b416de7
match colors/txt to maple badges
Shane98c 3143338
handle error state
Shane98c a03adfc
spacing fixes for tablet/mobile
Shane98c a1ed843
rm unused import
Shane98c e022389
no pointer on detail charts
Shane98c 4a4ce4b
don't show expander/expand if empty
Shane98c ff10316
cursor styling when no expansion possible
Shane98c 978e004
prevent flash during expansion
Shane98c 68558d6
fix mobile spacing
Shane98c 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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
.DS_Store | ||
.next/ | ||
node_modules/ | ||
.env.local | ||
.vscode/ | ||
.env.local |
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
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,132 @@ | ||
import { useState, useEffect } from 'react' | ||
import { Box, Flex, Badge } from 'theme-ui' | ||
import { Row, Column } from '@carbonplan/components' | ||
import { alpha } from '@theme-ui/color' | ||
import { COLORS, LABELS } from '../constants' | ||
import { formatValue } from '../utils' | ||
|
||
const DetailCharts = ({ issued, retired, isLoading, error }) => { | ||
const [previousCategories, setPreviousCategories] = useState([]) | ||
|
||
useEffect(() => { | ||
if (!isLoading && !error) { | ||
setPreviousCategories(Object.keys(issued.mapping)) | ||
} | ||
}, [isLoading, error]) | ||
|
||
const createGradient = (theme, l, isRetired) => { | ||
const percent = ((issued.mapping[l] ?? 0) / issued.total) * 100 | ||
const retiredPercent = isRetired | ||
? ((retired.mapping[l] ?? 0) / issued.total) * 100 | ||
: percent | ||
|
||
if (isRetired) { | ||
return `linear-gradient(to right, | ||
${theme.rawColors[COLORS[l]]} 0%, | ||
${theme.rawColors[COLORS[l]]} ${retiredPercent}%, | ||
${alpha( | ||
theme.rawColors[COLORS[l]], | ||
0.3 | ||
)(theme)} ${retiredPercent}%, | ||
${alpha(theme.rawColors[COLORS[l]], 0.3)(theme)} ${percent}%, | ||
${theme.colors.muted} ${percent}%, | ||
${theme.colors.muted} 100%)` | ||
} else { | ||
return `linear-gradient(to right, ${ | ||
theme.colors[COLORS[l]] | ||
} 0% ${percent}%, ${theme.colors.muted} ${percent}% 100%)` | ||
} | ||
} | ||
const chartColumn = (isRetired) => { | ||
const categoryKeys = | ||
isLoading || error | ||
? previousCategories | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Super clean, very nice! |
||
: Object.keys(LABELS.category).filter((l) => Boolean(issued.mapping[l])) | ||
|
||
return ( | ||
<Column | ||
start={[ | ||
isRetired ? 4 : 1, | ||
isRetired ? 5 : 1, | ||
isRetired ? 5 : 1, | ||
isRetired ? 5 : 1, | ||
]} | ||
width={[3, 4, 4, 4]} | ||
> | ||
{categoryKeys.map((l) => ( | ||
<Box key={l} sx={{ mb: 2 }}> | ||
<Flex | ||
sx={{ | ||
justifyContent: 'space-between', | ||
fontSize: 2, | ||
mb: 1, | ||
}} | ||
> | ||
{isLoading || error ? ( | ||
<Flex sx={{ gap: 2, alignItems: 'center' }}> | ||
<Box | ||
sx={{ | ||
width: '8px', | ||
height: '8px', | ||
backgroundColor: 'muted', | ||
}} | ||
/> | ||
<Box sx={{ fontSize: 1, color: 'muted' }}>----</Box> | ||
</Flex> | ||
) : ( | ||
<Flex sx={{ gap: 2, alignItems: 'center' }}> | ||
<Box | ||
sx={{ | ||
width: '8px', | ||
height: '8px', | ||
backgroundColor: COLORS[l], | ||
}} | ||
/> | ||
<Box sx={{ fontSize: 1 }}>{LABELS.category[l]}</Box> | ||
</Flex> | ||
)} | ||
|
||
<Badge | ||
sx={{ | ||
color: isLoading || error ? 'primary' : COLORS[l], | ||
backgroundColor: | ||
isLoading || error ? 'muted' : alpha(COLORS[l], 0.3), | ||
fontSize: 2, | ||
mb: '3px', | ||
}} | ||
> | ||
{isLoading || error | ||
? '-' | ||
: formatValue( | ||
isRetired ? retired.mapping[l] : issued.mapping[l] | ||
) ?? 0} | ||
</Badge> | ||
</Flex> | ||
<Box | ||
sx={{ | ||
height: '5px', | ||
width: '100%', | ||
transition: 'background 0.2s', | ||
background: | ||
isLoading || error | ||
? 'muted' | ||
: (theme) => createGradient(theme, l, isRetired), | ||
}} | ||
/> | ||
</Box> | ||
))} | ||
</Column> | ||
) | ||
} | ||
|
||
return ( | ||
<> | ||
<Row columns={[6, 8, 8, 8]} sx={{ mb: 5 }}> | ||
{chartColumn(false)} | ||
{chartColumn(true)} | ||
</Row> | ||
</> | ||
) | ||
} | ||
|
||
export default DetailCharts |
Oops, something went wrong.
Oops, something went wrong.
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.
this is looking really really nice 🤌