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

Feature/set agent color #325

Merged
merged 36 commits into from
Oct 5, 2023
Merged

Feature/set agent color #325

merged 36 commits into from
Oct 5, 2023

Conversation

interim17
Copy link
Contributor

@interim17 interim17 commented Aug 17, 2023

Problem

Closes Set Agent Color #148

Solution

In brief: colorChanges are now part of SelectionStateInfo. Viewer watches for changes to selectionStateInfo.colorChanges and calls changeAgentsColor in response to changes. changeAgentsColor updates visGeometry and UiDisplayData to ensure color changes are represented both in the viewport and in embedding applications that reference the UiDisplayData.

Added a few helper functions, cleaned unused ColorMapping in visGeo and made small updates to existing functions to accommodate new behavior.

Selection Interface:

  • Added property to the SelectionEntry type so that it now includes colorChanges
  • previous function setAgentColors divided into setInitialAgentColors and updateAgentColors

Viewport:

  • ComponentDidUpdate checks for new colorChangeAgents and calls changeAgentsColor which is the primary method for this PR

VisGeometry:

  • add applyColorToAgents and indexOfColor, remove unused ColorMapping functions

Example Viewer/ColorPicker.tsx

  • Added a new component file to prevent further growth of massive Viewer.tsx file, maybe a refactor of Viewer.tsx into different components would be wise at some point
  • New feature (non-breaking change which adds functionality)

Steps to Verify:

  1. Try it out in the example viewer: select agents (and optionally subagents), select a color, apply color to agent. New colors can be provided via input field.

@github-actions
Copy link

github-actions bot commented Aug 17, 2023

jest coverage report 🧪

Total coverage

Status Category Percentage Covered / Total
🔴 Statements 40.15% 1959/4879
🔴 Branches 43.82% 819/1869
🔴 Functions 37.13% 404/1088
🔴 Lines 40.42% 1877/4643

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

Show files with reduced coverage 🔻

Reduced coverage

Status Filename Statements Branches Functions Lines
🔴 index.ts 7.41% 7.31% 5.34% 7.4%
🔴 src/viewport 14.76% 12.3% 15.38% (-1.28% 🔻) 14.28%
🔴 index.tsx 14.76% 12.3% 15.38% (-1.28% 🔻) 14.28%
🔴 src/visGeometry 19.89% 21.73% 25.19% 19.9%

Status of coverage: 🟢 - ok, 🟡 - slightly more than threshold, 🔴 - under the threshold

src/visGeometry/index.ts Outdated Show resolved Hide resolved
@interim17 interim17 marked this pull request as ready for review September 22, 2023 22:48
@interim17 interim17 requested a review from a team as a code owner September 22, 2023 22:48
@interim17 interim17 requested review from ShrimpCryptid, frasercl and ascibisz and removed request for a team September 22, 2023 22:48
const colorNumber = convertColorStringToNumber(color);
const newColor = [
((colorNumber & 0x00ff0000) >> 16) / 255.0,
((colorNumber & 0x0000ff00) >> 8) / 255.0,
((colorNumber & 0x000000ff) >> 0) / 255.0,
1.0,
];
const currentIndex = this.indexOfColor(newColor);
Copy link
Contributor

@toloudis toloudis Sep 25, 2023

Choose a reason for hiding this comment

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

when does addNewColor get called? Do you always know the agent type when you are calling it? ... trying to understand why indexOfColor is needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

it's just in the case that the user changed the color of an agent to a color already in the data array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These get called in changeAgentsColor in viewport, which takes agent, tags, and color in the form of colorChanges. The function call that needs the IDs returned from addNewColor is setColorForIds in visGeo.

import { EncodedTypeMapping } from "./types";
import { convertColorNumberToString } from "../visGeometry/color-utils";
import _ from "lodash";
Copy link
Contributor

@toloudis toloudis Sep 25, 2023

Choose a reason for hiding this comment

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

can remove (see npm run lint output)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oops, fixed this and the two other things the linter caught

@@ -15,9 +18,15 @@ export interface SelectionEntry {
tags: string[];
}

export interface ColorChanges {
agents: SelectionEntry[];
Copy link
Contributor

Choose a reason for hiding this comment

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

this would be better named as agentTypes.

Copy link
Contributor

Choose a reason for hiding this comment

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

on second thought, I realize we use "agents" in other SelectionEntry names as well. so at least it's consistent. Slightly confusing because we don't set colors on individual agents.

Copy link
Contributor

@toloudis toloudis left a comment

Choose a reason for hiding this comment

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

LGTM!

): void {
const newColor = convertColorNumberToString(color);
const entry = this.entries[agentName];
// if no display state update parent color
Copy link
Contributor

@meganrm meganrm Oct 3, 2023

Choose a reason for hiding this comment

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

  • This comment isn't necessary

Copy link
Contributor

@meganrm meganrm left a comment

Choose a reason for hiding this comment

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

looks good, there's just one comment I left to myself that is no longer relevant

@meganrm
Copy link
Contributor

meganrm commented Oct 3, 2023

  • todo: make sure ColorChanges and SelectionEntry are exported from type-declarations before you merge this

Comment on lines +5 to +9
uiDisplayData,
particleTypeNames,
agentColors,
setColorSelectionInfo,
updateAgentColorArray,
Copy link
Contributor

@ShrimpCryptid ShrimpCryptid Oct 5, 2023

Choose a reason for hiding this comment

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

Just peeking in, should these props have type annotations or does it not need them?

Copy link
Contributor

Choose a reason for hiding this comment

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

I am guessing that the type checking rules are not set up to enforce this in our typecheck/linter. It would be good to turn those rules on in a separate PR!

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 example Viewer code can be a bit fast and loose compared the to the core Viewer code. I like the idea of typing it better, or even refactoring it into component files someday when there is bandwidth.

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't realize this was the viewer test-app code. Totally agree that the bar is lower for those source files, although it doesn't need to be.

@interim17 interim17 merged commit 18e0547 into main Oct 5, 2023
5 of 6 checks passed
@interim17 interim17 deleted the feature/set-agent-color branch October 5, 2023 22:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants