Skip to content

Commit

Permalink
Rewrite about page
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanjc committed Dec 17, 2019
1 parent 3e9a3bc commit 52da05b
Show file tree
Hide file tree
Showing 8 changed files with 557 additions and 171 deletions.
4 changes: 4 additions & 0 deletions components/about-header.mdx
@@ -0,0 +1,4 @@
This is a visualization of Congress’ funding on gun issues. The data is
from the [Center for Responsive Politics](https://www.opensecrets.org).
The code is [open source](https://github.com/lachlanjc/gunfunded).
[Lachlan Campbell](https://lachlanjc.me) made it.
138 changes: 1 addition & 137 deletions components/lobbying.js
Expand Up @@ -10,147 +10,11 @@ import {
} from 'recharts'
import { palette } from './theme'

const data = [
{
year: 1998,
gunControl: 160000,
gunRights: 4498393,
gunManufacturing: 530000
},
{
year: 1999,
gunControl: 840000,
gunRights: 5891966,
gunManufacturing: 795000
},
{
year: 2000,
gunControl: 440000,
gunRights: 6710758,
gunManufacturing: 500000
},
{
year: 2001,
gunControl: 2113699,
gunRights: 6236161,
gunManufacturing: 708000
},
{
year: 2002,
gunControl: 1842054,
gunRights: 5684546,
gunManufacturing: 660000
},
{
year: 2003,
gunControl: 1021665,
gunRights: 4283326,
gunManufacturing: 672000
},
{
year: 2004,
gunControl: 1352346,
gunRights: 4342400,
gunManufacturing: 880000
},
{
year: 2005,
gunControl: 230000,
gunRights: 4070587,
gunManufacturing: 1395000
},
{
year: 2006,
gunControl: 90100,
gunRights: 3184231,
gunManufacturing: 1400000
},
{
year: 2007,
gunControl: 208374,
gunRights: 3962242,
gunManufacturing: 1368000
},
{
year: 2008,
gunControl: 150000,
gunRights: 4128771,
gunManufacturing: 1398000
},
{
year: 2009,
gunControl: 251425,
gunRights: 5209870,
gunManufacturing: 1594000
},
{
year: 2010,
gunControl: 290000,
gunRights: 5847597,
gunManufacturing: 1585000
},
{
year: 2011,
gunControl: 280000,
gunRights: 5580651,
gunManufacturing: 1375000
},
{
year: 2012,
gunControl: 250000,
gunRights: 6129911,
gunManufacturing: 979500
},
{
year: 2013,
gunControl: 2217765,
gunRights: 15292052,
gunManufacturing: 850000
},
{
year: 2014,
gunControl: 1942396,
gunRights: 12013482,
gunManufacturing: 817500
},
{
year: 2015,
gunControl: 1678956,
gunRights: 11406347,
gunManufacturing: 1010000
},
{
year: 2016,
gunControl: 1657992,
gunRights: 11181199,
gunManufacturing: 1120000
},
{
year: 2017,
gunControl: 1942415,
gunRights: 11440684,
gunManufacturing: 1334000
},
{
year: 2018,
gunControl: 2039212,
gunRights: 12453572,
gunManufacturing: 1161000
},
{
year: 2019,
gunControl: 1800000,
gunRights: 8164488,
gunManufacturing: 1210000
}
]

export default () => (
export default ({ data }) => (
<BarChart
width={512}
height={300}
data={data}
style={{ maxWidth: '100vw' }}
>
<CartesianGrid strokeDasharray="3 3" stroke={palette.muted} />
<XAxis dataKey="year" stroke={palette.muted} />
Expand Down
16 changes: 9 additions & 7 deletions components/profile-methodology.mdx
Expand Up @@ -4,10 +4,12 @@ import { Heading } from '@theme-ui/components'

[Gun Rights](https://www.opensecrets.org/industries/summary.php?ind=Q13&recipdetail=A&sortorder=U&cycle=All) and [Gun Control](https://www.opensecrets.org/industries/summary.php?ind=Q12&recipdetail=A&sortorder=U&cycle=All) data from the [Center for Responsive Politics](https://www.opensecrets.org/about/).

**Total**: the total money given to the member’s campaign or leadership PAC from gun rights or gun control PACs or individuals in all of CRP’s data (back to 1989 for members for whom that is relevant).

**Support/oppose:** numbers are money spent by outside groups supporting and opposing these candidates. _Gun rights support_, for example, shows money spent by gun rights groups on independent expenditures supporting this candidate.

**Net:** Gun rights funding _(gun rights total, gun rights support, gun control opposition)_ **minus** gun&nbsp;control funding _(gun control total, gun control support, gun rights opposition)_.

**Rank:** Ranking based on the net amount.
- The first row is money in support of a candidate on **gun rights** (“rights” = against placing restrictions on firearms, typically more Republican)
- The second row is in support of **gun control** (“control” = supports placing restrictions on firearms, typically more Democratic)
- The first column is **direct contributions**: groups like the NRA & Everytown directly giving money to a candidate
- The second two columns are **independent expenditure**: those groups running ads to support/oppose candidates, funneling money through other organizations

- **Total**: the total money given to the member’s campaign or leadership PAC from gun rights or gun control PACs or individuals in all of CRP’s data (back to 1989 for members for whom that is relevant).
- **Support/oppose:** numbers are money spent by outside groups supporting and opposing these candidates. _Gun rights support_, for example, shows money spent by gun rights groups on independent expenditures supporting this candidate.
- **Net funding** (internal) is gun rights funding _(gun rights total, gun rights support, gun control opposition)_ **minus** gun&nbsp;control funding _(gun control total, gun control support, gun rights opposition)_
- **Ranking** uses the net funding amount—from most gun rights to most gun control, with those with zero funding in the middle
35 changes: 35 additions & 0 deletions data/about.js
@@ -0,0 +1,35 @@
const neatCsv = require('neat-csv')
const writeJsonFile = require('write-json-file')
const _ = require('lodash')
const records = require('./records.json')
const groups = require('./groups.json')
const fs = require('fs')
const rawLobbying = fs.readFileSync('./data/raw/lobbying.csv')

const getStats = () => ({
gunRightsTotal: _.sum(_.map(records, 'gunRightsTotal')),
gunControlTotal: _.sum(_.map(records, 'gunControlTotal')),
unRightsCount: _.filter(records, ['gunRightsTotal', 0]).length
})

const getProfiles = () => ({
sample: _.find(records, ['id', 'VA-sen-1']),
highestRights: _.last(_.sortBy(records, 'net')),
highestRightsDem: _.first(_.sortBy(_.filter(records, ['party', 'Democrat'], 'net'))),
highestRightsDirect: _.last(_.sortBy(records, 'gunRightsDirect')),
highestControl: _.last(_.orderBy(records, 'gunControlTotal'))
})
const getLobbying = () => neatCsv(rawLobbying)

const getData = () =>
Promise.all([getLobbying(), getProfiles(), getStats()])
.catch(() => {
console.error('🚨 ERROR')
})
.then(([lobbying, profiles, stats]) => ({stats, profiles, lobbying}))
const save = data => {
writeJsonFile('./data/about.json', data).then(() => {
console.log(`✅ Saved`)
})
}
getData().then(data => save(data))

0 comments on commit 52da05b

Please sign in to comment.