Skip to content

Commit

Permalink
beam viz keeps the highlight on new data
Browse files Browse the repository at this point in the history
  • Loading branch information
tdev committed Oct 14, 2024
1 parent 3313453 commit ad4ac48
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions webview/visualizers/beam.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,17 @@ let jbeamData = null
let currentPartName = null
let beamCache // contains the high level object info
let selectedBeamIndices = null // arry of selected beam or null for no selection
let lastCusorPos = null

// buffers for the 3d geometry
let linesObject // the scene object

// Helper function to check if the cursor is within a given range
function cursorInRange(range) {
// only check the lines for now
return range[0] >= lastCusorPos[0] && range[0] <= lastCusorPos[2]
}

function updateBeamViz() {
let vertexPositions = []
beamCache = []
Expand Down Expand Up @@ -197,34 +204,22 @@ function focusBeams(beamsArrToFocus, triggerEditor = true) {
}
}

function onCursorChangeEditor(message) {
function onCursorChangeEditor() {
if(!beamCache) return

if(currentPartName !== message.currentPartName) {
currentPartName = message.currentPartName
updateBeamViz()
}

let beamsFound = []
// Helper function to check if the cursor is within a given range
const cursorInRange = (range) => {
// only check the lines for now
return range[0] >= message.range[0] && range[0] <= message.range[2]
};

for (let i = 0; i < beamCache.length; i++) {
if (cursorInRange(beamCache[i].__meta.range)) {
beamsFound.push(i)
if(lastCusorPos) {
for (let i = 0; i < beamCache.length; i++) {
if (cursorInRange(beamCache[i].__meta.range)) {
beamsFound.push(i)
}
}
}

//console.log(message.range, beamsFound, beamCache)

focusBeams(beamsFound, false)
}

function onReceiveMessage(event) {
//console.log(">>> onReceiveMessage >>>", event)
//console.log(">>> BEAMS: onReceiveMessage >>>", event)
const message = event.data;
switch (message.command) {
case 'jbeamData':
Expand All @@ -233,9 +228,15 @@ function onReceiveMessage(event) {
currentPartName = null
//console.log("GOT DATA: ", jbeamData)
updateBeamViz()
onCursorChangeEditor()
break;
case 'cursorChanged':
onCursorChangeEditor(message)
if(currentPartName !== message.currentPartName) {
currentPartName = message.currentPartName
updateBeamViz()
}
lastCusorPos = message.range
onCursorChangeEditor()
break
}
}
Expand All @@ -249,7 +250,6 @@ export function dispose() {
window.removeEventListener('message', onReceiveMessage);
window.removeEventListener('mousemove', onMouseMove);
if(linesObject) {
if (linesObject.geometry) linesObject.geometry.dispose()
if (linesObject.geometry) linesObject.geometry.dispose()
scene.remove(linesObject)
}
Expand Down

0 comments on commit ad4ac48

Please sign in to comment.