Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Michał Woźniak
covid
Commits
d40293ce
Commit
d40293ce
authored
Apr 20, 2020
by
Michał Woźniak
Browse files
working on sanely processing URL hashes
parent
5fcb6d96
Changes
1
Show whitespace changes
Inline
Side-by-side
covid.js
View file @
d40293ce
...
...
@@ -996,21 +996,6 @@ let calculateAverageRate = (data) => {
}
/*
* assemble and set the url hash
* without firing a hashchange event
*/
let
setUrlHash
=
()
=>
{
var
selected_sites
=
[]
for
(
let
sselect
of
sitesSelects
)
{
selected_sites
.
push
(
sselect
.
value
.
toLowerCase
().
replace
(
/
[^
a-z0-9
]
/g
,
'
-
'
))
}
// using History.pushState() because we don't want the onhashchange event to fire
history
.
pushState
({},
''
,
'
#
'
+
selected_sites
.
join
(
'
,
'
))
}
/*
* handling a .sites-select change
*/
...
...
@@ -1032,7 +1017,7 @@ let selectSite = (e) => {
var
site
=
theSelect
.
value
// set the URL hash without firing the hashchange event
set
UrlHash
()
update
UrlHash
()
// using a timeout to give the user a chance to change their mind
theSelect
.
selectTimeout
=
setTimeout
(
function
(){
...
...
@@ -1671,31 +1656,55 @@ let testAllSites = () => {
/*
* fun with data
* let's get the sites with negative new active cases
* helper: get all the chart settings as an object
*/
let
sitesWithNegativeNewActiveCases
=
()
=>
{
Object
.
keys
(
siteData
)
.
forEach
((
site
)
=>
{
var
active
=
0
var
new_active
=
0
try
{
if
(
"
active
"
in
siteData
[
site
].
data
[
1
])
{
active
=
siteData
[
site
].
data
.
slice
(
-
1
)[
0
].
active
new_active
=
siteData
[
site
].
data
.
slice
(
-
1
)[
0
].
new_active
}
else
{
sd
=
siteData
[
site
].
data
.
slice
(
-
2
)
active
=
sd
[
1
].
confirmed
-
sd
[
1
].
recovered
-
sd
[
1
].
deaths
new_active
=
active
-
(
sd
[
0
].
confirmed
-
sd
[
0
].
recovered
-
sd
[
0
].
deaths
)
let
getChartSettings
=
()
=>
{
return
{
}
if
(
new_active
<
0
)
{
console
.
log
(
`
${
site
}
::
${
active
}
::
${
new_active
}
`
)
}
/*
* helper: set all the chart settings from an object
*/
let
setChartSettings
=
(
settingsObj
)
=>
{
}
/*
* get an array of sites from a string
* used mainly in context of the URL hash
*
* takes a comma-separated string of URL-normalized country names
* and returns the country names as used in siteData
*/
let
getSitesFromUrlString
=
(
sites_string
)
=>
{
// get the non-empty site names
hash_sites
=
sites_string
.
split
(
'
,
'
)
// split by ',' in case we have a number of sites to handle
// filter out empty strings
.
reduce
((
acc
,
el
)
=>
{
if
(
el
)
{
acc
.
push
(
el
);
}
}
catch
(
e
){
console
.
log
(
`
${
site
}
:: skipped, no data`
)
return
acc
;
},
[])
// find the sites that match those strings
return
Object
.
keys
(
siteData
)
.
filter
(
site
=>
hash_sites
.
includes
(
site
.
toLowerCase
().
replace
(
/
[^
a-z
]
/g
,
'
-
'
)))
}
/*
* assemble and set the url hash
* without firing a hashchange event
*/
let
updateUrlHash
=
()
=>
{
var
selected_sites
=
[]
for
(
let
sselect
of
sitesSelects
)
{
selected_sites
.
push
(
sselect
.
value
.
toLowerCase
().
replace
(
/
[^
a-z0-9
]
/g
,
'
-
'
))
}
})
// using History.pushState() because we don't want the onhashchange event to fire
history
.
pushState
({},
''
,
'
#
'
+
selected_sites
.
join
(
'
,
'
))
}
...
...
@@ -2018,7 +2027,7 @@ document.addEventListener('DOMContentLoaded', (e)=>{
sitesSelects
[
0
].
value
=
"
select one
"
}
// using History.pushState() because we don't want the onhashchange event to fire
set
UrlHash
()
update
UrlHash
()
// update the chart
updateChartSettings
()
...
...
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