fix: update trace tree

This commit is contained in:
Qiuxia Fan 2022-02-25 13:31:52 +08:00
parent bbb57160fe
commit 8c7d708257
6 changed files with 56 additions and 33 deletions

View File

@ -90,6 +90,9 @@ const msg = {
backgroundColors: "Background Colors", backgroundColors: "Background Colors",
fontColors: "Font Colors", fontColors: "Font Colors",
iconTheme: "Icon Theme", iconTheme: "Icon Theme",
default: "Default",
topSlow: "Top 5 of slow",
topChildren: "Top 5 of children",
hourTip: "Select Hour", hourTip: "Select Hour",
minuteTip: "Select Minute", minuteTip: "Select Minute",
secondTip: "Select Second", secondTip: "Select Second",

View File

@ -89,6 +89,9 @@ const msg = {
backgroundColors: "背景颜色", backgroundColors: "背景颜色",
fontColors: "字体颜色", fontColors: "字体颜色",
iconTheme: "图标主题", iconTheme: "图标主题",
default: "默认",
topSlow: "迟缓的前5名",
topChildren: "小孩数量的前5名",
showDepth: "展示深度选择器", showDepth: "展示深度选择器",
hourTip: "选择小时", hourTip: "选择小时",
minuteTip: "选择分钟", minuteTip: "选择分钟",

View File

@ -14,7 +14,7 @@ limitations under the License. -->
<div class="trace-t-loading" v-show="loading"> <div class="trace-t-loading" v-show="loading">
<Icon iconName="spinner" size="sm" /> <Icon iconName="spinner" size="sm" />
</div> </div>
<div ref="traceGraph"></div> <div ref="traceGraph" class="d3-graph"></div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref, watch, onBeforeUnmount, onMounted } from "vue"; import { ref, watch, onBeforeUnmount, onMounted } from "vue";
@ -62,7 +62,11 @@ onMounted(() => {
); );
} }
loading.value = false; loading.value = false;
window.addEventListener("resize", resize);
}); });
function resize() {
tree.value.resize();
}
function handleSelectSpan(i: any) { function handleSelectSpan(i: any) {
currentSpan.value = i.data; currentSpan.value = i.data;
showDetail.value = true; showDetail.value = true;
@ -263,6 +267,7 @@ function collapse(d: Span) {
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
d3.selectAll(".d3-tip").remove(); d3.selectAll(".d3-tip").remove();
window.removeEventListener("resize", resize);
}); });
watch( watch(
() => props.data, () => props.data,
@ -286,6 +291,10 @@ watch(
); );
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.d3-graph {
height: 100%;
}
.trace-node .group { .trace-node .group {
cursor: pointer; cursor: pointer;
fill-opacity: 0; fill-opacity: 0;

View File

@ -11,10 +11,10 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div class="time-charts"> <div class="charts">
<div> <div>
<span <span
class="time-charts-item mr-5" class="charts-item mr-5"
v-for="(i, index) in list" v-for="(i, index) in list"
:key="index" :key="index"
:style="`color:${computedScale(index)}`" :style="`color:${computedScale(index)}`"
@ -26,7 +26,7 @@ limitations under the License. -->
{{ t("exportImage") }} {{ t("exportImage") }}
</el-button> </el-button>
</div> </div>
<div class="trace-chart"> <div>
<Graph :data="data" :traceId="traceId" type="List" /> <Graph :data="data" :traceId="traceId" type="List" />
</div> </div>
</div> </div>
@ -56,6 +56,7 @@ function computedScale(i: number) {
.interpolator(d3.interpolateCool); .interpolator(d3.interpolateCool);
return sequentialScale(i); return sequentialScale(i);
} }
function downloadTrace() { function downloadTrace() {
const serializer = new XMLSerializer(); const serializer = new XMLSerializer();
const svgNode: any = d3.select(".trace-list-dowanload").node(); const svgNode: any = d3.select(".trace-list-dowanload").node();
@ -84,14 +85,14 @@ function downloadTrace() {
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.time-charts { .charts {
overflow: auto; overflow: auto;
padding: 10px; padding: 10px;
height: calc(100% - 95px); height: calc(100% - 95px);
width: 100%; width: 100%;
} }
.time-charts-item { .charts-item {
display: inline-block; display: inline-block;
padding: 2px 8px; padding: 2px 8px;
border: 1px solid; border: 1px solid;
@ -99,10 +100,6 @@ function downloadTrace() {
border-radius: 4px; border-radius: 4px;
} }
.trace-chart {
fill: rgba(0, 0, 0, 0);
}
.btn { .btn {
float: right; float: right;
} }

View File

@ -23,16 +23,18 @@ limitations under the License. -->
<span>{{ i }}</span> <span>{{ i }}</span>
</span> </span>
</div> </div>
<div style="padding: 0 30px"> <div style="padding: 10px 0">
<a class="trace-tree-btn mr-10" @click="tree.setDefault()">Default</a> <a class="trace-tree-btn mr-10" @click="tree.setDefault()">
{{ t("default") }}
</a>
<a class="trace-tree-btn mr-10" @click="tree.getTopSlow()"> <a class="trace-tree-btn mr-10" @click="tree.getTopSlow()">
Top 5 of slow {{ t("topSlow") }}
</a> </a>
<a class="trace-tree-btn mr-10" @click="tree.getTopChild()"> <a class="trace-tree-btn mr-10" @click="tree.getTopChild()">
Top 5 of children {{ t("topChildren") }}
</a> </a>
</div> </div>
<div class="trace-tree" style="height: 100%"> <div class="trace-tree">
<Graph :data="data" :traceId="traceId" type="Tree" /> <Graph :data="data" :traceId="traceId" type="Tree" />
</div> </div>
</div> </div>
@ -66,6 +68,11 @@ function computedScale(i: number) {
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
.trace-tree {
height: 100%;
overflow: auto;
}
.trace-tree-btn { .trace-tree-btn {
display: inline-block; display: inline-block;
border-radius: 4px; border-radius: 4px;
@ -75,7 +82,7 @@ function computedScale(i: number) {
font-size: 11px; font-size: 11px;
} }
.time-charts { .trace-tree-charts {
overflow: auto; overflow: auto;
padding: 10px; padding: 10px;
position: relative; position: relative;

View File

@ -18,6 +18,7 @@
import * as d3 from "d3"; import * as d3 from "d3";
import d3tip from "d3-tip"; import d3tip from "d3-tip";
import { Trace, Span } from "@/types/trace"; import { Trace, Span } from "@/types/trace";
import { style } from "d3";
export default class TraceMap { export default class TraceMap {
private i = 0; private i = 0;
@ -51,8 +52,8 @@ export default class TraceMap {
this.i = 0; this.i = 0;
this.topSlow = []; this.topSlow = [];
this.topChild = []; this.topChild = [];
this.width = el.clientWidth; this.width = el.clientWidth - 20;
this.height = el.clientHeight - 28; this.height = el.clientHeight;
this.body = d3 this.body = d3
.select(this.el) .select(this.el)
.append("svg") .append("svg")
@ -87,12 +88,10 @@ export default class TraceMap {
if (!this.el) { if (!this.el) {
return; return;
} }
// reset svg size
this.width = this.el.clientWidth; this.width = this.el.clientWidth;
this.height = this.el.clientHeight - 28; this.height = this.el.clientHeight + 100;
this.body.attr("width", this.width).attr("height", this.height); this.body.attr("width", this.width).attr("height", this.height);
this.body.select("g").attr("transform", () => `translate(160, 0)`); this.body.select("g").attr("transform", () => `translate(160, 0)`);
// reset zoom function for translate
const transform = d3.zoomTransform(this.body).translate(0, 0); const transform = d3.zoomTransform(this.body).translate(0, 0);
d3.zoom().transform(this.body, transform); d3.zoom().transform(this.body, transform);
} }
@ -280,8 +279,6 @@ export default class TraceMap {
.attr("transform", function (d: any) { .attr("transform", function (d: any) {
return "translate(" + d.y + "," + d.x + ")"; return "translate(" + d.y + "," + d.x + ")";
}); });
// Update the node attributes and style
nodeUpdate nodeUpdate
.select("circle.node") .select("circle.node")
.attr("r", 5) .attr("r", 5)
@ -295,8 +292,6 @@ export default class TraceMap {
(d3 as any).event.stopPropagation(); (d3 as any).event.stopPropagation();
click(d); click(d);
}); });
// Remove any exiting nodes
const nodeExit = node const nodeExit = node
.exit() .exit()
.transition() .transition()
@ -312,7 +307,7 @@ export default class TraceMap {
const link = this.svg const link = this.svg
.selectAll("path.tree-link") .selectAll("path.tree-link")
.data(links, function (d: any) { .data(links, function (d: { id: string }) {
return d.id; return d.id;
}) })
.style("stroke-width", 1.5); .style("stroke-width", 1.5);
@ -325,7 +320,9 @@ export default class TraceMap {
const o = { x: source.x0, y: source.y0 }; const o = { x: source.x0, y: source.y0 };
return diagonal(o, o); return diagonal(o, o);
}) })
.style("stroke-width", 1.5); .style("stroke-width", 1.5)
.style("fill", "none")
.attr("stroke", "rgba(0, 0, 0, 0.1)");
const linkUpdate = linkEnter.merge(link); const linkUpdate = linkEnter.merge(link);
linkUpdate linkUpdate
@ -334,6 +331,16 @@ export default class TraceMap {
.attr("d", function (d: any) { .attr("d", function (d: any) {
return diagonal(d, d.parent); return diagonal(d, d.parent);
}); });
link
.exit()
.transition()
.duration(600)
.attr("d", function () {
const o = { x: source.x, y: source.y };
return diagonal(o, o);
})
.style("stroke-width", 1.5)
.remove();
nodes.forEach(function (d: any) { nodes.forEach(function (d: any) {
d.x0 = d.x; d.x0 = d.x;
@ -398,12 +405,9 @@ export default class TraceMap {
return d3 return d3
.zoom() .zoom()
.scaleExtent([0.3, 10]) .scaleExtent([0.3, 10])
.on("zoom", () => { .on("zoom", (d: any) => {
g.attr( g.attr("transform", d3.zoomTransform(this.svg.node())).attr(
"transform", `translate(${d.transform.x},${d.transform.y})scale(${d.transform.k})`
`translate(${(d3 as any).event.transform.x + 120},${
(d3 as any).event.transform.y
})scale(${(d3 as any).event.transform.k})`
); );
}); });
} }