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

Implement Black & Red Line Chart #2

Merged
merged 164 commits into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
164 commits
Select commit Hold shift + click to select a range
2100fe7
Add line chart
snuggs Feb 10, 2018
3be7f02
Add whitespace
snuggs Feb 10, 2018
ea33dae
Add style for line chart
snuggs Feb 10, 2018
6428e8d
Change line-chart
snuggs Feb 10, 2018
ca7b1a7
Align text center
snuggs Feb 10, 2018
9bbfa4b
Remove margin
snuggs Feb 10, 2018
a26b4bb
Add width height margin and display
snuggs Feb 10, 2018
48482ba
Fix margin
snuggs Feb 10, 2018
d7a189a
Add main
snuggs Feb 10, 2018
cafab01
Add line-chart height
snuggs Feb 10, 2018
a991abf
Add dashed outline for line-chart
snuggs Feb 10, 2018
a7aa52a
Add canvas
snuggs Feb 10, 2018
3d484d8
Make background green for canvas
snuggs Feb 10, 2018
f0f2079
Add chart bundle
snuggs Feb 10, 2018
ec2f732
Add chart
snuggs Feb 10, 2018
c857ab6
Add chart
snuggs Feb 10, 2018
0ce309d
Add black class
snuggs Feb 10, 2018
b06a3f0
Convert to line
snuggs Feb 10, 2018
c9b3345
Add
snuggs Feb 10, 2018
066b39f
Convert height
snuggs Feb 10, 2018
d87ee94
convert canvas width and height
snuggs Feb 10, 2018
1635c3f
Fix graph
snuggs Feb 10, 2018
3c43a2b
fix formatting
snuggs Feb 10, 2018
5a26cce
Fix border width
snuggs Feb 10, 2018
7491091
Add BTC Bitcoin to the mix
snuggs Feb 10, 2018
faaae10
Convert labels to years
snuggs Feb 10, 2018
d7f23ae
Add background and border color
snuggs Feb 10, 2018
7c7fbaf
Update backgrounds
snuggs Feb 10, 2018
169313e
Add Historical pricing
snuggs Feb 10, 2018
8c3ae42
Add historical price
snuggs Feb 10, 2018
4387c56
Update data points
snuggs Feb 10, 2018
b42ebce
Fix whitespace
snuggs Feb 10, 2018
12871b6
Add bitcoin prices
snuggs Feb 10, 2018
c3a0e7e
Fix spacing
snuggs Feb 11, 2018
8cd1777
Add comments
snuggs Feb 11, 2018
a1ce305
Add red class
snuggs Feb 11, 2018
d26eb61
Add line-chart header css
snuggs Feb 11, 2018
d0876fb
Add canvas.red CSS
snuggs Feb 11, 2018
a5f6bf3
Add line-chart to mix
snuggs Feb 12, 2018
cf66c9a
Convert to black
snuggs Feb 12, 2018
0495179
Move public/chart to public line-chart
snuggs Feb 12, 2018
64a13e5
Change to line chart
snuggs Feb 12, 2018
80c395d
Change to context change
snuggs Feb 12, 2018
b461736
Add snuggsi
snuggs Feb 12, 2018
ba96ffa
Add element
snuggs Feb 12, 2018
97d8a27
Console log canvas
snuggs Feb 12, 2018
fe3d8b4
Add type and canvas
snuggs Feb 12, 2018
6526539
Add border size
snuggs Feb 12, 2018
c79b060
Remove console log
snuggs Feb 12, 2018
dbe73b8
Add options
snuggs Feb 12, 2018
b273bda
Add labels
snuggs Feb 12, 2018
42b9b22
format labels
snuggs Feb 12, 2018
83ea1c2
Return header
snuggs Feb 12, 2018
f03b152
Update sets on line-chart
snuggs Feb 12, 2018
0bab9c4
Update chart
snuggs Feb 12, 2018
f47c7a8
Remove old chart
snuggs Feb 12, 2018
10cc7b0
Remove serializing label
snuggs Feb 12, 2018
c3525b3
Format serialized line-chart
snuggs Feb 12, 2018
7b6ca32
Add header label
snuggs Feb 12, 2018
79d2e13
Change border size
snuggs Feb 12, 2018
0f88565
Reorder class attributes
snuggs Feb 12, 2018
ef993d5
Add context values
snuggs Feb 12, 2018
9ea7f01
Refactor to deconstruct labels
snuggs Feb 12, 2018
623039f
Deconstruct serialization
snuggs Feb 12, 2018
c18c2a2
Add onidle comment
snuggs Feb 12, 2018
2e7d6e7
Migrate labels
snuggs Feb 12, 2018
98ba614
Migrate labels
snuggs Feb 12, 2018
83731d1
Reformat white spacing
snuggs Feb 12, 2018
c67d674
Add hydrate functionality
snuggs Feb 12, 2018
30e2344
Format data
snuggs Feb 12, 2018
a20be4e
Change name to datasets
snuggs Feb 12, 2018
e51f7c4
Add whitespace for line-chart
snuggs Feb 12, 2018
72e6e1f
Add historical.es javascript
snuggs Feb 12, 2018
3353c68
Add hydration routine
snuggs Feb 12, 2018
632013d
Add formatting
snuggs Feb 12, 2018
cf5e241
Migrate Historical.since
snuggs Feb 12, 2018
34019be
Remove hydrate function
snuggs Feb 12, 2018
850002f
Format options
snuggs Feb 12, 2018
2309c93
Convert to use new Historical
snuggs Feb 12, 2018
2165c68
Formatting
snuggs Feb 12, 2018
f7d32e5
Convert to historical data
snuggs Feb 12, 2018
17d1d14
Add whitespace clearance
snuggs Feb 12, 2018
51b9e92
Add data variable
snuggs Feb 12, 2018
7a3dea8
Add formatting
snuggs Feb 12, 2018
8273c74
Add Historic data
snuggs Feb 12, 2018
91b177d
Update to fix
snuggs Feb 12, 2018
204160d
Migrate to onconnect
snuggs Feb 12, 2018
588ccbd
Migrate to onconnect
snuggs Feb 12, 2018
731c5ec
Migrate to onconnect
snuggs Feb 12, 2018
1088ec5
Remove idle
snuggs Feb 12, 2018
6936ee0
Refactor chart
snuggs Feb 12, 2018
9b0bc5b
Format month labels
snuggs Feb 12, 2018
8e9ada0
Change to Historic Price
snuggs Feb 12, 2018
d25e20a
Aggregate for daily
snuggs Feb 12, 2018
a6f4b07
Add header
snuggs Feb 12, 2018
592856d
Change to symbol attribute
snuggs Feb 12, 2018
2291d47
Update chart to use BTC and since and border attribute
snuggs Feb 12, 2018
2b7ff21
Update background
snuggs Feb 14, 2018
99d7810
Update comments
snuggs Feb 15, 2018
78868c0
change console log
snuggs Feb 15, 2018
71e8164
Add whatever response
snuggs Feb 15, 2018
e5ade6a
Add https
snuggs Feb 15, 2018
5936970
Migrate seconds
snuggs Feb 15, 2018
18006ae
Migrate fetch
snuggs Feb 15, 2018
af442d1
Add endpoint
snuggs Feb 15, 2018
325a086
Add querystring parameter
snuggs Feb 15, 2018
26ef4b6
rename variable to query
snuggs Feb 15, 2018
dbb77a4
rename variable to query
snuggs Feb 15, 2018
dcfac87
Add aggregate limit and endpoint
snuggs Feb 15, 2018
bd9556f
Change data
snuggs Feb 15, 2018
bfa7494
Change fetch to url
snuggs Feb 15, 2018
d8965da
change to use this.collect
snuggs Feb 15, 2018
f25be04
Add collect
snuggs Feb 15, 2018
b1f8038
return data
snuggs Feb 15, 2018
22e9138
Chnage to remove data
snuggs Feb 15, 2018
2761a4b
Remove json promise
snuggs Feb 15, 2018
0e71096
Add async collect
snuggs Feb 15, 2018
a4e2979
Return json data
snuggs Feb 15, 2018
cd6cfce
Convert endpoint
snuggs Feb 15, 2018
8780a91
Update collect method signature to async
snuggs Feb 15, 2018
5cefc0a
Update to use timestamp callback in map procedure
snuggs Feb 15, 2018
197370c
Update to use timestamp callback in map procedure
snuggs Feb 15, 2018
354c1ae
Remove comments from Historical class
snuggs Feb 15, 2018
5cb8e78
Remove console.log
snuggs Feb 15, 2018
94f4327
Bind date to collect
snuggs Feb 15, 2018
99447b3
Remove white spacing
snuggs Feb 15, 2018
d7c2106
Add filter for collection set
snuggs Feb 15, 2018
1325944
Remove white spacing
snuggs Feb 15, 2018
7c803e9
Add console logging
snuggs Feb 15, 2018
b455701
Fix method signature for collect
snuggs Feb 16, 2018
66dd463
Add aggregate symbol
snuggs Feb 16, 2018
6975f31
Refactor return statement
snuggs Feb 16, 2018
2d82db2
Update to use exchange
snuggs Feb 16, 2018
acc81a8
Update to use exchange
snuggs Feb 16, 2018
2f09285
Add link to Historic Pricing on Investopedia.com
snuggs Feb 16, 2018
22f8759
Remove semicolons
snuggs Feb 16, 2018
45d1ee6
Remove semicolons
snuggs Feb 16, 2018
2ba0681
Remove semicolons
snuggs Feb 16, 2018
a0f8442
Remove semicolons
snuggs Feb 16, 2018
a83951f
Remove semicolons
snuggs Feb 16, 2018
cf8fe90
Migrate historical
snuggs Feb 16, 2018
7a73a38
Migrate historical
snuggs Feb 16, 2018
85fe84b
Format onconnect routine
snuggs Feb 16, 2018
0a606d3
Remove www
snuggs Feb 16, 2018
b69c9da
Add rel help
snuggs Feb 16, 2018
4b3301d
Add rel help
snuggs Feb 16, 2018
3974928
Add proper title for Black investopedia.com reference
snuggs Feb 16, 2018
4dd2c35
Add formatting for a link
snuggs Feb 16, 2018
6d8085d
Update formatting
snuggs Feb 16, 2018
3cfb462
Update formatting
snuggs Feb 16, 2018
f0c6885
Add meta tag for charset
snuggs Feb 16, 2018
054bb80
add meta viewport
snuggs Feb 16, 2018
fef2a05
Add leading zero to month attribute
snuggs Feb 16, 2018
eabcee6
Add leading zero to day attribute
snuggs Feb 16, 2018
d67669c
Reorder object attributes
snuggs Feb 16, 2018
36e6eb8
Aggregate by the day
snuggs Feb 16, 2018
b8def64
Add hover mode
snuggs Feb 16, 2018
04c5d32
Add configurations settings for chart
snuggs Feb 16, 2018
ebb6abe
Add configuration settings for chart
snuggs Feb 16, 2018
6669bef
Reorder configuration settings for chart
snuggs Feb 16, 2018
49be3fe
Add tooltips section for chart options
snuggs Feb 16, 2018
86ecfec
Change aggregate
snuggs Feb 17, 2018
58ac11c
Update copy footer
snuggs Feb 17, 2018
24d10d4
Update intersect for tooltips
snuggs Feb 17, 2018
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
49 changes: 49 additions & 0 deletions public/historical.es
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
class Historical {

constructor (symbols)
{ this.symbols = symbols }

convert (to) {
this.to = to
return this
}

async since ( date, seconds = (date.getTime () / 1000) ) {
const
url = `${this.endpoint}` //&toTs=${seconds}`

return await
fetch (url)
.then (this.collect.bind (date))
}

async collect (response) {
const
timestamp = record =>
(record.time = new Date (record.time * 1000))
&& record

return (await response.json ())
.Data
.filter (record => (record.time * 1000) >= +this)
.map (timestamp)
}

get endpoint () {
const
aggregate = 1 // 30 = month
, limit = 2000
, exchanges = 'CCCAGG'
, endpoint = 'https://min-api.cryptocompare.com/data/histoday'

, query = [
`e=${exchanges}`
, `limit=${limit}`
, `tsym=${this.to}`
, `fsym=${this.symbols}`
, `aggregate=${aggregate}`
].join `&`

return [endpoint,query].join `?`
}
}
4 changes: 2 additions & 2 deletions public/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ html {
}

