-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
svg.js
40 lines (31 loc) · 997 Bytes
/
svg.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
var xtend = require('xtend')
, contextify = require('./contextify')
, svgTemplate = require('./svg-template')
, defaultOpts = require('./default-opts')
function narrowify(context, opts) {
function processNode(n) {
n.class = n.narrow ? 'hidden' : '';
}
function filterNode(n) {
return !n.narrow;
}
if (opts.removenarrows) context.nodes = context.nodes.filter(filterNode);
else context.nodes.forEach(processNode);
}
var go = module.exports =
/**
* Creates a context from a call graph that has been collapsed (`stackcollapse-*`) and renders svg from it.
*
* @name flamegraph::svg
* @function
* @param {Array.<string>} collapsedLines callgraph that has been collapsed
* @param {Object} opts options
* @return {string} svg
*/
function svg(processedCpuProfile, opts) {
opts = xtend(defaultOpts, opts);
var context = contextify(processedCpuProfile, opts)
narrowify(context, opts);
return svgTemplate(context);
}