Debian Codegraph @

htrace-htraced/go/web/app/span_group_widget.js

raw
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 var htrace = htrace || {};
21
22 // Widget containing a group of trace spans displayed on the canvas.
23 htrace.SpanGroupWidget = function(params) {
24 this.draw = function() {
25 this.ctx.save();
26 this.ctx.fillStyle="#ffffff";
27 this.ctx.fillRect(this.x0, this.y0, this.xF - this.x0, this.yF - this.y0);
28 this.ctx.strokeStyle="#aaaaaa";
29 this.ctx.beginPath();
30 this.ctx.moveTo(this.x0, this.y0);
31 this.ctx.lineTo(this.xF, this.y0);
32 this.ctx.stroke();
33 this.ctx.beginPath();
34 this.ctx.moveTo(this.x0, this.yF);
35 this.ctx.lineTo(this.xF, this.yF);
36 this.ctx.stroke();
37 this.ctx.restore();
38 return true;
39 };
40
41 this.createSpanWidget = function(node, indentLevel,
42 allowUpButton, allowDownButton) {
43 new htrace.SpanWidget({
44 manager: this.manager,
45 ctx: this.ctx,
46 span: node,
47 x0: this.x0,
48 xB: this.xB,
49 xD: this.xD,
50 xF: this.xF,
51 xT: this.childIndent * indentLevel,
52 y0: this.spanY,
53 yF: this.spanY + this.spanWidgetHeight,
54 allowUpButton: allowUpButton,
55 allowDownButton: allowDownButton,
56 begin: this.begin,
57 end: this.end
58 });
59 this.spanY += this.spanWidgetHeight;
60 }
61
62 this.handle = function(e) {
63 switch (e.type) {
64 case "draw":
65 this.draw();
66 return true;
67 }
68 }
69
70 for (var k in params) {
71 this[k]=params[k];
72 }
73 this.manager.register("draw", this);
74 this.spanY = this.y0 + 4;
75
76 // Figure out how much to indent each child's description text.
77 this.childIndent = Math.max(10, (this.xF - this.xD) / 50);
78
79 // Get the maximum depth of the parents tree to find out how far to indent.
80 var parentTreeHeight =
81 htrace.treeHeight(this.span, htrace.getReifiedParents);
82
83 // Traverse the parents tree upwards.
84 var thisWidget = this;
85 htrace.treeTraverseDepthFirstPost(this.span, htrace.getReifiedParents, 0,
86 function(node, depth) {
87 if (depth > 0) {
88 thisWidget.createSpanWidget(node,
89 parentTreeHeight - depth, true, false);
90 }
91 });
92 thisWidget.createSpanWidget(this.span, parentTreeHeight, true, true);
93 // Traverse the children tree downwards.
94 htrace.treeTraverseDepthFirstPre(this.span, htrace.getReifiedChildren, 0,
95 function(node, depth) {
96 if (depth > 0) {
97 thisWidget.createSpanWidget(node,
98 parentTreeHeight + depth, false, true);
99 }
100 });
101 this.yF = this.spanY + 4;
102 return this;
103 };