提交 35bdb3a6 编写于 作者: W WeiFeng-mindinsight

fix bug of step trace, the text of small data will show outside of the rect which own it

上级 6f5d4f70
...@@ -186,7 +186,7 @@ limitations under the License. ...@@ -186,7 +186,7 @@ limitations under the License.
<div class="cell-container device_queue_op" <div class="cell-container device_queue_op"
clickKey="device_queue_op"> clickKey="device_queue_op">
<div class="title"> <div class="title">
{{$t('profiling.deviceQueueOpTip')}} {{$t('profiling.deviceQueueOp')}}
</div> </div>
</div> </div>
...@@ -351,6 +351,7 @@ export default { ...@@ -351,6 +351,7 @@ export default {
totalTime: 0, totalTime: 0,
rowHeight: 60, rowHeight: 60,
markerPadding: 4, markerPadding: 4,
minRate: 0.05,
namespaceURI: 'http://www.w3.org/2000/svg', namespaceURI: 'http://www.w3.org/2000/svg',
resizeTimer: null, resizeTimer: null,
colorList: [ colorList: [
...@@ -650,20 +651,28 @@ export default { ...@@ -650,20 +651,28 @@ export default {
const traceDom = document.querySelector('#trace'); const traceDom = document.querySelector('#trace');
if (traceDom) { if (traceDom) {
this.svg.totalWidth = traceDom.offsetWidth - this.svg.svgPadding * 2; this.svg.totalWidth = traceDom.offsetWidth - this.svg.svgPadding * 2;
if (this.svg.data[0] && this.svg.data[0].length) { if (this.svg.data[0] && this.svg.data[0].length) {
const svg = document.querySelector('#trace svg'); const svg = traceDom.querySelector('svg');
this.svg.totalTime = this.svg.data[0][0].duration; this.svg.totalTime = this.svg.data[0][0].duration;
if (this.svg.totalTime) { if (this.svg.totalTime) {
this.svg.colorIndex = 0; this.svg.colorIndex = 0;
const minTime = this.svg.minRate * this.svg.totalTime;
this.svg.data.forEach((row, index) => { this.svg.data.forEach((row, index) => {
if (row && row.length) { if (row && row.length) {
const dashedLine = this.addDashedLine(index); const dashedLine = this.addDashedLine(index);
svg.insertBefore(dashedLine, svg.querySelector('g')); svg.insertBefore(dashedLine, svg.querySelector('g'));
row.forEach((i) => { row.forEach((i) => {
if (i.duration) { if (i.duration) {
if (i.name) { if (i.name) {
const tempDom = this.createRect(i, index); const tempDom = this.createRect(i, index);
svg.insertBefore(tempDom, svg.querySelector('g')); const tempStr = `g${
i.duration > minTime ? '' : '.arrow'
}`;
svg.insertBefore(tempDom, svg.querySelector(tempStr));
} else { } else {
const tempDom = this.createArrow(i, index); const tempDom = this.createArrow(i, index);
svg.appendChild(tempDom); svg.appendChild(tempDom);
...@@ -690,19 +699,27 @@ export default { ...@@ -690,19 +699,27 @@ export default {
line.setAttribute('style', 'stroke:#E2E2E2;stroke-width:1'); line.setAttribute('style', 'stroke:#E2E2E2;stroke-width:1');
line.setAttribute('stroke-dasharray', '5 5'); line.setAttribute('stroke-dasharray', '5 5');
const g = document.createElementNS(this.svg.namespaceURI, 'g'); const g = document.createElementNS(this.svg.namespaceURI, 'g');
g.setAttribute('class', 'dashedLine');
g.appendChild(line); g.appendChild(line);
return g; return g;
}, },
createRect(data, rowIndex) { createRect(data, rowIndex) {
const color = this.svg.colorList[this.svg.colorIndex++ % 4]; const color = this.svg.colorList[
rowIndex > 1 ? 3 : this.svg.colorIndex++ % 4
];
const height = 40; const height = 40;
const width = (data.duration / this.svg.totalTime) * this.svg.totalWidth; const width = (data.duration / this.svg.totalTime) * this.svg.totalWidth;
const fontSize = 12;
const normalRect = data.duration > this.svg.minRate * this.svg.totalTime;
const x1 = const x1 =
(data.start / this.svg.totalTime) * this.svg.totalWidth + (data.start / this.svg.totalTime) * this.svg.totalWidth +
this.svg.svgPadding; this.svg.svgPadding;
const y1 = const y1 =
rowIndex * this.svg.rowHeight + (this.svg.rowHeight - height) / 2; rowIndex * this.svg.rowHeight + (this.svg.rowHeight - height) / 2;
const g = document.createElementNS(this.svg.namespaceURI, 'g'); const g = document.createElementNS(this.svg.namespaceURI, 'g');
g.setAttribute('class', 'rect');
const gChild = document.createElementNS(this.svg.namespaceURI, 'g'); const gChild = document.createElementNS(this.svg.namespaceURI, 'g');
let name = ''; let name = '';
switch (data.name) { switch (data.name) {
...@@ -710,7 +727,7 @@ export default { ...@@ -710,7 +727,7 @@ export default {
name = this.$t('profiling.lterationGap'); name = this.$t('profiling.lterationGap');
break; break;
case 'fp_and_bp': case 'fp_and_bp':
name = this.$t('profiling.deviceQueueOpTip'); name = this.$t('profiling.deviceQueueOp');
break; break;
case 'tail': case 'tail':
name = this.$t('profiling.lterationTail'); name = this.$t('profiling.lterationTail');
...@@ -731,16 +748,30 @@ export default { ...@@ -731,16 +748,30 @@ export default {
this.svg.namespaceURI, this.svg.namespaceURI,
'foreignObject', 'foreignObject',
); );
foreignObject.setAttribute('x', x1); foreignObject.textContent = `${name}: ${data.duration.toFixed(4)}ms`;
foreignObject.setAttribute('y', y1); const textWidth = this.getTextWidth(foreignObject.textContent);
foreignObject.setAttribute('height', height);
foreignObject.setAttribute(
'x',
normalRect
? x1
: Math.min(
this.svg.svgPadding * 2 + this.svg.totalWidth - textWidth,
Math.max(0, x1 + width / 2 - textWidth / 2),
),
);
foreignObject.setAttribute(
'y',
y1 + (height - fontSize) / 2 + (normalRect ? 0 : fontSize),
);
foreignObject.setAttribute('height', fontSize);
foreignObject.setAttribute('width', width); foreignObject.setAttribute('width', width);
foreignObject.setAttribute('style', `color:${color[0]}`);
foreignObject.setAttribute( foreignObject.setAttribute(
'style', 'class',
`overflow:hidden;text-align:center;text-overflow:ellipsis;` + `content${normalRect ? '' : ' content-mini'}`,
`white-space:nowrap;font-size:12px;line-height:${height}px;color:${color[0]}`,
); );
foreignObject.textContent = `${name}: ${data.duration.toFixed(4)}ms`;
const title = document.createElementNS(this.svg.namespaceURI, 'title'); const title = document.createElementNS(this.svg.namespaceURI, 'title');
title.textContent = `${name}: ${data.duration.toFixed(4)}ms`; title.textContent = `${name}: ${data.duration.toFixed(4)}ms`;
...@@ -761,6 +792,7 @@ export default { ...@@ -761,6 +792,7 @@ export default {
const x2 = x1 + width - this.svg.markerPadding * 2; const x2 = x1 + width - this.svg.markerPadding * 2;
const y = rowIndex * this.svg.rowHeight + this.svg.rowHeight / 2; const y = rowIndex * this.svg.rowHeight + this.svg.rowHeight / 2;
const g = document.createElementNS(this.svg.namespaceURI, 'g'); const g = document.createElementNS(this.svg.namespaceURI, 'g');
g.setAttribute('class', 'arrow');
const line = document.createElementNS(this.svg.namespaceURI, 'line'); const line = document.createElementNS(this.svg.namespaceURI, 'line');
line.setAttribute('x1', x1); line.setAttribute('x1', x1);
...@@ -1036,6 +1068,17 @@ export default { ...@@ -1036,6 +1068,17 @@ export default {
.training-trace { .training-trace {
position: relative; position: relative;
height: 0; height: 0;
.content {
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 12px;
line-height: 12px;
}
.content-mini {
overflow: visible;
}
} }
} }
} }
...@@ -1213,6 +1256,7 @@ export default { ...@@ -1213,6 +1256,7 @@ export default {
.pie-chart { .pie-chart {
width: 100%; width: 100%;
height: 260px; height: 260px;
overflow: hidden;
} }
.image-noData { .image-noData {
width: 100%; width: 100%;
......
...@@ -162,6 +162,7 @@ export default { ...@@ -162,6 +162,7 @@ export default {
totalTime: 0, totalTime: 0,
rowHeight: 60, rowHeight: 60,
markerPadding: 4, markerPadding: 4,
minRate: 0.05,
namespaceURI: 'http://www.w3.org/2000/svg', namespaceURI: 'http://www.w3.org/2000/svg',
resizeTimer: null, resizeTimer: null,
colorList: [ colorList: [
...@@ -328,7 +329,6 @@ export default { ...@@ -328,7 +329,6 @@ export default {
type: 'category', type: 'category',
data: xAxisData, data: xAxisData,
name: 'step', name: 'step',
max: this.steps.max,
}, },
yAxis: { yAxis: {
type: 'value', type: 'value',
...@@ -456,33 +456,43 @@ export default { ...@@ -456,33 +456,43 @@ export default {
}, },
dealTraceData() { dealTraceData() {
this.svg.totalWidth = const traceDom = document.querySelector('#trace');
document.querySelector('#trace').offsetWidth - this.svg.svgPadding * 2; if (traceDom) {
if (this.svg.data[0] && this.svg.data[0].length) { this.svg.totalWidth = traceDom.offsetWidth - this.svg.svgPadding * 2;
const svg = document.querySelector('#trace svg');
this.svg.totalTime = this.svg.data[0][0].duration; if (this.svg.data[0] && this.svg.data[0].length) {
if (this.svg.totalTime) { const svg = traceDom.querySelector('svg');
this.svg.colorIndex = 0; this.svg.totalTime = this.svg.data[0][0].duration;
this.svg.data.forEach((row, index) => {
if (row && row.length) { if (this.svg.totalTime) {
const dashedLine = this.addDashedLine(index); this.svg.colorIndex = 0;
svg.insertBefore(dashedLine, svg.querySelector('g')); const minTime = this.svg.minRate * this.svg.totalTime;
row.forEach((i) => {
if (i.duration) { this.svg.data.forEach((row, index) => {
if (i.name) { if (row && row.length) {
const tempDom = this.createRect(i, index); const dashedLine = this.addDashedLine(index);
svg.insertBefore(tempDom, svg.querySelector('g')); svg.insertBefore(dashedLine, svg.querySelector('g'));
} else {
const tempDom = this.createArrow(i, index); row.forEach((i) => {
svg.appendChild(tempDom); if (i.duration) {
if (i.name) {
const tempDom = this.createRect(i, index);
const tempStr = `g${
i.duration > minTime ? '' : '.arrow'
}`;
svg.insertBefore(tempDom, svg.querySelector(tempStr));
} else {
const tempDom = this.createArrow(i, index);
svg.appendChild(tempDom);
}
} }
} });
}); }
} });
}); }
} else {
this.removeTrace();
} }
} else {
this.removeTrace();
} }
}, },
addDashedLine(index) { addDashedLine(index) {
...@@ -497,19 +507,27 @@ export default { ...@@ -497,19 +507,27 @@ export default {
line.setAttribute('style', 'stroke:#E2E2E2;stroke-width:1'); line.setAttribute('style', 'stroke:#E2E2E2;stroke-width:1');
line.setAttribute('stroke-dasharray', '5 5'); line.setAttribute('stroke-dasharray', '5 5');
const g = document.createElementNS(this.svg.namespaceURI, 'g'); const g = document.createElementNS(this.svg.namespaceURI, 'g');
g.setAttribute('class', 'dashedLine');
g.appendChild(line); g.appendChild(line);
return g; return g;
}, },
createRect(data, rowIndex) { createRect(data, rowIndex) {
const color = this.svg.colorList[this.svg.colorIndex++ % 4]; const color = this.svg.colorList[
rowIndex > 1 ? 3 : this.svg.colorIndex++ % 4
];
const height = 40; const height = 40;
const width = (data.duration / this.svg.totalTime) * this.svg.totalWidth; const width = (data.duration / this.svg.totalTime) * this.svg.totalWidth;
const fontSize = 12;
const normalRect = data.duration > this.svg.minRate * this.svg.totalTime;
const x1 = const x1 =
(data.start / this.svg.totalTime) * this.svg.totalWidth + (data.start / this.svg.totalTime) * this.svg.totalWidth +
this.svg.svgPadding; this.svg.svgPadding;
const y1 = const y1 =
rowIndex * this.svg.rowHeight + (this.svg.rowHeight - height) / 2; rowIndex * this.svg.rowHeight + (this.svg.rowHeight - height) / 2;
const g = document.createElementNS(this.svg.namespaceURI, 'g'); const g = document.createElementNS(this.svg.namespaceURI, 'g');
g.setAttribute('class', 'rect');
const gChild = document.createElementNS(this.svg.namespaceURI, 'g'); const gChild = document.createElementNS(this.svg.namespaceURI, 'g');
let name = ''; let name = '';
switch (data.name) { switch (data.name) {
...@@ -517,7 +535,7 @@ export default { ...@@ -517,7 +535,7 @@ export default {
name = this.$t('profiling.lterationGap'); name = this.$t('profiling.lterationGap');
break; break;
case 'fp_and_bp': case 'fp_and_bp':
name = this.$t('profiling.deviceQueueOpTip'); name = this.$t('profiling.deviceQueueOp');
break; break;
case 'tail': case 'tail':
name = this.$t('profiling.lterationTail'); name = this.$t('profiling.lterationTail');
...@@ -538,16 +556,30 @@ export default { ...@@ -538,16 +556,30 @@ export default {
this.svg.namespaceURI, this.svg.namespaceURI,
'foreignObject', 'foreignObject',
); );
foreignObject.setAttribute('x', x1); foreignObject.textContent = `${name}: ${data.duration.toFixed(4)}ms`;
foreignObject.setAttribute('y', y1); const textWidth = this.getTextWidth(foreignObject.textContent);
foreignObject.setAttribute('height', height);
foreignObject.setAttribute(
'x',
normalRect
? x1
: Math.min(
this.svg.svgPadding * 2 + this.svg.totalWidth - textWidth,
Math.max(0, x1 + width / 2 - textWidth / 2),
),
);
foreignObject.setAttribute(
'y',
y1 + (height - fontSize) / 2 + (normalRect ? 0 : fontSize),
);
foreignObject.setAttribute('height', fontSize);
foreignObject.setAttribute('width', width); foreignObject.setAttribute('width', width);
foreignObject.setAttribute('style', `color:${color[0]}`);
foreignObject.setAttribute( foreignObject.setAttribute(
'style', 'class',
`overflow:hidden;text-align:center;text-overflow:ellipsis;` + `content${normalRect ? '' : ' content-mini'}`,
`white-space:nowrap;font-size:12px;line-height:${height}px;color:${color[0]}`,
); );
foreignObject.textContent = `${name}: ${data.duration.toFixed(4)}ms`;
const title = document.createElementNS(this.svg.namespaceURI, 'title'); const title = document.createElementNS(this.svg.namespaceURI, 'title');
title.textContent = `${name}: ${data.duration.toFixed(4)}ms`; title.textContent = `${name}: ${data.duration.toFixed(4)}ms`;
...@@ -568,6 +600,7 @@ export default { ...@@ -568,6 +600,7 @@ export default {
const x2 = x1 + width - this.svg.markerPadding * 2; const x2 = x1 + width - this.svg.markerPadding * 2;
const y = rowIndex * this.svg.rowHeight + this.svg.rowHeight / 2; const y = rowIndex * this.svg.rowHeight + this.svg.rowHeight / 2;
const g = document.createElementNS(this.svg.namespaceURI, 'g'); const g = document.createElementNS(this.svg.namespaceURI, 'g');
g.setAttribute('class', 'arrow');
const line = document.createElementNS(this.svg.namespaceURI, 'line'); const line = document.createElementNS(this.svg.namespaceURI, 'line');
line.setAttribute('x1', x1); line.setAttribute('x1', x1);
...@@ -742,6 +775,17 @@ export default { ...@@ -742,6 +775,17 @@ export default {
cursor: pointer; cursor: pointer;
background-image: url('../../assets/images/download.png'); background-image: url('../../assets/images/download.png');
} }
.content {
overflow: hidden;
text-align: center;
text-overflow: ellipsis;
white-space: nowrap;
font-size: 12px;
line-height: 12px;
}
.content-mini {
overflow: visible;
}
} }
} }
.chart-wrap { .chart-wrap {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册