From 6a547b974c69465377b38028677d05df007c20d1 Mon Sep 17 00:00:00 2001 From: "Henri J. Norden" <55378880+Henri-J-Norden@users.noreply.github.com> Date: Fri, 26 Sep 2025 23:37:59 +0300 Subject: [PATCH 1/2] Fixes "ReferenceError: clearPerspective is not defined" regression caused by 6454ec4d --- src/fragments/diagrams/perspectives.jspf | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/fragments/diagrams/perspectives.jspf b/src/fragments/diagrams/perspectives.jspf index 47704f4..bb6f77c 100644 --- a/src/fragments/diagrams/perspectives.jspf +++ b/src/fragments/diagrams/perspectives.jspf @@ -7,6 +7,19 @@ } } + function clearPerspective(render) { + structurizr.diagram.clearPerspective(); + if (render === true) { + structurizr.diagram.renderPerspectiveOrTagsFilter(); + } + tooltip.enable(); + toggleTooltip(); + + $('#perspectivesOnButton').removeClass('hidden'); + $('#perspectivesOffButton').addClass('hidden'); + $('#perspectivesOffButton').attr('title', 'Perspectives'); + } + function openPerspectivesModal() { const perspectiveNames = structurizr.workspace.getPerspectiveNames(); @@ -35,14 +48,7 @@ $('#perspectivesOffButton').removeClass('hidden'); $('#perspectivesOffButton').attr('title', 'Perspective: ' + perspective); } else { - structurizr.diagram.clearPerspective(); - structurizr.diagram.renderPerspectiveOrTagsFilter(); - tooltip.enable(); - toggleTooltip(); - - $('#perspectivesOnButton').removeClass('hidden'); - $('#perspectivesOffButton').addClass('hidden'); - $('#perspectivesOffButton').attr('title', 'Perspectives'); + clearPerspective(true); } }); } From e3a45998ffcde1f6eb02e638438dab12b7b67503 Mon Sep 17 00:00:00 2001 From: "Henri J. Norden" <55378880+Henri-J-Norden@users.noreply.github.com> Date: Fri, 26 Sep 2025 23:40:53 +0300 Subject: [PATCH 2/2] Adds filter to exclude tags --- src/fragments/diagrams/controls.jspf | 4 ++ src/fragments/diagrams/exclude-tags.jspf | 76 ++++++++++++++++++++++++ src/fragments/diagrams/perspectives.jspf | 1 + src/js/structurizr-diagram.js | 41 +++++++++++-- src/jsp/diagrams.jsp | 2 + 5 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 src/fragments/diagrams/exclude-tags.jspf diff --git a/src/fragments/diagrams/controls.jspf b/src/fragments/diagrams/controls.jspf index 09be08c..0c5adb5 100644 --- a/src/fragments/diagrams/controls.jspf +++ b/src/fragments/diagrams/controls.jspf @@ -31,6 +31,8 @@ + + @@ -45,6 +47,8 @@ $('#diagramTooltipOffButton').click(function() { toggleTooltip(); }); $('#tagsOnButton').click(function() { openTagsModal(); }); $('#tagsOffButton').click(function() { openTagsModal(); }); + $('#excludeTagsOnButton').click(function() { openExcludeTagsModal(); }); + $('#excludeTagsOffButton').click(function() { openExcludeTagsModal(); }); $('#perspectivesOnButton').click(function() { openPerspectivesModal(); }); $('#perspectivesOffButton').click(function() { openPerspectivesModal(); }); $('#showDiagramScopeOnButton').click(function() { showDiagramScope(true); }); diff --git a/src/fragments/diagrams/exclude-tags.jspf b/src/fragments/diagrams/exclude-tags.jspf new file mode 100644 index 0000000..a422644 --- /dev/null +++ b/src/fragments/diagrams/exclude-tags.jspf @@ -0,0 +1,76 @@ + + + diff --git a/src/fragments/diagrams/perspectives.jspf b/src/fragments/diagrams/perspectives.jspf index bb6f77c..e5f3396 100644 --- a/src/fragments/diagrams/perspectives.jspf +++ b/src/fragments/diagrams/perspectives.jspf @@ -39,6 +39,7 @@ openNavigationModal(options, function(perspective) { if (perspective.length > 0) { clearTags(false); + clearExcludeTags(false); structurizr.diagram.changePerspective(perspective); structurizr.diagram.renderPerspectiveOrTagsFilter(); tooltip.disable(); diff --git a/src/js/structurizr-diagram.js b/src/js/structurizr-diagram.js index 6d9092e..207b57e 100644 --- a/src/js/structurizr-diagram.js +++ b/src/js/structurizr-diagram.js @@ -84,6 +84,7 @@ structurizr.ui.Diagram = function(id, diagramIsEditable, constructionCompleteCal var currentFilter; var currentPerspective; var currentTags = []; + var currentExcludeTags = []; var lassoStart; var lassoEnd; @@ -1404,8 +1405,28 @@ structurizr.ui.Diagram = function(id, diagramIsEditable, constructionCompleteCal return result; } + function hasExcludeTags(tags) { + var result = false; + + currentExcludeTags.forEach(function(tag) { + result = (result || tags.indexOf(tag) > -1); + }); + + return result; + } + + function areHiddenTags(tags) { + if (hasExcludeTags(tags) === true) { + return true; + } + if (currentTags.length === 0) { + return false; + } + return hasTags(tags) === false; + } + this.renderPerspectiveOrTagsFilter = function() { - if (currentPerspective === undefined && currentTags.length === 0) { + if (currentPerspective === undefined && currentTags.length === 0 && currentExcludeTags.length === 0) { Object.keys(cellsByElementId).forEach(function(elementId) { var cell = cellsByElementId[elementId]; changeColourOfCell(cell, cell._computedStyle.background, cell._computedStyle.color, cell._computedStyle.stroke); @@ -1501,13 +1522,13 @@ structurizr.ui.Diagram = function(id, diagramIsEditable, constructionCompleteCal }); } - if (currentTags.length > 0) { + if (currentTags.length > 0 || currentExcludeTags.length > 0) { Object.keys(cellsByElementId).forEach(function(elementId) { var cell = cellsByElementId[elementId]; var element = structurizr.workspace.findElementById(cell.elementInView.id); const tags = structurizr.workspace.getAllTagsForElement(element); - if (hasTags(tags) === false) { + if (areHiddenTags(tags)) { hideElement(element.id, "0.2"); } else { showElement(element.id); @@ -1518,7 +1539,7 @@ structurizr.ui.Diagram = function(id, diagramIsEditable, constructionCompleteCal var relationship = structurizr.workspace.findRelationshipById(line.relationshipInView.id); const tags = structurizr.workspace.getAllTagsForRelationship(relationship); - if (hasTags(tags) === false) { + if (areHiddenTags(tags)) { hideLine(relationship.id, "0.2"); } else { showLine(relationship.id); @@ -1563,6 +1584,18 @@ structurizr.ui.Diagram = function(id, diagramIsEditable, constructionCompleteCal return currentTags.length > 0; } + this.changeExcludeTags = function(tags) { + currentExcludeTags = tags; + }; + + this.clearExcludeTags = function() { + currentExcludeTags = []; + }; + + this.hasExcludeTags = function() { + return currentExcludeTags.length > 0; + } + this.isEditable = function() { return editable; }; diff --git a/src/jsp/diagrams.jsp b/src/jsp/diagrams.jsp index ece8ae1..eaea169 100644 --- a/src/jsp/diagrams.jsp +++ b/src/jsp/diagrams.jsp @@ -176,6 +176,7 @@ <%@ include file="/WEB-INF/fragments/diagrams/publish.jspf" %> <%@ include file="/WEB-INF/fragments/diagrams/perspectives.jspf" %> <%@ include file="/WEB-INF/fragments/diagrams/tags.jspf" %> +<%@ include file="/WEB-INF/fragments/diagrams/exclude-tags.jspf" %> <%@ include file="/WEB-INF/fragments/diagrams/autolayout.jspf" %> <%@ include file="/WEB-INF/fragments/diagrams/no-views-model.jspf" %> <%@ include file="/WEB-INF/fragments/diagrams/lasso.jspf" %> @@ -351,6 +352,7 @@ initEmbed(); initPerspectives(); initTags(); + initExcludeTags(); initAutoLayout(); initReview(); healthCheck = new structurizr.HealthCheck(updateHealth);