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 83360e6118387d957fdf4a6b139e5c079ce20ab8..07294ba5fb6a9b5864b240cedc4af74af30ff2ee 100644 (file)
@@ -29,6 +29,12 @@ if (isset($_REQUEST["S"]))
     $result = $DB->query("SELECT base_uri, filename, id FROM photos".
                         " WHERE id=$id");
   }
     $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"]))
  else
   {
     if (isset($_REQUEST["P"]))
index 82378b43636aa64efb5fd4ae3f8f3ea23f7049ce..aa799b98d868fb0f220e9484205499e709aa40d5 100644 (file)
--- a/index.php
+++ b/index.php
@@ -55,6 +55,7 @@ else
   </datalist>
 </form>
   Current tags:<span id="currenttags"></span>
   </datalist>
 </form>
   Current tags:<span id="currenttags"></span>
+  <button class="next" type="button" onclick="cloud()">tag cloud</button>
 </div>
 
 <div class="pics"> </div>
 </div>
 
 <div class="pics"> </div>
@@ -180,6 +181,26 @@ function right() {
   load_content(page);
 }
 
   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()
 {
 
 function checkbutton()
 {