aboutsummaryrefslogtreecommitdiff
path: root/guix
diff options
context:
space:
mode:
authorRicardo Wurmus <rekado@elephly.net>2016-10-22 00:02:19 +0200
committerRicardo Wurmus <rekado@elephly.net>2016-12-14 21:58:32 +0100
commit4d93f312f084c34a70cf7da3abe5f92a74d76861 (patch)
tree27d644c58b079fb19ebcb2a4e4fdeaad047c4641 /guix
parent642339dc3fc6df33edd78f3cdc170c20a32a3c7d (diff)
downloadgnu-guix-4d93f312f084c34a70cf7da3abe5f92a74d76861.tar
gnu-guix-4d93f312f084c34a70cf7da3abe5f92a74d76861.tar.gz
graph: Add d3js backend.
* d3.v3.js, graph.js: New files. * Makefile.am (EXTRA_DIST): List them. * guix/graph.scm (%d3js-backend): New variable. (emit-d3js-prologue, emit-d3js-epilogue, emit-d3js-node, emit-d3js-edge): New procedures. (%graph-backends): Add %d3js-backend.
Diffstat (limited to 'guix')
-rw-r--r--guix/graph.scm51
1 files changed, 50 insertions, 1 deletions
diff --git a/guix/graph.scm b/guix/graph.scm
index d2c1fa6c48..7af2cd3b80 100644
--- a/guix/graph.scm
+++ b/guix/graph.scm
@@ -22,6 +22,7 @@
#:use-module (guix monads)
#:use-module (guix records)
#:use-module (guix sets)
+ #:use-module (rnrs io ports)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-9)
#:use-module (srfi srfi-26)
@@ -43,6 +44,7 @@
node-reachable-count
%graph-backends
+ %d3js-backend
%graphviz-backend
graph-backend?
graph-backend
@@ -183,11 +185,58 @@ typically returned by 'node-edges' or 'node-back-edges'."
;;;
+;;; d3js export.
+;;;
+
+(define (emit-d3js-prologue name port)
+ (format port "\
+<!DOCTYPE html>
+<html>
+ <head>
+ <meta charset=\"utf-8\">
+ <style>
+text {
+ font: 10px sans-serif;
+ pointer-events: none;
+}
+ </style>
+ <script type=\"text/javascript\" src=\"~a\"></script>
+ </head>
+ <body>
+ <script type=\"text/javascript\">
+var nodes = {},
+ nodeArray = [],
+ links = [];
+" (search-path %load-path "d3.v3.js")))
+
+(define (emit-d3js-epilogue port)
+ (format port "</script><script type=\"text/javascript\" src=\"~a\"></script></body></html>"
+ (search-path %load-path "graph.js")))
+
+(define (emit-d3js-node id label port)
+ (format port "\
+nodes[\"~a\"] = {\"id\": \"~a\", \"label\": \"~a\", \"index\": nodeArray.length};
+nodeArray.push(nodes[\"~a\"]);~%"
+ id id label id))
+
+(define (emit-d3js-edge id1 id2 port)
+ (format port "links.push({\"source\": \"~a\", \"target\": \"~a\"});~%"
+ id1 id2))
+
+(define %d3js-backend
+ (graph-backend "d3js"
+ "Generate chord diagrams with d3js."
+ emit-d3js-prologue emit-d3js-epilogue
+ emit-d3js-node emit-d3js-edge))
+
+
+;;;
;;; Shared.
;;;
(define %graph-backends
- (list %graphviz-backend))
+ (list %graphviz-backend
+ %d3js-backend))
(define* (export-graph sinks port
#:key