added a tag cloud
authorArun Persaud <arun@nubati.net>
Tue, 24 Jan 2012 07:58:53 +0000 (23:58 -0800)
committerArun Persaud <apersaud@lbl.gov>
Tue, 24 Jan 2012 08:00:06 +0000 (00:00 -0800)
getjson.php
index.php

index 83360e6..07294ba 100644 (file)
@@ -29,6 +29,12 @@ if (isset($_REQUEST["S"]))
     $result = $DB->query("SELECT base_uri, filename, id FROM photos".
                         " WHERE id=$id");
   }
+ else if (isset($_REQUEST["CLOUD"]))
+  {
+    $result = $DB->query("SELECT t.name as name, count(*) as count FROM photo_tags pt ".
+                        " LEFT JOIN tags t on t.id=pt.tag_id".
+                        " GROUP BY t.id");
+  }
  else
   {
     if (isset($_REQUEST["P"]))
index 82378b4..aa799b9 100644 (file)
--- a/index.php
+++ b/index.php
@@ -55,6 +55,7 @@ else
   </datalist>
 </form>
   Current tags:<span id="currenttags"></span>
+  <button class="next" type="button" onclick="cloud()">tag cloud</button>
 </div>
 
 <div class="pics"> </div>
@@ -180,6 +181,26 @@ function right() {
   load_content(page);
 }
 
+function cloud() {
+
+  url = "<?php echo $webbase?>/getjson.php?CLOUD=1";
+
+  pics.selectAll("li").remove();
+
+  var svgelement=pics.append("li")
+    .append("svg").attr("width",400).attr("height",400);
+
+  /* update pics */
+  d3.json(url, function(json) {
+      svgelement.selectAll("text").data(json).enter().append("text")
+       .style("font-size", function(d){return Math.log(d.count+1)+"em"})
+       .text(function(d) { return d.name; })
+       .on("mouseover", function(d){ d3.select(this).style("color","red")} )
+       .on("mouseout", function(d){ d3.select(this).style("color","white")} )
+       .on("click", function(d) { document.location.href='<?php echo $webbase?>/tag/'+d.name })
+    });
+}
+
 function checkbutton()
 {