Skip to content

Commit b73608b

Browse files
committed
Improved graph reports
1 parent 505fd77 commit b73608b

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

swift_code_metrics/_graphics.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import string
22

33
import matplotlib.pyplot as plt
4+
from math import ceil
45
import os
56

67
from adjustText import adjust_text
@@ -14,10 +15,17 @@ def __init__(self, path=None):
1415
def bar_plot(self, title, data):
1516
plt.title(title)
1617
plt.ylabel(title)
17-
bar_width = 0.35
18+
bar_width = 0.75
1819
opacity = 0.4
19-
plotted_data = plt.bar(data[1], data[0], bar_width, alpha=opacity)
20-
plt.legend(plotted_data, data[2], loc='upper left')
20+
plotted_data = plt.barh(data[1], data[0], bar_width, alpha=opacity)
21+
22+
texts = []
23+
for i, v in enumerate(data[0]):
24+
texts.append(plt.text(v, i, f' {str(v)}', va='center', color='blue', size='smaller'))
25+
26+
adjust_text(texts, autoalign='x', only_move={'text': 'x'})
27+
28+
plt.legend(plotted_data, data[2], loc='lower right')
2129

2230
self.__render(plt, title)
2331

@@ -101,5 +109,3 @@ def format_filename(s):
101109
filename = ''.join(c for c in s if c in valid_chars)
102110
filename = filename.replace(' ', '_').lower()
103111
return filename
104-
105-

swift_code_metrics/_metrics.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,8 @@ def number_of_imports(self) -> int:
226226
@property
227227
def compact_name(self) -> str:
228228
all_capitals = ''.join(c for c in self.name if c.isupper())
229-
if len(all_capitals) > 3:
229+
if len(all_capitals) > 4:
230230
return all_capitals[0] + all_capitals[-1:]
231-
elif len(all_capitals) > 1:
232-
return all_capitals
233231
elif len(all_capitals) == 0:
234232
return self.name[0]
235233
else:

swift_code_metrics/tests/test_metrics.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,16 @@ def setUp(self):
1515
def test_representation(self):
1616
self.assertEqual(str(self.framework), 'AwesomeName(0 files)')
1717

18-
def test_compact_name(self):
19-
self.assertEqual(self.framework.compact_name, 'AN')
18+
def test_compact_name_morethanfourcapitals(self):
19+
test_framework = Framework('FrameworkWithMoreThanFourCapitals')
20+
self.assertEqual('FC', test_framework.compact_name)
21+
22+
def test_compact_name_lessthanfourcapitals(self):
23+
self.assertEqual('AN', self.framework.compact_name)
24+
25+
def test_compact_name_nocapitals(self):
26+
test_framework = Framework('nocapitals')
27+
self.assertEqual('n', test_framework.compact_name)
2028

2129
def test_compact_name_description(self):
2230
self.assertEqual(self.framework.compact_name_description, 'AN = AwesomeName')

0 commit comments

Comments
 (0)