Skip to content

Commit

Permalink
Merge 35e5a00 into eb1a24f
Browse files Browse the repository at this point in the history
  • Loading branch information
dustinengle committed Sep 4, 2018
2 parents eb1a24f + 35e5a00 commit 92dac82
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 0 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@
"webpack-dev-server": "^3.1.4"
},
"dependencies": {
"chart.js": "^2.7.2",
"d3-dsv": "^1.0.8",
"d3-format": "^1.3.0",
"d3-time-format": "^2.1.1",
"react": "^16.4.1",
"react-chartkick": "^0.3.0",
"react-dom": "^16.4.1",
"react-stockcharts": "^0.7.7"
},
Expand Down
44 changes: 44 additions & 0 deletions react/Chart.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Chart from 'chart.js'
import PropTypes from 'prop-types'
import React from 'react'
import ReactChartKick, {LineChart} from 'react-chartkick'
import {pickRest} from '../lib/utils'

ReactChartKick.addAdapter(Chart)

export const ChartLine = (props) => {
const [mods, {data, links, subtitle, title, ...rest}] = pickRest(props, [])

return (
<div block='chart' mods={mods} {...rest}>
<div block='chart' elem='head'>
<div block='chart__head' elem='title'>{title}</div>
{!!subtitle && <div block='chart__head' elem='subtitle'>{subtitle}</div>}
<div block='chart__head' elem='flex' />
{Array.isArray(links) &&
<div block='chart__head' elem='links'>
{links.map(l => (
<a className={l.active ? 'active' : ''} key={l.text} onClick={l.onClick}>{l.text}</a>
))}
</div>
}
</div>
<div block='chart' elem='body'>
<LineChart data={data} {...rest} />
</div>
</div>
)
}

ChartLine.propTypes = {
data: PropTypes.object.isRequired,
links: PropTypes.arrayOf(PropTypes.shape({
active: PropTypes.bool,
onClick: PropTypes.func.isRequired,
text: PropTypes.string.isRequired
})),
subtitle: PropTypes.string,
title: PropTypes.string.isRequired
}

export default {ChartLine}
1 change: 1 addition & 0 deletions sass/_library.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
@import 'inc/badge';
@import 'inc/button';
@import 'inc/card';
@import 'inc/chart';
@import 'inc/checkbox';
@import 'inc/drawer';
@import 'inc/grid';
Expand Down
52 changes: 52 additions & 0 deletions sass/inc/_chart.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@

.chart {
background-color: $black;
border-radius: 10px;
box-shadow: 0 0 5px 0 rgba(0, 0, 0, 0.25);
color: $white;

&__body {
padding: 0 24px 24px 24px;
text-align: center;
}

&__head {
display: flex;
flex-direction: row;
padding: 32px 24px;

* { display: inline-block; }

&__flex { flex: 1; }

&__links {
a {
color: $secondary;
cursor: pointer;
font-size: 14px;
font-weight: 500;
line-height: 19px;
margin-right: 56px;

&:last-child { margin-right: 0; }

&.active { color: $white; }
}
}

&__subtitle {
font-size: 14px;
line-height: 19px;
padding-top: 11px;
}

&__title {
font-family: $font-secondary;
font-size: 24px;
font-weight: bold;
letter-spacing: -1px;
line-height: 35px;
margin-right: 10px;
}
}
}
31 changes: 31 additions & 0 deletions test/Chart.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* global describe, it */
import React from 'react'
import expect from 'must'
import { shallow } from 'enzyme'
import {ChartLine} from '../react/Chart'

const data = {}
const keys = [1.1, 1.2301, 1.32, 1.30, 1.4, 1.5, 1.6]
keys.forEach((k, i) => { data[i] = k })

