-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanvas.js
More file actions
84 lines (79 loc) · 2.73 KB
/
Canvas.js
File metadata and controls
84 lines (79 loc) · 2.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import { Component } from "react";
import { CONSTANTS } from "../../Utility/config.js";
import SortingCanvasDescription from "./Description/SortingCanvasDescription.js";
import "./style.css";
class Canvas extends Component {
constructor(props) {
super(props);
}
render() {
const { generatedArray, showHeight, defaultBarColor } = this.props;
const arrayLength = generatedArray.length;
const MARGIN = CONSTANTS.margin;
const SCREEN_WIDTH = window.innerWidth;
const BAR_WIDTH = Math.floor(
(SCREEN_WIDTH - MARGIN * arrayLength) / arrayLength
);
const MARGIN_BTW_CANVAS_AND_OPTIONS = 147;
const CANVAS_HEIGHT =
window.innerHeight -
CONSTANTS.OFFSET +
MARGIN_BTW_CANVAS_AND_OPTIONS +
"px";
const FONT_SIZE = Math.floor(BAR_WIDTH * 0.4);
const PINK = "#ff595e";
const PURPLE = "#6a4c93";
const SHOW_HEIGHT_MAX_BARS = Math.floor((window.innerWidth - MARGIN) / 28);
// Math.floor((SCREEN_WIDTH - MARGIN * inputArrayLength) / inputArrayLength);
return (
<div
id="sorting-main-canvas"
className={`w-full flex justify-center dark:bg-gradient-to-b from-lightGray to-richBlue relative`}
style={{ minHeight: CANVAS_HEIGHT }}
>
<p
className="absolute top-3 z-10 font-semibold text-red-600 font-sans"
id="sort-canvas-error-msg"
></p>
<div className="flex items-end z-1">
{arrayLength > 1 ? (
generatedArray.map((element) => {
return (
<div
id={`${element}`}
fontSize={FONT_SIZE}
data={`${
BAR_WIDTH > 25 && element > FONT_SIZE + 16 && showHeight
? element
: ""
}`}
length="40px"
key={Math.random()}
style={{
"--bar-font-size": FONT_SIZE + "px",
height: element + "px",
width: BAR_WIDTH + "px",
backgroundColor: this.props.barColor,
}}
className={`array-bars z-10 m-[1px] rounded-t-md relative ${
defaultBarColor !== PINK &&
defaultBarColor !== PURPLE &&
defaultBarColor !== "black"
? "after:text-gray-700"
: "after:text-white"
}`}
/>
);
})
) : (
<SortingCanvasDescription
maxBarsToShowHeight={SHOW_HEIGHT_MAX_BARS}
/>
)}
</div>
<div className="main-canvas-grid z-0 dark:opacity-[0.03]" />
</div>
);
}
}
export { Canvas };