html * {
margin:0;
margin: 0;
padding: 0.02px 0
}

body { padding: 1.612em 0 }

body > *, body > header > p {
margin: var(--margin);
margin: 0;
margin-bottom: 1.612em
}

Expand Down
78 changes: 75 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,33 @@

<title>BlackHistory.io</title>

<meta charset=utf-8>

<meta
name=viewport
content=
'initial-scale=1,
minimum-scale=1,
maximum-scale=1,
user-scalable=yes,
width=device-width,
height=device-height'
>
<link
as=style
href=index.css
rel='preload stylesheet'
>

<script src=./historical.es></script>
<script src=//unpkg.com/snuggsi></script>


<header>
<a
rel=help
target=investopedia
title='What does the term Black mean?'
title='View Black on Investopedia.com'
href=//investopedia.com/terms/b/black.asp>
Black
</a>
Expand All @@ -21,12 +37,67 @@

<em>
Pull yourself out of the
<a target=investopedia title='What does the term Red mean?' href=https://www.investopedia.com/terms/r/red.asp>Red</a>
<a
rel=help
target=investopedia
title='View Red on Investopedia.com'
href=https://investopedia.com/terms/r/red.asp>Red</a>
</em>
</header>


<main>

<line-chart symbol=BTC since=2015-07-01 border=3>
<!-- https://investopedia.com/terms/h/historical-cost.asp -->
<!-- https://investopedia.com/terms/h/historic-pricing.asp -->
<header>{symbol}
<a
rel=help
target=investopedia
title='View Historic Pricing on Investopedia.com'
href=https://www.investopedia.com/terms/h/historic-pricing.asp>
Historic Price
</a>
</header>

