Skip to content

Commit 74c5fd6

Browse files
Added Chart using chart.js
1 parent 87bc92f commit 74c5fd6

File tree

5 files changed

+131
-50
lines changed

5 files changed

+131
-50
lines changed

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
"@testing-library/jest-dom": "^5.13.0",
77
"@testing-library/react": "^11.2.7",
88
"@testing-library/user-event": "^12.8.3",
9+
"chart.js": "^3.3.2",
910
"react": "^17.0.2",
11+
"react-chartjs-2": "^3.0.3",
1012
"react-dom": "^17.0.2",
1113
"react-scripts": "4.0.3",
1214
"web-vitals": "^1.1.2"

src/App.css

Lines changed: 6 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,10 @@
22
text-align: center;
33
}
44

5-
.App-logo {
6-
height: 40vmin;
7-
pointer-events: none;
8-
}
9-
10-
@media (prefers-reduced-motion: no-preference) {
11-
.App-logo {
12-
animation: App-logo-spin infinite 20s linear;
13-
}
14-
}
15-
16-
.App-header {
17-
background-color: #282c34;
18-
min-height: 100vh;
19-
display: flex;
20-
flex-direction: column;
21-
align-items: center;
22-
justify-content: center;
23-
font-size: calc(10px + 2vmin);
24-
color: white;
25-
}
26-
27-
.App-link {
28-
color: #61dafb;
29-
}
30-
31-
@keyframes App-logo-spin {
32-
from {
33-
transform: rotate(0deg);
34-
}
35-
to {
36-
transform: rotate(360deg);
37-
}
5+
.bar {
6+
width: 95%;
7+
margin: 0 auto;
8+
height: 350px;
9+
background-color: rgb(199, 199, 204);
10+
border: 1px solid lightgray;
3811
}

src/App.js

Lines changed: 91 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,98 @@
1-
import logo from './logo.svg';
2-
import './App.css';
1+
import "./App.css";
2+
import { Bar } from "react-chartjs-2";
3+
import { useState } from "react";
34

45
function App() {
6+
const [data, setData] = useState({
7+
labels: [10, 20, 30, 40, 10],
8+
datasets: [
9+
{
10+
data: [10, 20, 30, 40, 10],
11+
backgroundColor: ["rgb(248,248,248)"],
12+
},
13+
],
14+
});
15+
16+
const [sorting, setSorting] = useState(true);
17+
18+
var options = {
19+
maintainAspectRatio: false,
20+
responsive: true,
21+
scales: {
22+
x: {
23+
grid: {
24+
display: false,
25+
borderWidth: 0,
26+
},
27+
ticks: {
28+
display: true,
29+
// color: "white",
30+
},
31+
},
32+
y: {
33+
grid: {
34+
display: false,
35+
borderWidth: 0,
36+
},
37+
ticks: {
38+
display: false,
39+
},
40+
},
41+
},
42+
plugins: {
43+
legend: {
44+
display: false,
45+
},
46+
},
47+
events: [],
48+
};
49+
50+
// const alg = () => {
51+
// const state = data.datasets[0].data;
52+
// for (let i = 0; i < 5; i++) {
53+
// for (let j = 0; j < 5; j++) {
54+
// // console.log(state);
55+
// if (state[i] > state[j]) {
56+
// let temp = 0;
57+
// temp = state[i];
58+
// state[i] = state[j];
59+
// state[j] = temp;
60+
// // console.log(state);
61+
// setTimeout(
62+
// (s, i, j) => {
63+
// if (state[i] > state[j]) {
64+
// let temp = 0;
65+
// temp = state[i];
66+
// state[i] = state[j];
67+
// state[j] = temp;
68+
// }
69+
// setData((prev) => {
70+
// const newState = { ...prev };
71+
// console.log(newState);
72+
// console.log(s);
73+
// newState.datasets[0].data = s;
74+
// return newState;
75+
// });
76+
// },
77+
// 5000,
78+
// state,
79+
// i,
80+
// j
81+
// );
82+
// }
83+
// }
84+
// }
85+
// setSorting(false);
86+
// };
87+
// if (sorting) alg();
88+
589
return (
690
<div className="App">
7-
<header className="App-header">
8-
<img src={logo} className="App-logo" alt="logo" />
9-
<p>
10-
Edit <code>src/App.js</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
Learn React
19-
</a>
20-
</header>
91+
<h1>Sorting Visualizer</h1>
92+
<div className="bar">
93+
{/* {console.log(data)} */}
94+
<Bar data={data} options={options} />
95+
</div>
2196
</div>
2297
);
2398
}

src/logo.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)