Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed bug #2.

  • Loading branch information...
commit c1830deafec126f508943a91c810fc0cc6028635 1 parent 9a9524e
@niconoe authored
View
10 django_nuages_tag/templatetags/django_nuages_tag.py
@@ -57,9 +57,13 @@ def render(self, context):
def calculate_lin(current_count, smallest_count, largest_count, max_size, min_size):
""" Calculate ratio (linear version). """
- # Formula details:
- # http://blog.16codes.com/2007/12/how-to-create-tag-cloud-with-formula.html
- return ( ((current_count-smallest_count) * (max_size-min_size)) / (largest_count
+ # Specific case when smallest_count == largest_count: We want a medium value
+ if smallest_count == largest_count:
+ return (min_size + max_size) / 2.0
+ else:
+ # Formula details:
+ # http://blog.16codes.com/2007/12/how-to-create-tag-cloud-with-formula.html
+ return ( ((current_count-smallest_count) * (max_size-min_size)) / (largest_count
-smallest_count) ) + min_size
def calculate_log(current_count, smallest_count, largest_count, max_size, min_size):
View
7 django_nuages_tag/tests.py
@@ -158,6 +158,7 @@ def test_with_neg_lin(self):
self.assertAlmostEqual(self.TEST_DATA_DICT_NEG[2]['font-size'], 0) # PHP
# Regression test: when min value == max value in Lin mode, there was a ZeroDivisionError
+ # Here we check for correct value, will be stopped by exception if it occurs again
def test_with_min_eq_max_lin(self):
t = Template('{% load django_nuages_tag %}'
'{% compute_tag_cloud my_test_data interest font-size 10 100 lin %}')
@@ -165,8 +166,10 @@ def test_with_min_eq_max_lin(self):
c = Context({'my_test_data': self.TEST_DATA_MIN_EQ_MAX})
t.render(c)
- # Ensure they have the same result
- self.assertEqual(self.TEST_DATA_DICT_NEG[0]['font-size'], self.TEST_DATA_DICT_NEG[1])
+ # Ensure they have the same size...
+ self.assertEqual(self.TEST_DATA_MIN_EQ_MAX[0]['font-size'], self.TEST_DATA_MIN_EQ_MAX[1]['font-size'])
+ # ...And that this size is in the middle of the range
+ self.assertAlmostEqual(self.TEST_DATA_MIN_EQ_MAX[0]['font-size'], 55.0)
# TODO: test that the bounds (10-100) are taken into account... hmm only for lin ? is it normal ?
Please sign in to comment.
Something went wrong with that request. Please try again.