From: Arun Persaud Date: Tue, 24 Jan 2012 07:58:53 +0000 (-0800) Subject: added a tag cloud X-Git-Url: https://git.nubati.net/cgi-bin/gitweb.cgi?p=photo-tags.git;a=commitdiff_plain;h=8a26a320c6804949a140cc0b62de507c1d19f345 added a tag cloud --- diff --git a/getjson.php b/getjson.php index 83360e6..07294ba 100644 --- a/getjson.php +++ b/getjson.php @@ -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"])) diff --git a/index.php b/index.php index 82378b4..aa799b9 100644 --- a/index.php +++ b/index.php @@ -55,6 +55,7 @@ else Current tags: +
@@ -180,6 +181,26 @@ function right() { load_content(page); } +function cloud() { + + url = "/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='/tag/'+d.name }) + }); +} + function checkbutton() {