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

Color Customization V1 #2824

Merged
merged 75 commits into from
May 6, 2023
Merged

Color Customization V1 #2824

merged 75 commits into from
May 6, 2023

Conversation

lanzhenw
Copy link
Contributor

@lanzhenw lanzhenw commented Mar 21, 2023

Added color scheme set up feature:

  • User can set up the color setting in the UI to specify customized rules to display embedded document object's color setting.
  • User can apply color scheme rules in the SDK by defining session.color_scheme
  • User can save color scheme of the dataset to dataset.app_config

In loading, session color scheme >> dataset.app_config >> default app setting

Setting colors in the UI:
https://user-images.githubusercontent.com/17770824/234972360-44ea9c70-6a5e-4552-b7f3-5f231329c8f5.mp4

Setting the colors in the SDK:
https://user-images.githubusercontent.com/17770824/234973226-6a65fbc2-46db-428d-91f6-995b543c0069.mp4

Save to dataset:
https://user-images.githubusercontent.com/17770824/234973275-374a1c14-4977-4dbf-8814-f098f6121cca.mp4

How to test it?

import fiftyone as fo
import fiftyone.zoo as foz


dataset = foz.load_zoo_dataset("quickstart")
session = fo.launch_app(dataset)
    
color1 = fo.ColorScheme(color_pool=['blue', 'green', 'yellow', 'red'], customized_color_settings=[{'field': 'ground_truth', 'useFieldColor': True, 'fieldColor': 'pink',  'labelColors': [{'name': 'dog', 'color': 'purple'}, { 'name': 'cat', 'color': 'pink'}]}])
session.color_scheme = color1

What changes are proposed in this pull request?

How is this patch tested? If it is not, please explain why.

(Details)

Release Notes

Is this a user-facing change that should be mentioned in the release notes?

  • No. You can skip the rest of this section.
  • Yes. Give a description of this change to be included in the release
    notes for FiftyOne users.

(Details in 1-2 sentences. You can just refer to another PR with a description
if this PR is part of a larger change.)

What areas of FiftyOne does this PR affect?

  • App: FiftyOne application changes
  • Build: Build and test infrastructure changes
  • Core: Core fiftyone Python library changes
  • Documentation: FiftyOne documentation changes
  • Other

@lanzhenw lanzhenw added feature Work on a feature request app Issues related to App features labels Mar 21, 2023
@lanzhenw lanzhenw self-assigned this Mar 21, 2023
@codecov
Copy link

codecov bot commented Mar 24, 2023

Codecov Report

Patch coverage: 60.49% and project coverage change: -0.01 ⚠️

Comparison is base (71b5ea5) 62.00% compared to head (fe19f63) 62.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2824      +/-   ##
===========================================
- Coverage    62.00%   62.00%   -0.01%     
===========================================
  Files          260      264       +4     
  Lines        44185    44867     +682     
  Branches       354      356       +2     
===========================================
+ Hits         27399    27821     +422     
- Misses       16786    17046     +260     
Flag Coverage Δ
app 48.90% <60.49%> (+0.27%) ⬆️
python 99.43% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
...ackages/components/src/components/Popout/index.tsx 33.33% <0.00%> (ø)
app/packages/looker/src/overlays/heatmap.ts 16.06% <0.00%> (ø)
app/packages/state/src/recoil/looker.ts 29.70% <0.00%> (-0.61%) ⬇️
app/packages/looker/src/overlays/base.ts 39.15% <2.32%> (-10.09%) ⬇️
.../packages/state/src/hooks/useSessionColorScheme.ts 20.48% <20.48%> (ø)
app/packages/state/src/recoil/color.ts 43.06% <23.91%> (-9.02%) ⬇️
app/packages/looker/src/elements/common/tags.ts 15.62% <25.00%> (+3.24%) ⬆️
...ages/state/src/hooks/useClearSessionColorScheme.ts 30.18% <30.18%> (ø)
app/packages/looker/src/elements/common/util.ts 24.26% <30.76%> (+2.17%) ⬆️
app/packages/state/src/hooks/useStateUpdate.ts 28.42% <31.03%> (+0.35%) ⬆️
... and 17 more

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@lanzhenw lanzhenw force-pushed the feature/colorUpdate branch 2 times, most recently from d5aee66 to f98d0e8 Compare March 28, 2023 21:54
@lanzhenw lanzhenw force-pushed the feature/colorUpdate branch 4 times, most recently from 32dec3c to 677f5a1 Compare April 9, 2023 19:09
Copy link
Contributor

@manivoxel51 manivoxel51 left a comment

Choose a reason for hiding this comment

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

nice work Lanny! leaving some thoughts - still reviewing / testing

app/packages/app/src/Network.tsx Outdated Show resolved Hide resolved
app/yarn.lock Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
Copy link
Contributor

