Skip to content

Commit

Permalink
consolidate helper function into changeAgentsColor
Browse files Browse the repository at this point in the history
  • Loading branch information
interim17 committed Jul 19, 2024
1 parent a158e4e commit 8e54623
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 37 deletions.
32 changes: 0 additions & 32 deletions src/simularium/SelectionInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,38 +376,6 @@ class SelectionInterface {
});
return colors;
}

public getIdsAndColorsFromUIData = (
uiData: UIDisplayData
): {
agentIds: number[];
color: string | number;
}[] => {
const colorAssignments: {
agentIds: number[];
color: string | number;
}[] = [];

uiData.forEach((agent) => {
colorAssignments.push({
agentIds: this.getAgentIdsByNamesAndTags([
{ name: agent.name, tags: [] },
]),
color: agent.color,
});

agent.displayStates.forEach((newState) => {
colorAssignments.push({
agentIds: this.getAgentIdsByNamesAndTags([
{ name: agent.name, tags: [newState.name] },
]),
color: newState.color,
});
});
});

return colorAssignments;
};
}

export { SelectionInterface };
Expand Down
19 changes: 14 additions & 5 deletions src/viewport/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -596,13 +596,22 @@ class Viewport extends React.Component<
}

public changeAgentsColor(appliedColors: UIDisplayData): void {
const colorSettings =
this.selectionInterface.getIdsAndColorsFromUIData(appliedColors);
colorSettings.forEach((setting) => {
appliedColors.forEach((agent) => {
this.visGeometry.applyColorToAgents(
setting.agentIds,
setting.color
this.selectionInterface.getAgentIdsByNamesAndTags([
{ name: agent.name, tags: [] },
]),
agent.color
);

agent.displayStates.forEach((state) => {
this.visGeometry.applyColorToAgents(
this.selectionInterface.getAgentIdsByNamesAndTags([
{ name: agent.name, tags: [state.name] },
]),
state.color
);
});
});
}

Expand Down

0 comments on commit 8e54623

Please sign in to comment.