-
Notifications
You must be signed in to change notification settings - Fork 109
Improve visualizer usability #1382
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
Merged
+1,370
−5,119
Merged
Changes from all commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
e3b81f3
Complete reset when changing trace files
wenli-cai cbcea20
Fix naming for node current and past state
wenli-cai 9c1fc6a
Enumerate the specific changes for each node and color them accordingly
wenli-cai 25d04a4
Move away from using reflection for accessing node fields
wenli-cai 1ce9943
Change node data being visualized
wenli-cai b5d3b16
Remove unnecessary frame tracking in main composable
wenli-cai 6dddf94
Add legend for the colors used in the frame
wenli-cai 6d2d31b
Group unaffected and affected children separately
wenli-cai e71a870
Separate composable components and change workflow UI pattern
wenli-cai 18c3b6f
Don't apply simple/nested pattern for unaffected children group
wenli-cai 5646d10
Add file dump functionality from live tracing mode
wenli-cai 18f82cd
Fix NPE when enabling live view without a connected device
japplin 07ab5fd
Enable compose hot reload
japplin 58c58a9
Change sample/tutorial module's agp version
wenli-cai 2aaa120
WIP text diff
wenli-cai 5ec8a18
Add text-diff functionality
wenli-cai 82eae8b
Fix compose violations
wenli-cai 1633f4c
Merge branch 'main' into wenli/improve-visualizer
wenli-cai 1e1da90
Apply changes from dependencyGuardBaseline --refresh-dependencies
wenli-cai 8fbeab4
Apply changes from artifactsDump
workflow-pr-fixer[bot] a50f9a5
Fix merge bugs
wenli-cai c4fe05e
Allow device selection
wenli-cai 6687f04
Manual api dump
wenli-cai cdfbc82
Remove compose hot reload changes
wenli-cai 5d3e3f4
Apply changes from dependencyGuardBaseline --refresh-dependencies
wenli-cai fdf2253
Apply changes from apiDump
workflow-pr-fixer[bot] 5280f84
Apply changes from artifactsDump
workflow-pr-fixer[bot] a2c98ae
Clean up
wenli-cai 325b239
Add search box for available nodes in the specified frame
wenli-cai 688688e
Refactor directories
wenli-cai 24fae61
Improve error handling
wenli-cai cc40120
Make app window snap to the specific node when it is being searched.
wenli-cai a9a44e9
Fix zooming for sandbox
wenli-cai 4f9f92b
Replace color legend with tooltip display on node hover
wenli-cai 418abf1
New frame selector format
wenli-cai f2b5169
Fill background of info panel arrow
wenli-cai 7b7b41a
Usage guide gifs
wenli-cai a489f00
Improve readme
wenli-cai 03c505d
Fix reset state
wenli-cai 08f412c
Cleanup code for review
wenli-cai 543258b
Revert dependencies classpath
wenli-cai 4a8d29d
Add remaining internal modifiers
wenli-cai 6a056ca
Fix PR comments
wenli-cai d3645e1
Fix more PR comments
wenli-cai 4a6ca5b
Merge branch 'main' into wenli/improve-visualizer
wenli-cai 989766d
Apply changes from apiDump
wenli-cai 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
@@ -1,27 +1,38 @@ | ||
package com.squareup.workflow1.traceviewer | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableFloatStateOf | ||
import androidx.compose.runtime.mutableIntStateOf | ||
import androidx.compose.runtime.mutableStateListOf | ||
import androidx.compose.runtime.mutableStateMapOf | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.runtime.snapshotFlow | ||
import androidx.compose.runtime.snapshots.SnapshotStateMap | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.geometry.Offset | ||
import androidx.compose.ui.layout.onSizeChanged | ||
import androidx.compose.ui.unit.IntSize | ||
import androidx.compose.ui.unit.dp | ||
import com.squareup.workflow1.traceviewer.model.Node | ||
import com.squareup.workflow1.traceviewer.model.NodeUpdate | ||
import com.squareup.workflow1.traceviewer.ui.FrameSelectTab | ||
import com.squareup.workflow1.traceviewer.ui.RightInfoPanel | ||
import com.squareup.workflow1.traceviewer.ui.TraceModeToggleSwitch | ||
import com.squareup.workflow1.traceviewer.util.RenderTrace | ||
import com.squareup.workflow1.traceviewer.ui.control.DisplayDevices | ||
import com.squareup.workflow1.traceviewer.ui.control.FileDump | ||
import com.squareup.workflow1.traceviewer.ui.control.FrameNavigator | ||
import com.squareup.workflow1.traceviewer.ui.control.SearchBox | ||
import com.squareup.workflow1.traceviewer.ui.control.TraceModeToggleSwitch | ||
import com.squareup.workflow1.traceviewer.ui.control.UploadFile | ||
import com.squareup.workflow1.traceviewer.util.SandboxBackground | ||
import com.squareup.workflow1.traceviewer.util.UploadFile | ||
import com.squareup.workflow1.traceviewer.util.parser.RenderTrace | ||
import io.github.vinceglb.filekit.PlatformFile | ||
|
||
/** | ||
|
@@ -31,14 +42,20 @@ import io.github.vinceglb.filekit.PlatformFile | |
internal fun App( | ||
modifier: Modifier = Modifier | ||
) { | ||
var appWindowSize by remember { mutableStateOf(IntSize(0, 0)) } | ||
var selectedNode by remember { mutableStateOf<NodeUpdate?>(null) } | ||
val workflowFrames = remember { mutableStateListOf<Node>() } | ||
var frameSize by remember { mutableIntStateOf(0) } | ||
var rawRenderPass by remember { mutableStateOf("") } | ||
var frameIndex by remember { mutableIntStateOf(0) } | ||
val sandboxState = remember { SandboxState() } | ||
val nodeLocations = remember { mutableStateListOf<SnapshotStateMap<Node, Offset>>() } | ||
|
||
// Default to File mode, and can be toggled to be in Live mode. | ||
var active by remember { mutableStateOf(false) } | ||
var traceMode by remember { mutableStateOf<TraceMode>(TraceMode.File(null)) } | ||
var selectedTraceFile by remember { mutableStateOf<PlatformFile?>(null) } | ||
// frameIndex is set to -1 when app is in Live Mode, so we increment it by one to avoid off-by-one errors | ||
val frameInd = if (traceMode is TraceMode.Live) frameIndex + 1 else frameIndex | ||
|
||
LaunchedEffect(sandboxState) { | ||
snapshotFlow { frameIndex }.collect { | ||
|
@@ -47,47 +64,83 @@ internal fun App( | |
} | ||
|
||
Box( | ||
modifier = modifier | ||
modifier = modifier.onSizeChanged { | ||
appWindowSize = it | ||
} | ||
) { | ||
fun resetStates() { | ||
selectedTraceFile = null | ||
selectedNode = null | ||
frameIndex = 0 | ||
workflowFrames.clear() | ||
frameSize = 0 | ||
rawRenderPass = "" | ||
active = false | ||
nodeLocations.clear() | ||
} | ||
|
||
// Main content | ||
SandboxBackground( | ||
appWindowSize = appWindowSize, | ||
sandboxState = sandboxState, | ||
) { | ||
// if there is not a file selected and trace mode is live, then don't render anything. | ||
val readyForFileTrace = traceMode is TraceMode.File && selectedTraceFile != null | ||
val readyForLiveTrace = traceMode is TraceMode.Live | ||
val readyForFileTrace = TraceMode.validateFileMode(traceMode) | ||
val readyForLiveTrace = TraceMode.validateLiveMode(traceMode) | ||
|
||
if (readyForFileTrace || readyForLiveTrace) { | ||
active = true | ||
RenderTrace( | ||
traceSource = traceMode, | ||
frameInd = frameIndex, | ||
onFileParse = { workflowFrames.addAll(it) }, | ||
onNodeSelect = { node, prevNode -> | ||
selectedNode = NodeUpdate(node, prevNode) | ||
}, | ||
onNewFrame = { frameIndex += 1 } | ||
onFileParse = { frameSize += it }, | ||
onNodeSelect = { selectedNode = it }, | ||
onNewFrame = { frameIndex += 1 }, | ||
onNewData = { rawRenderPass += "$it," }, | ||
storeNodeLocation = { node, loc -> nodeLocations[frameInd] += (node to loc) } | ||
) | ||
} | ||
} | ||
|
||
FrameSelectTab( | ||
frames = workflowFrames, | ||
currentIndex = frameIndex, | ||
onIndexChange = { frameIndex = it }, | ||
modifier = Modifier.align(Alignment.TopCenter) | ||
) | ||
|
||
RightInfoPanel( | ||
selectedNode = selectedNode, | ||
Column( | ||
modifier = Modifier | ||
.align(Alignment.TopEnd) | ||
) | ||
.align(Alignment.TopCenter) | ||
.padding(top = 8.dp), | ||
verticalArrangement = Arrangement.spacedBy(8.dp), | ||
horizontalAlignment = Alignment.CenterHorizontally | ||
) { | ||
if (active) { | ||
// Frames that appear in composition may not happen sequentially, so when the current frame | ||
// locations is null, that means we've skipped frames and need to fill all the intermediate | ||
// ones. e.g. Frame 1 to Frame 10 | ||
if (nodeLocations.getOrNull(frameInd) == null) { | ||
// frameSize has not been updated yet, so on the first frame, frameSize = nodeLocations.size = 0, | ||
// and it will append a new map | ||
while (nodeLocations.size <= frameSize) { | ||
nodeLocations += mutableStateMapOf() | ||
} | ||
} | ||
|
||
val frameNodeLocations = nodeLocations[frameInd] | ||
SearchBox( | ||
nodes = frameNodeLocations.keys.toList(), | ||
onSearch = { name -> | ||
sandboxState.scale = 1f | ||
val node = frameNodeLocations.keys.first { it.name == name } | ||
val newX = (sandboxState.offset.x - frameNodeLocations.getValue(node).x | ||
+ appWindowSize.width / 2) | ||
val newY = (sandboxState.offset.y - frameNodeLocations.getValue(node).y | ||
+ appWindowSize.height / 2) | ||
sandboxState.offset = Offset(x = newX, y = newY) | ||
}, | ||
) | ||
|
||
FrameNavigator( | ||
totalFrames = frameSize, | ||
currentIndex = frameIndex, | ||
onIndexChange = { frameIndex = it }, | ||
) | ||
} | ||
} | ||
|
||
TraceModeToggleSwitch( | ||
onToggle = { | ||
|
@@ -96,13 +149,12 @@ internal fun App( | |
frameIndex = 0 | ||
TraceMode.File(null) | ||
} else { | ||
// TODO: TraceRecorder needs to be able to take in multiple clients if this is the case | ||
/* | ||
We set the frame to -1 here since we always increment it during Live mode as the list of | ||
frames get populated, so we avoid off by one when indexing into the frames. | ||
*/ | ||
frameIndex = -1 | ||
TraceMode.Live | ||
TraceMode.Live() | ||
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. If we dont provide the device ID here does it select one for us? was working through and noticed we require deviceId from Live trace |
||
} | ||
}, | ||
traceMode = traceMode, | ||
|
@@ -120,6 +172,26 @@ internal fun App( | |
modifier = Modifier.align(Alignment.BottomStart) | ||
) | ||
} | ||
|
||
if (traceMode is TraceMode.Live && (traceMode as TraceMode.Live).device == null) { | ||
DisplayDevices( | ||
onDeviceSelect = { selectedDevice -> | ||
traceMode = TraceMode.Live(selectedDevice) | ||
}, | ||
devices = listDevices(), | ||
modifier = Modifier.align(Alignment.Center) | ||
) | ||
|
||
FileDump( | ||
trace = rawRenderPass, | ||
modifier = Modifier.align(Alignment.BottomStart) | ||
) | ||
} | ||
|
||
RightInfoPanel( | ||
selectedNode = selectedNode, | ||
modifier = Modifier.align(Alignment.TopEnd) | ||
) | ||
} | ||
} | ||
|
||
|
@@ -134,5 +206,25 @@ internal class SandboxState { | |
|
||
internal sealed interface TraceMode { | ||
data class File(val file: PlatformFile?) : TraceMode | ||
data object Live : TraceMode | ||
data class Live(val device: String? = null) : TraceMode | ||
|
||
companion object { | ||
fun validateLiveMode(traceMode: TraceMode): Boolean { | ||
return traceMode is Live && traceMode.device != null | ||
} | ||
|
||
fun validateFileMode(traceMode: TraceMode): Boolean { | ||
return traceMode is File && traceMode.file != null | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Allows users to select from multiple devices that are currently running. | ||
*/ | ||
private fun listDevices(): List<String> { | ||
val process = ProcessBuilder("adb", "devices", "-l").start() | ||
process.waitFor() | ||
// We drop the header "List of devices attached" | ||
return process.inputStream.bufferedReader().readLines().drop(1).dropLast(1) | ||
} |
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.
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 think using square brackets to index could throw an IndexOutOfBoundsException right? Having
.getOrNull
was for the purpose when we go from frame 0 immediately to frame 10, so we would need to fill in the gap of frames with empty maps.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.
That's easy to miss, might be nice to add a comment about that intention.
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.
Fixed