Skip to content

[Web Components] Facet selection#6220

Merged
nick-nlb merged 11 commits into
datacommonsorg:masterfrom
nick-nlb:web-components-facet-selection
Apr 20, 2026
Merged

[Web Components] Facet selection#6220
nick-nlb merged 11 commits into
datacommonsorg:masterfrom
nick-nlb:web-components-facet-selection

Conversation

@nick-nlb
Copy link
Copy Markdown
Contributor

@nick-nlb nick-nlb commented Apr 17, 2026

Description

The various web components contain props to control the data displayed, but until now did not contain the ability to indicate specific facets.

This PR implements the first round of facet-based filtering functionality: the ability to specify facets by ID.

There are three props available, depending on how you wish to apply the facet filtering:

  • facetId: If you wish to apply a single facet across all variables, this is the simplest way to do this. It acts as a broadcast value for all variables in the component.
  • facetIds: If you wish to apply multiple facet IDs across multiple variables, use facetIds. This takes a space-delimited list of facet IDs (matching the variable list), and applies each facet ID to the respective variable positionally.
  • facetMapping: This takes a JSON string mapping variable DCIDs to facet IDs (e.g., '{"Count_Person": "123", "Median_Income_Household": "456"}'). This is the recommended approach for clarity and unambiguity, as it explicitly links a facet to a specific variable regardless of their order in the props.

Conflict Resolution

If a consumer provides multiple facet props simultaneously, the component resolves the facet for each variable using the following order of precedence:

  1. facetMapping: The component first checks if the variable has an explicit mapping in this JSON object.
  2. facetIds: If not found in the mapping, it checks for a facet ID at the matching index in the facetIds list.
  3. facetId: If neither of the above provides a facet ID, it falls back to the global facetId.

Although the resolution order described above is deterministic, it is recommended only to use one of the three in any one component to avoid confusion

Behavior of facetIds (Multiple Variables)

  • Single Value Broadcast: As a convenience, if facetIds contains exactly one ID (e.g., facetIds="123"), that ID will be applied to all variables, effectively behaving the same as facetId.
  • Partial Lists: If facetIds contains more than one ID but fewer than the number of variables, variables at indices that exceed the list length will fall back to the global facetId (if provided) or default resolution.

Notes

Facet Ids are currently transient in that the same facet may not have the same id over time. This will change in upcoming schema changes. However, in the meantime, use of these props should take this transience into account.

  • It is better not to use hard coded facet ids directly within an embedding [i.e., like what we do on the example page] until facet ids become fixed.
  • However, you can use this to flexibly update web components, for example, via an external facet selector or via an agent-based tool that uses the web-component to display facet-scoped information, because in those cases, the use of the facet and web component is not permanent, but rather using a facet id that was immediately looked up.

Testing and Examples

There is a page available only on dev that demonstrates this functionality across the various web components.

When running the website locally, you can access this page at:

Dev Example Page

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the web components library by adding support for facet-based filtering. It allows consumers to precisely control which data facets are displayed for specific variables using a flexible set of configuration props. The changes include updates to the component interfaces, the underlying rendering logic, and a new utility function to handle the facet resolution logic consistently across all components.

Highlights

  • Facet Filtering Support: Introduced new props (facetId, facetIds, facetMapping) across multiple web components to enable specific facet-based data filtering.
  • Deterministic Resolution Logic: Implemented a priority-based resolution system for facet selection, prioritizing explicit mapping, followed by positional lists, and finally a global fallback.
  • Developer Experience: Added a new development-only page to demonstrate and test the new facet filtering functionality across various components.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces facet filtering capabilities to several web components, including Bar, Highlight, Line, Map, Ranking, and Scatter charts, by adding facetId, facetIds, and facetMapping properties. It also includes a new development route and template to demonstrate these features. A bug was identified in the getFacetId utility function where an early return prevents proper fallback logic when a variable is missing from the mapping. Additionally, it was suggested to optimize performance by parsing the mapping JSON once per render cycle rather than for every variable.

Comment thread static/library/utils.ts Outdated
@nick-nlb nick-nlb marked this pull request as ready for review April 17, 2026 17:51
@nick-nlb nick-nlb requested review from dwnoble and keyurva April 17, 2026 17:51
Copy link
Copy Markdown
Contributor

@keyurva keyurva left a comment

Choose a reason for hiding this comment

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

Thanks Nick! This is very cool. Appreciate the super-fast turnaround!

Comment thread server/routes/dev/html.py Outdated

@bp.route('/facet-examples')
def facet_examples():
if os.environ.get('FLASK_ENV') == 'production':
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Consider wrapping this in a util function like isProd() or isEnvironment('production'). Currently the FLASK_ENV var is accessed from multiple places and starting to keep it confined will be useful.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good call! There is already a similar util function for checking if we are in a testing environment. I added one in for production that matches, and used it here.

Comment thread static/library/utils.ts
* @param facetId Optional fallback facet ID.
* @returns The resolved facet ID or empty string.
*/
export function getFacetId(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the preference order of various facet parameters documented somewhere? If not, consider capturing it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done!

@nick-nlb nick-nlb merged commit fac711d into datacommonsorg:master Apr 20, 2026
13 checks passed
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.

2 participants