Repository: voxel51/fiftyone

Issue:
[FR] Clicking on already opened graph tab should collapse it
It would be natural if clicking on an already-opened graphs tab would collapse the graphs section. This would present a more convenient alternative to mousing way over to the righthand side to click hide.

<img width="1266" alt="Screen Shot 2021-04-24 at 12 01 59 PM" src="https://user-images.githubusercontent.com/25985824/115964997-17501880-a4f5-11eb-84e9-517934326428.png">



Discussion:

Resolving patch:
diff --git a/fiftyone/server/main.py b/fiftyone/server/main.py
--- a/fiftyone/server/main.py
+++ b/fiftyone/server/main.py
@@ -964,20 +964,25 @@ async def on_distributions(cls, self, group):
 
         view = get_extended_view(view, state.filters)
 
-        if group == "labels" and results is None:
+        if group == "label tags" and results is None:
 
             def filter(field):
-                path = None
-                if isinstance(field, fof.EmbeddedDocumentField) and issubclass(
-                    field.document_type, fol.Label
-                ):
-                    path = field.name
-                    if issubclass(field.document_type, fol._HasLabelList):
-                        path = "%s.%s" % (
-                            path,
-                            field.document_type._LABEL_LIST_FIELD,
-                        )
+                path = _label_filter(field)
+
+                if path is not None:
+                    path = "%s.tags" % path
+
+                return path
+
+            aggs, fields = _count_values(filter, view)
+            results = await _gather_results(col, aggs, fields, view)
+
+        elif group == "labels" and results is None:
+
+            def filter(field):
+                path = _label_filter(field)
 
+                if path is not None:
                     path = "%s.label" % path
 
                 return path
@@ -985,7 +990,7 @@ def filter(field):
             aggs, fields = _count_values(filter, view)
             results = await _gather_results(col, aggs, fields, view)
 
-        elif group == "tags" and results is None:
+        elif group == "sample tags" and results is None:
             aggs = [foa.CountValues("tags")]
             try:
                 fields = [view.get_field_schema()["tags"]]
@@ -1021,6 +1026,18 @@ def filter(field):
         )
 
 
+def _label_filter(field):
+    path = None
+    if isinstance(field, fof.EmbeddedDocumentField) and issubclass(
+        field.document_type, fol.Label
+    ):
+        path = field.name
+        if issubclass(field.document_type, fol._HasLabelList):
+            path = "%s.%s" % (path, field.document_type._LABEL_LIST_FIELD,)
+
+    return path
+
+
 def _get_search_view(view, path, search, selected):
     search = _escape_regex_chars(search)
 
@@ -1151,10 +1168,12 @@ async def _gather_results(col, aggs, fields, view, ticks=None):
 
         name = agg.field_name
         if cls and issubclass(cls, fol.Label):
-            name = name[: -len(".label")]
-
-        if cls and issubclass(cls, fol._HasLabelList):
-            name = name[: -(len(cls._LABEL_LIST_FIELD) + 1)]
+            if view.media_type == fom.VIDEO and name.startswith(
+                view._FRAMES_PREFIX
+            ):
+                name = "".join(name.split(".")[:2])
+            else:
+                name = name.split(".")[0]
 
         data = sorters[type(agg)](result, field)
         result_ticks = 0
@@ -1169,9 +1188,15 @@ async def _gather_results(col, aggs, fields, view, ticks=None):
                 if result[2] > 0 and len(data) and data[-1]["key"] != "None":
                     result_ticks.append("None")
 
-        results.append(
-            {"data": data, "name": name, "ticks": result_ticks, "type": type_}
-        )
+        if data:
+            results.append(
+                {
+                    "data": data,
+                    "name": name,
+                    "ticks": result_ticks,
+                    "type": type_,
+                }
+            )
 
     return results
 


Test patch: