test-prof 0.1.0.beta4 → 0.1.0.pre2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +10 -0
- data/.rspec +2 -0
- data/.rubocop.yml +69 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/README.md +2 -16
- data/Rakefile +8 -0
- data/bin/setup +8 -0
- data/circle.yml +11 -0
- data/guides/any_fixture.md +1 -1
- data/guides/ruby_prof.md +0 -2
- data/guides/stack_prof.md +1 -5
- data/lib/test_prof.rb +6 -31
- data/lib/test_prof/event_prof.rb +4 -2
- data/lib/test_prof/event_prof/custom_events.rb +3 -3
- data/lib/test_prof/event_prof/custom_events/factory_create.rb +9 -11
- data/lib/test_prof/event_prof/custom_events/sidekiq_inline.rb +9 -11
- data/lib/test_prof/event_prof/custom_events/sidekiq_jobs.rb +11 -13
- data/lib/test_prof/event_prof/rspec.rb +1 -5
- data/lib/test_prof/factory_doctor.rb +9 -11
- data/lib/test_prof/factory_doctor/rspec.rb +3 -5
- data/lib/test_prof/ruby_prof.rb +12 -6
- data/lib/test_prof/stack_prof.rb +7 -14
- data/lib/test_prof/version.rb +1 -1
- data/spec/integrations/any_fixture_spec.rb +11 -0
- data/spec/integrations/before_all_spec.rb +11 -0
- data/spec/integrations/event_prof_spec.rb +100 -0
- data/spec/integrations/factory_doctor_spec.rb +20 -0
- data/spec/integrations/fixtures/rspec/any_fixture_fixture.rb +37 -0
- data/spec/integrations/fixtures/rspec/before_all_fixture.rb +32 -0
- data/spec/integrations/fixtures/rspec/event_prof_factory_create_fixture.rb +23 -0
- data/spec/integrations/fixtures/rspec/event_prof_fixture.rb +51 -0
- data/spec/integrations/fixtures/rspec/event_prof_sidekiq_fixture.rb +54 -0
- data/spec/integrations/fixtures/rspec/factory_doctor_fixture.rb +33 -0
- data/spec/spec_helper.rb +38 -0
- data/spec/support/ar_models.rb +43 -0
- data/spec/support/instrumenter_stub.rb +19 -0
- data/spec/support/integration_helpers.rb +13 -0
- data/spec/support/transactional_context.rb +11 -0
- data/spec/test_prof/any_fixture_spec.rb +66 -0
- data/spec/test_prof/event_prof_spec.rb +138 -0
- data/spec/test_prof/ext/float_duration_spec.rb +12 -0
- data/spec/test_prof/factory_doctor_spec.rb +84 -0
- data/spec/test_prof/ruby_prof_spec.rb +109 -0
- data/spec/test_prof/stack_prof_spec.rb +73 -0
- data/spec/test_prof_spec.rb +23 -0
- data/test-prof.gemspec +35 -0
- metadata +34 -49
- data/CHANGELOG.md +0 -7
- data/assets/flamegraph.demo.html +0 -173
- data/assets/flamegraph.template.html +0 -196
- data/assets/src/d3-tip.js +0 -352
- data/assets/src/d3-tip.min.js +0 -1
- data/assets/src/d3.flameGraph.css +0 -92
- data/assets/src/d3.flameGraph.js +0 -459
- data/assets/src/d3.flameGraph.min.css +0 -1
- data/assets/src/d3.flameGraph.min.js +0 -1
- data/assets/src/d3.v4.min.js +0 -8
- data/guides/factory_default.md +0 -109
- data/guides/factory_prof.md +0 -85
- data/guides/rspec_stamp.md +0 -53
- data/guides/rubocop.md +0 -48
- data/guides/tag_prof.md +0 -52
- data/guides/tests_sampling.md +0 -24
- data/lib/test_prof/cops/rspec/aggregate_failures.rb +0 -140
- data/lib/test_prof/factory_default.rb +0 -58
- data/lib/test_prof/factory_default/factory_girl_patch.rb +0 -22
- data/lib/test_prof/factory_prof.rb +0 -140
- data/lib/test_prof/factory_prof/factory_girl_patch.rb +0 -12
- data/lib/test_prof/factory_prof/printers/flamegraph.rb +0 -71
- data/lib/test_prof/factory_prof/printers/simple.rb +0 -28
- data/lib/test_prof/recipes/minitest/sample.rb +0 -29
- data/lib/test_prof/recipes/rspec/factory_default.rb +0 -9
- data/lib/test_prof/recipes/rspec/sample.rb +0 -13
- data/lib/test_prof/rspec_stamp.rb +0 -135
- data/lib/test_prof/rspec_stamp/parser.rb +0 -103
- data/lib/test_prof/rspec_stamp/rspec.rb +0 -95
- data/lib/test_prof/rubocop.rb +0 -3
- data/lib/test_prof/tag_prof.rb +0 -8
- data/lib/test_prof/tag_prof/rspec.rb +0 -84
data/assets/src/d3-tip.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
!function(t,e){if("function"==typeof define&&define.amd)define(["d3-collection","d3-selection"],e);else if("object"==typeof module&&module.exports){var n=require("d3-collection"),r=require("d3-selection");module.exports=e(n,r)}else{var o=t.d3;t.d3.tip=e(o,o)}}(this,function(t,e){return function(){function n(t){(C=m(t))&&(H=C.createSVGPoint(),b.appendChild(E))}function r(){return"n"}function o(){return[0,0]}function l(){return" "}function i(){var t=x();return{top:t.n.y-E.offsetHeight,left:t.n.x-E.offsetWidth/2}}function f(){var t=x();return{top:t.s.y,left:t.s.x-E.offsetWidth/2}}function u(){var t=x();return{top:t.e.y-E.offsetHeight/2,left:t.e.x}}function s(){var t=x();return{top:t.w.y-E.offsetHeight/2,left:t.w.x-E.offsetWidth}}function a(){var t=x();return{top:t.nw.y-E.offsetHeight,left:t.nw.x-E.offsetWidth}}function c(){var t=x();return{top:t.ne.y-E.offsetHeight,left:t.ne.x}}function p(){var t=x();return{top:t.sw.y,left:t.sw.x-E.offsetWidth}}function y(){var t=x();return{top:t.se.y,left:t.se.x}}function d(){var t=e.select(document.createElement("div"));return t.style("position","absolute").style("top",0).style("opacity",0).style("pointer-events","none").style("box-sizing","border-box"),t.node()}function m(t){var e=t.node();return e?"svg"===e.tagName.toLowerCase()?e:e.ownerSVGElement:null}function h(){return null==E&&(E=d(),b.appendChild(E)),e.select(E)}function x(){for(var t=S||e.event.target;null==t.getScreenCTM&&null==t.parentNode;)t=t.parentNode;var n={},r=t.getScreenCTM(),o=t.getBBox(),l=o.width,i=o.height,f=o.x,u=o.y;return H.x=f,H.y=u,n.nw=H.matrixTransform(r),H.x+=l,n.ne=H.matrixTransform(r),H.y+=i,n.se=H.matrixTransform(r),H.x-=l,n.sw=H.matrixTransform(r),H.y-=i/2,n.w=H.matrixTransform(r),H.x+=l,n.e=H.matrixTransform(r),H.x-=l/2,H.y-=i/2,n.n=H.matrixTransform(r),H.y+=i,n.s=H.matrixTransform(r),n}function v(t){return"function"==typeof t?t:function(){return t}}var g=r,w=o,T=l,b=document.body,E=d(),C=null,H=null,S=null;n.show=function(){var t=Array.prototype.slice.call(arguments);t[t.length-1]instanceof SVGElement&&(S=t.pop());var e,r=T.apply(this,t),o=w.apply(this,t),l=g.apply(this,t),i=h(),f=A.length,u=document.documentElement.scrollTop||b.scrollTop,s=document.documentElement.scrollLeft||b.scrollLeft;for(i.html(r).style("opacity",1).style("pointer-events","all");f--;)i.classed(A[f],!1);return e=W.get(l).apply(this),i.classed(l,!0).style("top",e.top+o[0]+u+"px").style("left",e.left+o[1]+s+"px"),n},n.hide=function(){return h().style("opacity",0).style("pointer-events","none"),n},n.attr=function(t,r){if(arguments.length<2&&"string"==typeof t)return h().attr(t);var o=Array.prototype.slice.call(arguments);return e.selection.prototype.attr.apply(h(),o),n},n.style=function(t,r){if(arguments.length<2&&"string"==typeof t)return h().style(t);var o=Array.prototype.slice.call(arguments);return e.selection.prototype.style.apply(h(),o),n},n.direction=function(t){return arguments.length?(g=null==t?t:v(t),n):g},n.offset=function(t){return arguments.length?(w=null==t?t:v(t),n):w},n.html=function(t){return arguments.length?(T=null==t?t:v(t),n):T},n.rootElement=function(t){return arguments.length?(b=null==t?t:v(t),n):b},n.destroy=function(){return E&&(h().remove(),E=null),n};var W=t.map({n:i,s:f,e:u,w:s,nw:a,ne:c,sw:p,se:y}),A=W.keys();return n}});
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
.d3-flame-graph rect {
|
|
2
|
-
stroke: #EEEEEE;
|
|
3
|
-
fill-opacity: .8;
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
.d3-flame-graph rect:hover {
|
|
7
|
-
stroke: #474747;
|
|
8
|
-
stroke-width: 0.5;
|
|
9
|
-
cursor: pointer;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.d3-flame-graph .label {
|
|
13
|
-
pointer-events: none;
|
|
14
|
-
white-space: nowrap;
|
|
15
|
-
text-overflow: ellipsis;
|
|
16
|
-
overflow: hidden;
|
|
17
|
-
font-size: 12px;
|
|
18
|
-
font-family: Verdana;
|
|
19
|
-
margin-left: 4px;
|
|
20
|
-
margin-right: 4px;
|
|
21
|
-
line-height: 1.5;
|
|
22
|
-
padding: 0 0 0;
|
|
23
|
-
font-weight: 400;
|
|
24
|
-
color: black;
|
|
25
|
-
text-align: left;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
.d3-flame-graph .fade {
|
|
29
|
-
opacity: 0.6 !important;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
.d3-flame-graph .title {
|
|
33
|
-
font-size: 20px;
|
|
34
|
-
font-family: Verdana;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
.d3-flame-graph-tip {
|
|
38
|
-
line-height: 1;
|
|
39
|
-
font-family: Verdana;
|
|
40
|
-
font-size: 12px;
|
|
41
|
-
padding: 12px;
|
|
42
|
-
background: rgba(0, 0, 0, 0.8);
|
|
43
|
-
color: #fff;
|
|
44
|
-
border-radius: 2px;
|
|
45
|
-
pointer-events: none;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/* Creates a small triangle extender for the tooltip */
|
|
49
|
-
.d3-flame-graph-tip:after {
|
|
50
|
-
box-sizing: border-box;
|
|
51
|
-
display: inline;
|
|
52
|
-
font-size: 10px;
|
|
53
|
-
width: 100%;
|
|
54
|
-
line-height: 1;
|
|
55
|
-
color: rgba(0, 0, 0, 0.8);
|
|
56
|
-
position: absolute;
|
|
57
|
-
pointer-events: none;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/* Northward tooltips */
|
|
61
|
-
.d3-flame-graph-tip.n:after {
|
|
62
|
-
content: "\25BC";
|
|
63
|
-
margin: -1px 0 0 0;
|
|
64
|
-
top: 100%;
|
|
65
|
-
left: 0;
|
|
66
|
-
text-align: center;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/* Eastward tooltips */
|
|
70
|
-
.d3-flame-graph-tip.e:after {
|
|
71
|
-
content: "\25C0";
|
|
72
|
-
margin: -4px 0 0 0;
|
|
73
|
-
top: 50%;
|
|
74
|
-
left: -8px;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/* Southward tooltips */
|
|
78
|
-
.d3-flame-graph-tip.s:after {
|
|
79
|
-
content: "\25B2";
|
|
80
|
-
margin: 0 0 1px 0;
|
|
81
|
-
top: -8px;
|
|
82
|
-
left: 0;
|
|
83
|
-
text-align: center;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/* Westward tooltips */
|
|
87
|
-
.d3-flame-graph-tip.w:after {
|
|
88
|
-
content: "\25B6";
|
|
89
|
-
margin: -4px 0 0 -1px;
|
|
90
|
-
top: 50%;
|
|
91
|
-
left: 100%;
|
|
92
|
-
}
|
data/assets/src/d3.flameGraph.js
DELETED
|
@@ -1,459 +0,0 @@
|
|
|
1
|
-
(function() {
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
function flameGraph() {
|
|
5
|
-
|
|
6
|
-
var w = 960, // graph width
|
|
7
|
-
h = 540, // graph height
|
|
8
|
-
c = 18, // cell height
|
|
9
|
-
selection = null, // selection
|
|
10
|
-
tooltip = true, // enable tooltip
|
|
11
|
-
title = "", // graph title
|
|
12
|
-
transitionDuration = 750,
|
|
13
|
-
transitionEase = d3.easeCubic, // tooltip offset
|
|
14
|
-
sort = true,
|
|
15
|
-
reversed = false, // reverse the graph direction
|
|
16
|
-
clickHandler = null;
|
|
17
|
-
|
|
18
|
-
var tip = d3.tip()
|
|
19
|
-
.direction("s")
|
|
20
|
-
.offset([8, 0])
|
|
21
|
-
.attr('class', 'd3-flame-graph-tip')
|
|
22
|
-
.html(function(d) { return label(d); });
|
|
23
|
-
|
|
24
|
-
var svg;
|
|
25
|
-
|
|
26
|
-
var label = function(d) {
|
|
27
|
-
return d.data.name + " (" + d3.format(".3f")(100 * (d.x1 - d.x0), 3) + "%, " + d.data.value + " samples)";
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
function setDetails(t) {
|
|
31
|
-
var details = document.getElementById("details");
|
|
32
|
-
if (details)
|
|
33
|
-
details.innerHTML = t;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
function name(d) {
|
|
37
|
-
return d.data.name;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
var colorMapper = function(d) {
|
|
41
|
-
return d.highlight ? "#E600E6" : colorHash(d.data);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
function generateHash(name) {
|
|
45
|
-
// Return a vector (0.0->1.0) that is a hash of the input string.
|
|
46
|
-
// The hash is computed to favor early characters over later ones, so
|
|
47
|
-
// that strings with similar starts have similar vectors. Only the first
|
|
48
|
-
// 6 characters are considered.
|
|
49
|
-
var hash = 0, weight = 1, max_hash = 0, mod = 10, max_char = 6;
|
|
50
|
-
if (name) {
|
|
51
|
-
for (var i = 0; i < name.length; i++) {
|
|
52
|
-
if (i > max_char) { break; }
|
|
53
|
-
hash += weight * (name.charCodeAt(i) % mod);
|
|
54
|
-
max_hash += weight * (mod - 1);
|
|
55
|
-
weight *= 0.70;
|
|
56
|
-
}
|
|
57
|
-
if (max_hash > 0) { hash = hash / max_hash; }
|
|
58
|
-
}
|
|
59
|
-
return hash;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function colorHash(data) {
|
|
63
|
-
var name = data.name;
|
|
64
|
-
|
|
65
|
-
if (data.color) {
|
|
66
|
-
return data.color;
|
|
67
|
-
}
|
|
68
|
-
// Return an rgb() color string that is a hash of the provided name,
|
|
69
|
-
// and with a warm palette.
|
|
70
|
-
var vector = 0;
|
|
71
|
-
if (name) {
|
|
72
|
-
name = name.replace(/.*`/, ""); // drop module name if present
|
|
73
|
-
name = name.replace(/\(.*/, ""); // drop extra info
|
|
74
|
-
vector = generateHash(name);
|
|
75
|
-
}
|
|
76
|
-
var r = 200 + Math.round(55 * vector);
|
|
77
|
-
var g = 0 + Math.round(230 * vector);
|
|
78
|
-
var b = 0 + Math.round(55 * vector);
|
|
79
|
-
data.color = "rgb(" + r + "," + g + "," + b + ")";
|
|
80
|
-
return data.color;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function hide(d) {
|
|
84
|
-
if(!d.data.original) {
|
|
85
|
-
d.data.original = d.data.value;
|
|
86
|
-
}
|
|
87
|
-
d.data.value = 0;
|
|
88
|
-
if(d.children) {
|
|
89
|
-
d.children.forEach(hide);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function show(d) {
|
|
94
|
-
d.data.fade = false;
|
|
95
|
-
if(d.data.original) {
|
|
96
|
-
d.data.value = d.data.original;
|
|
97
|
-
}
|
|
98
|
-
if(d.children) {
|
|
99
|
-
d.children.forEach(show);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
function getSiblings(d) {
|
|
104
|
-
var siblings = [];
|
|
105
|
-
if (d.parent) {
|
|
106
|
-
var me = d.parent.children.indexOf(d);
|
|
107
|
-
siblings = d.parent.children.slice(0);
|
|
108
|
-
siblings.splice(me, 1);
|
|
109
|
-
}
|
|
110
|
-
return siblings;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function hideSiblings(d) {
|
|
114
|
-
var siblings = getSiblings(d);
|
|
115
|
-
siblings.forEach(function(s) {
|
|
116
|
-
hide(s);
|
|
117
|
-
});
|
|
118
|
-
if(d.parent) {
|
|
119
|
-
hideSiblings(d.parent);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function fadeAncestors(d) {
|
|
124
|
-
if(d.parent) {
|
|
125
|
-
d.parent.data.fade = true;
|
|
126
|
-
fadeAncestors(d.parent);
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function getRoot(d) {
|
|
131
|
-
if(d.parent) {
|
|
132
|
-
return getRoot(d.parent);
|
|
133
|
-
}
|
|
134
|
-
return d;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
function zoom(d) {
|
|
138
|
-
tip.hide(d);
|
|
139
|
-
hideSiblings(d);
|
|
140
|
-
show(d);
|
|
141
|
-
fadeAncestors(d);
|
|
142
|
-
update();
|
|
143
|
-
if (typeof clickHandler === 'function') {
|
|
144
|
-
clickHandler(d);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
function searchTree(d, term) {
|
|
149
|
-
var re = new RegExp(term),
|
|
150
|
-
searchResults = [];
|
|
151
|
-
|
|
152
|
-
function searchInner(d) {
|
|
153
|
-
var label = d.data.name;
|
|
154
|
-
|
|
155
|
-
if (d.children) {
|
|
156
|
-
d.children.forEach(function (child) {
|
|
157
|
-
searchInner(child);
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (label.match(re)) {
|
|
162
|
-
d.highlight = true;
|
|
163
|
-
searchResults.push(d);
|
|
164
|
-
} else {
|
|
165
|
-
d.highlight = false;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
searchInner(d);
|
|
170
|
-
return searchResults;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function clear(d) {
|
|
174
|
-
d.highlight = false;
|
|
175
|
-
if(d.children) {
|
|
176
|
-
d.children.forEach(function(child) {
|
|
177
|
-
clear(child);
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
function doSort(a, b) {
|
|
183
|
-
if (typeof sort === 'function') {
|
|
184
|
-
return sort(a, b);
|
|
185
|
-
} else if (sort) {
|
|
186
|
-
return d3.ascending(a.data.name, b.data.name);
|
|
187
|
-
} else {
|
|
188
|
-
return 0;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
var partition = d3.partition();
|
|
193
|
-
|
|
194
|
-
function update() {
|
|
195
|
-
|
|
196
|
-
selection.each(function(root) {
|
|
197
|
-
var x = d3.scaleLinear().range([0, w]),
|
|
198
|
-
y = d3.scaleLinear().range([0, c]);
|
|
199
|
-
|
|
200
|
-
root.sort(doSort);
|
|
201
|
-
root.sum(function(d) {
|
|
202
|
-
if (d.fade) {
|
|
203
|
-
return 0;
|
|
204
|
-
}
|
|
205
|
-
// The node's self value is its total value minus all children.
|
|
206
|
-
var v = d.v || d.value || 0;
|
|
207
|
-
if (d.children) {
|
|
208
|
-
for (var i = 0; i < d.children.length; i++) {
|
|
209
|
-
v -= d.children[i].value;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
return v;
|
|
213
|
-
});
|
|
214
|
-
partition(root);
|
|
215
|
-
|
|
216
|
-
var kx = w / (root.x1 - root.x0);
|
|
217
|
-
function width(d) { return (d.x1 - d.x0) * kx; }
|
|
218
|
-
|
|
219
|
-
var g = d3.select(this).select("svg").selectAll("g").data(root.descendants());
|
|
220
|
-
|
|
221
|
-
g.transition()
|
|
222
|
-
.duration(transitionDuration)
|
|
223
|
-
.ease(transitionEase)
|
|
224
|
-
.attr("transform", function(d) { return "translate(" + x(d.x0) + ","
|
|
225
|
-
+ (reversed ? y(d.depth) : (h - y(d.depth) - c)) + ")"; });
|
|
226
|
-
|
|
227
|
-
g.select("rect").transition()
|
|
228
|
-
.duration(transitionDuration)
|
|
229
|
-
.ease(transitionEase)
|
|
230
|
-
.attr("width", width);
|
|
231
|
-
|
|
232
|
-
var node = g.enter()
|
|
233
|
-
.append("svg:g")
|
|
234
|
-
.attr("transform", function(d) { return "translate(" + x(d.x0) + ","
|
|
235
|
-
+ (reversed ? y(d.depth) : (h - y(d.depth) - c)) + ")"; });
|
|
236
|
-
|
|
237
|
-
node.append("svg:rect").attr("width", width);
|
|
238
|
-
|
|
239
|
-
if (!tooltip)
|
|
240
|
-
node.append("svg:title");
|
|
241
|
-
|
|
242
|
-
node.append("foreignObject")
|
|
243
|
-
.append("xhtml:div");
|
|
244
|
-
|
|
245
|
-
// Now we have to re-select to see the new elements (why?).
|
|
246
|
-
g = d3.select(this).select("svg").selectAll("g").data(root.descendants());
|
|
247
|
-
|
|
248
|
-
g.attr("width", width)
|
|
249
|
-
.attr("height", function(d) { return c; })
|
|
250
|
-
.attr("name", function(d) { return d.data.name; })
|
|
251
|
-
.attr("class", function(d) { return d.data.fade ? "frame fade" : "frame"; });
|
|
252
|
-
|
|
253
|
-
g.select("rect")
|
|
254
|
-
.attr("height", function(d) { return c; })
|
|
255
|
-
.attr("fill", function(d) { return colorMapper(d); });
|
|
256
|
-
|
|
257
|
-
if (!tooltip)
|
|
258
|
-
g.select("title")
|
|
259
|
-
.text(label);
|
|
260
|
-
|
|
261
|
-
g.select("foreignObject")
|
|
262
|
-
.attr("width", width)
|
|
263
|
-
.attr("height", function(d) { return c; })
|
|
264
|
-
.select("div")
|
|
265
|
-
.attr("class", "label")
|
|
266
|
-
.style("display", function(d) { return (width(d) < 35) ? "none" : "block";})
|
|
267
|
-
.text(name);
|
|
268
|
-
|
|
269
|
-
g.on('click', zoom);
|
|
270
|
-
|
|
271
|
-
g.exit().remove();
|
|
272
|
-
|
|
273
|
-
g.on('mouseover', function(d) {
|
|
274
|
-
if (tooltip) tip.show(d);
|
|
275
|
-
setDetails(label(d));
|
|
276
|
-
}).on('mouseout', function(d) {
|
|
277
|
-
if (tooltip) tip.hide(d);
|
|
278
|
-
setDetails("");
|
|
279
|
-
});
|
|
280
|
-
});
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
function merge(data, samples) {
|
|
284
|
-
samples.forEach(function (sample) {
|
|
285
|
-
var node = _.find(data, function (element) {
|
|
286
|
-
return element.name === sample.name;
|
|
287
|
-
});
|
|
288
|
-
|
|
289
|
-
if (node) {
|
|
290
|
-
if (node.original) {
|
|
291
|
-
node.original += sample.value;
|
|
292
|
-
} else {
|
|
293
|
-
node.value += sample.value;
|
|
294
|
-
}
|
|
295
|
-
if (sample.children) {
|
|
296
|
-
if (!node.children) {
|
|
297
|
-
node.children = [];
|
|
298
|
-
}
|
|
299
|
-
merge(node.children, sample.children)
|
|
300
|
-
}
|
|
301
|
-
} else {
|
|
302
|
-
data.push(sample);
|
|
303
|
-
}
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
function chart(s) {
|
|
308
|
-
var root = d3.hierarchy(s.datum(), function(d) { return d.c || d.children; });
|
|
309
|
-
selection = s.datum(root);
|
|
310
|
-
|
|
311
|
-
if (!arguments.length) return chart;
|
|
312
|
-
|
|
313
|
-
selection.each(function(data) {
|
|
314
|
-
|
|
315
|
-
if (!svg) {
|
|
316
|
-
svg = d3.select(this)
|
|
317
|
-
.append("svg:svg")
|
|
318
|
-
.attr("width", w)
|
|
319
|
-
.attr("height", h)
|
|
320
|
-
.attr("class", "partition d3-flame-graph")
|
|
321
|
-
.call(tip);
|
|
322
|
-
|
|
323
|
-
svg.append("svg:text")
|
|
324
|
-
.attr("class", "title")
|
|
325
|
-
.attr("text-anchor", "middle")
|
|
326
|
-
.attr("y", "25")
|
|
327
|
-
.attr("x", w/2)
|
|
328
|
-
.attr("fill", "#808080")
|
|
329
|
-
.text(title);
|
|
330
|
-
}
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
// first draw
|
|
334
|
-
update();
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
chart.height = function (_) {
|
|
338
|
-
if (!arguments.length) { return h; }
|
|
339
|
-
h = _;
|
|
340
|
-
return chart;
|
|
341
|
-
};
|
|
342
|
-
|
|
343
|
-
chart.width = function (_) {
|
|
344
|
-
if (!arguments.length) { return w; }
|
|
345
|
-
w = _;
|
|
346
|
-
return chart;
|
|
347
|
-
};
|
|
348
|
-
|
|
349
|
-
chart.cellHeight = function (_) {
|
|
350
|
-
if (!arguments.length) { return c; }
|
|
351
|
-
c = _;
|
|
352
|
-
return chart;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
chart.tooltip = function (_) {
|
|
356
|
-
if (!arguments.length) { return tooltip; }
|
|
357
|
-
if (typeof _ === "function") {
|
|
358
|
-
tip = _;
|
|
359
|
-
}
|
|
360
|
-
tooltip = true;
|
|
361
|
-
return chart;
|
|
362
|
-
};
|
|
363
|
-
|
|
364
|
-
chart.title = function (_) {
|
|
365
|
-
if (!arguments.length) { return title; }
|
|
366
|
-
title = _;
|
|
367
|
-
return chart;
|
|
368
|
-
};
|
|
369
|
-
|
|
370
|
-
chart.transitionDuration = function (_) {
|
|
371
|
-
if (!arguments.length) { return transitionDuration; }
|
|
372
|
-
transitionDuration = _;
|
|
373
|
-
return chart;
|
|
374
|
-
};
|
|
375
|
-
|
|
376
|
-
chart.transitionEase = function (_) {
|
|
377
|
-
if (!arguments.length) { return transitionEase; }
|
|
378
|
-
transitionEase = _;
|
|
379
|
-
return chart;
|
|
380
|
-
};
|
|
381
|
-
|
|
382
|
-
chart.sort = function (_) {
|
|
383
|
-
if (!arguments.length) { return sort; }
|
|
384
|
-
sort = _;
|
|
385
|
-
return chart;
|
|
386
|
-
};
|
|
387
|
-
|
|
388
|
-
chart.reversed = function (_) {
|
|
389
|
-
if (!arguments.length) { return reversed; }
|
|
390
|
-
reversed = _;
|
|
391
|
-
return chart;
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
chart.label = function(_) {
|
|
395
|
-
if (!arguments.length) { return label; }
|
|
396
|
-
label = _;
|
|
397
|
-
return chart;
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
chart.search = function(term) {
|
|
401
|
-
var searchResults = [];
|
|
402
|
-
selection.each(function(data) {
|
|
403
|
-
searchResults = searchTree(data, term);
|
|
404
|
-
update();
|
|
405
|
-
});
|
|
406
|
-
return searchResults;
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
chart.clear = function() {
|
|
410
|
-
selection.each(function(data) {
|
|
411
|
-
clear(data);
|
|
412
|
-
update();
|
|
413
|
-
});
|
|
414
|
-
};
|
|
415
|
-
|
|
416
|
-
chart.zoomTo = function(d) {
|
|
417
|
-
zoom(d);
|
|
418
|
-
};
|
|
419
|
-
|
|
420
|
-
chart.resetZoom = function() {
|
|
421
|
-
selection.each(function (data) {
|
|
422
|
-
zoom(data); // zoom to root
|
|
423
|
-
});
|
|
424
|
-
};
|
|
425
|
-
|
|
426
|
-
chart.onClick = function(_) {
|
|
427
|
-
if (!arguments.length) {
|
|
428
|
-
return clickHandler;
|
|
429
|
-
}
|
|
430
|
-
clickHandler = _;
|
|
431
|
-
return chart;
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
chart.merge = function(samples) {
|
|
435
|
-
var newRoot; // Need to re-create hierarchy after data changes.
|
|
436
|
-
selection.each(function (root) {
|
|
437
|
-
merge([root.data], [samples]);
|
|
438
|
-
newRoot = d3.hierarchy(root.data, function(d) { return d.c || d.children; });
|
|
439
|
-
});
|
|
440
|
-
selection = selection.datum(newRoot);
|
|
441
|
-
update();
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
chart.color = function(_) {
|
|
445
|
-
if (!arguments.length) { return colorMapper; }
|
|
446
|
-
colorMapper = _;
|
|
447
|
-
return chart;
|
|
448
|
-
};
|
|
449
|
-
|
|
450
|
-
return chart;
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
if (typeof module !== 'undefined' && module.exports){
|
|
454
|
-
module.exports = flameGraph;
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
d3.flameGraph = flameGraph;
|
|
458
|
-
}
|
|
459
|
-
})();
|