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

chart refinements #701

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sass/util/_border.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
.border-bottom-dotted { border-bottom: $border-width dotted $body-color; }

.border-w2 { border-width: 2px; }
.border-w8 { border-width: 8px; }

.rounded-br { border-bottom-right-radius: $border-radius; }

@media #{$breakpoint-md} {
Expand Down
2 changes: 1 addition & 1 deletion src/components/NibrsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ const NibrsContainer = ({

return (
<div>
<div className='mb2 p2 sm-p4 bg-blue-lighter'>
<div className='mb2 p2 sm-p4 bg-white border-top border-blue border-w8'>
<h2 className='m0 fs-24 sm-fs-32 sans-serif'>
{startCase(crime)} incident details in {startCase(place)},{' '}
<br className='xs-hide' />
Expand Down
4 changes: 1 addition & 3 deletions src/components/NoData.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@ import React from 'react'


const NoData = () => (
<div className='p4 bg-white'>
<div className='fs-18'>🙁 There’s no data at this time.</div>
</div>
<div className='fs-18'>There’s no data at this time.</div>
)

export default NoData
4 changes: 2 additions & 2 deletions src/components/TrendChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class TrendChart extends React.Component {
)

return (
<div className='px2 py3 sm-p4 bg-white'>
<div>
<TrendChartDetails
colors={colors}
crime={crime}
Expand Down Expand Up @@ -268,7 +268,7 @@ class TrendChart extends React.Component {
</div>
<div className='my1 fs-10 sm-fs-12 monospace center'>
<div className='bold'>{startCase(crime)} rate per 100,000 people</div>
<div className='italic'>(Does not include estimates)</div>
<div className='italic'>(Does not include estimates; rates are rounded)</div>
</div>
<DownloadDataBtn data={download} />
</div>
Expand Down
28 changes: 19 additions & 9 deletions src/components/TrendChartDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,25 @@ import mapCrimeToGlossaryTerm from '../util/glossary'
import { nationalKey } from '../util/usa'


const formatRate = format('.1f')
const formatRate = n => format(`,.${+n > 10 ? 0 : 1}f`)(n)
const formatTotal = format(',.0f')

const highlight = v => <span className='bold blue'>{v}</span>
const getComparison = ({ place, data }) => {
const threshold = 3
const placeRate = data[place].rate
const nationalRate = data[nationalKey].rate
const difference = (placeRate - nationalRate)
const diff = ((placeRate / nationalRate) - 1) * 100
const diffAbs = Math.abs(diff)

if (Math.abs(difference) < 2) return 'about the same as'
else if (difference > 2) return 'higher than'
return 'lower than'
return (diffAbs < threshold) ? (
<span>{highlight(`about the same (within ${threshold}%)`)} as</span>
) : (
<span>
{highlight(`${formatRate(diffAbs)}% ${diff > threshold ? 'higher' : 'lower'}`)}
{' '}than
</span>
)
}

const TrendChartDetails = ({ colors, crime, data, dispatch, keys }) => {
Expand All @@ -26,7 +34,6 @@ const TrendChartDetails = ({ colors, crime, data, dispatch, keys }) => {
const rate = data[slug].rate
const year = data.date.getFullYear()

const highlight = v => <span className='bold blue'>{v}</span>
const isOnlyNational = keys.length === 1
const term = (
<Term dispatch={dispatch} id={mapCrimeToGlossaryTerm(crime)}>
Expand All @@ -35,7 +42,7 @@ const TrendChartDetails = ({ colors, crime, data, dispatch, keys }) => {
)

return (
<div className='mb2 lg-flex'>
<div className='mb3 lg-flex'>
<div className='flex-auto'>
<h4 className='mt0 mb1 fs-18 sans-serif'>{year}</h4>
<p className='mb1 lg-m0 lg-pr4 lg-mh-72p fs-14 sm-fs-16'>
Expand All @@ -50,14 +57,17 @@ const TrendChartDetails = ({ colors, crime, data, dispatch, keys }) => {
</p>
</div>
<div>
<table className='mb1 lg-m0' style={{ maxWidth: 300 }}>
<table className='mb1 lg-m0 p2 md-p3 col-12 sm-col-5 bg-blue-white'>
<thead className='fs-12 line-height-3'>
<tr><td /><td>Rate</td><td>Total</td></tr>
</thead>
<tbody className='fs-14 bold'>
{keys.map((k, i) => (
<tr key={i}>
<td className='pr2 sm-pr3 fs-12 nowrap align-bottom'>
<td
className='pr2 sm-pr3 fs-12 nowrap truncate align-bottom'
style={{ maxWidth: 125 }}
>
<span
className='mr1 inline-block circle'
style={{ width: 8, height: 8, backgroundColor: colors[i] || '#000' }}
Expand Down
6 changes: 3 additions & 3 deletions src/components/TrendContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ const TrendContainer = ({ crime, place, filters, data, dispatch, loading, keys }

return (
<div>
<div className='mb2 p2 sm-p4 bg-blue-lighter'>
<h2 className='m0 fs-24 sm-fs-32 sans-serif'>
<div className='mb2 p2 sm-p4 bg-white border-top border-blue border-w8'>
<h2 className='mt0 mb3 fs-24 sm-fs-32 sans-serif'>
{startCase(crime)} rate in {startCase(place)},{' '}
<br className='xs-hide' />
{since}–{until}
</h2>
{content}
</div>
<div className='mb2'>{content}</div>
{!loading && (
<TrendSourceText
dispatch={dispatch}
Expand Down