The more in the category, the bigger the font... [solved]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

The more in the category, the bigger the font... [solved]

Post by Skara »

Ok, I want to do something like this...
http://wordpress.org/extend/plugins/tags/

If someone knows where I can find that code, great. If not, I need to figure it out myself. ->


So, the more items that are in a tag/category, the bigger the font.

I'm not quite sure how to go about it. I have about 2000 entries, and the list is growing. I'll probably have around 50 tags or so. Maybe as many as 100.

So, I would like to do something like this...

Code: Select all

$min = 12; //px
$max = 24; //px
// biggest category = 1400
// middle categories...
// smallest category = 5

scale_sizes($categorylist,$min,$max); # <---

// biggest category font size = 24
// middle categories proportionately spaced in size
// smallest category font size = 12
example:

Code: Select all

$categories = array(18,27,36);
#result:
$categoryfontsizes = array(12,18,24);
I just don't know the math behind scaling a range like that.
Last edited by Skara on Thu Mar 22, 2007 5:36 pm, edited 1 time in total.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Basic distribution is "somewhat" simple:

Code: Select all

(maximum quantity - minimum quantity) × (maximum size - minimum size) / (current quantity - minimum quantity) + minimum size
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

I could be mistaken, but isn't wordpress both open source AND in PHP?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post by dude81 »

Kieran Huggins wrote:I could be mistaken, but isn't wordpress both open source AND in PHP?
wordpress is an opensource, but the url skara pointed to is wordpress website , and such feature is not avaialble within wordpress.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

feyd wrote:Basic distribution is "somewhat" simple:

Code: Select all

(maximum quantity - minimum quantity) × (maximum size - minimum size) / (current quantity - minimum quantity) + minimum size
well. It is "somewhat" simple, but I never would have figured it out myself. Thanks!
User avatar
stereofrog
Forum Contributor
Posts: 386
Joined: Mon Dec 04, 2006 6:10 am

Post by stereofrog »

feyd's formula is reverse proportional, to get "more = bigger" proportion, you need something like

Code: Select all

$font_size = ($current_qty - $qty_min) * ($size_max - $size_min) / ($qty_max - $qty_min) + $size_min;
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

You may also want to search for Tag Clouds, as they are commonly referred to.
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Post by Skara »

ah, yeah, I did finally find they were called "tag clouds"

It's all working great now. Thanks.
Post Reply