|
|
|
@ -7,21 +7,30 @@ import Point, {PointContentType} from './point.jsx'; |
|
|
|
import { useControls, button } from "leva"; |
|
|
|
import { useControls, button } from "leva"; |
|
|
|
import { sendOsc } from '../utils/osc.js'; |
|
|
|
import { sendOsc } from '../utils/osc.js'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getColorFromIndex(index, length){ |
|
|
|
|
|
|
|
const hue = (index / length) * 360; |
|
|
|
|
|
|
|
return `hsl(${hue}, 100%, 50%)`; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export default function Graph({results}){ |
|
|
|
export default function Graph({results}){ |
|
|
|
|
|
|
|
|
|
|
|
const [points, setPoints]=useState(); |
|
|
|
const [points, setPoints]=useState(); |
|
|
|
const [lines, setLines]=useState(); |
|
|
|
const [lines, setLines]=useState(); |
|
|
|
|
|
|
|
|
|
|
|
// const [drawLines, setDrawLines]=useState(false); |
|
|
|
// const [drawLines, setDrawLines]=useState(false); |
|
|
|
|
|
|
|
|
|
|
|
// const [showContent, setShowContent]=useState(true); |
|
|
|
// const [showContent, setShowContent]=useState(true); |
|
|
|
// const [showKeyword, setShowKeyword]=useState(false); |
|
|
|
// const [showKeyword, setShowKeyword]=useState(false); |
|
|
|
|
|
|
|
|
|
|
|
const { showContent, contentType, showKeywords, showLines, textToShow } = useControls({ |
|
|
|
const { showContent, contentType, showKeywords, showLines, textToShow, drawDistance, distToKeywords, keywordColor } = useControls({ |
|
|
|
showContent: { value: true }, |
|
|
|
showContent: { value: true }, |
|
|
|
contentType: { options: Object.values(PointContentType), value: PointContentType.Teaser }, |
|
|
|
contentType: { options: Object.values(PointContentType), value: PointContentType.Teaser }, |
|
|
|
showKeywords: { value: false }, |
|
|
|
showKeywords: { value: false }, |
|
|
|
showLines: { value: false }, |
|
|
|
showLines: { value: false }, |
|
|
|
textToShow: { value: 20, min: 5, max: 100, step: 5 }, |
|
|
|
textToShow: { value: 20, min: 5, max: 100, step: 5 }, |
|
|
|
|
|
|
|
drawDistance: { value: 0.2, min: 0.1, max: 5, step: 0.01 }, |
|
|
|
|
|
|
|
keywordColor: { value: true }, |
|
|
|
|
|
|
|
distToKeywords: { value: 3, min: 0.1, max: 10, step: 0.01 }, |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -35,13 +44,36 @@ export default function Graph({results}){ |
|
|
|
bounds?.refresh().clip().fit(); |
|
|
|
bounds?.refresh().clip().fit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getColorByGroup(result){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!keywordColor) return 'white'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!result || !result.payload ) |
|
|
|
|
|
|
|
return 'white'; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(result.type==='keyword'){ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return getColorFromIndex(parseInt(result.id), 20); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const group = result.payload.group[0]; |
|
|
|
|
|
|
|
if(group.distance<distToKeywords){ |
|
|
|
|
|
|
|
const index=parseInt(group.id); |
|
|
|
|
|
|
|
console.log("Group color index:", index, "for group id:", group.id); |
|
|
|
|
|
|
|
return getColorFromIndex(index, 20); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 'white'; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
useEffect(()=>{ |
|
|
|
zoomToFit(); |
|
|
|
zoomToFit(); |
|
|
|
|
|
|
|
|
|
|
|
if(!points || points.length===0) return; |
|
|
|
if(!points || points.length===0) return; |
|
|
|
|
|
|
|
|
|
|
|
points.forEach((point, index)=>{ |
|
|
|
points.forEach((point, index)=>{ |
|
|
|
console.log(`send osc Point ${index}: (${point[0].toFixed(2)}, ${point[1].toFixed(2)}, ${point[2].toFixed(2)})`); |
|
|
|
// console.log(`send osc Point ${index}: (${point[0].toFixed(2)}, ${point[1].toFixed(2)}, ${point[2].toFixed(2)})`); |
|
|
|
sendOsc('/point',JSON.stringify({ |
|
|
|
sendOsc('/point',JSON.stringify({ |
|
|
|
index: index, |
|
|
|
index: index, |
|
|
|
x: point[0], |
|
|
|
x: point[0], |
|
|
|
@ -52,6 +84,18 @@ export default function Graph({results}){ |
|
|
|
}); |
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
}, [points]); |
|
|
|
}, [points]); |
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
|
|
|
|
if(!results || results.length===0){ |
|
|
|
|
|
|
|
setLines([]); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generateLinesFromPoints(points, drawDistance).then(newLines=>{ |
|
|
|
|
|
|
|
console.log("Lines updated due to drawDistance change:", newLines); |
|
|
|
|
|
|
|
setLines(newLines); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
},[drawDistance]); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(()=>{ |
|
|
|
useEffect(()=>{ |
|
|
|
if(!results || results.length===0){ |
|
|
|
if(!results || results.length===0){ |
|
|
|
@ -68,7 +112,7 @@ export default function Graph({results}){ |
|
|
|
console.log("3D Points:", newPoints); |
|
|
|
console.log("3D Points:", newPoints); |
|
|
|
setPoints(newPoints); |
|
|
|
setPoints(newPoints); |
|
|
|
|
|
|
|
|
|
|
|
generateLinesFromPoints(newPoints, 10).then(newLines=>{ |
|
|
|
generateLinesFromPoints(newPoints, drawDistance).then(newLines=>{ |
|
|
|
console.log("Lines:", newLines); |
|
|
|
console.log("Lines:", newLines); |
|
|
|
setLines(newLines); |
|
|
|
setLines(newLines); |
|
|
|
}); |
|
|
|
}); |
|
|
|
@ -94,6 +138,7 @@ export default function Graph({results}){ |
|
|
|
result={results?.[index]} |
|
|
|
result={results?.[index]} |
|
|
|
showContent={showContent} showKeyword={showKeywords} contentType={contentType} |
|
|
|
showContent={showContent} showKeyword={showKeywords} contentType={contentType} |
|
|
|
textToShow={textToShow} |
|
|
|
textToShow={textToShow} |
|
|
|
|
|
|
|
color={getColorByGroup(results?.[index])} |
|
|
|
/> |
|
|
|
/> |
|
|
|
))} |
|
|
|
))} |
|
|
|
</group> |
|
|
|
</group> |
|
|
|
|