提交 a2dd0c13 编写于 作者: M mindspore-ci-bot 提交者: Gitee

!62 45 UI support histogram visualization(4th commit)

Merge pull request !62 from 潘慧/master_ph
...@@ -90,6 +90,7 @@ limitations under the License. ...@@ -90,6 +90,7 @@ limitations under the License.
<div class="chars-container"> <div class="chars-container">
<div class="char-item-content" <div class="char-item-content"
:id="sampleItem.domId"></div> :id="sampleItem.domId"></div>
<div class="tag-title">{{sampleItem.tagName}}</div>
</div> </div>
</div> </div>
</div> </div>
...@@ -213,6 +214,7 @@ export default { ...@@ -213,6 +214,7 @@ export default {
this.curPageArr.forEach((item) => { this.curPageArr.forEach((item) => {
if (item.zr) { if (item.zr) {
item.zr.off('mouseout', 'mousemove'); item.zr.off('mouseout', 'mousemove');
item.zr = null;
} }
}); });
} }
...@@ -354,6 +356,10 @@ export default { ...@@ -354,6 +356,10 @@ export default {
if (!noPageDataNumChange) { if (!noPageDataNumChange) {
this.curPageArr.forEach((sampleItem) => { this.curPageArr.forEach((sampleItem) => {
sampleItem.show = false; sampleItem.show = false;
if (sampleItem.zr) {
sampleItem.zr.off('mouseout', 'mousemove');
sampleItem.zr = null;
}
}); });
} }
// This interface is used to obtain the current page group and hide the current page group. // This interface is used to obtain the current page group and hide the current page group.
...@@ -437,6 +443,12 @@ export default { ...@@ -437,6 +443,12 @@ export default {
* Clear data * Clear data
*/ */
clearAllData() { clearAllData() {
this.originDataArr.forEach((item) => {
if (item.zr) {
item.zr.off('mouseout', 'mousemove');
item.zr = null;
}
});
this.tagList = []; this.tagList = [];
this.originDataArr = []; this.originDataArr = [];
this.curFullTagDic = {}; this.curFullTagDic = {};
...@@ -631,117 +643,118 @@ export default { ...@@ -631,117 +643,118 @@ export default {
setTimeout(() => { setTimeout(() => {
sampleObject.charObj.setOption(sampleObject.charData.charOption, true); sampleObject.charObj.setOption(sampleObject.charData.charOption, true);
}, 10); }, 10);
if (sampleObject.zr) { if (!sampleObject.zr) {
sampleObject.zr.off('mouseout', 'mousemove'); sampleObject.zr = sampleObject.charObj.getZr();
} const p = Math.max(0, d3.precisionRound(0.01, 1.01) - 1);
sampleObject.zr = sampleObject.charObj.getZr(); const yValueFormat = d3.format('.' + p + 'e');
const p = Math.max(0, d3.precisionRound(0.01, 1.01) - 1); const chartData = sampleObject.charData.oriData.chartData;
const yValueFormat = d3.format('.' + p + 'e'); const rawData = charOption.seriesData;
const chartData = sampleObject.charData.oriData.chartData; /**
const rawData = charOption.seriesData; * get convert point
/** * @param {Array} pt value
* get convert point * @return {Array}
* @param {Array} pt value */
* @return {Array} function getCoord(pt) {
*/ return sampleObject.charObj.convertToPixel('grid', pt);
function getCoord(pt) {
return sampleObject.charObj.convertToPixel('grid', pt);
}
/**
* find nearest value
* @param {Array} eventPoint value
* @return {Object}
*/
function findNearestValue(eventPoint) {
if (
!eventPoint ||
!eventPoint.length ||
!sampleObject ||
!sampleObject.charObj
) {
return;
}
const value = sampleObject.charObj.convertFromPixel('grid', eventPoint);
let binIndex = null;
let yIndex = null;
let nearestX = Infinity;
let nearestY = -Infinity;
let nearestYData = Infinity;
if (!sampleObject.charData.oriData || !value || !value.length) {
return;
} }
const gridRect = sampleObject.charObj /**
.getModel() * find nearest value
.getComponent('grid', 0) * @param {Array} eventPoint value
.coordinateSystem.getRect(); * @return {Object}
const gridRectY = gridRect.y - 10; */
const x = value[0]; function findNearestValue(eventPoint) {
chartData.forEach((dataItem, i) => { if (
let distY; !eventPoint ||
let yAxis; !eventPoint.length ||
for (let k = 0; k < dataItem.items.length - 1; k++) { !sampleObject ||
const item = dataItem.items[k]; !sampleObject.charObj
const itemNext = dataItem.items[k + 1]; ) {
const nextX = itemNext[2]; return;
const nextZ = itemNext[3];
if (item.length >= 4) {
if (item[2] < x && nextX >= x) {
const proportionX = (x - item[2]) / (nextX - item[2]);
yAxis = (nextZ - item[3]) * proportionX + item[3];
distY = Math.abs(value[1] - yAxis);
break;
}
}
} }
if (curViewName === 0 && distY < nearestYData) { const value = sampleObject.charObj.convertFromPixel(
nearestYData = distY; 'grid',
yIndex = i; eventPoint,
} else if (curViewName === 1) { );
const pt = getCoord([x, dataItem.step]); let binIndex = null;
const ptStep = pt[1]; let yIndex = null;
pt[1] -= let nearestX = Infinity;
((yAxis - charOption.minZ) / let nearestY = -Infinity;
(charOption.maxZ - charOption.minZ)) * let nearestYData = Infinity;
gridRectY; if (!sampleObject.charData.oriData || !value || !value.length) {
if ( return;
eventPoint[1] > pt[1] &&
eventPoint[1] < ptStep &&
ptStep > nearestY
) {
nearestY = ptStep;
yIndex = i;
}
} }
}); const gridRect = sampleObject.charObj
if (yIndex === null && curViewName === 1) { .getModel()
chartData.forEach((item, index) => { .getComponent('grid', 0)
if (item.step > value[1]) { .coordinateSystem.getRect();
yIndex = yIndex === null ? index : Math.min(yIndex, index); const gridRectY = gridRect.y - 10;
const x = value[0];
chartData.forEach((dataItem, i) => {
let distY;
let yAxis;
for (let k = 0; k < dataItem.items.length - 1; k++) {
const item = dataItem.items[k];
const itemNext = dataItem.items[k + 1];
const nextX = itemNext[2];
const nextZ = itemNext[3];
if (item.length >= 4) {
if (item[2] < x && nextX >= x) {
const proportionX = (x - item[2]) / (nextX - item[2]);
yAxis = (nextZ - item[3]) * proportionX + item[3];
distY = Math.abs(value[1] - yAxis);
break;
}
}
} }
}); if (curViewName === 0 && distY < nearestYData) {
} nearestYData = distY;
if (yIndex !== null) { yIndex = i;
const yData = chartData[yIndex].items; } else if (curViewName === 1) {
yData.forEach((ele, index) => { const pt = getCoord([x, dataItem.step]);
const distX = Math.abs(ele[2] - value[0]); const ptStep = pt[1];
if (distX < nearestX) { pt[1] -=
nearestX = distX; ((yAxis - charOption.minZ) /
binIndex = index; (charOption.maxZ - charOption.minZ)) *
gridRectY;
if (
eventPoint[1] > pt[1] &&
eventPoint[1] < ptStep &&
ptStep > nearestY
) {
nearestY = ptStep;
yIndex = i;
}
} }
}); });
binIndex = if (yIndex === null && curViewName === 1) {
binIndex === 0 chartData.forEach((item, index) => {
? 1 if (item.step > value[1]) {
: binIndex === yData.length - 1 yIndex = yIndex === null ? index : Math.min(yIndex, index);
? yData.length - 2 }
: binIndex; });
}
if (yIndex !== null) {
const yData = chartData[yIndex].items;
yData.forEach((ele, index) => {
const distX = Math.abs(ele[2] - value[0]);
if (distX < nearestX) {
nearestX = distX;
binIndex = index;
}
});
binIndex =
binIndex === 0
? 1
: binIndex === yData.length - 1
? yData.length - 2
: binIndex;
}
return {
binIndex,
yIndex,
};
} }
return { sampleObject.zr.off('mouseout', 'mousemove');
binIndex,
yIndex,
};
}
if (sampleObject.zr) {
sampleObject.zr.on('mouseout', (e) => { sampleObject.zr.on('mouseout', (e) => {
if (!rawData || !rawData.length) { if (!rawData || !rawData.length) {
return; return;
...@@ -933,7 +946,6 @@ export default { ...@@ -933,7 +946,6 @@ export default {
this.zrDrawElement.tooltipX = new echarts.graphic.Text({ this.zrDrawElement.tooltipX = new echarts.graphic.Text({
position: [itemX, gridRect.y + gridRect.height], position: [itemX, gridRect.y + gridRect.height],
style: { style: {
fontFamily: 'Merriweather Sans',
text: Math.round(x * 1000) / 1000, text: Math.round(x * 1000) / 1000,
textFill: '#fff', textFill: '#fff',
textAlign: 'center', textAlign: 'center',
...@@ -947,14 +959,17 @@ export default { ...@@ -947,14 +959,17 @@ export default {
}); });
sampleObject.zr.add(this.zrDrawElement.tooltipX); sampleObject.zr.add(this.zrDrawElement.tooltipX);
if (curViewName === 1 && linePoints && linePoints.length) { if (curViewName === 1 && linePoints && linePoints.length) {
let text = '';
if (yIndex) {
text = this.yAxisFormatter(sampleIndex, yIndex);
}
this.zrDrawElement.tooltipY = new echarts.graphic.Text({ this.zrDrawElement.tooltipY = new echarts.graphic.Text({
position: [ position: [
gridRect.x + gridRect.width, gridRect.x + gridRect.width,
linePoints[linePoints.length - 1][1], linePoints[linePoints.length - 1][1],
], ],
style: { style: {
fontFamily: 'Merriweather Sans', text: text,
text: hoveredItem.step,
textFill: '#fff', textFill: '#fff',
textVerticalAlign: 'middle', textVerticalAlign: 'middle',
fontSize: 12, fontSize: 12,
...@@ -1067,7 +1082,6 @@ export default { ...@@ -1067,7 +1082,6 @@ export default {
}, },
formatDataToChar(dataIndex) { formatDataToChar(dataIndex) {
const dataItem = this.originDataArr[dataIndex].charData.oriData; const dataItem = this.originDataArr[dataIndex].charData.oriData;
const title = this.originDataArr[dataIndex].tagName;
const seriesData = []; const seriesData = [];
let maxStep = -Infinity; let maxStep = -Infinity;
let minStep = Infinity; let minStep = Infinity;
...@@ -1101,7 +1115,6 @@ export default { ...@@ -1101,7 +1115,6 @@ export default {
}); });
} }
return { return {
title,
seriesData, seriesData,
maxStep, maxStep,
minStep, minStep,
...@@ -1119,20 +1132,10 @@ export default { ...@@ -1119,20 +1132,10 @@ export default {
const fullScreenFun = this.toggleFullScreen; const fullScreenFun = this.toggleFullScreen;
const curAxisName = this.curAxisName; const curAxisName = this.curAxisName;
const option = { const option = {
textStyle: {fontFamily: 'Merriweather Sans'},
title: {
text: charOption.title || '',
textStyle: {
fontSize: '16',
fontWeight: '600',
},
bottom: 6,
left: 'center',
},
grid: { grid: {
left: 15, left: 15,
top: 60, top: 60,
right: 40, right: 50,
bottom: 60, bottom: 60,
}, },
xAxis: { xAxis: {
...@@ -1216,24 +1219,7 @@ export default { ...@@ -1216,24 +1219,7 @@ export default {
option.yAxis.inverse = true; option.yAxis.inverse = true;
const that = this; const that = this;
option.yAxis.axisLabel.formatter = function(value) { option.yAxis.axisLabel.formatter = function(value) {
let data = ''; return that.yAxisFormatter(sampleIndex, value);
const filter = sampleObject.charData.oriData.chartData.filter(
(k) => k.step === value,
);
if (filter.length) {
if (curAxisName === 2) {
data = sampleObject.fullScreen
? that.dealrelativeTime(
new Date(filter[0].wall_time).toString(),
)
: [];
} else if (curAxisName === 1) {
data = (filter[0].relative_time / 1000).toFixed(3);
} else {
data = filter[0].step;
}
}
return data;
}; };
option.visualMap = { option.visualMap = {
type: 'continuous', type: 'continuous',
...@@ -1266,6 +1252,25 @@ export default { ...@@ -1266,6 +1252,25 @@ export default {
} }
return option; return option;
}, },
yAxisFormatter(sampleIndex, value) {
const sampleObject = this.originDataArr[sampleIndex];
let data = '';
const filter = sampleObject.charData.oriData.chartData.filter(
(k) => k.step === value,
);
if (filter.length) {
if (this.curAxisName === 2) {
data = sampleObject.fullScreen
? this.dealrelativeTime(new Date(filter[0].wall_time).toString())
: [];
} else if (this.curAxisName === 1) {
data = `${(filter[0].relative_time / 3600).toFixed(3)}h`;
} else {
data = filter[0].step;
}
}
return data;
},
formatColor(str) { formatColor(str) {
if (!str) { if (!str) {
return; return;
...@@ -1331,6 +1336,7 @@ export default { ...@@ -1331,6 +1336,7 @@ export default {
if (!sampleObject) { if (!sampleObject) {
return; return;
} }
this.removeTooltip(sampleIndex);
sampleObject.fullScreen = !sampleObject.fullScreen; sampleObject.fullScreen = !sampleObject.fullScreen;
if (sampleObject.fullScreen) { if (sampleObject.fullScreen) {
if (this.curAxisName === 2) { if (this.curAxisName === 2) {
...@@ -1425,7 +1431,13 @@ export default { ...@@ -1425,7 +1431,13 @@ export default {
position: relative; position: relative;
.char-item-content { .char-item-content {
width: 100%; width: 100%;
height: 100%; height: calc(100% - 26px);
}
.tag-title {
width: 100%;
font-size: 16px;
font-weight: 600;
text-align: center;
} }
} }
} }
......
...@@ -903,7 +903,7 @@ export default { ...@@ -903,7 +903,7 @@ export default {
overflow: hidden; overflow: hidden;
.top-area { .top-area {
margin: 24px 32px 16px; margin: 24px 32px 12px;
display: flex; display: flex;
justify-content: flex-end; justify-content: flex-end;
.checkbox { .checkbox {
...@@ -935,6 +935,7 @@ export default { ...@@ -935,6 +935,7 @@ export default {
} }
.btns { .btns {
margin-left: 20px; margin-left: 20px;
padding-top: 12px;
.custom-btn { .custom-btn {
border: 1px solid #00a5a7; border: 1px solid #00a5a7;
border-radius: 2px; border-radius: 2px;
...@@ -953,7 +954,7 @@ export default { ...@@ -953,7 +954,7 @@ export default {
.table-container { .table-container {
background-color: white; background-color: white;
height: calc(60% - 74px); height: calc(60% - 74px);
padding: 12px 32px; padding: 2px 32px;
position: relative; position: relative;
.custom-label { .custom-label {
max-width: calc(100% - 25px); max-width: calc(100% - 25px);
......
...@@ -55,8 +55,11 @@ limitations under the License. ...@@ -55,8 +55,11 @@ limitations under the License.
@click="viewMoreHistogram"> @click="viewMoreHistogram">
<div class="cl-dashboard-title">{{$t("histogram.titleText")}}</div> <div class="cl-dashboard-title">{{$t("histogram.titleText")}}</div>
<div class="cl-module"> <div class="cl-module">
<div id="distribution-chart" <div id="histogram-char-container"
v-show="!!histogramTag && !wrongPlugin"></div> v-show="!!histogramTag && !wrongPlugin">
<div id="distribution-chart"></div>
<div class="tag-text">{{histogramTag}}</div>
</div>
<div class="no-data-img" <div class="no-data-img"
key="no-chart-data" key="no-chart-data"
v-show="!histogramTag || wrongPlugin"> v-show="!histogramTag || wrongPlugin">
...@@ -670,7 +673,7 @@ export default { ...@@ -670,7 +673,7 @@ export default {
grid: { grid: {
top: 20, top: 20,
bottom: 66, bottom: 66,
left: 66, left: 60,
right: 60, right: 60,
}, },
xAxis: [ xAxis: [
...@@ -837,7 +840,6 @@ export default { ...@@ -837,7 +840,6 @@ export default {
}, },
formatDataToChar() { formatDataToChar() {
const dataItem = this.histogramData; const dataItem = this.histogramData;
const title = dataItem.tag;
const seriesData = []; const seriesData = [];
let maxStep = -Infinity; let maxStep = -Infinity;
let minStep = Infinity; let minStep = Infinity;
...@@ -862,7 +864,6 @@ export default { ...@@ -862,7 +864,6 @@ export default {
}); });
} }
return { return {
title,
seriesData, seriesData,
maxStep, maxStep,
minStep, minStep,
...@@ -874,13 +875,6 @@ export default { ...@@ -874,13 +875,6 @@ export default {
}, },
formatCharOption(charOption) { formatCharOption(charOption) {
const option = { const option = {
textStyle: {fontFamily: 'Merriweather Sans'},
title: {
text: charOption.title || '',
textStyle: {fontSize: '12', fontWeight: '400'},
bottom: 6,
left: 'center',
},
grid: { grid: {
left: 15, left: 15,
top: 126, top: 126,
...@@ -1840,11 +1834,21 @@ export default { ...@@ -1840,11 +1834,21 @@ export default {
} }
} }
#distribution-chart { #distribution-chart {
height: 100%; height: calc(100% - 19px);
canvas { canvas {
cursor: pointer; cursor: pointer;
} }
} }
.histogram-char-container {
height: 100%;
width: 100%;
cursor: pointer;
.tag-text {
font-size: 12px;
font-weight: 400;
text-align: center;
}
}
#dataMapGraph { #dataMapGraph {
.CreatDataset > polygon, .CreatDataset > polygon,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册