Skip to content
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

cleanup the single bar component #39

Merged
merged 6 commits into from
Mar 24, 2022
Merged

cleanup the single bar component #39

merged 6 commits into from
Mar 24, 2022

Conversation

derekeder
Copy link
Member

@derekeder derekeder commented Mar 23, 2022

Overview

Small PR to clean up the code from #36 and place it in the proper place on the home page

Closes #18

Demo

Screen Shot 2022-03-22 at 10 09 36 PM

Testing Instructions

  • confirm the single stacked bar chart renders as expected on the home page

@derekeder derekeder requested a review from vkoves March 23, 2022 03:11
@netlify
Copy link

netlify bot commented Mar 23, 2022

Deploy Preview for state-decarbonize ready!

Name Link
🔨 Latest commit 96eba17
🔍 Latest deploy log https://app.netlify.com/sites/state-decarbonize/deploys/623cebff2598a300098f5749
😎 Deploy Preview https://deploy-preview-39--state-decarbonize.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@nofurtherinformation
Copy link
Collaborator

nofurtherinformation commented Mar 23, 2022

Hey @derekeder, was just taking a look at this out of curiosity, one more peculiarity of the content property on LabelList is that it exposes the additive y axis value for each stacked bar, not the source data value value (so, buildings appears as to represent ~57%, since that is its total accumulated amount in the stack, but not individual percent).

valueAccessor exposes the actual data value though, so something like the below works -- what do you think? Happy to push on this PR if ok!

// helpers

const getPct = (value, total) => { return Math.round((value/total)*100) }
const getLabel = (
  entry, 
  total, 
  field, 
  label
) => { 
  return `${label}: ${getPct(entry[field], total)}%` 
}

function SingleBarChart ({emissions_data}) {
  // sum all emissions fields except year
  const totalEmissions = Object.entries(emissions_data[0])
    .filter((key) => key !== 'year')
    .reduce((acc, curr) => acc + curr[1], 0);
  // ... some lines later
  <Bar dataKey="dumps_farms_industrial_other" stackId="a" fill="#98886c">
          <LabelList 
            valueAccessor={entry => getLabel(
              entry, 
              totalEmissions, 
              'dumps_farms_industrial_other', 
              'Dumps, Farms, Industrial & Other'
            )} 
            position="insideTopLeft" 
            /> 
  </Bar>
}

Looks like:
Screen Shot 2022-03-23 at 9 11 25 AM

@derekeder
Copy link
Member Author

@nofurtherinformation nice! one question for the bar in your screenshot, why do the totals add up to less than 100%? (20 + 7 + 23 + 28 = 78%)

@nofurtherinformation
Copy link
Collaborator

nofurtherinformation commented Mar 23, 2022 via email

@vkoves
Copy link
Collaborator

vkoves commented Mar 24, 2022

@derekeder - this look solid but I don't think it actually closes #17, since that also includes a drawdown graph showing emissions going down to 0. I think this does close Issue #29.

Also could we move the axis closer to the actual data? It's really hard to read in my mind since it's so far away. However, if the specific Gigatonne values don't matter (which I am open to, since it's basically for showing percentages), we could just drop the axis and the label.

@derekeder
Copy link
Member Author

derekeder commented Mar 24, 2022

@nofurtherinformation nice - this looks correct now. Thanks for the assist

@vkoves I agree the YAxis is a bit far away. It doesn't give us much value so I removed it. Also updated the issue description so it closes #18, which was mistakenly closed from the previous PR #36.

Screen Shot 2022-03-24 at 2 51 05 PM

This is ready for another look

Copy link
Collaborator

@vkoves vkoves left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome work! There's a few unused variables and imports GitHub is pointing out, but I don't think that's a blocker - I'd rather get this merged so I can integrate it on the state details page and start figuring out how to highlight individual sections as green.

@derekeder
Copy link
Member Author

@vkoves cool. I removed those references. Once it builds I'll bring this in.

@derekeder derekeder merged commit 7448d27 into main Mar 24, 2022
@vkoves vkoves deleted the dwe/single-bar-cleanup branch April 27, 2022 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create stacked bar chart for one year
3 participants