|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677 |
- <script>
- import RequestService from '@/services/request-service';
- import {select, selectAll, zoom, dispatch} from 'd3';
- import 'd3-graphviz';
- const d3 = {select, selectAll, zoom, dispatch};
- export default {
- data() {
- return {
- conditionRulesMap: this.$t('debugger.tensorTuningRule'),
- };
- },
- methods: {
- showOrigin() {
- this.loadOriginalTree();
- this.queryWatchPoints();
- },
- /**
- * Initialize the condition
- */
- initCondition() {
- RequestService.queryConditions(this.trainId).then((res) => {
- if (res && res.data) {
- this.conditionCollections = res.data;
- }
- });
- },
- transCondition(str) {
- if (!str) {
- return '';
- }
- let temp;
- if (this.conditionRulesMap[str]) {
- temp = this.conditionRulesMap[str];
- } else if (str.endsWith('_lt')) {
- temp = str.replace(/_lt$/, ' <');
- } else if (str.endsWith('_gt')) {
- temp = str.replace(/_gt$/, ' >');
- } else if (str.endsWith('_ge')) {
- temp = str.replace(/_ge$/, ' >=');
- } else {
- temp = str;
- }
-
- if (temp.includes('max_min')) {
- temp = temp.replace('max_min', 'max-min');
- }
- return temp;
- },
- /**
- * Collaspe btn click function
- */
- collapseBtnClick() {
- this.leftShow = !this.leftShow;
- setTimeout(() => {
- this.resizeCallback();
- }, 500);
- },
- /**
- * Step input validation
- */
- stepChange() {
- if (this.step === '') {
- return;
- }
- const maxStep = 2147483648;
- this.step = this.step
- .toString()
- .replace(/[^\.\d]/g, '')
- .replace(/\./g, '');
- this.step = Number(this.step);
- if (this.step === 0) {
- this.step = 1;
- }
- if (this.step >= maxStep) {
- this.step = maxStep - 1;
- }
- },
- /**
- * Query current node info
- */
- getCurrentNodeInfo() {
- let name = this.currentNodeName;
- const params = {
- mode: 'node',
- params: {
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- name,
- single_node: true,
- node_type: 'leaf',
- },
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- name = `${this.metadata.graph_name}/${this.currentNodeName}`;
- params.params.name = name;
- } else {
- if (this.metadata.graph_name !== this.graphFiles.value) {
- this.graphFiles.value = this.metadata.graph_name;
- this.isCurrentGraph = false;
- }
- params.params.graph_name = this.graphFiles.value;
- }
- RequestService.retrieve(params).then(
- (res) => {
- if (res.data) {
- if (res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- if (res.data.graph) {
- const graph = res.data.graph;
- if (graph.nodes && !this.isCurrentGraph) {
- this.node.childNodes = [];
- this.origialTree = graph.nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
- ...val,
- showCheckbox: val.type !== this.unCheckedNodeType,
- };
- });
- this.resolve(this.origialTree);
- // watched 0:unchecked 1:indeterminate 2:checked
- this.node.childNodes.forEach((val) => {
- if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
- val.checked = true;
- }
- if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
- val.indeterminate = true;
- }
- });
- this.isCurrentGraph = true;
- this.firstFloorNodes = [];
- this.allGraphData = {};
- d3.select('#graph svg').remove();
- this.selectedNode.name = '';
- this.packageDataToObject('', true, JSON.parse(JSON.stringify(graph.nodes)));
- this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
- } else {
- this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
- }
- if (graph.children) {
- this.dealTreeData(graph.children, name);
- this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
- }
- }
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * Query next node info
- */
- getNextNodeInfo() {
- this.watchPointHits = [];
- const params = {
- mode: 'continue',
- level: 'node',
- name: '',
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- RequestService.control(params).then(
- (res) => {},
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * In Ascend environment,query node info.
- * @param {Boolean} ascend previous or next
- */
- getNodeByBfs(ascend) {
- const data = this.$refs.tree.getCurrentNode();
- let name = this.$refs.tree.getCurrentKey();
- if (
- (data && (data.type === 'name_scope' || data.type === 'aggregation_scope')) ||
- this.curLeafNodeName === null
- ) {
- name = this.curLeafNodeName;
- }
- const params = {
- ascend,
- name,
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- RequestService.retrieveNodeByBfs(params).then(
- (res) => {
- if (res.data && res.data.graph && res.data.name) {
- this.retrieveTensorHistory({name: res.data.name});
- const graph = res.data.graph;
- this.curLeafNodeName = res.data.name;
- this.nodeName = res.data.name;
- if (graph.children) {
- this.dealTreeData(graph.children, name);
- this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
- }
- this.querySingleNode(JSON.parse(JSON.stringify(graph)), res.data.name);
- } else if (ascend) {
- this.$message.success(this.$t('debugger.nextNodeTip'));
- } else {
- this.$message.success(this.$t('debugger.previousNodeTip'));
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * Terminate current training
- */
- terminate() {
- this.$confirm(this.$t('debugger.ternimateConfirm'), this.$t('public.notice'), {
- confirmButtonText: this.$t('public.sure'),
- cancelButtonText: this.$t('public.cancel'),
- type: 'warning',
- }).then(
- () => {
- this.control(2);
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * Table row add className
- * @return { String }
- */
- tableRowClassName({row}) {
- if (row.is_hit) {
- return 'success-row';
- }
- return '';
- },
- /**
- * Table merged cells
- * @return { Object }
- */
- objectSpanMethod({row, column, rowIndex, columnIndex}) {
- let inputLength = 0;
- let outputLength = 0;
- if (this.tabs.activeName === 'tensor') {
- inputLength = this.inputLength;
- outputLength = this.outputLength;
- } else {
- inputLength = this.selectedNode.inputNum;
- outputLength = this.selectedNode.outputNum;
- }
- if (columnIndex === 0 && outputLength > 0) {
- if (rowIndex === 0) {
- return {
- rowspan: outputLength,
- colspan: 1,
- };
- } else if (rowIndex > 0 && rowIndex < outputLength) {
- return {
- rowspan: 0,
- colspan: 0,
- };
- } else if (rowIndex === outputLength) {
- return {
- rowspan: inputLength,
- colspan: 1,
- };
- } else {
- return {
- rowspan: 0,
- colspan: 0,
- };
- }
- }
- },
- /**
- * Table header merged cells
- * @return { Object }
- */
- discountHeaderStyle({row, column, rowIndex, columnIndex}) {
- if (rowIndex === 1) {
- return {display: 'none'};
- }
- },
- /**
- * Handle node click
- * @param { Object } data node data
- */
- handleNodeClick(data) {
- this.isIntoView = false;
- this.selectedNode.name = data.name;
- if (this.treeFlag) {
- this.querySingleNode({}, data.name, true);
- } else {
- if (this.graphFiles.value === this.$t('debugger.all')) {
- const graphName = data.name.split('/')[0];
- this.queryAllTreeData(data.name.replace(`${graphName}/`, ''), true, graphName);
- } else {
- this.queryAllTreeData(data.name, true, this.graphFiles.value);
- }
- }
- },
- /**
- * Query tensor value
- * @param { Object } data node info
- * @param { String } graphName Graph name
- */
- retrieveTensorHistory(data, graphName) {
- const params = {
- name: data.name,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- params.name = `${graphName}/${data.name}`;
- } else {
- params.graph_name = graphName;
- }
- RequestService.retrieveTensorHistory(params).then(
- (res) => {
- if (res.data && res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- if (data.name === this.nodeName) {
- if (res.data && res.data.tensor_history) {
- this.tableData = res.data.tensor_history;
- this.dealTableData(this.tableData);
- } else {
- this.tableData = [];
- }
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * Deal tensor history table data
- * @param {Array} arr tensor history data
- */
- dealTableData(arr) {
- const output = arr.filter((val) => val.type === 'output');
- const input = arr.filter((val) => val.type === 'input');
- this.outputLength = output.length;
- this.inputLength = input.length;
- arr.splice(0, arr.length, ...output.concat(input));
- arr.forEach((val) => {
- if (Array.isArray(val.shape)) {
- val.shape = `[${val.shape.toString()}]`;
- } else {
- if (val.shape !== undefined) {
- val.shape = val.shape + '';
- }
- }
- if (val.value === 'click to view') {
- } else {
- if (Array.isArray(val.value)) {
- val.value = `[${val.value.toString()}]`;
- } else {
- if (val.value !== undefined) {
- val.value = val.value + '';
- }
- }
- }
- if (val.dtype !== undefined) {
- val.dtype = val.dtype + '';
- }
- });
- },
- /**
- * Deal metadata
- * @param {Object} metadata metadata
- * @param {Boolean} isQuery wheather to query tree data
- */
- dealMetadata(metadata) {
- if (
- metadata.graph_name &&
- metadata.graph_name !== this.graphFiles.value &&
- this.graphFiles.value !== this.$t('debugger.all')
- ) {
- this.graphFiles.value = metadata.graph_name;
- this.isCurrentGraph = false;
- }
- this.metadata.pos = metadata.pos;
- this.enableRecheck = metadata.enable_recheck;
- if (metadata.state) {
- this.metadata.state = metadata.state;
- }
- if (metadata.debugger_version) {
- this.debuggerVersion = metadata.debugger_version;
- }
- if (metadata.node_name !== undefined && metadata.step !== undefined) {
- const nodeName = metadata.node_name;
- if ((nodeName !== this.currentNodeName && nodeName !== '') || this.metadata.step !== metadata.step) {
- this.nodeName = nodeName ? nodeName : this.nodeName;
- this.currentNodeName = nodeName ? nodeName : this.currentNodeName;
- this.metadata.step = metadata.step;
- this.metadata.graph_name = metadata.graph_name ? metadata.graph_name : this.metadata.graph_name;
- let graphName = this.graphFiles.value === this.$t('debugger.all') ? '' : this.graphFiles.value;
- if (this.graphFiles.value === this.$t('debugger.all') && this.selectedNode.name) {
- graphName = this.selectedNode.name.split('/')[0];
- }
- if (metadata.graph_name) {
- graphName = metadata.graph_name;
- }
- if (this.nodeName) {
- this.queryAllTreeData(this.nodeName, true, graphName);
- }
- }
- }
- if (metadata.step && metadata.step > this.metadata.step) {
- this.metadata.step = metadata.step;
- }
-
- if (metadata.graph_name && metadata.tensor_name && this.tensorCompareFlag) {
- const debTensor = this.$refs['deb-tensor'];
- if (debTensor) {
- debTensor.updateGraphData(metadata.graph_name, metadata.tensor_name);
- }
- }
- },
- /**
- * Long polling,update some info
- */
- pollData() {
- const params = {
- pos: this.metadata.pos,
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- RequestService.pollData(params).then(
- (res) => {
- if (res.data) {
- if (res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- let name = null;
- if (this.$refs.tree && this.$refs.tree.getCurrentKey()) {
- name = this.$refs.tree.getCurrentKey();
- }
- let graphName = this.graphFiles.value;
- if (
- res.data.receive_tensor &&
- res.data.metadata &&
- res.data.metadata.step >= this.metadata.step &&
- res.data.receive_tensor.node_name === name
- ) {
- if (this.graphFiles.value === this.$t('debugger.all')) {
- graphName = name.split('/')[0];
- name = name.replace(`${graphName}/`, '');
- }
- this.retrieveTensorHistory(
- {
- name,
- },
- graphName,
- );
- }
- if (res.data.watch_point_hits && res.data.watch_point_hits.length > 0) {
- this.radio1 = 'hit';
- this.dealWatchpointHits(res.data.watch_point_hits);
- }
- this.pollData();
- }
- },
- (err) => {
- if (!err || (err && err.message !== 'routeJump')) {
- this.initFail = true;
- this.dialogVisible = true;
- }
- },
- );
- },
- /**
- * Step,continue,pause,terminate opesssrate
- * @param {Number} type
- */
- control(type) {
- if (type !== 3) {
- this.watchPointHits = [];
- }
- const params = {};
- if (type === 0) {
- if (!this.step) {
- return;
- }
- params.mode = 'continue';
- params.steps = parseInt(this.step);
- } else if (type === 1) {
- params.mode = 'continue';
- params.steps = -1;
- } else if (type === 2) {
- params.mode = 'terminate';
- } else if (type === 3) {
- params.mode = 'pause';
- }
- RequestService.control(params).then(
- (res) => {
- if (res.data && res.data.metadata) {
- const h = this.$createElement;
- this.$message({
- message: h('p', null, [
- h('span', null, this.$t('debugger.backstageStatus')),
- h('i', {style: 'color: teal'}, res.data.metadata.state),
- ]),
- });
- this.metadata.state = res.data.metadata.state;
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * Show orginal tree
- */
- loadOriginalTree() {
- this.node.childNodes = [];
- this.curWatchPointId = null;
- this.defaultCheckedArr = [];
- this.resolve(JSON.parse(JSON.stringify(this.origialTree)));
- this.resetGraph();
- },
- recheckWatchpoint() {
- RequestService.recheckWatchPoints().then(
- (res) => {
- if (res && res.data && res.data.metadata) {
- this.enableRecheck = res.data.metadata.enable_recheck;
- }
- this.$message.success(this.$t('debugger.recheckSucess'));
- },
- (err) => {},
- );
- },
- /**
- * Add watchpoint
- */
- addWatchPoint() {
- this.createWatchPointArr.push({
- collection: {
- selectedId: this.conditionCollections[0].id,
- },
- condition: {
- selectedId: '',
- options: [],
- },
- param: {
- options: [],
- name: '',
- value: '',
- type: '',
- },
- compositeParams: {
- options: [],
- selections: [],
- },
- });
- this.collectionChange(this.createWatchPointArr[0]);
- this.createWPDialogVisible = true;
- this.curWatchPointId = null;
- },
- /**
- * Delete new watchpoint
- * @param {Object} item watchpoint data
- */
- deleteWatchpoint(item) {
- if (!this.watchPointArr.length) {
- return;
- }
- if ((item && item.id) || !item) {
- const msg = item ? this.$t('debugger.deleteWatchpointConfirm') : this.$t('debugger.clearWatchpointConfirm');
- this.$confirm(msg, this.$t('public.notice'), {
- confirmButtonText: this.$t('public.sure'),
- cancelButtonText: this.$t('public.cancel'),
- type: 'warning',
- }).then(() => {
- if (!item) {
- this.curWatchPointId = null;
- this.watchPointArr = [];
- }
- const params = {watch_point_id: item ? item.id : null};
- RequestService.deleteWatchpoint(params).then(
- (res) => {
- this.loadOriginalTree();
- this.queryWatchPoints();
- this.$message.success(this.$t('debugger.successDeleteWP'));
- if (res && res.data && res.data.metadata) {
- this.enableRecheck = res.data.metadata.enable_recheck;
- }
- this.curWatchPointId = null;
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- });
- } else {
- this.curWatchPointId = null;
- }
- },
- validateParam(item) {
- this.$forceUpdate();
- const reg = /^(\-|\+)?\d+(\.\d+)?$/;
- this.validPram = reg.test(item.param.value);
- item.compositeParams.selections.forEach((i) => {
- this.validPram = this.validPram && reg.test(i.value);
- });
- },
- /**
- * Create new watchpoint
- * @param {Boolean} creatFlag Whether create watchpoint
- */
- createWatchPoint(creatFlag) {
- if (creatFlag) {
- const item = this.createWatchPointArr[0];
- const params = {
- condition: {
- id: item.condition.selectedId,
- params: [],
- },
- watch_nodes: [],
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
-
- if (item.param.options.length) {
- params.condition.params = [
- {
- name: item.param.name,
- value: item.param.type === 'BOOL' ? Boolean(item.param.value) : Number(item.param.value),
- },
- ];
- }
- if (item.compositeParams.selections.length) {
- item.compositeParams.selections.forEach((i) => {
- params.condition.params.push({
- name: i.name,
- value: i.type === 'BOOL' ? Boolean(i.value) : Number(i.value),
- });
- });
- }
- RequestService.createWatchpoint(params).then(
- (res) => {
- this.createWatchPointArr = [];
- this.createWPDialogVisible = false;
- this.$message.success(this.$t('debugger.successCreateWP'));
- if (res && res.data && res.data.metadata) {
- this.enableRecheck = res.data.metadata.enable_recheck;
- }
-
- this.queryWatchPoints(true);
- },
- (err) => {
- this.loadOriginalTree();
- this.queryWatchPoints();
- this.showErrorMsg(err);
- },
- );
- } else {
- this.createWatchPointArr = [];
- this.createWPDialogVisible = false;
- }
- },
- /**
- * Collection change processing
- * @param {Object} item
- */
- collectionChange(item) {
- const collection = this.conditionCollections.filter((i) => {
- return i.id === item.collection.selectedId;
- })[0];
-
- if (collection.conditions && collection.conditions.length) {
- item.condition.options = collection.conditions;
- item.condition.selectedId = item.condition.options[0].id;
- this.conditionChange(item);
- } else {
- item.condition.options = [];
- item.condition.selectedId = '';
-
- item.param.options = [];
- item.param.name = '';
- item.param.type = '';
- item.param.value = '';
- this.validPram = false;
- }
- },
- /**
- * Condition change processing
- * @param {Object} item
- */
- conditionChange(item) {
- const condition = item.condition.options.filter((i) => {
- return i.id === item.condition.selectedId;
- })[0];
-
- if (condition.parameters && condition.parameters.length) {
- item.param.options = condition.parameters.filter((i) => {
- return i.param_type !== 'SUPPORT_PARAM';
- });
-
- item.compositeParams.options = condition.parameters.filter((i) => {
- return i.param_type === 'SUPPORT_PARAM';
- });
-
- item.param.name = item.param.options[0].name;
- this.paramChange(item);
- } else {
- item.param.options = [];
- item.param.name = '';
- item.param.type = '';
- item.param.value = '';
- this.validPram = true;
-
- item.compositeParams.options = [];
- item.compositeParams.selections = [];
- }
- },
- /**
- * Parameter change processing
- * @param {Object} item
- */
- paramChange(item) {
- const param = item.param.options.filter((i) => {
- return i.name === item.param.name;
- })[0];
-
- if (param.required_params && param.required_params.length) {
- item.compositeParams.selections = item.compositeParams.options.filter((i) => {
- return param.required_params.includes(i.name);
- });
- item.compositeParams.selections.forEach((i) => {
- i.value = i.type === 'BOOL' ? true : '';
- });
- } else {
- item.compositeParams.selections = [];
- }
-
- item.param.type = param.type;
- item.param.value = '';
- this.validPram = false;
- if (item.param.type === 'BOOL') {
- item.param.value = true;
- this.validPram = true;
- }
- },
- /** Draw the tree
- * @param {Object} obj Current checked obj
- */
- check(obj) {
- const node = this.$refs.tree.getNode(obj.name);
- const check = node.checked;
- if (this.treeFlag && node.childNodes) {
- this.dealCheckPro(node.childNodes, node.indeterminate || check);
- }
- if (this.curWatchPointId) {
- this.$refs.tree.getCheckedKeys().forEach((val) => {
- const node = this.$refs.tree.getNode(val);
- if (node.data.type === this.unCheckedNodeType) {
- node.checked = false;
- }
- });
- const checkedKeys = this.$refs.tree.getCheckedKeys();
- const watchNodes = [];
- if (this.defaultCheckedArr.length === checkedKeys.length) {
- return;
- } else if (this.defaultCheckedArr.length > checkedKeys.length) {
- watchNodes.push(obj.name);
- } else {
- checkedKeys.forEach((val) => {
- if (this.defaultCheckedArr.indexOf(val) === -1) {
- watchNodes.push(val);
- }
- });
- }
- const params = {
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- watch_nodes: watchNodes,
- mode: node.indeterminate || check ? 1 : 0,
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- if (this.searchWord !== '') {
- params.name = this.searchWord;
- params.watch_nodes = [obj.name];
- params.mode = check ? 1 : 0;
- }
- RequestService.updateWatchpoint(params).then(
- (res) => {
- this.defaultCheckedArr = checkedKeys;
- this.enableRecheck = res.data.metadata.enable_recheck;
- this.$nextTick(() => {
- if (node.indeterminate) {
- node.checked = true;
- node.indeterminate = false;
- }
- if (check) {
- this.dealParentNode(node);
- }
- });
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- }
- },
- dealParentNode(node) {
- const parent = node.parent;
- if (
- parent &&
- !parent.childNodes
- .filter((val) => val.data.type !== this.unCheckedNodeType)
- .find((val) => val.checked === false)
- ) {
- parent.checked = true;
- parent.indeterminate = false;
- this.dealParentNode(parent);
- }
- },
- searchCheck(obj) {
- const node = this.$refs.searchTree.getNode(obj.name);
- const check = node.checked;
- if (node.childNodes) {
- this.dealCheckPro(node.childNodes, node.indeterminate || check);
- }
- const params = {
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- watch_nodes: [obj.name],
- mode: check ? 1 : 0,
- graph_name: this.graphFiles.value,
- search_pattern: {name: this.searchedWord, node_category: obj.type},
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- RequestService.updateWatchpoint(params).then(
- (res) => {
- this.enableRecheck = res.data.metadata.enable_recheck;
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /** Deal tree data
- * @param {Object} childNodes tree node
- * @param { Boolean } check check status
- */
- dealCheckPro(childNodes, check) {
- childNodes.forEach((val) => {
- val.indeterminate = false;
- if (val.data.type !== this.unCheckedNodeType) {
- val.checked = check;
- } else {
- val.checked = false;
- }
- if (val.childNodes) {
- this.dealCheckPro(val.childNodes, check);
- }
- });
- },
- /**
- * Collapse node
- * @param {Object} _
- * @param {Object} node node data
- */
- nodeCollapse(_, node) {
- node.loaded = false;
- node.childNodes = [];
- if (this.treeFlag) {
- this.dealDoubleClick(node.data.name);
- }
- },
- /**
- * Function to be executed after the search value changes
- */
- filterChange() {
- if (this.searchWord === '' && this.nodeTypes.value === 'all') {
- this.treeFlag = true;
- this.$nextTick(() => {
- setTimeout(() => {
- const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
- if (dom) {
- dom.scrollIntoView();
- }
- }, 800);
- });
- }
- },
- /**
- * Filter tree data by node name
- */
- filter() {
- this.treeFlag = this.searchWord === '' && this.nodeTypes.value === 'all';
- if (this.searchWord || this.nodeTypes.value !== 'all') {
- this.searchedWord = this.searchWord;
- const params = {
- name: this.searchWord,
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- if (this.nodeTypes.value !== 'all') {
- params.node_category = this.nodeTypes.value;
- }
- RequestService.search(params).then(
- (res) => {
- if (res.data && res.data.nodes) {
- this.searchTreeData = res.data.nodes;
- this.searchHalfCheckedArr = [];
- this.dealSearchResult(this.searchTreeData);
- this.defaultCheckedArr = this.searchCheckedArr;
- this.searchNode.childNodes = [];
- const data = res.data.nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- ...val,
- };
- });
- const currentData = JSON.parse(JSON.stringify(data));
- currentData.forEach((val) => {
- val.nodes = [];
- });
- this.searchResolve(currentData);
- // watched 0:unchecked 1:indeterminate 2:checked
- this.searchNode.childNodes.forEach((val) => {
- if (val.data.watched === 1) {
- val.indeterminate = true;
- }
- if (val.data.watched === 2) {
- val.checked = true;
- }
- });
- data.forEach((val, key) => {
- if (val.nodes && val.nodes.length) {
- val.nodes.forEach((value) => {
- value.parentName = val.name;
- });
- this.dealSearchTreeData(val.nodes);
- }
- });
- this.searchHalfCheckedArr.forEach((val) => {
- this.$refs.searchTree.getNode(val).indeterminate = true;
- });
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- }
- },
- dealSearchTreeData(children) {
- children.forEach((val) => {
- const node = this.$refs.searchTree.getNode(val.parentName);
- val.label = val.name.split('/').pop();
- val.leaf = val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true;
- this.$refs.searchTree.append(val, node);
- node.expanded = true;
- // watched 0:unchecked 1:indeterminate 2:checked
- node.childNodes.forEach((value) => {
- if (value.data.watched === 1) {
- value.indeterminate = true;
- }
- if (value.data.watched === 2) {
- value.checked = true;
- }
- });
- if (val.nodes && val.nodes.length) {
- val.nodes.forEach((value) => {
- value.parentName = val.name;
- });
- this.dealSearchTreeData(val.nodes);
- }
- });
- },
- /**
- * Deal search data
- * @param {Array} arr search tree data
- */
- dealSearchResult(arr) {
- arr.forEach((val) => {
- if (val.nodes) {
- this.dealSearchResult(val.nodes);
- }
- // watched 0:unchecked 1:indeterminate 2:checked
- if (val.watched === 2 && val.type !== this.unCheckedNodeType) {
- this.searchCheckedArr.push(val.name);
- }
- val.label = val.name.split('/').pop();
- });
- },
- /**
- * Draw the tree
- * @param {Object} node tree root node
- * @param {Function} resolve callback function ,return next node data
- */
- loadNode(node, resolve) {
- if (node.level === 0) {
- const loadingInstance = this.$loading(this.loadingOption);
- node.childNodes = [];
- if (!this.node && !this.resolve) {
- this.node = node;
- this.resolve = resolve;
- }
- const params = {
- mode: 'all',
- };
- RequestService.retrieve(params).then(
- (res) => {
- loadingInstance.close();
- this.initFail = false;
- this.dialogVisible = false;
- if (res.data) {
- if (res.data.graph && res.data.graph.nodes) {
- this.graphFiles.options = res.data.graph.graph_names || [];
- if (this.graphFiles.options.length > 1) {
- this.graphFiles.options.unshift(this.$t('debugger.all'));
- }
- this.graphFiles.value = this.graphFiles.options[0];
- this.origialTree = res.data.graph.nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
- ...val,
- };
- });
- resolve(this.origialTree);
- this.dealGraphData(JSON.parse(JSON.stringify(res.data.graph.nodes)));
- }
- if (res.data.watch_points) {
- this.watchPointArr = res.data.watch_points.map((val) => {
- return {
- id: val.id,
- condition: val.watch_condition.id,
- params: val.watch_condition.params || [],
- selected: false,
- };
- });
- }
- if (res.data.metadata) {
- if (res.data.metadata.debugger_version) {
- this.debuggerVersion = res.data.metadata.debugger_version;
- }
- this.metadata = res.data.metadata;
- this.enableRecheck = res.data.metadata.enable_recheck;
- if (this.metadata.backend) {
- this.version = this.metadata.backend;
- }
- this.trainId = encodeURIComponent(res.data.metadata.ip);
- if (this.trainId) {
- this.initCondition();
- }
- if (!res.data.metadata.recommendation_confirmed && this.trainId) {
- this.recommendWatchPointDialog = true;
- }
-
- this.nodeName = this.metadata.node_name;
- this.currentNodeName = this.nodeName;
- if (this.pollInit) {
- this.pollData();
- this.pollInit = false;
- }
- }
- }
- },
- (err) => {
- this.initFail = true;
- this.dialogVisible = true;
- loadingInstance.close();
- },
- );
- } else if (node.level >= 1) {
- this.isIntoView = false;
- const curHalfCheckedKeys = this.$refs.tree.getHalfCheckedKeys();
- const params = {
- mode: 'node',
- params: {
- node_type: node.data.type,
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- name: node.data.name,
- graph_name: this.graphFiles.value,
- },
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.params.graph_name;
- }
- RequestService.retrieve(params).then(
- (res) => {
- if (res.data && res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- if (res.data && res.data.graph) {
- const graph = res.data.graph;
- this.curNodeData = graph.nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
- ...val,
- showCheckbox: val.type !== this.unCheckedNodeType,
- };
- });
- resolve(this.curNodeData);
- // watched 0:unchecked 1:indeterminate 2:checked
- this.defaultCheckedArr = this.defaultCheckedArr.concat(
- this.curNodeData
- .filter((val) => {
- return val.watched === 2 && val.type !== this.unCheckedNodeType;
- })
- .map((val) => val.name),
- );
- const halfSelectArr = this.curNodeData
- .filter((val) => {
- return val.watched === 1 && val.type !== this.unCheckedNodeType;
- })
- .map((val) => val.name);
- node.childNodes.forEach((val) => {
- if (halfSelectArr.indexOf(val.data.name) !== -1) {
- val.indeterminate = true;
- node.indeterminate = true;
- [...new Set(curHalfCheckedKeys.concat(this.$refs.tree.getHalfCheckedKeys()))].forEach((val) => {
- this.$refs.tree.getNode(val).indeterminate = true;
- });
- }
- });
- this.selectedNode.name = node.data.name;
- if (!this.allGraphData[node.data.name].isUnfold) {
- this.dealGraphData(JSON.parse(JSON.stringify(graph.nodes)), node.data.name);
- } else {
- this.selectNode(true);
- }
- } else {
- this.selectedNode.name = node.data.name;
- this.selectNode(true);
- resolve([]);
- }
- },
- (err) => {
- this.showErrorMsg(err);
- resolve([]);
- },
- );
- }
- },
- /**
- * Draw the tree
- * @param {Object} node tree root node
- * @param {Function} resolve callback function ,return next node data
- */
- loadSearchNode(node, resolve) {
- if (node.level === 0) {
- node.childNodes = [];
- if (!this.searchNode && !this.searchResolve) {
- this.searchNode = node;
- this.searchResolve = resolve;
- }
- } else if (node.level >= 1) {
- const curHalfCheckedKeys = this.$refs.searchTree.getHalfCheckedKeys();
- if (node.childNodes && node.childNodes.length) {
- node.expanded = true;
- node.loaded = true;
- node.loading = false;
- return;
- }
- const params = {
- mode: 'node',
- params: {
- node_type: node.data.type,
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- name: node.data.name,
- graph_name: this.graphFiles.value,
- },
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.params.graph_name;
- }
- RequestService.retrieve(params).then((res) => {
- if (res.data && res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- if (res.data && res.data.graph && res.data.graph.nodes) {
- this.curNodeData = res.data.graph.nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
- ...val,
- showCheckbox: val.type !== this.unCheckedNodeType,
- };
- });
- resolve(this.curNodeData);
- // watched 0:unchecked 1:indeterminate 2:checked
- const halfSelectArr = this.curNodeData
- .filter((val) => {
- return val.watched === 1;
- })
- .map((val) => val.name);
- node.childNodes.forEach((val) => {
- if (val.data.watched === 2) {
- val.checked = true;
- }
- if (halfSelectArr.indexOf(val.data.name) !== -1) {
- val.indeterminate = true;
- node.indeterminate = true;
- [...new Set(curHalfCheckedKeys.concat(this.$refs.searchTree.getHalfCheckedKeys()))].forEach((val) => {
- this.$refs.searchTree.getNode(val).indeterminate = true;
- });
- }
- });
- }
- });
- }
- },
- initRecommendWatchPoints(value) {
- this.recommendWatchPointDialog = false;
- const params = {
- trainId: this.trainId,
- body: {
- requestBody: {
- set_recommended: value,
- },
- },
- };
- RequestService.setRecommendWatchPoints(params).then((res) => {
- if (res && res.data) {
- if (value) {
- this.queryWatchPoints(false);
- }
- }
- });
- },
- /**
- * Show data of current selected watchpoint
- * @param {Number} key watchpoint id
- */
- selectWatchPoint(key) {
- this.curLeafNodeName = null;
- this.curHalfCheckedKeys = [];
- this.watchPointArr.forEach((val, index) => {
- if (index === key) {
- if (val.id) {
- val.selected = true;
- this.curWatchPointId = val.id;
- if (this.searchWord === '') {
- this.queryGraphByWatchpoint(val.id);
- } else {
- this.filter();
- }
- } else {
- this.loadOriginalTree();
- }
- } else {
- if (val.selected) {
- val.selected = false;
- }
- }
- });
- },
- /**
- * Query WatchPoints
- * @param {Boolean} focusLast
- */
- queryWatchPoints(focusLast) {
- const params = {
- mode: 'watchpoint',
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- RequestService.retrieve(params).then(
- (res) => {
- if (res.data.watch_points) {
- this.watchPointArr = res.data.watch_points.map((val) => {
- return {
- id: val.id,
- condition: val.watch_condition.id,
- params: val.watch_condition.params || [],
- selected: false,
- };
- });
-
- if (focusLast) {
- this.selectWatchPoint(this.watchPointArr.length - 1);
- this.$nextTick(() => {
- const newWatchPointDom = document.querySelector('#watch-point-list>li:last-child');
- if (newWatchPointDom) {
- newWatchPointDom.scrollIntoView();
- }
- });
- }
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * Tree linkage with graph Expand of current node
- * @param {Obejct} nodes Data of children of current node
- * @param {Obejct} name The name of the current node
- */
- nodeExpandLinkage(nodes, name) {
- const curNodeData = nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- ...val,
- showCheckbox: val.type !== this.unCheckedNodeType,
- };
- });
- const node = this.$refs.tree.getNode(name);
- curNodeData.forEach((val) => {
- this.$refs.tree.append(val, name);
- });
- // watched 0:unchecked 1:indeterminate 2:checked
- node.childNodes.forEach((val) => {
- if (
- node.checked &&
- !node.childNodes.find((val) => val.data.watched !== 2) &&
- val.data.type !== this.unCheckedNodeType
- ) {
- val.checked = true;
- }
- if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
- val.checked = true;
- }
- if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
- val.indeterminate = true;
- }
- if (val.data.type !== 'name_scope' && val.data.type !== 'aggregation_scope') {
- val.isLeaf = true;
- }
- });
- node.expanded = true;
- node.loading = false;
- this.$refs.tree.setCurrentKey(name);
- this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
- this.$nextTick(() => {
- if (
- node.indeterminate &&
- !node.childNodes
- .filter((val) => val.data.type !== this.unCheckedNodeType)
- .find((val) => val.checked === false)
- ) {
- node.indeterminate = false;
- node.checked = true;
- this.dealParentNode(node);
- }
- setTimeout(() => {
- const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
- if (dom) {
- dom.scrollIntoView();
- }
- }, 800);
- });
- },
- /**
- * Query WatchpointHits
- */
- getWatchpointHits() {
- if (this.radio1 === 'hit') {
- const params = {
- mode: 'watchpoint_hit',
- graph_name: this.graphFiles.value,
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.graph_name;
- }
- RequestService.retrieve(params).then(
- (res) => {
- if (res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- if (res.data && res.data.watch_point_hits) {
- this.hitsOutdated = res.data.outdated;
- this.dealWatchpointHits(res.data.watch_point_hits);
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- } else {
- this.$nextTick(() => {
- setTimeout(() => {
- const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
- if (dom) {
- dom.scrollIntoView();
- }
- }, 200);
- });
- }
- },
- dealWatchpointHits(data) {
- this.watchPointHits = [];
- const tipsMapping = {1: 'NAN', 2: 'INF', 3: 'NAN, INF'};
- if (data && data.length) {
- data.forEach((hit) => {
- const obj = {
- name: hit.node_name,
- lists: [],
- selected: false,
- id: hit.node_name,
- graph_name: hit.graph_name,
- };
- if (hit.tensors && hit.tensors.length) {
- hit.tensors.forEach((i) => {
- const tensorName = `slot: ${i.slot}, `;
- if (i.watch_points && i.watch_points.length) {
- i.watch_points.forEach((j, key) => {
- let item = `${tensorName} Watch Point Id: ${j.id}, `;
- if (j.watch_condition) {
- item += ` ${this.transCondition(j.watch_condition.id)}`;
- const param = (j.watch_condition.params || [])
- .map((k) =>
- !k.actual_value
- ? `${this.transCondition(k.name)}: ${this.$t('debugger.setValue')}:${k.value}`
- : `${this.transCondition(k.name)}: ${this.$t('debugger.setValue')}:${k.value}${this.$t(
- 'debugger.actualValue',
- )}:${k.actual_value}`,
- )
- .join(', ');
- if (param) {
- item += ` (${param})`;
- }
- }
- obj.lists.push({
- name: item,
- id: `${key}${hit.node_name}`,
- tip: j.watch_condition.error_code
- ? this.$t('debugger.checkTips', {msg: tipsMapping[j.watch_condition.error_code]})
- : '',
- });
- });
- }
- });
- }
- this.watchPointHits.push(obj);
- });
- this.focusWatchpointHit();
- }
- },
- focusWatchpointHit() {
- if (this.selectedNode.name) {
- let selectedNodeName = this.selectedNode.name;
- if (this.graphFiles.value === this.$t('debugger.all')) {
- selectedNodeName = selectedNodeName.replace(`${selectedNodeName.split('/')[0]}/`, '');
- }
- this.expandKeys = [];
- this.watchPointHits.forEach((val) => {
- if (val.name === selectedNodeName) {
- val.selected = true;
- this.expandKeys.push(val.id);
- } else {
- val.selected = false;
- }
- });
- this.$nextTick(() => {
- setTimeout(() => {
- const dom = document.querySelector('.hit-item.selected');
- if (dom) {
- dom.scrollIntoView();
- }
- }, 200);
- });
- }
- },
- /**
- * Update tensor value
- * @param {number} key The index of the node of the watchPointHits currently clicked
- */
- updateTensorValue(key) {
- const currentHit = this.watchPointHits[key];
- const name = currentHit.name;
- const temName = this.nodeName;
- this.nodeName = name;
- this.isHitIntoView = false;
- const params = {
- mode: 'watchpoint_hit',
- params: {
- name,
- single_node: true,
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- graph_name: currentHit.graph_name,
- },
- };
- if (this.graphFiles.value === this.$t('debugger.all')) {
- delete params.params.graph_name;
- params.params.name = `${currentHit.graph_name}/${name}`;
- }
- this.watchPointHits.forEach((val, index) => {
- if (key === index) {
- val.selected = true;
- } else {
- val.selected = false;
- }
- });
- this.watchPointHits = JSON.parse(JSON.stringify(this.watchPointHits));
- RequestService.retrieve(params).then(
- (res) => {
- if (res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- this.retrieveTensorHistory({name: this.nodeName}, currentHit.graph_name);
- if (res.data && res.data.graph) {
- const graph = res.data.graph;
-
- if (
- this.graphFiles.value !== currentHit.graph_name &&
- this.graphFiles.value !== this.$t('debugger.all')
- ) {
- this.graphFiles.value = currentHit.graph_name;
- this.resetAllData(graph, params.params.name);
- } else {
- this.querySingleNode(JSON.parse(JSON.stringify(graph)), params.params.name, true);
- }
- if (graph.children) {
- this.dealTreeData(graph.children, name);
- this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
- }
- }
- },
- (err) => {
- this.showErrorMsg(err);
- this.nodeName = temName;
- },
- );
- },
- /**
- * Query the graph data
- * @param {String} nodeName The name of the node that needs to be query
- * @param {Boolean} isQueryTensor The name of the node that needs to be query
- * @param {String} graphName Graph file name
- */
- queryAllTreeData(nodeName, isQueryTensor, graphName) {
- let name = nodeName ? nodeName.split(':')[0] : '';
- const params = {
- mode: 'node',
- params: {
- name,
- single_node: true,
- watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
- },
- };
- if (this.graphFiles.value === this.$t('debugger.all') && graphName && name) {
- name = `${graphName}/${name}`;
- params.params.name = name;
- } else {
- params.params.graph_name = graphName;
- }
- RequestService.retrieve(params).then(
- (res) => {
- if (res.data && res.data.metadata) {
- this.dealMetadata(res.data.metadata);
- }
- if (res.data && res.data.graph) {
- const graph = res.data.graph;
- if (graph.nodes && !this.isCurrentGraph) {
- this.resetAllData(graph, name);
- this.isCurrentGraph = true;
- } else {
- this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
- }
- if (graph.children) {
- this.dealTreeData(graph.children, name);
- this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
- }
- }
- },
- (err) => {
- this.showErrorMsg(err);
- },
- );
- },
- /**
- * Draw the tree
- * @param {Object} children child node
- * @param {String} name The name of the node that needs to be highlighted
- */
- dealTreeData(children, name) {
- if (children.nodes) {
- const data = children.nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- ...val,
- showCheckbox: val.type !== this.unCheckedNodeType,
- };
- });
- data.forEach((val) => {
- const node = this.$refs.tree.getNode(children.scope_name);
- if (node.childNodes) {
- if (node.childNodes.map((value) => value.data.name).indexOf(val.name) === -1) {
- this.$refs.tree.append(val, node);
- }
- } else {
- this.$refs.tree.append(val, node);
- }
- });
- const node = this.$refs.tree.getNode(children.scope_name);
- // watched 0:unchecked 1:indeterminate 2:checked
- node.childNodes.forEach((val) => {
- if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
- val.checked = true;
- }
- if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
- val.indeterminate = true;
- }
- if (val.data.type !== 'name_scope' && val.data.type !== 'aggregation_scope') {
- val.isLeaf = true;
- }
- });
- node.expanded = true;
- node.loading = false;
- } else {
- this.$refs.tree.setCurrentKey(name);
- this.$nextTick(() => {
- setTimeout(() => {
- const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
- if (dom) {
- dom.scrollIntoView();
- }
- }, 800);
- });
- }
- if (children.children) {
- this.dealTreeData(children.children, name);
- }
- },
- resetAllData(graph, name) {
- this.node.childNodes = [];
- this.origialTree = graph.nodes.map((val) => {
- return {
- label: val.name.split('/').pop(),
- leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
- ...val,
- showCheckbox: val.type !== this.unCheckedNodeType,
- };
- });
- this.resolve(this.origialTree);
- // watched 0:unchecked 1:indeterminate 2:checked
- this.node.childNodes.forEach((val) => {
- if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
- val.checked = true;
- }
- if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
- val.indeterminate = true;
- }
- });
- this.firstFloorNodes = [];
- this.allGraphData = {};
- d3.select('#graph svg').remove();
- this.packageDataToObject('', true, JSON.parse(JSON.stringify(graph.nodes)));
- if (name) {
- this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
- } else {
- this.resetGraph();
- }
- },
- },
- };
- </script>
|