describe('<ChartLine />', () => {
const links = [
{active: true, onClick: () => {}, text: 'One'},
{onClick: () => {}, text: 'Two'}
]
const wrapper = shallow(
<ChartLine data={data} links={links} subtitle='Sub' title='Test' />
)

it('renders as a div', () => {
expect(wrapper.is('div')).to.be.true()
})

it('renders body, links, subtitle, and title', () => {
expect(wrapper.find('.chart__body')).to.have.length(1)
expect(wrapper.find('.chart__head')).to.have.length(1)
expect(wrapper.childAt(0).find('.chart__head__title')).to.have.length(1)
expect(wrapper.childAt(0).find('.chart__head__subtitle')).to.have.length(1)
expect(wrapper.childAt(0).find('.chart__head__links')).to.have.length(1)
})
})
2 changes: 2 additions & 0 deletions todo/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { render } from 'react-dom'
import BadgeDemo from './Section/BadgeDemo'
import ButtonDemo from './Section/ButtonDemo'
import CardDemo from './Section/CardDemo'
import ChartDemo from './Section/ChartDemo'
import CheckboxDemo from './Section/CheckboxDemo'
import {Drawer, DrawerDivider, DrawerHeader, DrawerLink} from '../react/Drawer'
import FontDemo from './Section/FontDemo'
Expand Down Expand Up @@ -67,6 +68,7 @@ class App extends React.Component {
<PaginationDemo />
<StepperDemo />
<TableDemo />
<ChartDemo />
</div>
<div style={{height: 100}} />
</div>
Expand Down
52 changes: 52 additions & 0 deletions todo/Section/ChartDemo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import React from 'react'

import {ChartLine} from '../../react/Chart'

const data = {}
const keys = [1.1, 1.2301, 1.32, 1.30, 1.4, 1.5, 1.6]
keys.forEach((k, i) => { data[i] = k })

const ButtonDemo = () => (
<div>
<h3>Chart</h3>
<ChartLine
data={data}
colors={['#ffffff']}
legend={false}
library={{
scales: {
xAxes: [{gridLines: {display: false}, ticks: {display: false}}],
yAxes: [{gridLines: {display: false}}]
},
tooltips: {
backgroundColor: '#ffffff',
bodyFontColor: '#252525',
bodyFontFamily: "'Roboto', sans-serif",
bodyFontSize: 14,
bodySpacing: 2,
caretPadding: 9,
cornerRadius: 5,
footerFontSize: 0,
titleFontSize: 0,
titleMarginBottom: 0,
titleSpacing: 0,
xPadding: 20,
yPadding: 6
}
}}
links={[
{active: true, onClick: f => f, text: '1 Day'},
{onClick: f => f, text: '1 Week'},
{onClick: f => f, text: '1 Month'}
]}
max={1.6}
messages={{empty: 'No data'}}
min={1.1}
prefix='$'
subtitle='Data courtesy of CoinMarketCap'
thousands=','
title='Bulwark Price' />
</div>
)

export default ButtonDemo
42 changes: 42 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,30 @@ chardet@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/chardet/-/chardet-0.5.0.tgz#fe3ac73c00c3d865ffcc02a0682e2c20b6a06029"

chart.js@^2.7.2:
version "2.7.2"
resolved "https://registry.yarnpkg.com/chart.js/-/chart.js-2.7.2.tgz#3c9fde4dc5b95608211bdefeda7e5d33dffa5714"
dependencies:
chartjs-color "^2.1.0"
moment "^2.10.2"

chartjs-color-string@^0.5.0:
version "0.5.0"
resolved "https://registry.yarnpkg.com/chartjs-color-string/-/chartjs-color-string-0.5.0.tgz#8d3752d8581d86687c35bfe2cb80ac5213ceb8c1"
dependencies:
color-name "^1.0.0"

chartjs-color@^2.1.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/chartjs-color/-/chartjs-color-2.2.0.tgz#84a2fb755787ed85c39dd6dd8c7b1d88429baeae"
dependencies:
chartjs-color-string "^0.5.0"
color-convert "^0.5.3"

chartkick@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/chartkick/-/chartkick-3.0.1.tgz#f325041bfc15f5d18074d4803549efc3751ccd81"

cheerio@^1.0.0-rc.2:
version "1.0.0-rc.2"
resolved "https://registry.yarnpkg.com/cheerio/-/cheerio-1.0.0-rc.2.tgz#4b9f53a81b27e4d5dac31c0ffd0cfa03cc6830db"
Expand Down Expand Up @@ -1712,6 +1736,10 @@ collection-visit@^1.0.0:
map-visit "^1.0.0"
object-visit "^1.0.0"

color-convert@^0.5.3:
version "0.5.3"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-0.5.3.tgz#bdb6c69ce660fadffe0b0007cc447e1b9f7282bd"

color-convert@^1.9.0:
version "1.9.2"
resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.2.tgz#49881b8fba67df12a96bdf3f56c0aab9e7913147"
Expand All @@ -1722,6 +1750,10 @@ color-name@1.1.1:
version "1.1.1"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.1.tgz#4b1415304cf50028ea81643643bd82ea05803689"

color-name@^1.0.0:
version "1.1.3"
resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25"

colors@0.5.x:
version "0.5.1"
resolved "https://registry.yarnpkg.com/colors/-/colors-0.5.1.tgz#7d0023eaeb154e8ee9fce75dcb923d0ed1667774"
Expand Down Expand Up @@ -4977,6 +5009,10 @@ mkdirp@0.5.x, "mkdirp@>=0.5 0", mkdirp@^0.5.0, mkdirp@^0.5.1, mkdirp@~0.5.0:
dependencies:
minimist "0.0.8"

moment@^2.10.2:
version "2.22.2"
resolved "https://registry.yarnpkg.com/moment/-/moment-2.22.2.tgz#3c257f9839fc0e93ff53149632239eb90783ff66"

moo@^0.4.3:
version "0.4.3"
resolved "https://registry.yarnpkg.com/moo/-/moo-0.4.3.tgz#3f847a26f31cf625a956a87f2b10fbc013bfd10e"
Expand Down Expand Up @@ -5936,6 +5972,12 @@ rc@^1.2.7:
minimist "^1.2.0"
strip-json-comments "~2.0.1"

react-chartkick@^0.3.0:
version "0.3.0"
resolved "https://registry.yarnpkg.com/react-chartkick/-/react-chartkick-0.3.0.tgz#692461eb808e18e7a2860129247476d55295e677"
dependencies:
chartkick "^3.0.0"

react-dom@^16.4.1:
version "16.4.1"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.4.1.tgz#7f8b0223b3a5fbe205116c56deb85de32685dad6"
Expand Down

0 comments on commit 92dac82

Please sign in to comment.