Platform
Resources
Pricing
Sign in
Get started
Mark E. Haase
Workspace
Fork
Public
By
Mark E. Haase
Edited
Feb 2, 2023
Fork of
White House Twitter
1
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
barUpdate
=
{
const
barChart
=
BrushableBarChart
(
)
.
width
(
400
)
.
height
(
400
)
.
x
(
"count"
)
.
y
(
"day"
)
.
onBrush
(
(
_selected
)
=>
{
mutable
selected
=
_selected
;
}
)
;
d3
.
select
(
bar
)
.
datum
(
tweetsByDay
)
.
call
(
barChart
)
;
}
Insert cell
Insert cell
height
=
width
*
1.5
Insert cell
iwidth
=
width
-
margin
.
left
-
margin
.
right
Insert cell
iheight
=
height
-
margin
.
top
-
margin
.
bottom
Insert cell
x
=
d3
.
scaleBand
(
)
.
domain
(
d3
.
range
(
24
)
)
.
range
(
[
0
,
iwidth
]
)
Insert cell
y
=
d3
.
scaleBand
(
)
.
domain
(
d3
.
range
(
60
)
)
.
range
(
[
0
,
iheight
]
)
Insert cell
color
=
d3
.
scaleSequential
(
d3
.
interpolateReds
)
.
domain
(
[
0
,
6
]
)
Insert cell
Insert cell
data
=
FileAttachment
(
"WHtweets.csv"
)
.
csv
(
)
Insert cell
tweets
=
d3
.
map
(
data
,
(
d
)
=>
{
const
ts
=
new
Date
(
Date
.
parse
(
d
.
timestamp
.
replace
(
" +0000"
,
"Z"
)
)
)
;
return
{
id
:
d
.
tweet_id
,
timestamp
:
ts
}
;
}
)
Insert cell
daysOfWeek
=
[
"Sun"
,
"Mon"
,
"Tue"
,
"Wed"
,
"Thu"
,
"Fri"
,
"Sat"
]
Insert cell
tweetsByDay
=
{
const
r
=
d3
.
rollup
(
tweets
,
(
v
)
=>
v
.
length
,
(
d
)
=>
d
.
timestamp
.
getDay
(
)
)
;
const
d
=
Array
.
from
(
r
,
(
[
k
,
v
]
)
=>
(
{
dow
:
k
,
day
:
daysOfWeek
[
k
]
,
count
:
v
}
)
)
;
d
.
sort
(
(
a
,
b
)
=>
a
.
dow
-
b
.
dow
)
;
return
d
;
}
Insert cell
groupedTweets
=
d3
.
rollup
(
tweets
,
(
v
)
=>
v
.
length
,
(
d
)
=>
d
.
timestamp
.
getDay
(
)
,
(
d
)
=>
d
.
timestamp
.
getHours
(
)
,
(
d
)
=>
d
.
timestamp
.
getMinutes
(
)
)
Insert cell
mutable
selected
=
null
Insert cell
flatTweets
=
{
const
flat
=
new
Array
(
)
;
const
selectedDays
=
selected
===
null
?
d3
.
range
(
7
)
:
Array
.
from
(
selected
,
(
d
)
=>
d
.
dow
)
;
groupedTweets
.
forEach
(
(
innerGroup
,
day
)
=>
{
if
(
selectedDays
.
indexOf
(
day
)
===
-
1
)
{
return
;
}
innerGroup
.
forEach
(
(
innerGroup2
,
hour
)
=>
innerGroup2
.
forEach
(
(
count
,
minute
)
=>
flat
.
push
(
{
day
,
hour
,
minute
,
count
:
Math
.
log
(
count
)
}
)
)
)
;
}
)
;
return
flat
;
}
Insert cell
Insert cell
Insert cell
import
{
BrushableBarChart
}
from
"@john-guerra/d3-reusable-brushable-barchart-pattern"
Insert cell
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Compare fork
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
bar
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
barUpdate
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
margin
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
height
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
iwidth
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
iheight
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
x
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
y
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
color
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
data
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tweets
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
daysOfWeek
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
tweetsByDay
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
groupedTweets
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
selected
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
flatTweets
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
d3
Edit
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML