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

!504 UI add graph plug-in compatible code

Merge pull request !504 from 黄伟锋/myMaster
...@@ -146,6 +146,7 @@ limitations under the License. ...@@ -146,6 +146,7 @@ limitations under the License.
import RequestService from '../../services/request-service'; import RequestService from '../../services/request-service';
import CommonProperty from '@/common/common-property.js'; import CommonProperty from '@/common/common-property.js';
import {select, selectAll, zoom} from 'd3'; import {select, selectAll, zoom} from 'd3';
import {event as currentEvent} from 'd3-selection';
import 'd3-graphviz'; import 'd3-graphviz';
const d3 = {select, selectAll, zoom}; const d3 = {select, selectAll, zoom};
export default { export default {
...@@ -385,10 +386,12 @@ export default { ...@@ -385,10 +386,12 @@ export default {
const zoom = d3 const zoom = d3
.zoom() .zoom()
.on('start', () => { .on('start', () => {
const event = currentEvent.sourceEvent;
pointer.start.x = event.x; pointer.start.x = event.x;
pointer.start.y = event.y; pointer.start.y = event.y;
}) })
.on('zoom', () => { .on('zoom', () => {
const event = currentEvent.sourceEvent;
const transformData = this.getTransformData(graphDom); const transformData = this.getTransformData(graphDom);
if (!Object.keys(graphTransform).length) { if (!Object.keys(graphTransform).length) {
graphTransform = { graphTransform = {
...@@ -444,8 +447,8 @@ export default { ...@@ -444,8 +447,8 @@ export default {
pointer.start.x = pointer.end.x; pointer.start.x = pointer.end.x;
pointer.start.y = pointer.end.y; pointer.start.y = pointer.end.y;
} else if (event.type === 'wheel') { } else if (event.type === 'wheel') {
const wheelDelta = event.wheelDelta; const wheelDelta = -event.deltaY;
const rate = Math.abs(wheelDelta / 100); const rate = 1.2;
scale = scale =
wheelDelta > 0 wheelDelta > 0
? transformData.scale[0] * rate ? transformData.scale[0] * rate
......
...@@ -415,6 +415,7 @@ import Autocomplete from '@/components/autocomplete'; ...@@ -415,6 +415,7 @@ import Autocomplete from '@/components/autocomplete';
import CommonProperty from '@/common/common-property.js'; import CommonProperty from '@/common/common-property.js';
import RequestService from '@/services/request-service'; import RequestService from '@/services/request-service';
import {select, selectAll, zoom} from 'd3'; import {select, selectAll, zoom} from 'd3';
import {event as currentEvent} from 'd3-selection';
import 'd3-graphviz'; import 'd3-graphviz';
const d3 = {select, selectAll, zoom}; const d3 = {select, selectAll, zoom};
export default { export default {
...@@ -679,69 +680,82 @@ export default { ...@@ -679,69 +680,82 @@ export default {
*/ */
startApp() { startApp() {
const nodes = d3.selectAll('g.node, g.cluster'); const nodes = d3.selectAll('g.node, g.cluster');
nodes.on('click', (target, index, nodesList) => { nodes.on(
// The target value of the element converted from the HTML attribute of the variable is null. 'click',
const clickNode = nodesList[index]; (target, index, nodesList) => {
const nodeId = clickNode.id; // The target value of the element converted from the HTML attribute of the variable is null.
const nodeClass = clickNode.classList.value; const event = currentEvent;
setTimeout(() => { event.stopPropagation();
this.clickScope = { event.preventDefault();
id: nodeId,
class: nodeClass, const clickNode = nodesList[index];
}; const nodeId = clickNode.id;
}, 10); const nodeClass = clickNode.classList.value;
setTimeout(() => { setTimeout(() => {
this.clickScope = {}; this.clickScope = {
}, 1000); id: nodeId,
this.selectedNode.name = nodeId; class: nodeClass,
this.selectNode(false); };
if (!event || !event.type || event.type !== 'click') { }, 10);
return; setTimeout(() => {
} this.clickScope = {};
event.stopPropagation(); }, 1000);
event.preventDefault(); this.selectedNode.name = nodeId;
}); this.selectNode(false);
},
false,
);
// namespaces Expansion or Reduction // namespaces Expansion or Reduction
nodes.on('dblclick', (target, index, nodesList) => { nodes.on(
// The target of the element converted from the HTML attribute of the variable is empty and 'dblclick',
// needs to be manually encapsulated. (target, index, nodesList) => {
const clickNode = nodesList[index]; // The target of the element converted from the HTML attribute of the variable is empty and
const nodeId = clickNode.id; // needs to be manually encapsulated.
const nodeClass = clickNode.classList.value; const event = currentEvent;
let name = nodeId; event.stopPropagation();
this.selectedNode.more = event.preventDefault();
name.indexOf('more...') !== -1 &&
document const clickNode = nodesList[index];
.querySelector(`#graph g[id="${name}"]`) const nodeId = clickNode.id;
.attributes.class.value.indexOf('plain') === -1; const nodeClass = clickNode.classList.value;
let name = nodeId;
const unfoldFlag = this.selectedNode.more =
(nodeClass.includes('aggregation') || name.indexOf('more...') !== -1 &&
nodeClass.includes('cluster') || document
this.selectedNode.more) && .querySelector(`#graph g[id="${name}"]`)
(!this.clickScope.id || .attributes.class.value.indexOf('plain') === -1;
(this.clickScope.id && nodeId === this.clickScope.id));
const unfoldFlag =
if (this.selectedNode.more) { (nodeClass.includes('aggregation') ||
const changePage = name.includes('right') ? 1 : -1; nodeClass.includes('cluster') ||
const parentId = document.querySelector(`#graph g[id="${name}"]`) this.selectedNode.more) &&
.parentNode.id; (!this.clickScope.id ||
name = parentId.replace('_unfold', ''); (this.clickScope.id && nodeId === this.clickScope.id));
this.allGraphData[name].index += changePage;
this.selectedNode.name = name; if (this.selectedNode.more) {
} const changePage = name.includes('right') ? 1 : -1;
if (unfoldFlag) { const parentId = document.querySelector(`#graph g[id="${name}"]`)
this.dealDoubleClick(name); .parentNode.id;
} else if (this.clickScope.id) { name = parentId.replace('_unfold', '');
this.selectedNode.name = this.clickScope.id; this.allGraphData[name].index += changePage;
this.selectNode(false); this.allGraphData[name].index = Math.max(
} 0,
if (!event || !event.type || event.type !== 'dblclick') { Math.min(
return; this.allGraphData[name].index,
} this.allGraphData[name].childIdsList.length - 1,
event.stopPropagation(); ),
event.preventDefault(); );
}); this.selectedNode.name = name;
}
if (unfoldFlag) {
this.dealDoubleClick(name);
} else if (this.clickScope.id) {
this.selectedNode.name = this.clickScope.id;
this.selectNode(false);
}
},
false,
);
this.initZooming(); this.initZooming();
if (this.selectedNode.name) { if (this.selectedNode.name) {
this.selectNode(true); this.selectNode(true);
...@@ -758,10 +772,15 @@ export default { ...@@ -758,10 +772,15 @@ export default {
const zoom = d3 const zoom = d3
.zoom() .zoom()
.on('start', () => { .on('start', () => {
const event = currentEvent.sourceEvent;
pointer.start.x = event.x; pointer.start.x = event.x;
pointer.start.y = event.y; pointer.start.y = event.y;
}) })
.on('zoom', () => { .on('zoom', () => {
const event = currentEvent.sourceEvent;
event.stopPropagation();
event.preventDefault();
const transformData = this.getTransformData(this.graph.dom); const transformData = this.getTransformData(this.graph.dom);
let tempStr = ''; let tempStr = '';
let change = {}; let change = {};
...@@ -809,8 +828,8 @@ export default { ...@@ -809,8 +828,8 @@ export default {
pointer.start.x = pointer.end.x; pointer.start.x = pointer.end.x;
pointer.start.y = pointer.end.y; pointer.start.y = pointer.end.y;
} else if (event.type === 'wheel') { } else if (event.type === 'wheel') {
const wheelDelta = event.wheelDelta; const wheelDelta = -event.deltaY;
const rate = Math.abs(wheelDelta / 100); const rate = 1.2;
scale = scale =
wheelDelta > 0 wheelDelta > 0
? transformData.scale[0] * rate ? transformData.scale[0] * rate
...@@ -838,11 +857,11 @@ export default { ...@@ -838,11 +857,11 @@ export default {
this.graph.transRate = this.graph.transRate =
graphRect.width / graphBox.width / this.graph.transform.k; graphRect.width / graphBox.width / this.graph.transform.k;
tempStr = `translate(${this.graph.transform.x},${this.graph.transform.y}) scale(${this.graph.transform.k})`; tempStr =
`translate(${this.graph.transform.x},${this.graph.transform.y}) ` +
`scale(${this.graph.transform.k})`;
this.graph.dom.setAttribute('transform', tempStr); this.graph.dom.setAttribute('transform', tempStr);
this.setInsideBoxData(); this.setInsideBoxData();
event.stopPropagation();
event.preventDefault();
}); });
const svg = d3.select('#graph svg'); const svg = d3.select('#graph svg');
...@@ -930,8 +949,8 @@ export default { ...@@ -930,8 +949,8 @@ export default {
*/ */
layoutNamescope(name, toUnfold) { layoutNamescope(name, toUnfold) {
this.$nextTick(() => { this.$nextTick(() => {
const dotStr = this.packageNamescope(name);
try { try {
const dotStr = this.packageNamescope(name);
this.graphvizTemp = d3 this.graphvizTemp = d3
.select('#graphTemp') .select('#graphTemp')
.graphviz({useWorker: false, totalMemory: this.totalMemory}) .graphviz({useWorker: false, totalMemory: this.totalMemory})
...@@ -2678,12 +2697,11 @@ export default { ...@@ -2678,12 +2697,11 @@ export default {
}; };
// Mouse wheel event // Mouse wheel event
smallContainer.onmousewheel = (e) => { smallContainer.onwheel = (e) => {
e = e || window.event; e = e || window.event;
const wheelDelta = e.wheelDelta ? e.wheelDelta : e.detail; const wheelDelta = e.wheelDelta ? e.wheelDelta : -e.deltaY;
if (!isNaN(this.graph.transform.k) && this.graph.transform.k !== 0) { if (!isNaN(this.graph.transform.k) && this.graph.transform.k !== 0) {
let rate = let rate = wheelDelta > 0 ? 1.2 : 1 / 1.2;
wheelDelta > 0 ? wheelDelta / 100 : -1 / (wheelDelta / 100);
let scaleTemp = this.graph.transform.k / rate; let scaleTemp = this.graph.transform.k / rate;
if (scaleTemp <= this.graph.minScale) { if (scaleTemp <= this.graph.minScale) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册