MCPcopy Create free account
hub / github.com/algorithm-visualizer/algorithm-visualizer / Renderer

Class Renderer

src/core/renderers/Renderer/index.js:6–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4import { classes } from 'common/util';
5
6class Renderer extends React.Component {
7 constructor(props) {
8 super(props);
9
10 this.handleMouseDown = this.handleMouseDown.bind(this);
11 this.handleMouseMove = this.handleMouseMove.bind(this);
12 this.handleMouseUp = this.handleMouseUp.bind(this);
13 this.handleWheel = this.handleWheel.bind(this);
14
15 this._handleMouseDown = this.handleMouseDown;
16 this._handleWheel = this.handleWheel;
17 this.togglePan(false);
18 this.toggleZoom(false);
19
20 this.lastX = null;
21 this.lastY = null;
22 this.centerX = 0;
23 this.centerY = 0;
24 this.zoom = 1;
25 this.zoomFactor = 1.01;
26 this.zoomMax = 20;
27 this.zoomMin = 1 / 20;
28 }
29
30 componentDidUpdate(prevProps, prevState, snapshot) {
31 }
32
33 togglePan(enable = !this.handleMouseDown) {
34 this.handleMouseDown = enable ? this._handleMouseDown : undefined;
35 }
36
37 toggleZoom(enable = !this.handleWheel) {
38 this.handleWheel = enable ? this._handleWheel : undefined;
39 }
40
41 handleMouseDown(e) {
42 const { clientX, clientY } = e;
43 this.lastX = clientX;
44 this.lastY = clientY;
45 document.addEventListener('mousemove', this.handleMouseMove);
46 document.addEventListener('mouseup', this.handleMouseUp);
47 }
48
49 handleMouseMove(e) {
50 const { clientX, clientY } = e;
51 const dx = clientX - this.lastX;
52 const dy = clientY - this.lastY;
53 this.centerX -= dx;
54 this.centerY -= dy;
55 this.refresh();
56 this.lastX = clientX;
57 this.lastY = clientY;
58 }
59
60 handleMouseUp(e) {
61 document.removeEventListener('mousemove', this.handleMouseMove);
62 document.removeEventListener('mouseup', this.handleMouseUp);
63 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected