Skip to content

Commit

Permalink
Do initial refresh safely when autorefresh is off
Browse files Browse the repository at this point in the history
  • Loading branch information
markgrahamdawson committed Apr 17, 2024
1 parent 9abf4dc commit 5cffe97
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/views/Graph.vue
Original file line number Diff line number Diff line change
Expand Up @@ -282,16 +282,12 @@ export default {
},
mounted () {
if (!this.autoRefresh) {
// load the graph if the autorefresh is off
this.refreshTimer = setInterval(this.refresh, 1000)
this.refreshTimer = null
}
// compile & instantiate graphviz wasm
/** @type {Promise<Graphviz>} */
this.graphviz = Graphviz.load()
// allow render to happen before we go configuring svgPanZoom
this.$nextTick(() => {
this.refresh()
this.updateTimer()
})
this.mountSVGPanZoom()
Expand Down Expand Up @@ -588,7 +584,10 @@ export default {
this.updating = true
// extract the graph (non reactive lists of nodes & edges)
const nodes = this.getGraphNodes()
const nodes = await this.waitFor(() => {
const nodes = this.getGraphNodes()
return nodes.length ? nodes : false
})
const edges = this.getGraphEdges()
if (!nodes.length) {
Expand Down Expand Up @@ -622,11 +621,9 @@ export default {
// obtain the node dimensions to use in the layout
// NOTE: need to wait for the nodes to all be rendered before we can
// measure them
let nodeDimensions
await this.waitFor(() => {
const nodeDimensions = await this.waitFor(() => {
try {
nodeDimensions = this.getNodeDimensions(nodes)
return true // all nodes rendered
return this.getNodeDimensions(nodes) // all nodes rendered
} catch {
return false // one or more nodes awaiting render
}
Expand Down Expand Up @@ -664,9 +661,8 @@ export default {
// Will return when the callback returns something truthy.
// OR after the configured number of retries
for (let retry = 0; retry < retries; retry++) {
if (callback()) {
break
}
const ret = callback()
if (ret) return ret
await new Promise(requestAnimationFrame)
await this.$nextTick()
}
Expand Down

0 comments on commit 5cffe97

Please sign in to comment.