Skip to content

[Tree widget]: Add docs for visibility handling#1606

Open
JonasDov wants to merge 20 commits intotree-widget/nextfrom
JonasD/visibility-md
Open

[Tree widget]: Add docs for visibility handling#1606
JonasDov wants to merge 20 commits intotree-widget/nextfrom
JonasD/visibility-md

Conversation

@JonasDov
Copy link
Contributor

Added Visibility.md file, it explains the structure of how visibility handling works in tree widget. Also, added diagrams that showcase how visibility status is determined for different types of nodes.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tree-Widget Next benchmark

Benchmark suite Current: 1dc2819 Previous: 9e3cf65 Deviation Status
categories tree creates initial filtered view for 50k items 1523.75 ms 1491.45 ms 2.17% 〰️
categories tree creates initial filtered view for 50k items (P95 of main thread blocks) 78 ms 78 ms 0% 🟰
categories tree changing definition container visibility changes visibility for 50k subCategories 7353.04 ms 5447.92 ms 34.97% 🚨
categories tree changing definition container visibility changes visibility for 50k subCategories (P95 of main thread blocks) 41 ms 66 ms -37.88% 〰️
categories tree changing definition container visibility changes visibility for 50k categories 12501.56 ms 10935.91 ms 14.32% 🚨
categories tree changing definition container visibility changes visibility for 50k categories (P95 of main thread blocks) 297 ms 571 ms -47.99%
classifications tree loads initial view for iModel with 50k classifications 31.18 ms 37.72 ms -17.34% 〰️
classifications tree loads initial view for iModel with 50k classifications (P95 of main thread blocks) 0 ms 0 ms 0% 🟰
classifications tree loads first branch for iModel with 50k classifications 876.92 ms 899.54 ms -2.51% 〰️
classifications tree loads first branch for iModel with 50k classifications (P95 of main thread blocks) 119 ms 79 ms 50.63% 〰️
models tree creates initial filtered view for 50k target items 905.78 ms 889.52 ms 1.83% 〰️
models tree creates initial filtered view for 50k target items (P95 of main thread blocks) 69 ms 82 ms -15.85% 〰️
models tree validates categories visibility for imodel with 50k categories 4749.56 ms 4572.18 ms 3.88% 〰️
models tree validates categories visibility for imodel with 50k categories (P95 of main thread blocks) 170 ms 175 ms -2.86% 〰️
models tree changing model visibility changes visibility for 50k elements 2080.67 ms 1994.85 ms 4.30% 〰️
models tree changing model visibility changes visibility for 50k elements (P95 of main thread blocks) 0 ms 0 ms 0% 🟰
models tree changing category visibility changes visibility for 50k elements 2057.06 ms 1999.18 ms 2.90% 〰️
models tree changing category visibility changes visibility for 50k elements (P95 of main thread blocks) 0 ms 0 ms 0% 🟰
models tree changing per-model-category override changes visibility for 50k elements 2034.94 ms 1957.44 ms 3.96% 〰️
models tree changing per-model-category override changes visibility for 50k elements (P95 of main thread blocks) 0 ms 0 ms 0% 🟰
models tree changing element visibility changes only parent nodes visibility with 50k elements 2766.17 ms 2768.95 ms -0.10% 〰️
models tree changing element visibility changes only parent nodes visibility with 50k elements (P95 of main thread blocks) 360 ms 312 ms 15.38% 〰️
models tree changing element visibility changes only parent nodes visibility with 50k child elements with different categories 2747.39 ms 2696.04 ms 1.90% 〰️
models tree changing element visibility changes only parent nodes visibility with 50k child elements with different categories (P95 of main thread blocks) 335 ms 384 ms -12.76% 〰️

This comment was automatically generated by workflow using github-action-benchmark.

@grigasp
Copy link
Member

grigasp commented Feb 23, 2026

what do you think about using this?

R3[/hidden/]

