Add a hash param to control view-mode (#362)

e.g. "view=left-heavy", "view=sandwich"

Fixes #355
This commit is contained in:
David Judd
2022-05-17 00:15:51 -07:00
committed by GitHub
parent ca8fcb48cc
commit 48d692c2a3
5 changed files with 37 additions and 8 deletions
+1 -6
View File
@@ -1,4 +1,5 @@
import {Atom} from '../lib/atom'
import {ViewMode} from '../lib/view-mode'
import {getHashParams, HashParams} from '../lib/hash-params'
import {ProfileGroupAtom} from './profile-group'
@@ -13,12 +14,6 @@ export const flattenRecursionAtom = new Atom<boolean>(false, 'flattenRecursion')
export const searchIsActiveAtom = new Atom<boolean>(false, 'searchIsActive')
export const searchQueryAtom = new Atom<string>('', 'searchQueryAtom')
export const enum ViewMode {
CHRONO_FLAME_CHART,
LEFT_HEAVY_FLAME_GRAPH,
SANDWICH_VIEW,
}
// Which top-level view should be displayed
export const viewModeAtom = new Atom<ViewMode>(ViewMode.CHRONO_FLAME_CHART, 'viewMode')
+23
View File
@@ -1,7 +1,23 @@
import {ViewMode} from '../lib/view-mode'
export interface HashParams {
profileURL?: string
title?: string
localProfilePath?: string
viewMode?: ViewMode
}
function getViewMode(value: string): ViewMode | null {
switch (value) {
case 'time-ordered':
return ViewMode.CHRONO_FLAME_CHART
case 'left-heavy':
return ViewMode.LEFT_HEAVY_FLAME_GRAPH
case 'sandwich':
return ViewMode.SANDWICH_VIEW
default:
return null
}
}
export function getHashParams(hashContents = window.location.hash): HashParams {
@@ -20,6 +36,13 @@ export function getHashParams(hashContents = window.location.hash): HashParams {
result.title = value
} else if (key === 'localProfilePath') {
result.localProfilePath = value
} else if (key === 'view') {
const mode = getViewMode(value)
if (mode !== null) {
result.viewMode = mode
} else {
console.error(`Ignoring invalid view specifier: ${value}`)
}
}
}
return result
+5
View File
@@ -0,0 +1,5 @@
export const enum ViewMode {
CHRONO_FLAME_CHART,
LEFT_HEAVY_FLAME_GRAPH,
SANDWICH_VIEW,
}
+6 -1
View File
@@ -13,7 +13,8 @@ import {CanvasContext} from '../gl/canvas-context'
import {Toolbar} from './toolbar'
import {importJavaScriptSourceMapSymbolRemapper} from '../lib/js-source-map'
import {Theme, withTheme} from './themes/theme'
import {canUseXHR, ViewMode} from '../app-state'
import {ViewMode} from '../lib/view-mode'
import {canUseXHR} from '../app-state'
import {ProfileGroupState} from '../app-state/profile-group'
import {HashParams} from '../lib/hash-params'
import {StatelessComponent} from '../lib/preact-helpers'
@@ -199,6 +200,10 @@ export class Application extends StatelessComponent<ApplicationProps> {
}
document.title = `${profileGroup.name} - speedscope`
if (this.props.hashParams.viewMode) {
this.props.setViewMode(this.props.hashParams.viewMode)
}
for (let profile of profileGroup.profiles) {
await profile.demangle()
}
+2 -1
View File
@@ -7,7 +7,8 @@ import {ProfileSelect} from './profile-select'
import {Profile} from '../lib/profile'
import {objectsHaveShallowEquality} from '../lib/utils'
import {colorSchemeToString, useTheme, withTheme} from './themes/theme'
import {ViewMode, viewModeAtom} from '../app-state'
import {ViewMode} from '../lib/view-mode'
import {viewModeAtom} from '../app-state'
import {ProfileGroupState} from '../app-state/profile-group'
import {colorSchemeAtom} from '../app-state/color-scheme'
import {useAtom} from '../lib/atom'