Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
I
interface
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
LuckySwap
interface
Commits
b791e2aa
Commit
b791e2aa
authored
Apr 03, 2018
by
Uciel Vilchis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
polish line graph
parent
955d5bab
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
17 deletions
+29
-17
Visualization.js
src/components/Visualization.js
+29
-17
No files found.
src/components/Visualization.js
View file @
b791e2aa
...
@@ -61,25 +61,27 @@ class Visualization extends Component {
...
@@ -61,25 +61,27 @@ class Visualization extends Component {
createLineGraph
()
{
createLineGraph
()
{
// TODO: as you change whether you want to see days or years, change the extent
// TODO: as you change whether you want to see days or years, change the extent
// scales are wicked important
// scales are wicked important
let
width
=
1039
;
let
height
=
200
;
let
margin
=
{
top
:
20
,
bottom
:
20
,
left
:
20
,
right
:
20
}
let
margin
=
{
top
:
20
,
bottom
:
20
,
left
:
20
,
right
:
20
}
let
width
=
1039
-
margin
.
left
-
margin
.
right
;
let
height
=
325
-
margin
.
top
-
margin
.
bottom
;
let
svg
=
this
.
d3Graph
let
svg
=
this
.
d3Graph
// first we want to see the min and max of our token prices
// first we want to see the min and max of our token prices
let
ethValueOfTokenExtent
=
d3
.
extent
(
this
.
state
.
data
,
element
=>
element
.
ethValueOfToken
);
let
ethValueOfTokenExtent
=
d3
.
extent
(
this
.
state
.
data
,
element
=>
element
.
ethValueOfToken
);
console
.
log
(
'
initial data visualized
'
,
this
.
state
.
data
)
console
.
log
(
'
initial data visualized
'
,
this
.
state
.
data
,
'
extent of data
'
,
ethValueOfTokenExtent
)
// create a y scale, for the eth value of the token
// create a y scale, for the eth value of the token
let
yScale
=
d3
.
scaleLinear
()
let
yScale
=
d3
.
scaleLinear
()
.
domain
(
ethValueOfTokenExtent
)
.
domain
(
[
ethValueOfTokenExtent
[
1
],
ethValueOfTokenExtent
[
0
]]
)
.
range
([
margin
.
bottom
,
height
-
margin
.
top
]);
.
range
([
margin
.
bottom
,
height
-
margin
.
top
]);
// now that we have the scale, we create the actual axis
// now that we have the scale, we create the actual axis
let
yAxis
=
d3
.
axisLeft
()
let
yAxis
=
d3
.
axisLeft
()
.
scale
(
yScale
);
.
scale
(
yScale
)
.
ticks
(
8
)
// time to put this y axis on the page
// time to put this y axis on the page
svg
.
append
(
'
g
'
)
svg
.
append
(
'
g
'
)
.
attr
(
'
class
'
,
'
y axis
'
)
.
attr
(
'
class
'
,
'
y axis
'
)
.
attr
(
'
transform
'
,
'
translate(
5
0)
'
)
.
attr
(
'
transform
'
,
'
translate(
10
0)
'
)
.
call
(
yAxis
);
.
call
(
yAxis
);
// sanitize the data for the x-axis
// sanitize the data for the x-axis
...
@@ -99,9 +101,18 @@ class Visualization extends Component {
...
@@ -99,9 +101,18 @@ class Visualization extends Component {
// append the axis to the DOM, make sure it's positioned correctly
// append the axis to the DOM, make sure it's positioned correctly
svg
.
append
(
'
g
'
)
svg
.
append
(
'
g
'
)
.
attr
(
'
class
'
,
'
x axis
'
)
.
attr
(
'
class
'
,
'
x axis
'
)
.
attr
(
'
transform
'
,
'
translate(
30, 180
)
'
)
.
attr
(
'
transform
'
,
'
translate(
80, 265
)
'
)
.
call
(
xAxis
);
.
call
(
xAxis
);
// this right here is the x-axis label
svg
.
append
(
"
text
"
)
.
attr
(
"
transform
"
,
"
rotate(-90)
"
)
.
attr
(
"
y
"
,
20
)
.
attr
(
"
x
"
,
0
-
(
height
/
2
))
.
attr
(
"
dy
"
,
"
1em
"
)
.
attr
(
'
font-size
'
,
'
15px
'
)
.
style
(
"
text-anchor
"
,
"
middle
"
)
.
text
(
"
Price (ETH)
"
);
let
line
=
d3
.
line
()
let
line
=
d3
.
line
()
.
x
(
element
=>
xScale
(
element
.
createdAt
))
.
x
(
element
=>
xScale
(
element
.
createdAt
))
.
y
(
element
=>
yScale
(
element
.
ethValueOfToken
))
.
y
(
element
=>
yScale
(
element
.
ethValueOfToken
))
...
@@ -114,14 +125,14 @@ class Visualization extends Component {
...
@@ -114,14 +125,14 @@ class Visualization extends Component {
.
attr
(
"
stroke
"
,
"
steelblue
"
)
.
attr
(
"
stroke
"
,
"
steelblue
"
)
.
attr
(
"
stroke-linejoin
"
,
"
round
"
)
.
attr
(
"
stroke-linejoin
"
,
"
round
"
)
.
attr
(
"
stroke-linecap
"
,
"
round
"
)
.
attr
(
"
stroke-linecap
"
,
"
round
"
)
.
attr
(
"
stroke-width
"
,
1
.5
)
.
attr
(
"
stroke-width
"
,
2
.5
)
.
attr
(
'
transform
'
,
'
translate(
3
0)
'
)
.
attr
(
'
transform
'
,
'
translate(
8
0)
'
)
}
}
createNewLineGraph
(){
createNewLineGraph
()
{
let
width
=
1039
;
let
height
=
200
;
let
margin
=
{
top
:
20
,
bottom
:
20
,
left
:
20
,
right
:
20
}
let
margin
=
{
top
:
20
,
bottom
:
20
,
left
:
20
,
right
:
20
}
let
width
=
1039
-
margin
.
left
-
margin
.
right
;
let
height
=
325
-
margin
.
top
-
margin
.
bottom
;
this
.
state
.
data
.
map
(
e
=>
e
.
createdAt
=
new
Date
(
e
.
createdAt
));
this
.
state
.
data
.
map
(
e
=>
e
.
createdAt
=
new
Date
(
e
.
createdAt
));
console
.
log
(
'
data is being set correctly
'
,
this
.
state
.
data
)
console
.
log
(
'
data is being set correctly
'
,
this
.
state
.
data
)
// we set the range of the data again
// we set the range of the data again
...
@@ -131,7 +142,7 @@ class Visualization extends Component {
...
@@ -131,7 +142,7 @@ class Visualization extends Component {
console
.
log
(
'
new xExtent
'
,
xExtent
)
console
.
log
(
'
new xExtent
'
,
xExtent
)
// we also redefine the scales for the new data
// we also redefine the scales for the new data
let
yScale
=
d3
.
scaleLinear
()
let
yScale
=
d3
.
scaleLinear
()
.
domain
(
yExtent
)
.
domain
(
[
yExtent
[
1
],
yExtent
[
0
]]
)
.
range
([
margin
.
bottom
,
height
-
margin
.
top
]);
.
range
([
margin
.
bottom
,
height
-
margin
.
top
]);
let
xScale
=
d3
.
scaleTime
()
let
xScale
=
d3
.
scaleTime
()
.
domain
(
xExtent
)
.
domain
(
xExtent
)
...
@@ -141,6 +152,7 @@ class Visualization extends Component {
...
@@ -141,6 +152,7 @@ class Visualization extends Component {
.
scale
(
xScale
)
.
scale
(
xScale
)
let
yAxis
=
d3
.
axisLeft
()
let
yAxis
=
d3
.
axisLeft
()
.
scale
(
yScale
)
.
scale
(
yScale
)
.
ticks
(
8
)
let
svg
=
this
.
d3Graph
.
transition
()
let
svg
=
this
.
d3Graph
.
transition
()
let
line
=
d3
.
line
()
let
line
=
d3
.
line
()
...
@@ -159,10 +171,10 @@ class Visualization extends Component {
...
@@ -159,10 +171,10 @@ class Visualization extends Component {
}
}
render
()
{
render
()
{
const
width
=
10
00
;
const
width
=
10
39
;
const
height
=
200
;
const
height
=
375
;
return
(
return
(
<
div
className
=
"
visualization
"
align
=
"
center
"
>
<
div
align
=
"
center
"
>
<
svg
width
=
{
width
}
height
=
{
height
}
>
<
svg
width
=
{
width
}
height
=
{
height
}
>
<
g
ref
=
"
graph
"
/>
<
g
ref
=
"
graph
"
/>
<
/svg
>
<
/svg
>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment