Skip to content

Commit 6be1576

Browse files
Create tabs on benchmakrs page with benchmakrs for each tab
1 parent 1c503a5 commit 6be1576

File tree

5 files changed

+141
-5
lines changed

5 files changed

+141
-5
lines changed

Diff for: _includes/head.html

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<!-- google fonts -->
88
<link defer async href="https://fonts.googleapis.com/css?family=Fira+Sans|Sen:800&display=swap" rel="stylesheet">
99
<!-- stylesheet -->
10+
<link defer async rel="stylesheet" href="{{ "/assets/tabs.css" | relative_url }}">
1011
<link defer async rel="stylesheet" href="{{ "/assets/style.css" | relative_url }}">
1112
<link defer async rel="stylesheet" href="{{ "/assets/media.css" | relative_url }}">
1213
<link defer async rel="stylesheet" href="{{ "/assets/github.css" | relative_url }}">

Diff for: _layouts/benchmarks.html

+48-5
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,55 @@
2222
{{ content }}
2323
</div>
2424

25+
<!-- TODO clean up this code a bit -->
26+
27+
{% assign folders = "" | split: ", " %}
2528
{% for image in site.static_files %}
26-
{% if image.path contains 'benchmarks' %}
27-
<figure>
28-
<img src="{{ site.baseurl }}{{ image.path }}" alt="image" width="30%" />
29-
<figcaption>{{ image.name }}</figcaption>
30-
</figure>
29+
{% if image.path contains 'criterion/' %}
30+
{% assign imagepath = image.path | split: "/" %}
31+
{% for subpath in imagepath %}
32+
{% if forloop.index0 == 3 %}
33+
{% assign folders = folders | append: pathName %}
34+
{% endif %}
35+
{% endfor %}
3136
{% endif %}
3237
{% endfor %}
38+
{% assign folders = folders | uniq %}
39+
40+
<!-- {% assign folders = "" | split: ", " %}
41+
{% for folder in site.static_files %}
42+
{% if folder.path contains 'criterion/' %}
43+
{% assign temp = folder.path | split: 'criterion/' %}
44+
{% assign pathName = temp[1] | split: '/' | first %}
45+
{% assign pathName = pathName | split: ", " %}
46+
{% assign folders = folders | concat: pathName %}
47+
{% endif %}
48+
{% endfor%}
49+
{% assign folders = folders | uniq %} -->
50+
51+
<!-- TODO check if the folders list is empty, if so, display corresponding message -->
52+
<!-- TODO add text that explains the violin plots -->
53+
54+
<ul class="tab" data-tab="benchmarks">
55+
{% for folder in folders %}
56+
<li {% if forloop.index==1 %} class="active" {% endif %}>
57+
<a href="">{{ folder }}</a>
58+
</li>
59+
{% endfor%}
60+
</ul>
61+
<ul class="tab-content" id="benchmarks">
62+
{% for folder in folders %}
63+
<li {% if forloop.index==1 %} class="active" {% endif %}>
64+
<br>
65+
{% for image in site.static_files %}
66+
{% if image.path contains folder %}
67+
<figure>
68+
<img src="{{ site.baseurl }}{{ image.path }}" alt="image" width="50%" />
69+
<figcaption>{{ image.name }}</figcaption>
70+
</figure>
71+
{% endif %}
72+
{% endfor%}
73+
</li>
74+
{% endfor%}
75+
</ul>
3376
</div>

Diff for: _layouts/default.html

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
{%- include footer.html -%}
1717

18+
<script src="{{ "/assets/js/tabs.js" | relative_url }}"></script>
1819
</body>
1920

2021
</html>

Diff for: assets/js/tabs.js

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
const removeActiveClasses = function (ulElement) {
2+
const lis = ulElement.querySelectorAll('li');
3+
Array.prototype.forEach.call(lis, function(li) {
4+
li.classList.remove('active');
5+
});
6+
}
7+
8+
const getChildPosition = function (element) {
9+
var parent = element.parentNode;
10+
var i = 0;
11+
for (var i = 0; i < parent.children.length; i++) {
12+
if (parent.children[i] === element) {
13+
return i;
14+
}
15+
}
16+
17+
throw new Error('No parent found');
18+
}
19+
20+
window.addEventListener('load', function () {
21+
const tabLinks = document.querySelectorAll('ul.tab li a');
22+
23+
Array.prototype.forEach.call(tabLinks, function(link) {
24+
link.addEventListener('click', function (event) {
25+
event.preventDefault();
26+
27+
liTab = link.parentNode;
28+
ulTab = liTab.parentNode;
29+
position = getChildPosition(liTab);
30+
if (liTab.className.includes('active')) {
31+
return;
32+
}
33+
34+
removeActiveClasses(ulTab);
35+
tabContentId = ulTab.getAttribute('data-tab');
36+
tabContentElement = document.getElementById(tabContentId);
37+
removeActiveClasses(tabContentElement);
38+
39+
tabContentElement.querySelectorAll('li')[position].classList.add('active');
40+
liTab.classList.add('active');
41+
}, false);
42+
});
43+
});

Diff for: assets/tabs.css

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
.tab {
2+
display: flex;
3+
flex-wrap: wrap;
4+
margin-left: -20px;
5+
padding: 0;
6+
list-style: none;
7+
position: relative;
8+
}
9+
10+
.tab > * {
11+
flex: none;
12+
padding-left: 20px;
13+
position: relative;
14+
}
15+
16+
.tab > * > a {
17+
display: block;
18+
text-align: center;
19+
padding: 9px 20px;
20+
color: #999;
21+
border-bottom: 2px solid transparent;
22+
border-bottom-color: transparent;
23+
font-size: 12px;
24+
text-transform: uppercase;
25+
transition: color .1s ease-in-out;
26+
line-height: 20px;
27+
}
28+
29+
.tab > .active > a {
30+
color:#222;
31+
border-color: #1e87f0;
32+
}
33+
34+
.tab li a {
35+
text-decoration: none;
36+
cursor: pointer;
37+
}
38+
39+
.tab-content{
40+
padding: 0;
41+
}
42+
43+
.tab-content li {
44+
display: none;
45+
}
46+
.tab-content li.active {
47+
display: initial;
48+
}

0 commit comments

Comments
 (0)