Skip to content

Commit

Permalink
Support Matrix Rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
YeonV committed Apr 17, 2023
1 parent 19dc1d2 commit 365a388
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 5 deletions.
9 changes: 6 additions & 3 deletions src/components/PixelGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ const PixelGraph = ({
className = '',
active = false,
intGraphs = false,
showMatrix = false,
}: {
virtId: string;
dummy?: boolean;
className?: string;
active?: boolean;
intGraphs?: boolean;
showMatrix?: boolean;
}) => {
const [pixels, setPixels] = useState<any>([]);
const pixelGraphs = useStore((state) => state.pixelGraphs);
Expand All @@ -23,7 +25,8 @@ const PixelGraph = ({
const graphs = useStore((state) => state.graphs);
const rows = virtuals[virtId].is_device ? devices[virtuals[virtId].is_device]?.config?.rows || virtuals[virtId].config.rows || 1 : virtuals[virtId].config.rows || 1;


console.log(rows, pixels[0]?.length)

useEffect(() => {
const handleWebsockets = (e: any) => {
if (e.detail.id === virtId) {
Expand Down Expand Up @@ -62,7 +65,7 @@ const PixelGraph = ({
}}
/>
</div>
) : pixels && pixels[0] && pixels[0].length && rows > 1 ? <div
) : pixels && pixels[0] && pixels[0].length && rows > 1 && showMatrix ? <div
style={{
maxWidth: '520px',
display: 'flex',
Expand All @@ -73,7 +76,7 @@ const PixelGraph = ({
margin: '0.5rem 0 0 0',
}}
className={`${className} ${active ? 'active' : ''}`}
>{[0,1,2,3,4,5,6,7,8].map((row) => (
>{Array.from(Array(rows).keys()).map((row) => (

<div
key={`row-${row}`}
Expand Down
18 changes: 17 additions & 1 deletion src/pages/Device/Effects.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ import {
Typography,
Box,
} from '@mui/material';
import { Clear, ExpandMore, Pause, PlayArrow } from '@mui/icons-material';
import {
Clear,
ExpandMore,
Pause,
PlayArrow,
GridOn,
GridOff,
} from '@mui/icons-material';
import useStore from '../../store/useStore';
import EffectDropDown from '../../components/SchemaForm/components/DropDown/DropDown.wrapper';
import BladeEffectSchemaForm from '../../components/SchemaForm/EffectsSchemaForm/EffectSchemaForm';
Expand Down Expand Up @@ -63,6 +70,7 @@ const orderEffectProperties = (

const EffectsCard = ({ virtId }: { virtId: string }) => {
const [fade, setFade] = useState(false);
const [matrix, setMatrix] = useState(false);
const getVirtuals = useStore((state) => state.getVirtuals);
const getSchemas = useStore((state) => state.getSchemas);
const clearVirtualEffect = useStore((state) => state.clearVirtualEffect);
Expand Down Expand Up @@ -171,6 +179,13 @@ const EffectsCard = ({ virtId }: { virtId: string }) => {
>
<Casino />
</Button> */}
<Button
style={{ marginRight: '.5rem' }}
className="step-device-six"
onClick={() => setMatrix(!matrix)}
>
{matrix ? <GridOff /> : <GridOn />}
</Button>
<Button
style={{ marginRight: '.5rem' }}
className="step-device-six"
Expand Down Expand Up @@ -206,6 +221,7 @@ const EffectsCard = ({ virtId }: { virtId: string }) => {
}}
>
<PixelGraph
showMatrix={matrix}
virtId={virtId}
active={
virtuals &&
Expand Down
5 changes: 5 additions & 0 deletions src/pages/Devices/DeviceCard/DeviceCard.interface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export interface DeviceCardProps {
* Do not send to leds
*/
graphsMulti?: boolean;
/**
* Show Matrix
*/
showMatrix?: boolean;
/**
* Colorize?
*/
Expand Down Expand Up @@ -117,4 +121,5 @@ export const DeviceCardDefaults: DeviceCardProps = {
transitionTime: 5,
isDevice: 'yz-quad',
graphsActive: true,
showMatrix: false,
};
2 changes: 2 additions & 0 deletions src/pages/Devices/DeviceCard/DeviceCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const DeviceCard = ({
transitionTime,
isDevice,
graphsMulti,
showMatrix,
activateDevice,
}: DeviceCardProps) => {
const classes = useStyle();
Expand Down Expand Up @@ -259,6 +260,7 @@ const DeviceCard = ({
}}
>
<PixelGraph
showMatrix={showMatrix}
intGraphs={graphsActive}
active={isActive}
virtId={virtId || ''}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/Devices/DeviceCard/DeviceCard.wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const DeviceCardWrapper = ({
const clearVirtualEffect = useStore((state) => state.clearVirtualEffect);
const updateVirtual = useStore((state) => state.updateVirtual);
const activateDevice = useStore((state) => state.activateDevice);
const showMatrix = useStore((state) => state.showMatrix);

const [_fade, setFade] = useState(false);
const [_isActive, setIsActive] = useState(
Expand Down Expand Up @@ -114,6 +115,7 @@ const DeviceCardWrapper = ({
effectName={virtuals[virtual]?.effect.name}
graphsActive={graphs && graphsMulti}
graphsMulti={graphsMulti}
showMatrix={showMatrix}
isDevice={virtuals[virtual]?.is_device}
activateDevice={handleActivateDevice}
colorIndicator={false}
Expand Down
9 changes: 8 additions & 1 deletion src/pages/Settings/UICard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const UICard = () => {
const toggleGraphs = useStore((state) => state.toggleGraphs);
const graphsMulti = useStore((state) => state.graphsMulti);
const toggleGraphsMulti = useStore((state) => state.toggleGraphsMulti);
const showMatrix = useStore((state) => state.showMatrix);
const toggleShowMatrix = useStore((state) => state.toggleShowMatrix);
const setFeatures = useStore((state) => state.setFeatures);
const showFeatures = useStore((state) => state.showFeatures);
const features = useStore((state) => state.features);
Expand Down Expand Up @@ -56,12 +58,17 @@ const UICard = () => {
/>
{config.visualisation_fps && graphs && (
<>
<Divider sx={{ m: '0.25rem 0 0.5rem 0' }} />
<SettingsRow
title="Also on Devices page"
checked={graphsMulti}
onChange={() => toggleGraphsMulti()}
/>
<SettingsRow
title="Show Matrix on Devices page"
checked={showMatrix}
onChange={() => toggleShowMatrix()}
/>
<Divider sx={{ m: '0.25rem 0 0.5rem 0' }} />
<SettingsRow title="Frontend FPS" step="two">
<SettingsSlider
value={fps}
Expand Down
10 changes: 10 additions & 0 deletions src/store/ui/storeGeneral.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,16 @@ const storeGeneral = (set: any) => ({
'general/toggleGraphsMulti'
);
},
showMatrix: false,
toggleShowMatrix: () => {
set(
produce((state: IStore) => {
state.showMatrix = !state.showMatrix;
}),
false,
'general/toggleShowMatrix'
);
},

pixelGraphs: [] as string[],
setPixelGraphs: (virtuals: string[]): void =>
Expand Down

0 comments on commit 365a388

Please sign in to comment.