-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add EE for topics panel (#861)
* Add header section with button, slider, add table tray with tabs and resizable component * Add epoch table and more tabs * Move components and reorganize * Setup ee for PA * Add PA tables to tray config * Use half pointers for slider * Use props for tab state * Move active tab state a level up * Add callbacks to retrieve vertical bar color hash * Add query state * Change colors for dark mode * Add checkboxes for PA * Change checkboxes layout * Setup topics animation * Break p5 into files and use with React * Draw info box * Update container sizes * overflow to resize * Handle play/pause and reset callbacks * Handle animation speed step * Handle user visit data change * Render data in the tables * UI changes * Render border conditionally * Update border * Animation, table UI changes * Refactor code * Update UI, handle unexpected flow by updating calls * Auto change active tab * Extend timeline * Make animation continuous with animation consitency if moved to previous tab * Refactor callback and conditionally call user visit * use ref for not rendering on animation var value change * Dont overlap with horizontal lines * Update image data * Add line from circle to infoox * Update color circles sizes and text placement * handle restart of animation on complete when replay is clicked * Update callbacks for user visit
- Loading branch information
Showing
13 changed files
with
1,159 additions
and
477 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
101 changes: 101 additions & 0 deletions
101
...rc/view/devtools/components/privateAdvertising/topics/explorableExplanation/animation.tsx
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,101 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
/** | ||
* External dependencies. | ||
*/ | ||
import React, { useEffect, useRef, useState } from 'react'; | ||
import p5 from 'p5'; | ||
|
||
/** | ||
* Internal dependencies. | ||
*/ | ||
import { topicsAnimation } from './topicsAnimation'; | ||
|
||
interface AnimationProps { | ||
epoch: { datetime: string; website: string; topics: string[] }[]; | ||
isAnimating: boolean; | ||
siteAdTechs: Record<string, string[]>; | ||
handleUserVisit: (visitIndex: number, updateTopics?: boolean) => void; | ||
isPlaying: boolean; | ||
resetAnimation: boolean; | ||
speedMultiplier: number; | ||
} | ||
|
||
const Animation = ({ | ||
epoch, | ||
isAnimating, | ||
siteAdTechs, | ||
handleUserVisit, | ||
isPlaying, | ||
resetAnimation, | ||
speedMultiplier, | ||
}: AnimationProps) => { | ||
const node = useRef(null); | ||
const [togglePlayCallback, setTogglePlayCallback] = | ||
useState<(state: boolean) => void>(); | ||
const [resetCallback, setResetCallback] = useState<() => void>(); | ||
const [speedMultiplierCallback, setSpeedMultiplierCallback] = | ||
useState<(speed: number) => void>(); | ||
const animationRef = useRef(isAnimating); | ||
|
||
useEffect(() => { | ||
// Using the useRef hook to store the current value of isAnimating because the animation should not be re-rendered when the value of isAnimating changes. | ||
animationRef.current = isAnimating; | ||
}, [isAnimating]); | ||
|
||
useEffect(() => { | ||
const tAnimation = (p: p5) => { | ||
const { togglePlay, reset, updateSpeedMultiplier } = topicsAnimation( | ||
p, | ||
epoch, | ||
animationRef.current, | ||
siteAdTechs, | ||
animationRef.current | ||
? handleUserVisit | ||
: (idx: number) => handleUserVisit(idx, false) | ||
); | ||
|
||
setTogglePlayCallback(() => togglePlay); | ||
setResetCallback(() => reset); | ||
setSpeedMultiplierCallback(() => updateSpeedMultiplier); | ||
}; | ||
|
||
const p = node.current ? new p5(tAnimation, node.current) : null; | ||
|
||
return () => { | ||
p?.remove(); | ||
}; | ||
}, [epoch, handleUserVisit, siteAdTechs]); | ||
|
||
useEffect(() => { | ||
togglePlayCallback?.(isPlaying); | ||
}, [isPlaying, togglePlayCallback]); | ||
|
||
useEffect(() => { | ||
if (resetAnimation) { | ||
resetCallback?.(); | ||
} | ||
}, [resetAnimation, resetCallback]); | ||
|
||
useEffect(() => { | ||
speedMultiplierCallback?.(speedMultiplier); | ||
}, [speedMultiplier, speedMultiplierCallback]); | ||
|
||
return <div ref={node} className="overflow-auto" />; | ||
}; | ||
|
||
export default Animation; |
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
34 changes: 34 additions & 0 deletions
34
...ools/components/privateAdvertising/topics/explorableExplanation/topicsAnimation/config.ts
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,34 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
export const config = { | ||
canvas: { | ||
height: 500, | ||
}, | ||
timeline: { | ||
position: { x: 0, y: 120 }, | ||
circleProps: { | ||
diameter: 50, | ||
horizontalSpacing: 150, | ||
}, | ||
stepDelay: 1500, | ||
user: { | ||
width: 30, | ||
height: 30, | ||
}, | ||
circles: [], | ||
}, | ||
}; |
Oops, something went wrong.