Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
visualizer-embed
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Owen Graham
visualizer-embed
Commits
142d4bc2
Verified
Commit
142d4bc2
authored
3 years ago
by
Owen Graham
Browse files
Options
Downloads
Patches
Plain Diff
Simplify search parameters JavaScript
parent
e072cb39
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
visualizer/static/script.js
+18
-35
18 additions, 35 deletions
visualizer/static/script.js
with
18 additions
and
35 deletions
visualizer/static/script.js
+
18
−
35
View file @
142d4bc2
...
...
@@ -51,48 +51,33 @@ function appendYears(years, n) {
}
function
indexVisualize
()
{
const
params
=
{
station
:
selectVal
(
'
station
'
),
year
:
selectVal
(
'
year
'
),
measurement
:
selectVal
(
'
measurement
'
),
};
setSources
(
sourceLink
(
params
.
station
,
params
.
year
));
visualize
(
`
${
SCRIPT_ROOT
}
/plot`
,
params
);
const
params
=
getControlsParams
();
setSources
(
sourceLink
(
params
.
get
(
'
station
'
),
params
.
get
(
'
year
'
)));
visualize
(
`
${
SCRIPT_ROOT
}
/plot?
${
params
}
`
);
}
function
overlayVisualize
()
{
const
params
=
{
station1
:
selectVal
(
'
station-1
'
),
year1
:
selectVal
(
'
year-1
'
),
station2
:
selectVal
(
'
station-2
'
),
year2
:
selectVal
(
'
year-2
'
),
measurement
:
selectVal
(
'
measurement
'
),
};
setSources
(
sourceLink
(
params
.
station1
,
params
.
year1
,
1
),
sourceLink
(
params
.
station2
,
params
.
year2
,
2
));
visualize
(
`
${
SCRIPT_ROOT
}
/plot/overlay`
,
params
);
const
params
=
getControlsParams
();
setSources
(
sourceLink
(
params
.
get
(
'
station1
'
),
params
.
get
(
'
year1
'
),
1
),
sourceLink
(
params
.
get
(
'
station2
'
),
params
.
get
(
'
year2
'
),
2
));
visualize
(
`
${
SCRIPT_ROOT
}
/plot/overlay?
${
params
}
`
);
}
function
boxplotVisualize
()
{
const
params
=
{
station
:
selectVal
(
'
station
'
),
year1
:
selectVal
(
'
year-1
'
),
year2
:
selectVal
(
'
year-2
'
),
measurement
:
selectVal
(
'
measurement
'
),
};
setSources
(
sourceLink
(
params
.
station
,
params
.
year1
));
const
params
=
getControlsParams
();
setSources
(
sourceLink
(
params
.
get
(
'
station
'
),
params
.
get
(
'
year1
'
)));
// XXX No year 2?
visualize
(
`
${
SCRIPT_ROOT
}
/plot/boxplot
`
,
params
);
visualize
(
`
${
SCRIPT_ROOT
}
/plot/boxplot
?
${
params
}
`
);
}
/**
* Fetch the given plot and show it.
*/
function
visualize
(
path
,
params
)
{
function
visualize
(
imgSrc
)
{
const
plotDiv
=
document
.
getElementById
(
'
plot
'
);
const
visualization
=
document
.
getElementById
(
'
visualization
'
);
const
img
=
document
.
createElement
(
'
img
'
);
img
.
src
=
path
+
paramString
(
params
)
;
img
.
src
=
imgSrc
;
plotDiv
.
replaceChildren
(
img
);
visualization
.
hidden
=
false
;
}
...
...
@@ -109,7 +94,8 @@ function sourceLink(station, year, n) {
a
.
target
=
'
_blank
'
;
}
div
.
appendChild
(
a
);
fetch
(
`
${
SCRIPT_ROOT
}
/record/link
${
paramString
({
station
,
year
})}
`
)
const
params
=
new
URLSearchParams
({
station
,
year
});
fetch
(
`
${
SCRIPT_ROOT
}
/record/link?
${
params
}
`
)
.
then
(
response
=>
response
.
json
())
.
then
(
response
=>
{
a
.
href
=
response
;
...
...
@@ -126,14 +112,11 @@ function setSources(...sources) {
}
/**
* Ge
nerate a query string from parameter
s.
* Ge
t the search parameters from the "controls" form's input
s.
*/
function
paramString
(
params
)
{
const
strings
=
[];
for
(
const
key
in
params
)
{
strings
.
push
(
`
${
key
}
=
${
params
[
key
]}
`
);
}
return
`?
${
strings
.
join
(
'
&
'
)}
`
;
function
getControlsParams
()
{
const
controls
=
document
.
getElementById
(
'
controls
'
);
return
new
URLSearchParams
(
new
FormData
(
controls
));
}
/**
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment