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 sample tags to colorScheme editor #3171

Merged
merged 2 commits into from
Jun 8, 2023
Merged
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
8 changes: 5 additions & 3 deletions app/packages/core/src/components/ColorModal/SidebarList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import ListItemText from "@mui/material/ListItemText";
import { Resizable } from "re-resizable";
import React, { useState } from "react";
import { useRecoilCallback, useRecoilValue } from "recoil";
import { resizeHandle } from "./../Sidebar/Sidebar.module.css";
import styles from "../../../../../packages/components/src/scrollable.module.css";
import { ACTIVE_FIELD } from "./utils";
import { resizeHandle } from "./../Sidebar/Sidebar.module.css";
import { ACTIVE_FIELD, getDisplayName } from "./utils";

const WIDTH = 230;

Expand All @@ -22,6 +22,7 @@ const SidebarList: React.FC = () => {
const [width, setWidth] = useState(WIDTH);
const stableGroup = [
{ paths: [ACTIVE_FIELD.global, ACTIVE_FIELD.json], name: "general" },
{ paths: ["tags"], name: "tags" },
];
const fieldGroups = useRecoilValue(
fos.sidebarGroups({ modal: false, loading: false })
Expand Down Expand Up @@ -50,6 +51,7 @@ const SidebarList: React.FC = () => {
const getCurrentField = (activeField) => {
if (activeField === ACTIVE_FIELD.global) return ACTIVE_FIELD.global;
if (activeField === ACTIVE_FIELD.json) return ACTIVE_FIELD.json;

return activeField?.expandedPath;
};
return (
Expand Down Expand Up @@ -123,7 +125,7 @@ const SidebarList: React.FC = () => {
disableRipple
>
<ListItemText
primary={path}
primary={getDisplayName(path)}
onClick={() => onSelectField(path)}
sx={{ fontFamily: "palanquin, sans-serif" }}
/>
Expand Down
10 changes: 9 additions & 1 deletion app/packages/core/src/components/ColorModal/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isEmpty, xor } from "lodash";
import * as fos from "@fiftyone/state";
import { isEmpty, xor } from "lodash";

// Masataka Okabe and Kei Ito have proposed a palette of 8 colors on their
// website Color Universal Design (CUD). This palette is a “Set of colors that
Expand Down Expand Up @@ -35,6 +35,7 @@ export const fiftyoneDefaultColorPalette = [
export const ACTIVE_FIELD = {
["json"]: "JSON editor",
["global"]: "Global settings",
["_label_tags"]: "label tags",
};

// disregard the order
Expand Down Expand Up @@ -93,3 +94,10 @@ export const isDefaultSetting = (savedSetting: fos.ColorScheme) => {
(savedSetting.fields?.length == 0 || !savedSetting.fields)
);
};

export const getDisplayName = (path: string) => {
if (path === "tags") {
return "sample tags";
}
return path;
};
16 changes: 8 additions & 8 deletions app/packages/core/src/components/FieldLabelAndInfo/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import { InfoIcon, useTheme } from "@fiftyone/components";
import * as fos from "@fiftyone/state";
import { activeColorField, coloring } from "@fiftyone/state";
import { Field, formatDate, formatDateTime } from "@fiftyone/utilities";
import PaletteIcon from "@mui/icons-material/Palette";
import React, {
MutableRefObject,
useEffect,
useMemo,
useRef,
useState,
} from "react";
import ReactDOM from "react-dom";
import {
atom,
useRecoilState,
useRecoilValue,
useSetRecoilState,
} from "recoil";
import styled from "styled-components";
import * as fos from "@fiftyone/state";
import PaletteIcon from "@mui/icons-material/Palette";
import { ExternalLink } from "../../utils/generic";
import { InfoIcon, useTheme } from "@fiftyone/components";
import { Field, formatDate, formatDateTime } from "@fiftyone/utilities";
import { coloring, activeColorField } from "@fiftyone/state";
import ReactDOM from "react-dom";
import { ACTIVE_FIELD } from "../ColorModal/utils";

const selectedFieldInfo = atom<string | null>({
key: "selectedFieldInfo",
Expand Down Expand Up @@ -266,7 +267,6 @@ function FieldInfoExpanded({
setIsCustomizingColor({ field, expandedPath });
};

const isNotTag = field.path !== "tags";
useEffect(updatePosition, [field, isCollapsed]);
const timeZone = useRecoilValue(fos.timeZone);

Expand All @@ -280,7 +280,7 @@ function FieldInfoExpanded({
onClick={(e) => e.stopPropagation()}
>
<FieldInfoExpandedContainer color={color}>
{isNotTag && !isModal && (
{!isModal && (
<CustomizeColor
onClick={onClickCustomizeColor}
color={color}
Expand Down
10 changes: 9 additions & 1 deletion app/packages/looker/src/elements/common/tags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@
[BOOLEAN_FIELD]: (path, value: boolean) => {
const v = value ? "True" : "False";
return {
path,

Check warning on line 103 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L103

Added line #L103 was not covered by tests
value: v,
title: `${path}: ${v}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -115,7 +115,7 @@
const v = prettyNumber(value);

return {
path,

Check warning on line 118 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L118

Added line #L118 was not covered by tests
value: v,
title: `${path}: ${v}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -130,7 +130,7 @@
const v = formatDate(value.datetime);

return {
path,

Check warning on line 133 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L133

Added line #L133 was not covered by tests
value: v,
title: `${path}: ${v}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -145,7 +145,7 @@
const v = formatDateTime(value.datetime, timeZone);

return {
path,

Check warning on line 148 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L148

Added line #L148 was not covered by tests
value: v,
title: `${path}: ${v}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -160,7 +160,7 @@
const v = prettyNumber(value);

return {
path,

Check warning on line 163 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L163

Added line #L163 was not covered by tests
value: v,
title: `${path}: ${value}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -175,7 +175,7 @@
const v = prettyNumber(value);

return {
path,

Check warning on line 178 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L178

Added line #L178 was not covered by tests
value: v,
title: `${path}: ${v}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -189,7 +189,7 @@
[FRAME_SUPPORT_FIELD]: (path, value: [number, number]) => {
const v = `[${value.join(", ")}]`;
return {
path,

Check warning on line 192 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L192

Added line #L192 was not covered by tests
value: v,
title: `${path}: ${v}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -202,7 +202,7 @@
},
[OBJECT_ID_FIELD]: (path, value: string) => {
return {
path,

Check warning on line 205 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L205

Added line #L205 was not covered by tests
value,
title: `${path}: ${value}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -215,7 +215,7 @@
},
[STRING_FIELD]: (path, value: string) => {
return {
path,

Check warning on line 218 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L218

Added line #L218 was not covered by tests
value,
title: `${path}: ${value}`,
color: getColorFromOptionsPrimitives({
Expand All @@ -239,7 +239,7 @@
param: Classification
) => {
return {
path,

Check warning on line 242 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L242

Added line #L242 was not covered by tests
value: param.label,
title: `${path}: ${param.label}`,
color: getColorFromOptions({
Expand All @@ -254,7 +254,7 @@
[withPath(LABELS_PATH, REGRESSION)]: (path, param: Regression) => {
const v = prettyNumber(param.value);
return {
path,

Check warning on line 257 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L257

Added line #L257 was not covered by tests
value: v,
title: `${path}: ${v}`,
color: getColorFromOptions({
Expand All @@ -275,9 +275,16 @@
sample.tags.forEach((tag) => {
const v = coloring.by === "value" ? tag : "tags";
elements.push({
color: getColor(coloring.pool, coloring.seed, v),
color: getColorFromOptions({
coloring,
path,
param: tag,
customizeColorSetting,
labelDefault: false,
}),

Check warning on line 284 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L278-L284

Added lines #L278 - L284 were not covered by tests
title: tag,
value: tag,
path: v,

Check warning on line 287 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L287

Added line #L287 was not covered by tests
});
});
}
Expand All @@ -289,6 +296,7 @@
color: getColor(coloring.pool, coloring.seed, v),
title: value,
value: value,
path: v,

Check warning on line 299 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L299

Added line #L299 was not covered by tests
});
});
} else {
Expand Down Expand Up @@ -377,7 +385,7 @@
this.customizedColors = customizeColorSetting;
this.colorPool = coloring.pool as string[];

elements.forEach(({ path, value, color, title }) => {

Check warning on line 388 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L388

Added line #L388 was not covered by tests
const div = document.createElement("div");
const child = prettify(value);
child instanceof HTMLElement
Expand All @@ -385,7 +393,7 @@
: (div.innerHTML = child);
div.title = title;
div.style.backgroundColor = color;
div.setAttribute("data-cy", `tag-${path}`);

Check warning on line 396 in app/packages/looker/src/elements/common/tags.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/tags.ts#L396

Added line #L396 was not covered by tests
this.element.appendChild(div);
});

Expand Down
18 changes: 14 additions & 4 deletions app/packages/looker/src/elements/common/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@
return result;
};

// for classification types and regression types
// for classification types and regression and sample tag types
type Param = {
coloring: Coloring;
path: string;
param: Classification | Regression;
param: Classification | Regression | string;
customizeColorSetting: CustomizeColor[];
labelDefault: boolean; // use .label or .value as default
labelDefault: boolean; // use .label for classification or .value for regression
};
export const getColorFromOptions = ({
coloring,
Expand All @@ -118,7 +118,7 @@
}
return getColor(coloring.pool, coloring.seed, path);
}
if (coloring.by === "value") {
if (coloring.by === "value" && path !== "tags") {

Check warning on line 121 in app/packages/looker/src/elements/common/util.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/util.ts#L121

Added line #L121 was not covered by tests
if (setting) {
key = setting.colorByAttribute ?? labelDefault ? "label" : "value";
// check if this label has a assigned color, use it if it is a valid color
Expand All @@ -145,6 +145,16 @@
}
return getColor(coloring.pool, coloring.seed, param[key]);
}
if (coloring.by === "value" && path === "tags") {
if (setting) {
const valueColor = setting.valueColors?.find(
(v) => v.value === param
)?.color;
if (isValidColor(valueColor)) {
return valueColor;
}
}
}

Check warning on line 157 in app/packages/looker/src/elements/common/util.ts

View check run for this annotation

Codecov / codecov/patch

app/packages/looker/src/elements/common/util.ts#L148-L157

Added lines #L148 - L157 were not covered by tests
return getColor(coloring.pool, coloring.seed, path);
};

Expand Down
Loading