Skip to content

Commit

Permalink
Important fix for medatadata select nodes population when trying to l…
Browse files Browse the repository at this point in the history
…oad zooms in same window.
  • Loading branch information
aldelucaizs committed Jun 3, 2024
1 parent 33e6b5d commit 46fce63
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 92 deletions.
66 changes: 29 additions & 37 deletions js/file-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -397,17 +397,19 @@ gtiz_file_handler.parseMetadata = function(msg, lines, header_index) {
}

gtiz_tree.tree.addMetadataOptions(options);

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.value = category;
if (select.id == 'tree-node-label-text') {
let value = gtiz_tree.node_label ? gtiz_tree.node_label : category;
select.value = value;

if (gtiz_utils.medatadata_select_nodes && gtiz_utils.medatadata_select_nodes.length > 0) {
gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.value = category;
if (select.id == 'tree-node-label-text') {
let value = gtiz_tree.node_label ? gtiz_tree.node_label : category;
select.value = value;
}
}
}
});
});
}

gtiz_tree.tree.addMetadata(meta);
// to be changed in this way for parameters &x=title_name_longitute&y=title_name_latitudine
Expand Down Expand Up @@ -681,37 +683,27 @@ gtiz_file_handler.loadFailed = function(msg) {
gtiz_file_handler.loadTreeText = function(tree, json) {
gtiz_tree.initiateLoading("Processing tree file");

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
if (select.id == 'tree-node-label-text') {
let value = gtiz_tree.node_label ? gtiz_tree.node_label : category;
select.value = value;
} else {
select.value = category;
}
}
});

let metadata_select;
let node_label_text;
let metadata_map_select;

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
if (select.id == 'tree-metadata-select') {
metadata_select = select;
}
if (select.id == 'tree-node-label-text') {
node_label_text = select;
}
if (select.id == 'metadata-map-select') {
metadata_map_select = select;

if (gtiz_utils.medatadata_select_nodes && gtiz_utils.medatadata_select_nodes.length > 0) {
gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
if (select.id == 'tree-metadata-select') {
metadata_select = select;
}
if (select.id == 'tree-node-label-text') {
node_label_text = select;
}
if (select.id == 'metadata-map-select') {
metadata_map_select = select;
}
}
}
});
});
}

// give time to dialog to display
setTimeout(function(){
Expand Down
123 changes: 68 additions & 55 deletions js/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,20 +809,22 @@ gtiz_tree.hideToolTip = function() {
*
*/
gtiz_tree.addMetadataOptions = function (data) {
let options = gtiz_tree.getMetadataSelectOptions();

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
options.forEach(el => {
let option = document.createElement('option');
option.setAttribute('value', el.value);
option.innerHTML = el.label;
select.append(option);
});
}
});
if (gtiz_utils.medatadata_select_nodes && gtiz_utils.medatadata_select_nodes.length > 0) {
let options = gtiz_tree.getMetadataSelectOptions();

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
options.forEach(el => {
let option = document.createElement('option');
option.setAttribute('value', el.value);
option.innerHTML = el.label;
select.append(option);
});
}
});
}
}

/**
Expand Down Expand Up @@ -852,15 +854,17 @@ gtiz_tree.treeLoaded = function(tree) {

tree.addDisplayChangedListener(function(type, data) {
if (type === 'category_changed') {

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
if (select.id != 'tree-node-label-text') {
select.value = data;

if (gtiz_utils.medatadata_select_nodes && gtiz_utils.medatadata_select_nodes.length > 0) {
gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
if (select.id != 'tree-node-label-text') {
select.value = data;
}
}
}
});
});
}

if (gtiz_tree.change_counter === 1) {
gtiz_tree.original_tree.initial_category = data;
Expand Down Expand Up @@ -960,31 +964,36 @@ gtiz_tree.treeLoaded = function(tree) {
gtiz_video.reset();
}
};

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
options.forEach(el => {
let option = document.createElement('option');
option.setAttribute('value', el.value);
option.innerHTML = el.label;
select.append(option);
});

if (data['initial_category']) {
if (select.id == 'tree-node-label-text') {
let value = gtiz_tree.node_label ? gtiz_tree.node_label : data['initial_category'];
select.value = value;
if (gtiz_utils.medatadata_select_nodes && gtiz_utils.medatadata_select_nodes.length > 0) {
let options = gtiz_tree.getMetadataSelectOptions();

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
options.forEach(el => {
let option = document.createElement('option');
option.setAttribute('value', el.value);
option.innerHTML = el.label;
select.append(option);
});

if (data['initial_category']) {
if (select.id == 'tree-node-label-text') {
let value = gtiz_tree.node_label ? gtiz_tree.node_label : data['initial_category'];
select.value = value;
} else {
select.value = data['initial_category'];
}
} else {
select.value = data['initial_category'];
select.value = data['nothing'];
}
} else {
select.value = data['nothing'];

}
});

}
});
}

if (data['layout_data'] && data['layout_data']['nodes_links']) {
// setControlPanel(data['layout_data']['nodes_links'])
Expand Down Expand Up @@ -1031,13 +1040,15 @@ gtiz_tree.loadMSTree = function(data, json) {
gtiz_tree.tree.svg.remove();
gtiz_tree.tree.legend_div[0].remove();
gtiz_tree.tree.scale_div[0].remove();

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
}
});

if (gtiz_utils.medatadata_select_nodes && gtiz_utils.medatadata_select_nodes.length > 0) {
gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
}
});
}
}
gtiz_tree.tree = null;
gtiz_tree.tree = new D3MSTree("graph-div", JSON.parse(JSON.stringify(data)), function(tree, msg) {
Expand Down Expand Up @@ -1178,12 +1189,14 @@ gtiz_tree.initiateLoading = function(msg) {
tree_node.innerHTML = '';
}

gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
}
});
if (gtiz_utils.medatadata_select_nodes && gtiz_utils.medatadata_select_nodes.length > 0) {
gtiz_utils.medatadata_select_nodes.forEach((node) => {
let select = document.querySelector(node);
if (select) {
select.innerHTML = '';
}
});
}

gtiz_tree.metadata_options = {};
console.log(msg);
Expand Down

0 comments on commit 46fce63

Please sign in to comment.