-
Notifications
You must be signed in to change notification settings - Fork 22
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
feat(visualizer): update block colors #1193
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
18b49c8
feat(visualizer): update block colors
VmMad a33992a
Merge branch 'dev' into feat/nova-visualizer/update-block-colors
VmMad ea21b5d
chore: rename visualizer component to NovaVisualizer
VmMad 5eb6b4d
Merge branch 'dev' into feat/nova-visualizer/update-block-colors
VmMad cee811e
feat: adapt color legend to combile multi colors
begonaalvarezd d1cc4e9
Merge branch 'feat/nova-visualizer/update-block-colors' of github.com…
begonaalvarezd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import React from "react"; | ||
import { useGetThemeMode } from "~/helpers/hooks/useGetThemeMode.js"; | ||
import { VisualizerRouteProps } from "~/app/routes/VisualizerRouteProps.js"; | ||
import { RouteComponentProps } from "react-router-dom"; | ||
import VisualizerInstance from "./VisualizerInstance"; | ||
|
||
export default function NovaVisualizer(props: RouteComponentProps<VisualizerRouteProps>): React.JSX.Element { | ||
const theme = useGetThemeMode(); | ||
|
||
return <VisualizerInstance key={theme} {...props} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ import { devtools } from "zustand/middleware"; | |
import { ZOOM_DEFAULT, SPRAY_DISTANCE } from "../constants"; | ||
import { IFeedBlockData } from "~models/api/nova/feed/IFeedBlockData"; | ||
import { IThreeDimensionalPosition } from "../interfaces"; | ||
import { BlockId, SlotIndex } from "@iota/sdk-wasm-nova/web"; | ||
import { BlockId, BlockState, SlotIndex } from "@iota/sdk-wasm-nova/web"; | ||
import { getVisualizerConfigValues } from "~features/visualizer-threejs/ConfigControls"; | ||
|
||
export interface IBlockAnimationPosition { | ||
|
@@ -80,6 +80,9 @@ interface TangleState { | |
confirmedBlocksBySlot: Map<number, string[]>; | ||
addToConfirmedBlocksBySlot: (blockId: BlockId, slot: SlotIndex) => void; | ||
removeConfirmedBlocksSlot: (slot: SlotIndex) => void; | ||
|
||
blockIdToState: Map<BlockId, BlockState>; | ||
setBlockIdToBlockState: (blockId: BlockId, blockState: BlockState) => void; | ||
} | ||
|
||
const INITIAL_STATE = { | ||
|
@@ -97,12 +100,32 @@ const INITIAL_STATE = { | |
bps: 0, | ||
clickedInstanceId: null, | ||
confirmedBlocksBySlot: new Map(), | ||
blockIdToState: new Map(), | ||
}; | ||
|
||
export const useTangleStore = create<TangleState>()( | ||
devtools((set) => ({ | ||
...INITIAL_STATE, | ||
resetConfigState: () => set(INITIAL_STATE), | ||
resetConfigState: () => | ||
// hard cleanup of the store | ||
set((state) => { | ||
state.blockQueue = []; | ||
state.edgeQueue = []; | ||
state.colorQueue = []; | ||
state.blockIdToEdges = new Map(); | ||
state.blockIdToIndex = new Map(); | ||
state.blockIdToPosition = new Map(); | ||
state.blockMetadata = new Map(); | ||
state.blockIdToAnimationPosition = new Map(); | ||
state.indexToBlockId = []; | ||
state.zoom = ZOOM_DEFAULT; | ||
state.forcedZoom = undefined; | ||
state.bps = 0; | ||
state.clickedInstanceId = null; | ||
state.confirmedBlocksBySlot = new Map(); | ||
state.blockIdToState = new Map(); | ||
return state; | ||
}), | ||
updateBlockIdToAnimationPosition: (updatedPositions) => { | ||
set((state) => { | ||
updatedPositions.forEach((value, key) => { | ||
|
@@ -196,15 +219,18 @@ export const useTangleStore = create<TangleState>()( | |
updateBlockIdToIndex: (blockId: string, index: number) => { | ||
set((state) => { | ||
state.blockIdToIndex.set(blockId, index); | ||
if (state.indexToBlockId[index]) { | ||
const previousBlockId = state.indexToBlockId[index]; | ||
if (previousBlockId) { | ||
Comment on lines
+222
to
+223
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, I see. Maybe this is something that I was talking about in comment above. |
||
// Clean up map from old blockIds | ||
state.blockIdToIndex.delete(state.indexToBlockId[index]); | ||
state.blockIdToIndex.delete(previousBlockId); | ||
// Clean up old block edges | ||
state.blockIdToEdges.delete(state.indexToBlockId[index]); | ||
state.blockIdToEdges.delete(previousBlockId); | ||
// Clean up old block position | ||
state.blockIdToPosition.delete(state.indexToBlockId[index]); | ||
state.blockIdToPosition.delete(previousBlockId); | ||
// Clean up old block metadata | ||
state.blockMetadata.delete(state.indexToBlockId[index]); | ||
state.blockMetadata.delete(previousBlockId); | ||
// Cleanup old block state | ||
state.blockIdToState.delete(previousBlockId); | ||
} | ||
|
||
const nextIndexToBlockId = [...state.indexToBlockId]; | ||
|
@@ -268,5 +294,14 @@ export const useTangleStore = create<TangleState>()( | |
}; | ||
}); | ||
}, | ||
setBlockIdToBlockState(blockId, blockState) { | ||
set((state) => { | ||
state.blockIdToState.set(blockId, blockState); | ||
return { | ||
...state, | ||
blockIdToState: state.blockIdToState, | ||
}; | ||
}); | ||
}, | ||
})), | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
client/src/features/visualizer-threejs/wrapper/ColorPanel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { memo } from "react"; | ||
|
||
const ColorPanel = ({ label, color }: { label: string; color: string | string[] }): React.JSX.Element => ( | ||
<div className="key-panel-item"> | ||
{Array.isArray(color) ? ( | ||
<div className="key-panel-item-multi-color"> | ||
{color.map((c, index) => ( | ||
<div | ||
key={`${label}-${index}`} | ||
className="key-marker" | ||
style={{ | ||
backgroundColor: c, | ||
}} | ||
/> | ||
))} | ||
</div> | ||
) : ( | ||
<div | ||
className="key-marker" | ||
style={{ | ||
backgroundColor: color, | ||
}} | ||
/> | ||
)} | ||
<div className="key-label">{label}</div> | ||
</div> | ||
); | ||
|
||
export default memo(ColorPanel); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that we have a lot of data that related to blockId.
And usually when we need to remove block, we need to go through all maps, like:
blockIdToIndex, blockIdToEdges, blockIdToPosition, blockMetadata, blockIdToAnimationPosition, blockIdToState.
Maybe it's a good sign to:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created a new issue for this:
#1196