From 0435026f2300c418d6ddcbff4160f6d148be3ae3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20P=C3=B6ckelmann?= <marcus.poeckelmann@informatik.uni-halle.de> Date: Wed, 29 Nov 2023 14:35:40 +0100 Subject: [PATCH] v2.6.4: extension of data_change method --- catview.js | 83 ++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 74 insertions(+), 9 deletions(-) diff --git a/catview.js b/catview.js index 471c198..a8f3884 100644 --- a/catview.js +++ b/catview.js @@ -31,7 +31,7 @@ const CATview = new function() { if(CATview.debug) console.log('CATview.initialize'); - CATview.version = '2.6.3'; + CATview.version = '2.6.4'; // id of the parent container that will include CATview CATview.parent_id = 'CATview'; @@ -127,7 +127,7 @@ const CATview = new function() { // linking of rectangles - highlights linked rectangles on mouse hover by color CATview.rect_linking_enabled = false; - CATview.rect_linking_data = null; // an array with groups of linked rectangles identyfied by their data-segment-index attribute, e.g. + CATview.rect_linking_data = null; // an array with groups of linked rectangles identified by their data-segment-index attribute, e.g. // [ ['19_0', '16_0'], ['25_1', '26_1', '27_1'] ] // (link two segments for the first witness; and three segments for the second) @@ -255,6 +255,8 @@ const CATview = new function() { }; // slight change of the data + // TOOD search_results, extra_segments, edge_names, rect_scaling, rect_linking_data + // Auch bei geƤnderter Reihenfolge der names! this.data_change = function(changes){ if(CATview.debug) console.log('CATview.data_change'); @@ -274,19 +276,60 @@ const CATview = new function() { // todo remaining_edges (insert, remove) let type = changes[i][0]; let col = changes[i][1]; + let edge = changes[i][2][0] + //console.log(type + ' ' + col); + //console.log(changes[i][2] ); switch (type) { case 'replace': - CATview.edges[col] = changes[i][2][0]; + CATview.edges[col] = edge; + // update the extra_segments + for (let j = CATview.extra_segments.length - 1; j >= 0; j--) { + if (CATview.extra_segments[j][0] === col && edge[CATview.extra_segments[j][1]] !== -1){ + // extra segment will be deleted + // prior update corresponding rect linking, e.g. [ ['19_0', '16_0'], ['25_1', '26_1', '27_1'] ] + // TODO kann nicht mit Verschiebung umgehen! + for (let jj = CATview.rect_linking_data.length - 1; jj >= 0; jj--) { + for (let k = CATview.rect_linking_data[jj].length - 1; k >= 0; k--) { + if (CATview.rect_linking_data[jj][k] === '' + col + '_' + CATview.extra_segments[j][1] ) { + CATview.rect_linking_data[jj].splice(k, 1); + } + } + if(CATview.rect_linking_data[jj].length <= 1) + CATview.rect_linking_data.splice(jj, 1); + } + // and delete the extra segment + CATview.extra_segments.splice(j, 1); + + } + } + // TODO update the rect_scaling break; case 'insert': - CATview.edges.splice(col, 0, changes[i][2][0]); + CATview.edges.splice(col, 0, edge); // update the search results for (let j = 0; j < CATview.search_results.length; j++) { if (CATview.search_results[j][0] > col) CATview.search_results[j][0] += 1; } - // update the brush if displayed - // TODO + // update the extra_segments + for (let j = 0; j < CATview.extra_segments.length; j++) { + if (CATview.extra_segments[j][0] > col) + CATview.extra_segments[j][0] += 1; + } + // update the rect_linking_data, e.g. [ ['19_0', '16_0'], ['25_1', '26_1', '27_1'] ] + for (let j = 0; j < CATview.rect_linking_data.length; j++) { + for (let k = 0; k < CATview.rect_linking_data[j].length; k++) { + let pos = CATview.rect_linking_data[j][k].split('_') // [col, wit] + let _col = parseInt(pos[0]) + if(_col > col){ + CATview.rect_linking_data[j][k] = '' + (_col + 1 ) + '_' + pos[1] + } + } + } + // update the edge_names + CATview.edge_names.splice(col, 0, ''); + // TODO update the rect_scaling + // TODO update the brush if displayed break; case 'remove': CATview.edges.splice(col, 1); @@ -296,10 +339,32 @@ const CATview = new function() { CATview.search_results[j][0] -= 1; else if (CATview.search_results[j][0] === col) CATview.search_results.splice(j, 1); - } - // update the brush if displayed - // TODO + // update the extra_segments + for (let j = CATview.extra_segments.length - 1; j >= 0; j--) { + if (CATview.extra_segments[j][0] > col) + CATview.extra_segments[j][0] -= 1; + else if (CATview.extra_segments[j][0] === col) + CATview.extra_segments.splice(j, 1); + } + // update the rect_linking_data, e.g. [ ['19_0', '16_0'], ['25_1', '26_1', '27_1'] ] + for (let j = CATview.rect_linking_data.length - 1; j >= 0; j--) { + for (let k = CATview.rect_linking_data[j].length - 1; k >= 0; k--) { + let pos = CATview.rect_linking_data[j][k].split('_') // [col, wit] + let _col = parseInt(pos[0]) + if(_col > col) + CATview.rect_linking_data[j][k] = '' + (_col - 1 ) + '_' + pos[1] + else if (_col === col) { + CATview.rect_linking_data[j].splice(k, 1); + } + } + if(CATview.rect_linking_data[j].length <= 1) + CATview.rect_linking_data.splice(j, 1); + } + // update the edge_names + CATview.edge_names.splice(col, 1); + // TODO update the rect_scaling + // TODO update the brush if displayed break; default: console.log('CATview.data_change: unknown kind of change (' + changes[i][0] + ')'); -- GitLab