Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Color-coding operations #80

Open
wants to merge 33 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
6de2927
Add base color code functionality
distay0xGit Feb 22, 2022
6ee885b
Right-align color legend
distay0xGit Feb 23, 2022
66af752
Color-code some sorts
distay0xGit Feb 24, 2022
1426b53
Merge branch 'main' into main
Gaming32 Feb 26, 2022
e4d72c2
(hopefully) Make PR checkstyle-compliant
distay0xGit Feb 26, 2022
e823c40
Merge branch 'main' of https://github.com/distay0xGit/ArrayV
distay0xGit Feb 26, 2022
a3c5d55
Merge branch 'main' into pr/80
Gaming32 Feb 26, 2022
f27f7f5
Delete ExpliciumSort.java
distay0xGit Feb 26, 2022
f260d19
Fix ignored checkstyle violation
Gaming32 Feb 26, 2022
3bf1b0b
Move legend slightly, properly clear colorcodes
distay0xGit Feb 26, 2022
f3cec01
Checkstyle violation
distay0xGit Feb 26, 2022
fded4d3
(rough draft) Subarray colorcoding
distay0xGit Feb 27, 2022
c6aa3c6
Uninitialized variables are not fun (ArrayVList.java)
distay0xGit Feb 27, 2022
1b46832
Add ArrayVList colorcoding methods
distay0xGit Mar 1, 2022
c37b213
Fix non-linked ScatterPlot colorcodes
distay0xGit Mar 4, 2022
7098c89
Add colorcoding to more visual styles
distay0xGit Mar 9, 2022
4e9c511
Consistency
distay0xGit Mar 26, 2022
018eda7
Stepping
distay0xGit Mar 30, 2022
6bfed0b
Resolve conflicts attempt 1
distay0xGit Mar 30, 2022
62ff332
Resolve conflicts attempt 2
distay0xGit Mar 30, 2022
cc9ad39
Resolve conflicts attempt 3
distay0xGit Mar 30, 2022
dfdbabf
Resolve conflicts attempt 4
distay0xGit Mar 30, 2022
a0ba507
"Fix" checkstyle
distay0xGit Mar 30, 2022
b7fa847
If Git is causing issues, that doesn't mean checkstyle should be ignored
Gaming32 Mar 31, 2022
578d99b
Merge branch 'main' into main
Gaming32 Mar 31, 2022
11bc21b
Fix oddly duplicated code
Gaming32 Mar 31, 2022
078cdde
Polymorphism
Gaming32 Apr 3, 2022
e1587fa
Some slight optimizations
Gaming32 Apr 3, 2022
ee77bb6
Fix conflicts attempt 1
distay0xGit Feb 28, 2024
fc62dff
Fix conflicts attempt 2
distay0xGit Feb 28, 2024
f1bc5bd
Fix conflicts attempt 3
distay0xGit Feb 28, 2024
210e487
Fix conflicts attempt 4
distay0xGit Feb 28, 2024
9d8f799
Fix conflicts attempt 5
distay0xGit Feb 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions src/main/java/io/github/arrayv/main/ArrayVisualizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,8 @@ public void refreshSorts() {
private void drawStats(Color textColor, boolean dropShadow) {
int xOffset = 15;
int yOffset = 30;
int drawingFirstStat = 1;

if (dropShadow) {
xOffset += 3;
yOffset += 3;
Expand All @@ -674,14 +676,13 @@ private void drawStats(Color textColor, boolean dropShadow) {

this.mainRender.setColor(textColor);

statLoop:
for (StatisticType statType : statsConfig) {
// System.out.println(yPos);
String stat;
switch (statType) {
case LINE_BREAK:
yPos += (int)(fontSelectionScale / 25.0 * 15);
continue statLoop;
continue;
case SORT_IDENTITY:
stat = statSnapshot.getSortIdentity();
break;
Expand Down Expand Up @@ -725,6 +726,34 @@ private void drawStats(Color textColor, boolean dropShadow) {
stat = null; // Unreachable
}
mainRender.drawString(stat, xOffset, (int)(windowRatio * yPos) + yOffset);

if (drawingFirstStat == 1 && Highlights.getDeclaredColors().size() > 0) {
int startOffset = currentWidth(), metricFontHeight = mainRender.getFontMetrics().getHeight(),
startStat = mainRender.getFontMetrics().stringWidth(stat) + xOffset + 24,
copyYPos = (int)(windowRatio * yPos) + yOffset, textWidth;

for (String color : Highlights.getDeclaredColors()) {
textWidth = mainRender.getFontMetrics().stringWidth(color);
startOffset -= textWidth + metricFontHeight + 20;
if (startOffset <= startStat) {
startOffset = currentWidth() - textWidth - metricFontHeight - 20;
copyYPos += metricFontHeight + 8;
}

if (!dropShadow) {
mainRender.setColor(Highlights.getColorFromName(color));
}

mainRender.fillRect(startOffset, copyYPos - metricFontHeight + (metricFontHeight / 3), metricFontHeight, metricFontHeight);

if (!dropShadow) {
mainRender.setColor(textColor);
}

mainRender.drawString(color, startOffset + metricFontHeight + 6, copyYPos);
}
}
drawingFirstStat = 0;
yPos += fontSelectionScale;
}
}
Expand Down Expand Up @@ -1296,7 +1325,11 @@ public String formatTimes() {

public void endSort() {
this.Timer.disableRealTimer();

this.Highlights.clearAllMarks();
this.Highlights.clearAllColorsReferenced();
this.Highlights.clearColorList();

System.out.println(formatTimes());

this.isCanceled = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.arrayv.sorts.merge;

import java.awt.Color;

import io.github.arrayv.main.ArrayVisualizer;
import io.github.arrayv.sorts.templates.Sort;

Expand Down Expand Up @@ -46,14 +48,20 @@ public BlockSwapMergeSort(ArrayVisualizer arrayVisualizer) {
}

private void multiSwap(int[] array, int a, int b, int len) {
for(int i = 0; i < len; i++)
for(int i = 0; i < len; i++) {
Highlights.colorCode("blockswap", a+i, b+i);
Writes.swap(array, a+i, b+i, 1, true, false);
}
}

private int binarySearchMid(int[] array, int start, int mid, int end) {
int a = 0, b = Math.min(mid-start, end-mid), m = a+(b-a)/2;

while(b > a) {
Highlights.colorCode("double_binsearch", mid-m-1, mid+m);
Highlights.markArray(1, mid-m-1);
Highlights.markArray(2, mid+m);
Delays.sleep(2.5);
if(Reads.compareValues(array[mid-m-1], array[mid+m]) == 1)
a = m+1;
else
Expand All @@ -80,6 +88,9 @@ public void multiSwapMerge(int[] array, int start, int mid, int end) {
}

public void multiSwapMergeSort(int[] array, int a, int b) {
Highlights.retainColorMarks(true);;
Highlights.defineColor("double_binsearch", new Color(128, 0, 255));
Highlights.defineColor("blockswap", Color.ORANGE);
int len = b-a, i;

for(int j = 1; j < len; j *= 2) {
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/io/github/arrayv/sorts/merge/RotateMergeSort.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.arrayv.sorts.merge;

import java.awt.Color;

import io.github.arrayv.main.ArrayVisualizer;
import io.github.arrayv.sorts.templates.Sort;

Expand Down Expand Up @@ -45,8 +47,10 @@ public RotateMergeSort(ArrayVisualizer arrayVisualizer) {
}

private void multiSwap(int[] array, int a, int b, int len) {
for(int i = 0; i < len; i++)
for(int i = 0; i < len; i++) {
Highlights.colorCode("rotate", a+i, b+i);
Writes.swap(array, a+i, b+i, 1, true, false);
}
}

private void rotate(int[] array, int a, int m, int b) {
Expand All @@ -71,7 +75,9 @@ private void rotate(int[] array, int a, int m, int b) {
private int binarySearch(int[] array, int a, int b, int value, boolean left) {
while(a < b) {
int m = a+(b-a)/2;

Highlights.colorCode(m, "binsearch");
Highlights.markArray(1, m);
Delays.sleep(2.5);
boolean comp = left ? Reads.compareValues(value, array[m]) <= 0
: Reads.compareValues(value, array[m]) < 0;

Expand Down Expand Up @@ -102,6 +108,9 @@ private void rotateMerge(int[] array, int a, int m, int b) {
}

protected void rotateMergeSort(int[] array, int a, int b) {
Highlights.retainColorMarks(true);
Highlights.defineColor("binsearch", Color.CYAN);
Highlights.defineColor("rotate", Color.ORANGE);
int len = b-a, i;

for(int j = 1; j < len; j *= 2) {
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/io/github/arrayv/sorts/select/CycleSort.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.arrayv.sorts.select;

import java.awt.Color;

import io.github.arrayv.main.ArrayVisualizer;
import io.github.arrayv.sorts.templates.Sort;

Expand Down Expand Up @@ -51,15 +53,19 @@ private int countLesser(int[] array, int a, int b, int t) {
Highlights.markArray(1, r);
Highlights.markArray(2, i);
Delays.sleep(0.01);

r += Reads.compareValues(array[i], t) < 0 ? 1 : 0;
int cmp = Reads.compareIndexValue(array, i, t, 0.05, true) < 0 ? 1 : 0;
if(cmp == 1) {
Highlights.colorCode(i, "lower_rank");
}
r += cmp;
}
Highlights.clearMark(2);
return r;
}

@Override
public void runSort(int[] array, int length, int bucketCount) {
Highlights.defineColor("lower_rank", Color.GREEN);
for(int i = 0; i < length-1; i++) {
Highlights.markArray(3, i);

Expand All @@ -72,11 +78,14 @@ public void runSort(int[] array, int length, int bucketCount) {

int t1 = array[r];
Writes.write(array, r, t, 0.02, false, false);

Highlights.clearAllColors();
t = t1;

r = this.countLesser(array, i, length, t);
}
while(r != i);
Highlights.clearAllColors();

Writes.write(array, i, t, 0.02, false, false);
}
Expand Down
Loading