@benjaminpkane benjaminpkane left a comment

Choose a reason for hiding this comment

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

Looks really good! Still playing with functionality. We can sync up today to talk backend details

app/package.json Outdated Show resolved Hide resolved
app/packages/app/src/Network.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/Sidebar/Sidebar.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
app/packages/core/src/components/ColorModal/ColorModal.tsx Outdated Show resolved Hide resolved
@lanzhenw lanzhenw force-pushed the feature/colorUpdate branch 4 times, most recently from 885adfd to d9ce018 Compare April 24, 2023 19:30
@lanzhenw lanzhenw force-pushed the feature/colorUpdate branch 5 times, most recently from f6fdb45 to 973876b Compare April 27, 2023 20:39
@lanzhenw lanzhenw changed the title [WIP] Color Customization Color Customization V1 Apr 27, 2023
@lanzhenw lanzhenw marked this pull request as ready for review April 27, 2023 20:43
Copy link
Contributor

@manivoxel51 manivoxel51 left a comment

Choose a reason for hiding this comment

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

nice work @lanzhenw ! 🍨

The code is looking good! nice work separating the logic between different options in color settings 💯

it looks reasonably safe and isolated. Let's merge this if

  • basic app features are working as expected - for example, you can open sample modal, tag, navigate between them, filtering, visualization, etc.

for followup: One trend I noticed was filtering or mapping over collections and not caching them. This can cause performance issues if heavy calculations run for every field every re-render. We can avoid some these maybe by adding useMemos, useCallbacks, etc. to avoid re-defining these values/functions on re-renders

@@ -51,6 +58,11 @@ const ColorFooter: React.FC<Prop> = ({ eligibleFields }) => {
onCancel();
};

const onClearSave = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: useCallback cache the result on re-render

import useSendEvent from "./useSendEvent";
import { DEFAULT_APP_COLOR_SCHEME } from "../utils";

const useClearSessionColorScheme = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could combine this class with useClearSavedColorScheme - There are similarities

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Implemented.

Comment on lines 48 to 68
const videoFields = useRecoilValue(
fos.fields({
space: fos.State.SPACE.FRAME,
ftype: EMBEDDED_DOCUMENT_FIELD,
})
)?.filter((f) =>
VALID_LABEL_TYPES.includes(
f?.embeddedDocType?.split(".")?.slice(-1)[0] ?? ""
)
);
const sampleFields = useRecoilValue(
fos.fields({
space: fos.State.SPACE.SAMPLE,
ftype: EMBEDDED_DOCUMENT_FIELD,
})
)?.filter((f) =>
VALID_LABEL_TYPES.includes(
f?.embeddedDocType?.split(".")?.slice(-1)[0] ?? ""
)
);
const customizeColorFields = [...videoFields, ...sampleFields];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: for performance, we could cache these results by using useMemo or similar way

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I made a eligibleFieldsToCustomizeColor recoil selector.

const defaultColor =
coloring.pool[Math.floor(Math.random() * coloring.pool.length)];
const expandedPath = useRecoilValue(fos.expandPath(path!));
const VALID_COLOR_ATTRIBUTE_TYPES = [BOOLEAN_FIELD, INT_FIELD, STRING_FIELD];
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: move this to a constant outside

@@ -273,6 +293,13 @@ function FieldInfoExpanded({
onClick={(e) => e.stopPropagation()}
>
<FieldInfoExpandedContainer color={color}>
{field.embeddedDocType && !isModal && canEdit && (
Copy link
Contributor

Choose a reason for hiding this comment

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

this is basically one of the few places we are adding our feature 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, this is the place in the sidebar. I am moving canEdit flag to the saving part.

@@ -426,3 +423,58 @@ const getFieldAndValue = (

return [field, value, list];
};

const compareObjectArrays = (arr1, arr2) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can you use loadash for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the lodash isEqual function is strict with the order of the array. These two helper functions only check if elements are the same, regardless of order.

};

// Helper function to sort arrays of objects based on their key-value pairs
function sortObjectArrays(a, b) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: same here

Comment on lines 105 to 107
const fieldColor = customizeColorSetting.find(
(s) => s.field === this.field
)?.fieldColor;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I am unfamiliar with this code. hopefully the computation here is small enough not to impact rendering performance

view._dataset.save()
state.view = view

await dispatch_event(subscription, StateUpdate(state=state))
Copy link
Contributor

Choose a reason for hiding this comment

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

you might have to dispatch if save_to_app if you are following save view approach

@lanzhenw lanzhenw merged commit 46a1952 into develop May 6, 2023
@lanzhenw lanzhenw deleted the feature/colorUpdate branch May 6, 2023 02:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
app Issues related to App features feature Work on a feature request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants