-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Visualisation is in place, need to test in production for performance
- Loading branch information
Adam Roberts
authored and
Adam Roberts
committed
Apr 25, 2024
1 parent
9a58192
commit 6f2e269
Showing
6 changed files
with
201 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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 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 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 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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use client'; | ||
|
||
// Imports | ||
// ------------ | ||
import React, { useRef, useEffect } from 'react'; | ||
import Spline from '@splinetool/react-spline'; | ||
|
||
// Styles | ||
// ------------ | ||
import { Jacket, Container, SplineJacket } from './styles'; | ||
|
||
// Component | ||
// ------------ | ||
const Visualisation = ({ data }) => { | ||
// NOTE • Generate Grid | ||
const containerRef = useRef(null); | ||
|
||
// NOTE • Generate Grid | ||
const generateSpans = () => { | ||
const spans = []; | ||
for (let i = 1; i <= 1024; i++) { | ||
spans.push(<span key={i} className="grid-item"></span>); | ||
} | ||
return spans; | ||
}; | ||
|
||
// NOTE • Highlight Random Squares | ||
function highlightRandomSquares(num) { | ||
const squares = document.querySelectorAll('.grid-item'); | ||
const indices = []; | ||
|
||
// Remove selected class from all squares | ||
squares.forEach(square => { | ||
square.classList.remove('selected'); | ||
}); | ||
|
||
// Generate unique random indices | ||
while (indices.length < num) { | ||
const index = Math.floor(Math.random() * squares.length); | ||
if (!indices.includes(index)) { | ||
indices.push(index); | ||
} | ||
} | ||
|
||
// Highlight random squares | ||
indices.forEach(index => { | ||
squares[index].classList.add('selected'); | ||
}); | ||
} | ||
|
||
// NOTE • Interval highlight when data changes | ||
useEffect(() => { | ||
function getNumber(num) { | ||
const numberBeforeX = num.substring(0, num.indexOf('x')); | ||
|
||
return parseInt(numberBeforeX, 10); | ||
} | ||
|
||
let number = getNumber(data.networkHeadDataSquare); | ||
|
||
// Highlight random squares | ||
highlightRandomSquares(number); | ||
}, [data]); | ||
|
||
return ( | ||
<Jacket> | ||
<Container ref={containerRef}>{generateSpans()}</Container> | ||
<SplineJacket> | ||
<Spline scene="https://prod.spline.design/vS5y3FkvJJqrWPgq/scene.splinecode" /> | ||
</SplineJacket> | ||
</Jacket> | ||
); | ||
} | ||
|
||
export default Visualisation; |
This file contains 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Imports | ||
// ------------ | ||
import styled, { css } from 'styled-components'; | ||
import { bp, Div } from '@tackl'; | ||
|
||
// Exports | ||
// ------------ | ||
export const Jacket = styled(Div)(props => css` | ||
position: relative; | ||
`); | ||
|
||
export const Container = styled(Div)( | ||
props => css` | ||
position: relative; | ||
pointer-events: none; | ||
padding: 1px; | ||
display: grid; | ||
grid-template-columns: repeat(32, 1fr); | ||
grid-template-rows: repeat(32, 1fr); | ||
grid-gap: 1px; | ||
width: 42.08vw; | ||
height: 42.08vw; | ||
background: ${props.theme.colors.global.black10}; | ||
.grid-item { | ||
background: white; | ||
} | ||
.selected { | ||
background: ${props.theme.colors.brand.bc4}; | ||
} | ||
` | ||
); | ||
|
||
export const SplineJacket = styled(Div)(props => css` | ||
position: absolute; | ||
top: 0; left: 0; right: 0; bottom: 0; | ||
`); |