<canvas class=black></canvas>

<style>
line-chart {
width: 100vw;
height: 40vh;
margin: 1em 0;
display: block;
background: red;
text-align: center;
outline: 5px dashed #aaa
}

line-chart header {
font-size: 1.5em;
line-height: 1.6em
}

canvas {
width: 100vw;
height: 70vh;
background: green
}

canvas.black
{ background: black }

canvas.red
{ background: rgba(150,10,10,0.9) }

</style>

<script src=https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.bundle.min.js></script>
<script src=./line-chart.es></script>
</line-chart>


<figure class=frame>
<iframe src=https://www.youtube.com/embed/oxMc9uZ28g0 frameborder=0 allowfullscreen></iframe>
</figure>
Expand All @@ -35,7 +106,8 @@


<footer>
Made with ❤️ by th OSS blockchain communiy
Made with❤️ by the
<abbr title='Open Source Software'>OSS</abbr> blockchain community
<a target=github href=//github.com/devpunks/blackhistory.io>View Source Code on Github</a>

<em>&copy; Copyright 2018</em>
Expand Down
102 changes: 102 additions & 0 deletions public/line-chart.es
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
Element `line-chart`

(class extends HTMLElement {

async onconnect (data, to = 'USD') {

data = await
(new Historical (this.symbol))
.convert (to)
.since (this.since)

this.context.labels
= data.map (record => this.label (record.time))

this.context.values
= data.map (record => record.close)

new Chart
( this.canvas, this.serialize () )
}

label (date, MONTHS) {
MONTHS = [
'January', 'February', 'March', 'April',
'May', 'June', 'July', 'August', 'September',
'October', 'November', 'December'
]

return `${MONTHS [date.getMonth ()]} ${date.getFullYear ()}`
}

serialize () {
const
{ type, options, labels, datasets }
= this

, data
= { labels, datasets }

return { type, data, options }
}

get options () {
return {
hover:
{ mode: 'x' }
, tooltips: {
mode: 'x'
, intersect: false
}
, scales:
{ yAxes:
[ { ticks:
{ beginAtZero: true } } ] }
}
}

get type ()
{ return 'line' }

get symbol ()
{ return this.getAttribute `symbol` || 'BTC' }

get since ()
{ return new Date (this.getAttribute `since`) }

get canvas ()
{ return this.select `canvas` }

get labels ()
{ return this.context.labels }

get values ()
{ return this.context.values }

get datasets () {
return [ {
label: this.symbol

, data: this.values

// http://www.chartjs.org/docs/latest/charts/line.html

, lineTension: 0

, pointRadius: 1

, pointHoverRadius: 20

, borderJoinStyle: 'miter'

, borderWidth:
this.getAttribute `border`

, borderColor:
[ 'rgba(250,250,250, 0.7)' ]

, backgroundColor:
[ 'rgba(255, 255, 255, 0.1)' ]
} ]
}
})