Clock.js — react Source File
Architecture documentation for Clock.js, a javascript file in the react codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 3a7e99dd_a5c5_f3c7_9c40_65dc549077bf["Clock.js"] ac587885_e294_a1e9_b13f_5e7b920fdb42["react"] 3a7e99dd_a5c5_f3c7_9c40_65dc549077bf --> ac587885_e294_a1e9_b13f_5e7b920fdb42 b6b3cf8a_4317_6da2_264c_e7cff7c932c6["index.js"] b6b3cf8a_4317_6da2_264c_e7cff7c932c6 --> 3a7e99dd_a5c5_f3c7_9c40_65dc549077bf style 3a7e99dd_a5c5_f3c7_9c40_65dc549077bf fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import React, {createRef, PureComponent} from 'react';
const SPEED = 0.003 / Math.PI;
const FRAMES = 10;
export default class Clock extends PureComponent {
faceRef = createRef();
arcGroupRef = createRef();
clockHandRef = createRef();
frame = null;
hitCounter = 0;
rotation = 0;
t0 = Date.now();
arcs = [];
animate = () => {
const now = Date.now();
const td = now - this.t0;
this.rotation = (this.rotation + SPEED * td) % (2 * Math.PI);
this.t0 = now;
this.arcs.push({rotation: this.rotation, td});
let lx, ly, tx, ty;
if (this.arcs.length > FRAMES) {
this.arcs.forEach(({rotation, td}, i) => {
lx = tx;
ly = ty;
const r = 145;
tx = 155 + r * Math.cos(rotation);
ty = 155 + r * Math.sin(rotation);
const bigArc = SPEED * td < Math.PI ? '0' : '1';
const path = `M${tx} ${ty}A${r} ${r} 0 ${bigArc} 0 ${lx} ${ly}L155 155`;
const hue = 120 - Math.min(120, td / 4);
const colour = `hsl(${hue}, 100%, ${60 - i * (30 / FRAMES)}%)`;
if (i !== 0) {
const arcEl = this.arcGroupRef.current.children[i - 1];
arcEl.setAttribute('d', path);
arcEl.setAttribute('fill', colour);
}
});
this.clockHandRef.current.setAttribute('d', `M155 155L${tx} ${ty}`);
this.arcs.shift();
}
if (this.hitCounter > 0) {
this.faceRef.current.setAttribute(
'fill',
`hsla(0, 0%, ${this.hitCounter}%, 0.95)`
);
this.hitCounter -= 1;
} else {
this.hitCounter = 0;
this.faceRef.current.setAttribute('fill', 'hsla(0, 0%, 5%, 0.95)');
}
this.frame = requestAnimationFrame(this.animate);
};
componentDidMount() {
this.frame = requestAnimationFrame(this.animate);
if (this.faceRef.current) {
this.faceRef.current.addEventListener('click', this.handleClick);
}
}
componentDidUpdate() {
console.log('componentDidUpdate()', this.faceRef.current);
}
componentWillUnmount() {
this.faceRef.current.removeEventListener('click', this.handleClick);
if (this.frame) {
cancelAnimationFrame(this.frame);
}
}
handleClick = e => {
e.stopPropagation();
this.hitCounter = 50;
};
render() {
const paths = new Array(FRAMES);
for (let i = 0; i < FRAMES; i++) {
paths.push(<path className="arcHand" key={i} />);
}
return (
<div className="stutterer">
<svg height="310" width="310">
<circle
className="clockFace"
onClick={this.handleClick}
cx={155}
cy={155}
r={150}
ref={this.faceRef}
/>
<g ref={this.arcGroupRef}>{paths}</g>
<path className="clockHand" ref={this.clockHandRef} />
</svg>
</div>
);
}
}
Domain
Subdomains
Classes
Dependencies
- react
Imported By
Source
Frequently Asked Questions
What does Clock.js do?
Clock.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Entrypoint subdomain.
What does Clock.js depend on?
Clock.js imports 1 module(s): react.
What files import Clock.js?
Clock.js is imported by 1 file(s): index.js.
Where is Clock.js in the architecture?
Clock.js is located at fixtures/concurrent/time-slicing/src/Clock.js (domain: BabelCompiler, subdomain: Entrypoint, directory: fixtures/concurrent/time-slicing/src).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free