Skip to content
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

Add support for tooltip overwrite #5351

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 19 additions & 7 deletions fiftyone/operators/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1848,17 +1848,23 @@ class Tooltip(View):
column: the column of the tooltip
"""

def __init__(self, row, column, **kwargs):
def __init__(self, row, column, value, **kwargs):
super().__init__(**kwargs)
self.row = row
self.column = column
self.value = value

def clone(self):
clone = Tooltip(self.row, self.column, **self._kwargs)
clone = Tooltip(self.row, self.column, self.value, **self._kwargs)
return clone

def to_json(self):
return {**super().to_json(), "row": self.row, "column": self.column}
return {
**super().to_json(),
"row": self.row,
"column": self.column,
"value": self.value,
}


class TableView(View):
Expand Down Expand Up @@ -1906,11 +1912,17 @@ def add_row_action(
self.row_actions.append(row_action)
return row_action

def add_tooltip(self, row, column, value, **kwargs):
def add_tooltip(self, row, column, value, overwrite=False, **kwargs):
if (row, column) in self._tooltip_map:
raise ValueError(
f"Tooltip for row '{row}' and column '{column}' already exists"
)
if overwrite:
tooltip = self._tooltip_map[(row, column)]
tooltip.value = value
tooltip._kwargs = kwargs
return tooltip
else:
raise ValueError(
f"Tooltip for row '{row}' and column '{column}' already exists"
)

tooltip = Tooltip(row=row, column=column, value=value, **kwargs)
self.tooltips.append(tooltip)
Expand Down
14 changes: 14 additions & 0 deletions tests/unittests/operators/tableview_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@ def test_table_view_basic(self):

with self.assertRaises(ValueError):
table.add_tooltip(1, 1, "Tooltip 3")

table.add_tooltip(1, 1, "Tooltip 3", arg1=1, arg2=2, overwrite=True)
self.assertEqual(
set([tooltip.value for tooltip in table.tooltips]),
{"Tooltip 2", "Tooltip 3"},
)

tooltip = table._tooltip_map[(1, 1)]
self.assertEqual(tooltip.value, "Tooltip 3")
self.assertEqual(tooltip._kwargs, {"arg1": 1, "arg2": 2})

result = tooltip.to_json()
for key, value in {"value": "Tooltip 3", "arg1": 1, "arg2": 2}.items():
self.assertEqual(result[key], value)
Loading