%% Start
TITLE([getSubjectsVisibilityStatus]) --> A["Get models under Props.subjectIds from cache. These are related models and models of child subjects (can be nested)"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we put Props.subjectIds to backticks?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems that mermaid diagrams don't understand backticks and show backtick symbols instead. Wrapped in <code> sections instead.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the rest, too? E.g. TITLE, PROPS and function calls like

A -- modelIds --> B["<code><a href='./SharedVisibilityHandling.md#getmodelsvisibilitystatus'>getModelsVisibilityStatus</a>({ modelIds })</code>"]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

Comment on lines +86 to +88
PROPS[\"Props
<div style='text-align: left;'>- subjectIds: **Id64Arg**</div>
"\]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For me it would be clearer if Props started with lower case, e.g. props. Interesting in hearing others' thoughts (@saskliutas @MartynasStrazdas)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to props

Comment on lines +66 to +68
### Getting visibility status

#### getSubjectsVisibilityStatus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about structuring them based on the tree they're used in, instead of just having a plain list of diagrams?

Here's what I'm imagining:

  • Have a separate markdown file per tree + one for shared visibility handling.
    • Each tree specific markdown would have its specific diagrams (e.g. getSubjectsVisibilityStatus would be in models tree markdown) and reference the shared ones that apply to them (e.g. getModelsVisibilityStatus would be in shared markdown and referenced from models tree markdown).
  • The "Architecture" section stays, but instead of having all the diagrams it only references them.
  • Each file will have less diagrams, so we can provide a bit more details. E.g. I think it would be good to have a short description of the diagram. Don't need much for the ones that are clear (e.g. getSubjectsVisibilityStatus), but some of them aren't that clear (e.g. getModelWithCategoryVisibilityStatus) and could use an explanation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to split up based on your suggestion, added short descriptions. Have a look.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking again, I think "Architecture" should be renamed to "Visibility logic" or something like that. The diagrams don't show the architecture.

Also, instead of just linking the files, I'd rather there was a combined TOC for each tree, e.g.:

- Getting visibility status
  - Models tree
    - getSubjectsVisibilityStatus
    - getModelsVisibilityStatus
    - getCategoriesVisibilityStatus
    - getElementsVisibilityStatus
  - Categories tree
    - getDefinitionContainersVisibilityStatus
    - getCategoriesVisibilityStatus
    - getSubCategoriesVisibilityStatus
    - getElementsVisibilityStatus
  - Classifications tree
    - getClassificationTablesVisibilityStatus
    - getClassificationsVisibilityStatus
    - getCategoriesVisibilityStatus
    - getElementsVisibilityStatus

Note: I don't think we need to link utility functions like getAlwaysOrNeverDrawnVisibilityStatus - they get linked from each top-level function diagram.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renamed to Visibility logic added the suggestion inside Visibility logic

Copilot AI review requested due to automatic review settings February 26, 2026 15:34
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds comprehensive documentation for visibility handling in the tree widget component. The documentation explains how visibility is determined and changed across different tree types (Models, Categories, and Classifications) and node types, providing detailed architectural insights with Mermaid flowcharts.

Changes:

  • Added Visibility.md documentation file with detailed architecture explanations and Mermaid flowcharts showing visibility status determination for different node types
  • Added Mermaid Chart VS Code extension to recommended extensions for easier diagram editing

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
packages/itwin/tree-widget/Visibility.md New comprehensive documentation file explaining visibility handling architecture, including file structure overview, viewport visibility rules, and detailed flowcharts for visibility status methods
.vscode/extensions.json Added mermaidchart.vscode-mermaid-chart extension to support viewing and editing the Mermaid diagrams in the new documentation

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 9 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JonasDov JonasDov requested a review from grigasp March 5, 2026 10:58
- Data stored in this cache is requested only once, because it does not change.
- Tree-specific id caches ([`CategoriesTreeIdsCache`](../src/tree-widget-react/components/trees/categories-tree/internal/CategoriesTreeIdsCache.ts), [`ClassificationsTreeIdsCache`](../src/tree-widget-react/components/trees/classifications-tree/internal/ClassificationsTreeIdsCache.ts), [`ModelsTreeIdsCache`](../src/tree-widget-react/components/trees/models-tree/internal/ModelsTreeIdsCache.ts)):
- Store various tree-specific relationships, (e.g. models tree ids cache stores element's model <-> subject relationship).
- Implements `BaseVisibilityHandlerImpl` so each tree-specific cache can be used in [`BaseVisibilityHelper`](../src/tree-widget-react/components/trees/common/internal/visibility/BaseVisibilityHelper.ts).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extends BaseIdsCacheImpl?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed

- When changing element or element grouping nodes' visibility, need to put all children (nested as well) into always/never drawn list. This cache is used to retrieve child nodes' ids in such cases.
- It is not used (and should not be used) when getting visibility status:
- Only total children counts (this is stored on nodes `extendedData` property) and child always/never drawn elements (these are retrieved from [`AlwaysAndNeverDrawnElementInfoCache`](../src/tree-widget-react/components/trees/common/internal/caches/AlwaysAndNeverDrawnElementInfoCache.ts)) are needed for determining visibility.
- It should not be used when getting visibility status, since element might have hundreds of thousands of child elements. And retrieving this information for each element in the hierarchy would be very slow.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have "It is not used (and should not be used) when getting visibility status" above, so maybe remove that part from this bullet point and start it with "Element might have ..."

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


# Shared visibility handling

This document explains the shared parts of visibility handling in models, categories and classifications trees. Please read <a href='./Visibility.md#how-visibility-is-determined-in-the-viewport'>how visibility is determined in the viewport</a> before continuing.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should use markdown [label](./link.md#section) syntax for links

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed


This document explains the shared parts of visibility handling in models, categories and classifications trees. Please read <a href='./Visibility.md#how-visibility-is-determined-in-the-viewport'>how visibility is determined in the viewport</a> before continuing.

## Getting visibility status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a TOC above this section? The diagrams are big and there's a lot of scroll needed to find one that I'm interested in.

## Table of contents

- [Getting visibility status](#getting-visibility-status)
  - [getSubCategoriesVisibilityStatus](#getsubcategoriesvisibilitystatus)
  - [getModelsVisibilityStatus](#getmodelsvisibilitystatus)
  - [getCategoriesVisibilityStatus](#getcategoriesvisibilitystatus)
  - [getModelWithCategoryVisibilityStatus](#getmodelwithcategoryvisibilitystatus)
  - [getElementsVisibilityStatus](#getelementsvisibilitystatus)
  - [getAlwaysOrNeverDrawnVisibilityStatus](#getalwaysorneverdrawnvisibilitystatus)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added


This document explains visibility handling for models tree specific cases.

## Getting visibility status
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to my other comment, I'd add a TOC here. Also, in addition to getSubjectsVisibilityStatus, I'd link the high-level ones from shared (e.g. status getters for models, categories, elements)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added

R3[/hidden/]

%% Start
TITLE([getSubjectsVisibilityStatus]) --> A["Get models under Props.subjectIds from cache. These are related models and models of child subjects (can be nested)"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add the rest, too? E.g. TITLE, PROPS and function calls like

A -- modelIds --> B["<code><a href='./SharedVisibilityHandling.md#getmodelsvisibilitystatus'>getModelsVisibilityStatus</a>({ modelIds })</code>"]

Comment on lines +66 to +68
### Getting visibility status

#### getSubjectsVisibilityStatus
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After looking again, I think "Architecture" should be renamed to "Visibility logic" or something like that. The diagrams don't show the architecture.

Also, instead of just linking the files, I'd rather there was a combined TOC for each tree, e.g.:

- Getting visibility status
  - Models tree
    - getSubjectsVisibilityStatus
    - getModelsVisibilityStatus
    - getCategoriesVisibilityStatus
    - getElementsVisibilityStatus
  - Categories tree
    - getDefinitionContainersVisibilityStatus
    - getCategoriesVisibilityStatus
    - getSubCategoriesVisibilityStatus
    - getElementsVisibilityStatus
  - Classifications tree
    - getClassificationTablesVisibilityStatus
    - getClassificationsVisibilityStatus
    - getCategoriesVisibilityStatus
    - getElementsVisibilityStatus

Note: I don't think we need to link utility functions like getAlwaysOrNeverDrawnVisibilityStatus - they get linked from each top-level function diagram.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

JonasDov and others added 3 commits March 20, 2026 16:22
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants