From 4d93f312f084c34a70cf7da3abe5f92a74d76861 Mon Sep 17 00:00:00 2001 From: Ricardo Wurmus Date: Sat, 22 Oct 2016 00:02:19 +0200 Subject: 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. --- guix/graph.scm | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) (limited to 'guix/graph.scm') 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 @@ -181,13 +183,60 @@ typically returned by 'node-edges' or 'node-back-edges'." emit-prologue emit-epilogue emit-node emit-edge)) + +;;; +;;; d3js export. +;;; + +(define (emit-d3js-prologue name port) + (format port "\ + + + + + + + + + " + (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 -- cgit v1.2.3