Bugzilla – Attachment 10988 Details for
Bug 7642
The number that appears when hovering over a tag in the tag cloud isn't the number of items with that tag
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 7642 - fix the lost display of tag sizes
Bug-7642---fix-the-lost-display-of-tag-sizes.patch (text/plain), 9.81 KB, created by
Robin Sheat
on 2012-07-18 15:55:26 UTC
(
hide
)
Description:
Bug 7642 - fix the lost display of tag sizes
Filename:
MIME Type:
Creator:
Robin Sheat
Created:
2012-07-18 15:55:26 UTC
Size:
9.81 KB
patch
obsolete
>From a2e52bbc65c9b5adc88ebbc0f8830e4bc090b433 Mon Sep 17 00:00:00 2001 >From: Robin Sheat <robin@catalyst.net.nz> >Date: Wed, 18 Jul 2012 17:29:38 +0200 >Subject: [PATCH] Bug 7642 - fix the lost display of tag sizes > >This fixes the display of different sized words for differently popular >tags. It is a bit of a refactor of that part of the system, moving >logic to more sensible places (and removing an unused method on the >way.) > >Note that it isn't an attempt to reproduce what was there previously, >just to do something similar, and in an easier to change fashion. > >Sponsored-By: New Zealand Educational Institute >--- > C4/Tags.pm | 66 +++++++++++++--------- > koha-tmpl/opac-tmpl/prog/en/css/opac.css | 41 ++++++++++++++ > koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tt | 22 +------- > opac/opac-tags.pl | 29 +--------- > t/db_dependent/Tags.t | 55 +++++++++++++++++- > 5 files changed, 136 insertions(+), 77 deletions(-) > >diff --git a/C4/Tags.pm b/C4/Tags.pm >index 4786b2c..69d6090 100644 >--- a/C4/Tags.pm >+++ b/C4/Tags.pm >@@ -39,7 +39,6 @@ BEGIN { > &delete_tag_row_by_id > &remove_tag > &delete_tag_rows_by_ids >- &rectify_weights > &get_approval_rows > &blacklist > &whitelist >@@ -47,6 +46,7 @@ BEGIN { > &approval_counts > &get_count_by_tag_status > &get_filters >+ stratify_tags > ); > # %EXPORT_TAGS = (); > $ext_dict = C4::Context->preference('TagsExternalDictionary'); >@@ -490,33 +490,6 @@ sub get_tag { # by tag_id > return $sth->fetchrow_hashref; > } > >-sub rectify_weights { >- my $dbh = C4::Context->dbh; >- my $sth; >- my $query = " >- SELECT term,biblionumber,count(*) as count >- FROM tags_all >- "; >- (@_) and $query .= " WHERE term =? "; >- $query .= " GROUP BY term,biblionumber "; >- $sth = $dbh->prepare($query); >- if (@_) { >- $sth->execute(shift); >- } else { >- $sth->execute(); >- } >- my $results = $sth->fetchall_arrayref({}) or return undef; >- my %tally = (); >- foreach (@$results) { >- _set_weight($_->{count},$_->{term},$_->{biblionumber}); >- $tally{$_->{term}} += $_->{count}; >- } >- foreach (keys %tally) { >- _set_weight_total($tally{$_},$_); >- } >- return ($results,\%tally); >-} >- > sub increment_weights { > increment_weight(@_); > increment_weight_total(shift); >@@ -594,6 +567,43 @@ sub add_tag { # biblionumber,term,[borrowernumber,approvernumber] > } > } > >+# This takes a set of tags, as returned by C<get_approval_rows> and divides >+# them up into a number of "strata" based on their weight. This is useful >+# to display them in a number of different sizes. >+# >+# Usage: >+# ($min, $max) = stratify_tags($strata, $tags); >+# $stratum: the number of divisions you want >+# $tags: the tags, as provided by get_approval_rows >+# $min: the minumum stratum value >+# $max: the maximum stratum value. This may be the same as $min if there >+# is only one weight. Beware of divide by zeros. >+# This will add a field to the tag called "stratum" containing the calculated >+# value. >+sub stratify_tags { >+ my ( $strata, $tags ) = @_; >+ >+ my ( $min, $max ); >+ foreach (@$tags) { >+ my $w = $_->{weight_total}; >+ $min = $w if ( !defined($min) || $min > $w ); >+ $max = $w if ( !defined($max) || $max < $w ); >+ } >+ >+ # normalise min to zero >+ $max = $max - $min; >+ my $orig_min = $min; >+ $min = 0; >+ >+ # if min and max are the same, just make it 1 >+ my $span = ( $strata - 1 ) / ( $max || 1 ); >+ foreach (@$tags) { >+ my $w = $_->{weight_total}; >+ $_->{stratum} = int( ( $w - $orig_min ) * $span ); >+ } >+ return ( $min, $max ); >+} >+ > 1; > __END__ > >diff --git a/koha-tmpl/opac-tmpl/prog/en/css/opac.css b/koha-tmpl/opac-tmpl/prog/en/css/opac.css >index 1e5b0c6..060af5a 100644 >--- a/koha-tmpl/opac-tmpl/prog/en/css/opac.css >+++ b/koha-tmpl/opac-tmpl/prog/en/css/opac.css >@@ -2609,6 +2609,46 @@ ul.ui-tabs-nav li { > box-shadow: 1px 1px 3px 0 #666; > } > >+/* different sizes for different tags in opac-tags.tt */ >+.tagweight0 { >+ font-size: 12px; >+} >+ >+.tagweight1 { >+ font-size: 14px; >+} >+ >+.tagweight2 { >+ font-size: 16px; >+} >+ >+.tagweight3 { >+ font-size: 18px; >+} >+ >+.tagweight4 { >+ font-size: 20px; >+} >+ >+.tagweight5 { >+ font-size: 22px; >+} >+ >+.tagweight6 { >+ font-size: 24px; >+} >+ >+.tagweight7 { >+ font-size: 26px; >+} >+ >+.tagweight8 { >+ font-size: 28px; >+} >+ >+.tagweight9 { >+ font-size: 30px; >+} > /* ## BABELTHEQUE ##Â */ > /* Uncomment if babeltheque configuration no contains these lines */ > /* >@@ -2757,4 +2797,5 @@ ul.ui-tabs-nav li { > color: #FFFFCC; > } > >+ > */ >diff --git a/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tt b/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tt >index c76b726..ca053b8 100644 >--- a/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tt >+++ b/koha-tmpl/opac-tmpl/prog/en/modules/opac-tags.tt >@@ -21,26 +21,6 @@ > </style> > <script type="text/javascript"> > //<![CDATA[ >- var fontsizes = new Array (12,14,16,18,20,22,24,26,28,30); >- var fontcount = fontsizes.length; >- var maxcloudweight = 1; >- $(document).ready(function() { >- // $('#tagcloud').css('background-color','lightgrey'); >- // $('#tagcloud .tag').css('border','1px solid black'); >- $('#tagcloud .tag').each(function() { >- if (maxcloudweight < this.title) { maxcloudweight = this.title; } >- // have to run through the set of tags once to get the max: cannot be combined w/ 2nd pass >- }); >- $('#tagcloud .tag').each(function(i) { >- var pos = this.id; >- var weight = this.title; // "cloudweight" >- weight = (! weight) ? 1 : (weight > maxcloudweight) ? maxcloudweight : weight ; >- var index = Math.round(fontcount * weight/maxcloudweight) - 1; >- index = (! index ) ? 0 : ( index > fontcount ) ? fontcount : index ; >- var newsize = fontsizes[index]; >- // alert(pos+ " (" +i+ ") weight = " +weight+ " of " +maxcloudweight+ ", fontsize[" +index+ " of " +fontcount+ "] = " +newsize); >- $('#' + pos).css({"font-size":(newsize + 'px'), display:"inline"}); >- }); > $("#mytagst").tablesorter({[% IF ( dateformat == 'metric' ) %] > dateFormat: 'uk',[% END %] > widgets : ['zebra'], >@@ -90,7 +70,7 @@ > [% IF ( TAGLOOP ) %] > <div id="tagcloud"> > [% FOREACH TAGLOO IN TAGLOOP %] >- <span class="tag" id="tag[% loop.count %]"> >+ <span class="tag tagweight[% TAGLOO.stratum %]" id="tag[% loop.count %]" style="display:inline;"> > <a href="/cgi-bin/koha/opac-search.pl?tag=[% TAGLOO.term |url %]&q=[% TAGLOO.term |url %]"> > [% TAGLOO.term |html %]</a> > <span class="tagweight">[% TAGLOO.weight_total %]</span> >diff --git a/opac/opac-tags.pl b/opac/opac-tags.pl >index a0ed523..a856081 100755 >--- a/opac/opac-tags.pl >+++ b/opac/opac-tags.pl >@@ -41,7 +41,7 @@ use C4::Debug; > use C4::Output qw(:html :ajax pagination_bar); > use C4::Scrubber; > use C4::Biblio; >-use C4::Tags qw(add_tag get_approval_rows get_tag_rows remove_tag); >+use C4::Tags qw(add_tag get_approval_rows get_tag_rows remove_tag stratify_tags); > > use Data::Dumper; > >@@ -263,34 +263,9 @@ if ($add_op) { > $arghash->{biblionumber} = $arg; > } > $results = get_approval_rows($arghash); >- >+ stratify_tags(10, $results); # work out the differents sizes for things > my $count = scalar @$results; > $template->param(TAGLOOP_COUNT => $count, mine => $mine); >- # Here we make a halfhearted attempt to separate the tags into "strata" based on weight_total >- # FIXME: code4lib probably has a better algorithm, iirc >- # FIXME: when we get a better algorithm, move to C4 >- my $maxstrata = 5; >- my $strata = 1; >- my $previous = 0; >- my $chunk = ($count/$maxstrata)/2; >- my $total = 0; >- my %cloud; >- foreach (reverse @$results) { >- my $current = $_->{weight_total}; >- $total++; >- $cloud{$strata}++; >- if ($current == $previous) { >- $_->{cloudweight} = $strata; >- next; >- } >- if ($strata < $maxstrata and >- ($cloud{$strata} > $chunk or >- $count-$total <= $maxstrata-$strata)) { >- $strata++; >- } >- $_->{cloudweight} = $strata; >- $previous = $current; >- } > } > (scalar @errors ) and $template->param(ERRORS => \@errors); > my @orderedresult = sort { uc($a->{'term'}) cmp uc($b->{'term'}) } @$results; >diff --git a/t/db_dependent/Tags.t b/t/db_dependent/Tags.t >index 83b3c9b..3cc5cca 100755 >--- a/t/db_dependent/Tags.t >+++ b/t/db_dependent/Tags.t >@@ -6,9 +6,62 @@ > use strict; > use warnings; > >-use Test::More tests => 1; >+use Data::Dumper; >+ >+use Test::More tests => 30; > > BEGIN { > use_ok('C4::Tags'); > } > >+# Simple 'sequential 5' test >+my $tags = make_tags(1,2,3,4,5); >+my @strata = (0,1,2,3,4); >+my ($min, $max) = C4::Tags::stratify_tags(5, $tags); >+check_tag_strata($tags, \@strata, 'Sequential 5'); >+is($min, 0, 'Sequential 5 min'); >+is($max, 4, 'Sequential 5 max'); >+ >+# Reverse test - should have the same results as previous >+$tags = make_tags(5,4,3,2,1); >+@strata = (4,3,2,1,0); >+($min, $max) = C4::Tags::stratify_tags(5, $tags); >+check_tag_strata($tags, \@strata, 'Reverse Sequential 5'); >+is($min, 0, 'Sequential 5 min'); >+is($max, 4, 'Sequential 5 max'); >+ >+# All the same test - should all have the same results >+$tags = make_tags(4,4,4,4,4); >+@strata = (0,0,0,0,0); >+($min, $max) = C4::Tags::stratify_tags(5, $tags); >+check_tag_strata($tags, \@strata, 'All The Same'); >+is($min, 0, 'Sequential 5 min'); >+is($max, 0, 'Sequential 5 max'); >+ >+# Some the same, some different >+$tags = make_tags(1,2,2,3,3,8); >+@strata = (0,0,0,1,1,4); >+($min, $max) = C4::Tags::stratify_tags(5, $tags); >+check_tag_strata($tags, \@strata, 'All The Same'); >+is($min, 0, 'Sequential 5 min'); >+is($max, 7, 'Sequential 5 max'); >+ >+# Runs tests against the results >+sub check_tag_strata { >+ my ($tags, $expected, $name) = @_; >+ >+ foreach my $t (@$tags) { >+ my $w = $t->{weight_total}; >+ my $s = $t->{stratum}; >+ is($s, shift @$expected, $name . " - $w ($s)"); >+ } >+} >+ >+# Makes some tags with just enough info to test >+sub make_tags { >+ my @res; >+ while (@_) { >+ push @res, { weight_total => shift @_ }; >+ } >+ return \@res; >+} >-- >1.7.9.5
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 7642
:
9785
|
10028
|
10111
|
10123
|
10986
|
10987
|
10988
|
12014
|
12022
|
12604
|
12626