TagSpaces is an offline, open source, document manager with tagging support
Added some new vizualiazions to the perspectiveGraph
uggrock47365989431d
diff --git a/data/ext/perspectiveGraph/bilevelPartition.js b/data/ext/perspectiveGraph/bilevelPartition.jsnew file mode 100644index 000000000..80902d3a6--- /dev/null+++ b/data/ext/perspectiveGraph/bilevelPartition.js@@ -0,0 +1,161 @@+/* Copyright (c) 2012-2013 The TagSpaces Authors. All rights reserved.+ * Use of this source code is governed by a AGPL3 license that+ * can be found in the LICENSE file. */++define(function(require, exports, module) {+"use strict";+ console.log("Loading Quantified Self");++ var TSCORE = require("tscore");++ require("d3");++ // Based on http://bl.ocks.org/mbostock/5944371+ var drawPartition = function(svg, treeData) {++ var margin = {top: 350, right: 480, bottom: 350, left: 480},+ radius = Math.min(margin.top, margin.right, margin.bottom, margin.left);++ var hue = d3.scale.category10();++ var luminance = d3.scale.sqrt()+ .domain([0, 1e6])+ .clamp(true)+ .range([90, 20]);++ svg.append("g")+ .attr("transform", "translate(.5,.5)");++ var partition = d3.layout.partition()+ .sort(function(a, b) { return d3.ascending(a.name, b.name); })+ .size([2 * Math.PI, radius]);++ var arc = d3.svg.arc()+ .startAngle(function(d) { return d.x; })+ .endAngle(function(d) { return d.x + d.dx; })+ .innerRadius(function(d) { return radius / 3 * d.depth; })+ .outerRadius(function(d) { return radius / 3 * (d.depth + 1); });+++ // Compute the initial layout on the entire tree to sum sizes.+ // Also compute the full name and fill color for each node.+ partition+ .value(function(d) { return d.size; })+ .nodes(treeData)+ .forEach(function(d) { d.sum = d.value; d.key = key(d); d.fill = fill(d); });++ // Now redefine the value function to use the previously-computed sum.+ partition+ .children(function(d, depth) { return depth < 2 ? d.children : null; })+ .value(function(d) { return d.sum; });++ var center = svg.append("circle")+ .attr("r", radius / 3)+ .on("click", zoomOut);++ center.append("title")+ .text("zoom out");++ var path = svg.selectAll("path")+ .data(partition.nodes(treeData).slice(1))+ .enter().append("path")+ .attr("d", arc)+ .style("fill", function(d) { return d.fill; })+ .each(function(d) { this._current = updateArc(d); })+ .on("click", zoomIn);++ function zoomIn(p) {+ if (p.depth > 1) p = p.parent;+ if (!p.children) return;+ zoom(p, p);+ }++ function zoomOut(p) {+ if (!p.parent) return;+ zoom(p.parent, p);+ }++ // Zoom to the specified new root.+ function zoom(root, p) {+ if (document.documentElement.__transition__) return;++ // Stash the original root dimensions for transitions.+ var angle1 = d3.scale.linear()+ .domain([0, 2 * Math.PI])+ .range([root.x, root.x + root.dx]);++ function insideArc(d) {+ return p.key > d.key+ ? {depth: d.depth - 1, x: 0, dx: 0} : p.key < d.key+ ? {depth: d.depth - 1, x: 2 * Math.PI, dx: 0}+ : {depth: 0, x: 0, dx: 2 * Math.PI};+ }++ function outsideArc(d) {+ return {depth: d.depth + 1, x: angle1(d.x), dx: angle1(d.x + d.dx) - angle1(d.x)};+ }++ // When zooming in, arcs enter from the outside and exit to the inside.+ // When zooming out, arcs enter from the inside and exit to the outside.+ var enterArc = root === p ? outsideArc : insideArc,+ exitArc = root === p ? insideArc : outsideArc;++ center.datum(root);++ d3.transition().duration(750).each(function() {+ path = path.data(partition.nodes(root).slice(1), function(d) { return d.key; });++ path.transition()+ .attrTween("d", function(d) { return arcTween.call(this, updateArc(d)); });++ path.enter().append("path")+ .style("fill-opacity", 0)+ .style("fill", function(d) { return d.fill; })+ .on("click", zoomIn)+ .each(function(d) { this._current = enterArc(d); })+ .transition()+ .style("fill-opacity", 1)+ .attrTween("d", function(d) { return arcTween.call(this, updateArc(d)); });++ path.exit().transition()+ .style("fill-opacity", 0)+ .attrTween("d", function(d) { return arcTween.call(this, exitArc(d)); })+ .remove();+ });+ }++ function key(d) {+ var k = [], p = d;+ while (p.depth) k.push(p.name), p = p.parent;+ return k.reverse().join(".");+ }++ function fill(d) {+ var p = d;+ while (p.depth > 1) p = p.parent;+ var c = d3.lab(hue(p.name));+ c.l = luminance(d.sum);+ return c;+ }++ function arcTween(b) {+ var i = d3.interpolate(this._current, b);+ this._current = i(0);+ return function(t) {+ return arc(i(t));+ };+ }++ function updateArc(d) {+ return {depth: d.depth, x: d.x, dx: d.dx};+ }++ d3.select(self.frameElement).style("height", margin.top + margin.bottom + "px");++ }+++ // Methods+ exports.drawPartition = drawPartition;++});\ No newline at end of filediff --git a/data/ext/perspectiveGraph/extension.js b/data/ext/perspectiveGraph/extension.jsindex 82cd3cf08..9203e918d 100644--- a/data/ext/perspectiveGraph/extension.js+++ b/data/ext/perspectiveGraph/extension.js@@ -39,74 +39,67 @@ define(function(require, exports, module) {exports.load = function load() {console.log("Loading View "+extensionID);--/* switch (graphMode) {- case "quantYours":- require([- extensionDirectory+'/d3/d3.v3.js',- 'css!'+extensionDirectory+'/styles.css',- ], function() {- reDraw();- TSCORE.hideLoadingAnimation();- });- break;- case "treeMap":- require([- extensionDirectory+'/d3/d3.v3.js',- 'css!'+extensionDirectory+'/styles.css',- ], function() {- TSCORE.IO.createDirectoryTree(TSCORE.currentPath);- });- break;- case "tree":- require([- extensionDirectory+'/d3/d3.v3.js',- 'css!'+extensionDirectory+'/styles.css',- ], function() {- TSCORE.IO.createDirectoryTree(TSCORE.currentPath);- });- break;- default:- break;- } */+ TSCORE.IO.createDirectoryTree(TSCORE.currentPath);}var reDraw = function() {- d3.select("svg").remove();-- var svg = d3.select("#"+extensionID+"Container")- .append("svg")- .attr("width", viewContainer.width())- .attr("height", viewContainer.height())-switch (graphMode) {- case "quantYours":- require([- extensionDirectory+'/quantifiedSelfViz.js',- //'css!'+extensionDirectory+'/styles.css',- ], function(viz) {- viz.draw(svg);- TSCORE.hideLoadingAnimation();- });- break;case "treeMap":require([extensionDirectory+'/treeViz.js',- //'css!'+extensionDirectory+'/styles.css',+ 'css!'+extensionDirectory+'/styles.css',], function(viz) {+ d3.select("svg").remove();+ var svg = d3.select("#"+extensionID+"Container")+ .append("svg")+ .attr("width", viewContainer.width())+ .attr("height", viewContainer.height())viz.drawTreeMap(svg, treeData);TSCORE.hideLoadingAnimation();});break;+ case "treeMap2":+ require([+ extensionDirectory+'/treeMap.js',+ 'css!'+extensionDirectory+'/styles.css',+ ], function(viz) {+ d3.select("svg").remove();+ var svg = d3.select("#"+extensionID+"Container")+ .append("svg")+ .attr("width", viewContainer.width())+ .attr("height", viewContainer.height())+ viz.drawZoomableTreeMap(svg, treeData);+ TSCORE.hideLoadingAnimation();+ });+ break;case "tree":require([extensionDirectory+'/treeViz.js',- //'css!'+extensionDirectory+'/styles.css',+ 'css!'+extensionDirectory+'/styles.css',], function(viz) {+ d3.select("svg").remove();+ var svg = d3.select("#"+extensionID+"Container")+ .append("svg")+ .attr("width", viewContainer.width())+ .attr("height", viewContainer.height())viz.drawTree(svg, treeData);TSCORE.hideLoadingAnimation();});break;+ case "bilevelPartition":+ require([+ extensionDirectory+'/bilevelPartition.js',+ 'css!'+extensionDirectory+'/styles.css',+ ], function(viz) {+ d3.select("svg").remove();+ var svg = d3.select("#"+extensionID+"Container")+ .append("svg")+ .attr("width", viewContainer.width())+ .attr("height", viewContainer.height())+ viz.drawPartition(svg, treeData);+ TSCORE.hideLoadingAnimation();+ });+ break;default:break;}@@ -139,7 +132,6 @@ define(function(require, exports, module) {.append($("<button>", {class: "btn",title: "Activate Treemap Mode",- id: extensionID+"TreeMapMode",text: " TreeMap"}).button('toggle')@@ -150,11 +142,23 @@ define(function(require, exports, module) {}).prepend( "<i class='icon-th-large' />"))++ .append($("<button>", {+ class: "btn",+ title: "Activate Tree Map Navi",+ text: " TreeMap Navi"+ })+ .click(function() {+ graphMode = "treeMap2";+ TSCORE.showLoadingAnimation();+ TSCORE.IO.createDirectoryTree(TSCORE.currentPath);+ })+ .prepend( "<i class='icon-sitemap' />")+ ).append($("<button>", {class: "btn",title: "Activate Tree Mode",- id: extensionID+"TreeMode",text: " Tree"}).click(function() {@@ -163,21 +167,21 @@ define(function(require, exports, module) {TSCORE.IO.createDirectoryTree(TSCORE.currentPath);}).prepend( "<i class='icon-sitemap' />")- )+ )- .append($("<button>", {- class: "btn",- title: "Show Quantified Yourself Graphic",- id: extensionID+"QAMode",- text: " Quantified Self"+ .append($("<button>", {+ class: "btn",+ title: "Activate Bilevel Partition",+ text: " Bilevel Partition"}).click(function() {- graphMode = "quantYours";- TSCORE.showLoadingAnimation();- TSCORE.IO.createDirectoryIndex(TSCORE.currentPath);- })- .prepend( "<i class='icon-tasks' />")- )+ graphMode = "bilevelPartition";+ TSCORE.showLoadingAnimation();+ TSCORE.IO.createDirectoryTree(TSCORE.currentPath);+ })+ .prepend( "<i class='icon-sitemap' />")+ )+) // end button group}diff --git a/data/ext/perspectiveGraph/quantifiedSelfViz.js b/data/ext/perspectiveGraph/quantifiedSelfViz.jsindex 4d6610193..f75a29f38 100644--- a/data/ext/perspectiveGraph/quantifiedSelfViz.js+++ b/data/ext/perspectiveGraph/quantifiedSelfViz.js@@ -8,6 +8,8 @@ define(function(require, exports, module) {var TSCORE = require("tscore");+ require("d3");+var margin = {top: 20, right: 40, bottom: 30, left: 20},width = 960 - margin.left - margin.right,height = 500 - margin.top - margin.bottom,diff --git a/data/ext/perspectiveGraph/treeMap.js b/data/ext/perspectiveGraph/treeMap.jsnew file mode 100644index 000000000..cef772610--- /dev/null+++ b/data/ext/perspectiveGraph/treeMap.js@@ -0,0 +1,176 @@+/* Copyright (c) 2012-2013 The TagSpaces Authors. All rights reserved.+ * Use of this source code is governed by a AGPL3 license that+ * can be found in the LICENSE file. */++define(function(require, exports, module) {+"use strict";+ console.log("Loading Quantified Self");++ var TSCORE = require("tscore");++ require("d3");++ // Based on http://mbostock.github.io/d3/talk/20111018/treemap.html+ var drawZoomableTreeMap = function(svg, treeData) {++ var partition = d3.layout.partition()+ .size([svg.attr("width"), svg.attr("height")])+ .value(function(d) { return d.size; });++ //Setting the data++ var w = svg.attr("width"),+ h = svg.attr("height"),+ x = d3.scale.linear().range([0, w]),+ y = d3.scale.linear().range([0, h]),+ color = d3.scale.category20c(),+ root,+ node;++ var treemap = d3.layout.treemap()+ .round(false)+ .size([w, h])+ .sticky(true)+ .value(function(d) { return d.size; });++ svg.append("svg:g")+ .attr("transform", "translate(.5,.5)");++ node = root = treeData;++ var nodes = treemap.nodes(root)+ .filter(function(d) { return !d.children; });++ var cell = svg.selectAll("g")+ .data(nodes)+ .enter().append("svg:g")+ .attr("class", "cell")+ .attr("transform", function(d) { return "translate(" + d.x + "," + d.y + ")"; })+ .on("click", function(d) { return zoom(node == d.parent ? root : d.parent); });++ cell.append("svg:rect")+ .attr("width", function(d) { return d.dx - 1; })+ .attr("height", function(d) { return d.dy - 1; })+ .style("fill", function(d) { return color(d.parent.name); });++ cell.append("svg:text")+ .attr("x", function(d) { return d.dx / 2; })+ .attr("y", function(d) { return d.dy / 2; })+ .attr("dy", ".35em")+ .attr("text-anchor", "middle")+ .text(function(d) { return d.name; })+ .style("opacity", function(d) { d.w = this.getComputedTextLength(); return d.dx > d.w ? 1 : 0; });++ d3.select(window).on("click", function() { zoom(root); });++ d3.select("select").on("change", function() {+ treemap.value(this.value == "size" ? size : count).nodes(root);+ zoom(node);+ });+++ function size(d) {+ return d.size;+ }++ function count(d) {+ return 1;+ }++ function zoom(d) {+ var kx = w / d.dx, ky = h / d.dy;+ x.domain([d.x, d.x + d.dx]);+ y.domain([d.y, d.y + d.dy]);++ var t = svg.selectAll("g.cell").transition()+ .duration(d3.event.altKey ? 7500 : 750)+ .attr("transform", function(d) { return "translate(" + x(d.x) + "," + y(d.y) + ")"; });++ t.select("rect")+ .attr("width", function(d) { return kx * d.dx - 1; })+ .attr("height", function(d) { return ky * d.dy - 1; })++ t.select("text")+ .attr("x", function(d) { return kx * d.dx / 2; })+ .attr("y", function(d) { return ky * d.dy / 2; })+ .style("opacity", function(d) { return kx * d.dx > d.w ? 1 : 0; });++ node = d;+ d3.event.stopPropagation();+ }+ }++ // Based on http://mbostock.github.io/d3/talk/20111018/partition.html+ // Not working+ var drawTreeMap = function(svg, treeData) {+ //svg.append("g");++ var partition = d3.layout.partition()+ .size([svg.attr("width"), svg.attr("height")])+ .value(function(d) { return d.size; });++ //Setting the data++ var w = svg.attr("width"),+ h = svg.attr("height"),+ x = d3.scale.linear().range([0, w]),+ y = d3.scale.linear().range([0, h]);++ var g = svg.selectAll("g")+ .data(partition.nodes(treeData))+ .enter().append("svg:g")+ .attr("transform", function(d) { return "translate(" + x(d.y) + "," + y(d.x) + ")"; })+ .on("click", click);++ var kx = w / root.dx,+ ky = h / 1;++ g.append("svg:rect")+ .attr("width", root.dy * kx)+ .attr("height", function(d) { return d.dx * ky; })+ .attr("class", function(d) { return d.children ? "parent" : "child"; });++ g.append("svg:text")+ .attr("transform", transform)+ .attr("dy", ".35em")+ .style("opacity", function(d) { return d.dx * ky > 12 ? 1 : 0; })+ .text(function(d) { return d.name; })++ d3.select(window)+ .on("click", function() { click(root); })++ function click(d) {+ if (!d.children) return;++ kx = (d.y ? w - 40 : w) / (1 - d.y);+ ky = h / d.dx;+ x.domain([d.y, 1]).range([d.y ? 40 : 0, w]);+ y.domain([d.x, d.x + d.dx]);++ var t = g.transition()+ .duration(d3.event.altKey ? 7500 : 750)+ .attr("transform", function(d) { return "translate(" + x(d.y) + "," + y(d.x) + ")"; });++ t.select("rect")+ .attr("width", d.dy * kx)+ .attr("height", function(d) { return d.dx * ky; });++ t.select("text")+ .attr("transform", transform)+ .style("opacity", function(d) { return d.dx * ky > 12 ? 1 : 0; });++ d3.event.stopPropagation();+ }++ function transform(d) {+ return "translate(8," + d.dx * ky / 2 + ")";+ }+++ }++ // Methods+ exports.drawTreeMap = drawTreeMap;+ exports.drawZoomableTreeMap = drawZoomableTreeMap;++});\ No newline at end of filediff --git a/data/ext/perspectiveGraph/treeViz.js b/data/ext/perspectiveGraph/treeViz.jsindex e5f273256..8191863f3 100644--- a/data/ext/perspectiveGraph/treeViz.js+++ b/data/ext/perspectiveGraph/treeViz.js@@ -8,7 +8,8 @@ define(function(require, exports, module) {var TSCORE = require("tscore");-+ require("d3");+var drawTree2 = function(svg, treeData) {var diameter = height;