-
Notifications
You must be signed in to change notification settings - Fork 2
Add highlighting feature for data elements #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
edmundmiller
merged 6 commits into
main
from
claude/add-highlight-dots-bars-011CV2voFCuSPAJYUHjLRjpD
Nov 17, 2025
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9a21048
feat: add programmatic highlighting for UpSet intersections
claude e622a89
test: improve highlight tests to validate correctness
claude 6dc89bf
refactor: extract highlight logic into helper function
claude 95d7d4e
fix: raise errors for out-of-bounds highlight indices
claude 00e7378
docs: update CHANGELOG for programmatic highlighting feature
claude 92d1668
style: fix line length linting errors
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||||||
| from typing import List, Optional, Union | ||||||||||||||||||||||||||
| from typing import List, Literal, Optional, Union | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| import altair as alt | ||||||||||||||||||||||||||
| import pandas as pd | ||||||||||||||||||||||||||
|
|
@@ -9,6 +9,51 @@ | |||||||||||||||||||||||||
| from .transforms import create_base_chart | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| def _determine_highlighted_intersections( | ||||||||||||||||||||||||||
| data: pd.DataFrame, | ||||||||||||||||||||||||||
| highlight: Union[Literal["least", "greatest"], int, List[int]], | ||||||||||||||||||||||||||
| ) -> List[float]: | ||||||||||||||||||||||||||
| """Determine which intersection IDs to highlight based on the highlight parameter. | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Parameters | ||||||||||||||||||||||||||
| ---------- | ||||||||||||||||||||||||||
| data : pd.DataFrame | ||||||||||||||||||||||||||
| The preprocessed data with intersection_id and count columns | ||||||||||||||||||||||||||
| highlight : "least", "greatest", int, or list of int | ||||||||||||||||||||||||||
| The highlighting criteria | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| Returns | ||||||||||||||||||||||||||
| ------- | ||||||||||||||||||||||||||
| list of float | ||||||||||||||||||||||||||
| List of intersection_ids to highlight | ||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||
| # Get unique intersections with their counts | ||||||||||||||||||||||||||
| intersections = ( | ||||||||||||||||||||||||||
| data.groupby("intersection_id")["count"] | ||||||||||||||||||||||||||
| .first() | ||||||||||||||||||||||||||
| .reset_index() | ||||||||||||||||||||||||||
| .sort_index() | ||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if isinstance(highlight, str): | ||||||||||||||||||||||||||
| if highlight == "least": | ||||||||||||||||||||||||||
| min_idx = intersections["count"].idxmin() | ||||||||||||||||||||||||||
| return [intersections.loc[min_idx, "intersection_id"]] | ||||||||||||||||||||||||||
| else: # highlight == "greatest" | ||||||||||||||||||||||||||
| max_idx = intersections["count"].idxmax() | ||||||||||||||||||||||||||
| return [intersections.loc[max_idx, "intersection_id"]] | ||||||||||||||||||||||||||
| elif isinstance(highlight, int): | ||||||||||||||||||||||||||
| if highlight < len(intersections): | ||||||||||||||||||||||||||
| return [intersections.iloc[highlight]["intersection_id"]] | ||||||||||||||||||||||||||
| return [] | ||||||||||||||||||||||||||
| else: # isinstance(highlight, list) | ||||||||||||||||||||||||||
| return [ | ||||||||||||||||||||||||||
| intersections.iloc[i]["intersection_id"] | ||||||||||||||||||||||||||
| for i in highlight | ||||||||||||||||||||||||||
| if i < len(intersections) | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
| return [ | |
| intersections.iloc[i]["intersection_id"] | |
| for i in highlight | |
| if i < len(intersections) | |
| out_of_bounds = [i for i in highlight if i < 0 or i >= len(intersections)] | |
| if out_of_bounds: | |
| raise ValueError( | |
| f"The following indices are out of bounds for intersections (valid range: 0 to {len(intersections)-1}): {out_of_bounds}" | |
| ) | |
| return [ | |
| intersections.iloc[i]["intersection_id"] | |
| for i in highlight |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
-1.81 KB
(99%)
tests/__snapshots__/test_covid_mutations/test_covid_mutations[image].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an integer index is out of bounds, the function silently returns an empty list. This could lead to confusing behavior where no intersection is highlighted without any indication of why. Consider raising an IndexError or ValueError with a descriptive message instead.