Skip to content

Commit 8615b71

Browse files
dsschultgithub-actions
and
github-actions
authored
plotly donut plots (#3)
* plotly donut plots * <bot> update dependencies*.log files(s) --------- Co-authored-by: github-actions <github-actions@github.com>
1 parent d2f2df5 commit 8615b71

File tree

7 files changed

+56
-19
lines changed

7 files changed

+56
-19
lines changed

cephfs_disk_usage/server.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,32 @@ class DirEntry:
100100
path: str
101101
size: int
102102
nfiles: int
103-
children: list
103+
children: list[Entry]
104104

105105
@classmethod
106106
def from_entry(cls, e: Entry) -> Self:
107107
if not e.is_dir:
108108
raise Exception('is not a directory!')
109109
return cls(e.name, e.path, e.size, e.nfiles, [])
110110

111+
def child_summary(self, threshold=5) -> list[Entry]:
112+
"""
113+
Summarize children
114+
115+
Args:
116+
threshold: in percent (0-100)
117+
"""
118+
ret = []
119+
other = 0
120+
for child in self.children:
121+
if child.percent_size < threshold:
122+
other += child.size
123+
else:
124+
ret.append(child)
125+
if other:
126+
ret.append(Entry("Other", "", other, percent_size=other*100.0/self.size))
127+
return ret
128+
111129

112130
class POSIXFileSystem:
113131
def __init__(self, base_path):

cephfs_disk_usage/static/style.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,13 @@ footer {
7373
margin-top: 2em;
7474
}
7575

76+
div.piechart {
77+
max-width: 43em;
78+
}
79+
article.main div.piechart {
80+
max-width: 35em;
81+
}
82+
7683
div.articles {
7784
display: flex;
7885
flex-wrap: wrap;

cephfs_disk_usage/templates/details.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,5 @@ <h3>Path: {{ data.path }}</h3>
1010
{% end %}
1111

1212
{% block scripts %}
13-
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
1413
{% module Template('piechart.js', data=data) %}
1514
{% end %}

cephfs_disk_usage/templates/main.html

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ <h3>Path: {{ path }}</h3>
1414
{% end %}
1515

1616
{% block scripts %}
17-
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
1817
{% for path in paths %}
1918
{% module Template('piechart.js', data=paths[path]) %}
2019
{% end %}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<div id="piechart-{{ data.path }}"></div>
1+
<div id="piechart-{{ data.path }}" class="piechart"></div>
Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
11
{% autoescape None %}
22

3-
<script type="text/javascript">
4-
{% set funcname = 'draw'+data.path.replace('.','').replace('/','').replace('-','') %}
5-
{% set datatable = json_encode([['Name', 'Size']]+[[row.name, row.size] for row in data.children]) %}
6-
google.charts.load('current', {'packages':['corechart']});
7-
google.charts.setOnLoadCallback({{ funcname }});
8-
9-
function {{ funcname }}() {
3+
{% try %}
4+
{% if not piechart %}{% end %}
5+
{% except %}
6+
<script src="https://cdn.plot.ly/plotly-2.25.2.min.js" charset="utf-8"></script>
7+
{% set piechart = True %}
8+
{% end %}
109

11-
var data = google.visualization.arrayToDataTable({{ datatable }});
10+
<script type="text/javascript">
11+
{% set summary = data.child_summary() %}
12+
var data = [{
13+
values: {{ json_encode([row.size for row in summary]) }},
14+
labels: {{ json_encode([row.name for row in summary]) }},
15+
type: 'pie',
16+
hole: .4,
17+
sort: false,
18+
direction: "clockwise",
19+
textinfo: "label+percent",
20+
textposition: "outside",
21+
textfont: {
22+
size: 12
23+
},
24+
automargin: true
25+
}];
1226

13-
var options = {
14-
// title: 'My Daily Activities'
15-
};
27+
var layout = {
28+
margin: {"t": 0, "b": 0, "l": 0, "r": 0},
29+
showlegend: false
30+
};
1631

17-
var chart = new google.visualization.PieChart(document.getElementById("piechart-{{ data.path }}"));
32+
var config = {responsive: true}
1833

19-
chart.draw(data, options);
20-
}
34+
Plotly.newPlot("piechart-{{ data.path }}", data, layout, config);
2135
</script>

dependencies-from-Dockerfile.log

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ tornado==6.3.3
1414
typing_extensions==4.7.1
1515
urllib3==2.0.4
1616
wipac-dev-tools==1.6.16
17-
wipac-rest-tools==1.5.2
17+
wipac-rest-tools==1.5.3

0 commit comments

Comments
 (0)