FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
matplotlib.github.com/3.11.2/_static/sg-tags.js at main · matplotlib/matplotlib.github.com · GitHub
matplotlib
/
matplotlib.github.com
Public
Notifications
You must be signed in to change notification settings
Fork
62
Star
29
Code
Issues
1
Pull requests
2
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
matplotlib.github.com
/
3.11.2
/
_static
/
sg-tags.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
148 lines (130 loc) · 4.57 KB
Breadcrumbs
matplotlib.github.com
/
3.11.2
/
_static
/
sg-tags.js
Copy path
File metadata and controls
148 lines (130 loc) · 4.57 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
// Author: Stuart Mumford
// License: 3-clause BSD
// This code is used on gallery index pages to extract and display a
// list of tags for all examples on that page, and allow the user to
// filter by one or more tags.
// Create a subclass of Set where modifications trigger updates to the page.
class
TagSet
extends
Set
{
// Update the URL to include currently selected tags
updateURLTags
(
)
{
const
searchParams
=
new
URLSearchParams
(
window
.
location
.
search
)
;
if
(
this
.
size
>
0
)
{
const
tagStr
=
Array
.
from
(
this
)
.
join
(
","
)
searchParams
.
set
(
"sg-tags"
,
tagStr
)
;
}
else
{
searchParams
.
delete
(
"sg-tags"
)
;
}
// Update the URL
const
newUrl
=
`
${
window
.
location
.
pathname
}
?
${
searchParams
.
toString
(
)
}
`
;
window
.
history
.
replaceState
(
{
}
,
""
,
newUrl
)
;
}
// Set all the elements of the list of tags to reflect the currently active tags
updateTagButtons
(
)
{
const
tags
=
document
.
querySelectorAll
(
'.sphx-glr-tag'
)
;
tags
.
forEach
(
tagElement
=>
{
tagElement
.
classList
.
toggle
(
'active'
,
this
.
has
(
tagElement
.
textContent
)
)
;
}
)
;
}
// Set state of clear button
updateClearButton
(
)
{
const
clearElement
=
document
.
getElementById
(
'sphx-glr-tag-clear'
)
if
(
this
.
size
>
0
)
{
clearElement
.
style
.
display
=
'block'
;
}
else
{
clearElement
.
style
.
display
=
'none'
;
}
}
// Filter grid items based on selected tags
filterGrid
(
)
{
const
gridItems
=
document
.
querySelectorAll
(
'.sphx-glr-thumbcontainer'
)
;
gridItems
.
forEach
(
item
=>
{
let
itemTags
=
new
Set
(
)
;
if
(
item
.
dataset
.
sgtags
)
{
itemTags
=
new
Set
(
JSON
.
parse
(
item
.
dataset
.
sgtags
)
)
;
}
const
matchesAllSelected
=
[
...
this
]
.
every
(
tag
=>
itemTags
.
has
(
tag
)
)
;
item
.
style
.
display
=
matchesAllSelected
||
this
.
size
===
0
?
'block'
:
'none'
;
}
)
;
}
updateUI
(
)
{
// Update UI and filter grid
this
.
updateTagButtons
(
)
;
this
.
updateClearButton
(
)
this
.
updateURLTags
(
)
;
this
.
filterGrid
(
)
;
}
add
(
value
)
{
const
result
=
super
.
add
(
value
)
;
this
.
updateUI
(
)
;
return
result
;
}
delete
(
value
)
{
const
result
=
super
.
delete
(
value
)
;
this
.
updateUI
(
)
;
return
result
;
}
clear
(
)
{
const
result
=
super
.
clear
(
)
;
this
.
updateUI
(
)
;
return
result
;
}
}
// Track currently selected tags
let
selectedTags
=
new
TagSet
(
)
;
// Extract all unique tags and populate the tag list
function
extractTags
(
)
{
const
gridItems
=
document
.
querySelectorAll
(
'[data-sgtags]'
)
;
const
allTags
=
new
Set
(
)
;
gridItems
.
forEach
(
item
=>
{
if
(
item
.
dataset
.
sgtags
)
{
const
tags
=
JSON
.
parse
(
item
.
dataset
.
sgtags
)
;
tags
.
forEach
(
tag
=>
allTags
.
add
(
tag
)
)
;
}
}
)
;
const
tagList
=
document
.
getElementById
(
'sg-tag-list'
)
;
allTags
.
forEach
(
tag
=>
{
const
tagElement
=
document
.
createElement
(
'div'
)
;
tagElement
.
className
=
'sphx-glr-tag'
;
tagElement
.
textContent
=
tag
;
tagElement
.
addEventListener
(
'click'
,
(
)
=>
toggleTag
(
tag
)
)
;
tagList
.
appendChild
(
tagElement
)
;
}
)
;
if
(
allTags
.
size
>
0
)
{
nameElement
=
document
.
createElement
(
'div'
)
;
nameElement
.
className
=
'sphx-glr-tag-label'
;
nameElement
.
textContent
=
"🏷 Tags:"
;
tagList
.
prepend
(
nameElement
)
;
let
clearElement
=
document
.
createElement
(
'div'
)
;
clearElement
.
id
=
'sphx-glr-tag-clear'
;
clearElement
.
className
=
'sphx-glr-tag-label'
;
clearElement
.
textContent
=
"Clear"
;
clearElement
.
style
.
display
=
'none'
;
// Hide the element until there is a selected tag
clearElement
.
addEventListener
(
'click'
,
(
)
=>
selectedTags
.
clear
(
)
)
;
tagList
.
appendChild
(
clearElement
)
;
}
// Load any tags from the URL
const
searchParams
=
new
URLSearchParams
(
window
.
location
.
search
)
;
sgTagsParam
=
searchParams
.
get
(
"sg-tags"
)
;
if
(
sgTagsParam
!==
null
&&
sgTagsParam
!==
""
)
{
const
urlTags
=
searchParams
.
get
(
"sg-tags"
)
.
split
(
","
)
;
console
.
log
(
urlTags
)
;
urlTags
.
forEach
(
tag
=>
{
toggleTag
(
tag
)
;
}
)
;
}
}
// Toggle a tag's selected state and update the grid
function
toggleTag
(
tag
)
{
if
(
selectedTags
.
has
(
tag
)
)
{
selectedTags
.
delete
(
tag
)
;
}
else
{
selectedTags
.
add
(
tag
)
;
}
}
// Initialize
document
.
addEventListener
(
'DOMContentLoaded'
,
(
)
=>
{
extractTags
(
)
;
}
)
;
Back
|
FazBrowse Home
|
New Git URL