Skip to content
This repository was archived by the owner on Feb 28, 2023. It is now read-only.

Commit 20d644b

Browse files
committed
improved display
1 parent f68cad7 commit 20d644b

File tree

1 file changed

+7
-49
lines changed

1 file changed

+7
-49
lines changed

visualize.js

Lines changed: 7 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,6 @@ function display_array_pillars(arr) {
6969
ctx.stroke();
7070
}
7171
}
72-
function display_array_pillar_spiral(arr) {
73-
ctx.clearRect(0, 0, canvas.width, canvas.height);
74-
75-
for (let i = 360/(arr.length-1), c = 0; i < 360; i+=360/(arr.length-1), c++) {
76-
ctx.beginPath();
77-
ctx.strokeStyle = glob_themes[glob_theme]["color"];
78-
ctx.lineWidth = 4;
79-
80-
ctx.moveTo(canvas.width/2, canvas.height/2);
81-
ctx.lineTo((canvas.width/2) + arr[c] *Math.cos(Math.PI*i/180.0), (canvas.height/2) + arr[c] *Math.sin(Math.PI*i/180.0));
82-
ctx.stroke();
83-
}
84-
}
8572

8673
function draw_pillar(x1, y1, x2, y2, color, thickness) {
8774
color = color || glob_themes[glob_theme]["color"];
@@ -97,50 +84,21 @@ function draw_pillar(x1, y1, x2, y2, color, thickness) {
9784
ctx.stroke();
9885
}
9986
function display_pillars(arr, cu_el_i, l, r, cu_el_color, f_area_color) {
100-
cu_el_color = cu_el_color || "tomato";
87+
cu_el_color = cu_el_color || "#f00";
10188
f_area_color = f_area_color || "#ffcccc";
10289

10390
ctx.clearRect(0, 0, canvas.width, canvas.height);
10491
let scale = canvas.height / Math.max(...arr);
10592

106-
// -- DRAW NOT FOCUSED -- //
107-
for (let i = canvas.width / (arr.length+1); i <= (l+1) * (canvas.width/(arr.length+1)); i += canvas.width / (arr.length+1)) {
108-
draw_pillar(i, canvas.height, i, canvas.height - (arr[Math.floor(i / (canvas.width / (arr.length+1)))-1] * scale));
109-
}
110-
for (let i = (r + 2) * (canvas.width / (arr.length+1)); i <= canvas.width; i += canvas.width / (arr.length+1)) {
111-
draw_pillar(i, canvas.height, i, canvas.height - (arr[Math.floor(i / (canvas.width / (arr.length+1)))-1] * scale));
112-
}
93+
for (let i = canvas.width / (arr.length+1); i <= canvas.width; i += canvas.width / (arr.length+1)) {
94+
let index = Math.floor((i / (canvas.width / (arr.length+1))))-1,
95+
c = index == cu_el_i ? cu_el_color : index >= l && index <= r ? f_area_color : glob_themes[glob_theme]["color"],
96+
t = index == cu_el_i || (index >= l && index <= r) ? 5 : 4;
11397

114-
// -- DRAW FOCUSED -- //
115-
for (let i = (l + 1) * (canvas.width / (arr.length+1)); i <= (r + 2) * (canvas.width / (arr.length+1)); i += canvas.width / (arr.length+1)) {
116-
draw_pillar(i, canvas.height, i, canvas.height - (arr[Math.floor(i / (canvas.width / (arr.length+1)))-1] * scale), f_area_color);
117-
}
118-
119-
// -- DRAW CURRENT ELEMENT(S) -- //
120-
if (cu_el_i) {
121-
if (typeof cu_el_i == "number") {
122-
cu_x = (cu_el_i + 1) * (canvas.width / (arr.length+1));
123-
draw_pillar(cu_x, canvas.height, cu_x, canvas.height - (arr[cu_el_i] * scale), cu_el_color, 4);
124-
} else {
125-
cu_el_i.forEach(v => {
126-
cu_x = (v + 1) * (canvas.width / (arr.length+1));
127-
draw_pillar(cu_x, canvas.height, cu_x, canvas.height - (arr[v] * scale), cu_el_color, 4);
128-
});
129-
}
98+
draw_pillar(i, canvas.height, i, canvas.height - (arr[Math.floor(i / (canvas.width / (arr.length+1)))-1] * scale),
99+
c, t);
130100
}
131101
}
132-
// function display_pillar_spiral(arr, cu_el_i, l, r, cu_el_color, f_area_color) {
133-
// ctx.clearRect(0, 0, canvas.width, canvas.height);
134-
135-
// for (let i = 360/(arr.length-1), c = 0; i < 360; i+=360/(arr.length-1), c++) {
136-
// ctx.beginPath();
137-
// ctx.strokeStyle = "black";
138-
// ctx.moveTo(canvas.width/2, canvas.height/2);
139-
// ctx.lineTo((canvas.width/2) + arr[c] *Math.cos(Math.PI*i/180.0), (canvas.height/2) + arr[c] *Math.sin(Math.PI*i/180.0));
140-
// ctx.stroke();
141-
// }
142-
// }
143-
144102

145103
async function doSearchingAlgo(f) {
146104
document.getElementById('algorithm_settings').style.display = "none";

0 commit comments

Comments
 (0)