Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
timebars
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nesstar
timebars
Commits
5c362e1e
Commit
5c362e1e
authored
Feb 12, 2014
by
Kjetil Thuen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added play/pause button
parent
fc7d1f62
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
12 deletions
+26
-12
src/app/timebars.coffee
src/app/timebars.coffee
+21
-10
www/index.html
www/index.html
+5
-2
No files found.
src/app/timebars.coffee
View file @
5c362e1e
...
...
@@ -5,6 +5,7 @@ chartWidth = -> 900
chartHeight
=
->
500
numBars
=
->
100
speed
=
->
100
margin
=
->
10
next
=
(
prev
)
->
prv
=
(
if
prev
?
rvalue
then
prev
.
rvalue
else
25
)
...
...
@@ -26,7 +27,6 @@ y = d3.scale.linear()
.
rangeRound
[
0
,
chartHeight
()
]
addBar
=
(
newBar
)
->
console
.
log
"Adding a bar"
barGroup
=
newBar
.
append
"g"
.
attr
"class"
,
"valuepoint"
.
attr
"transform"
,
(
d
,
i
)
->
...
...
@@ -34,13 +34,13 @@ addBar = (newBar) ->
barGroup
.
append
"rect"
.
attr
"class"
,
"right"
.
attr
"x"
,
chartWidth
()
/
2
.
attr
"x"
,
chartWidth
()
/
2
-
margin
()
.
attr
"width"
,
(
d
)
->
x
d
.
rvalue
.
attr
"height"
,
barThickness
()
barGroup
.
append
"rect"
.
attr
"class"
,
"left"
.
attr
"x"
,
(
d
)
->
(
chartWidth
()
/
2
)
-
x
d
.
lvalue
.
attr
"x"
,
(
d
)
->
(
chartWidth
()
/
2
)
-
x
d
.
lvalue
+
margin
()
.
attr
"width"
,
(
d
)
->
x
d
.
lvalue
.
attr
"height"
,
barThickness
()
...
...
@@ -74,16 +74,27 @@ setupChart = (containerId, data) ->
updateData
=
(
data
)
->
lodash
.
rest
(
lodash
.
clone
(
data
).
concat
(
next
(
lodash
.
last
(
data
))))
# State (data and intervals) stored in the window object
window
.
initTimeBars
=
(
containerId
)
->
window
.
_
=
lodash
window
.
data
=
d3
.
range
numBars
()
.
map
->
next
lodash
.
last
(
window
.
data
)
setupChart
(
containerId
,
window
.
data
)
setInterval
->
data
=
updateData
window
.
data
updateChart
(
containerId
,
data
)
window
.
data
=
data
,
speed
()
updateChart
(
containerId
,
data
)
window
.
animateBarChart
=
(
containerId
)
->
if
window
.
timeBarAnim
?
console
.
log
(
"stopp"
)
clearInterval
(
window
.
timeBarAnim
)
window
.
timeBarAnim
=
undefined
document
.
getElementById
(
"playBtn"
).
innerHTML
=
"<i class='fa fa-play'></i>"
else
console
.
log
(
"start"
)
window
.
timeBarAnim
=
setInterval
->
data
=
updateData
window
.
data
updateChart
(
containerId
,
data
)
window
.
data
=
data
,
speed
()
document
.
getElementById
(
"playBtn"
).
innerHTML
=
"<i class='fa fa-pause'></i>"
undefined
www/index.html
View file @
5c362e1e
...
...
@@ -3,8 +3,8 @@
<head>
<title>
Nesstar backed animated barcharts
</title>
<meta
name=
"viewport"
content=
"initial-scale=1,maximum-scale=1,minimum-scale=1,user-scalable=no"
>
<link
href=
"//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css"
rel=
"stylesheet
"
>
<link
href=
"//netdna.bootstrapcdn.com/font-awesome/3.2.0/css/font-awesome.min.css"
rel=
"stylesheet
"
>
<link
rel=
"stylesheet"
href=
"//netdna.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css
"
>
<link
rel=
"stylesheet"
href=
"//netdna.bootstrapcdn.com/font-awesome/4.0.3/css/font-awesome.css
"
>
<link
href=
"css/timebars.css"
rel=
"stylesheet"
>
<script
src=
"js/timebars.js"
></script>
</head>
...
...
@@ -17,6 +17,9 @@
<div>
</div>
<div>
</div>
<section
id=
"content"
>
</section>
<button
id=
"playBtn"
class=
"btn btn-primary"
onclick=
"window.animateBarChart('#content')"
>
<i
class=
"fa fa-play"
></i>
</button>
<script>
window
.
initTimeBars
(
"
#content
"
);
</script>
...
...
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