Skip to content

Commit d2a3a71

Browse files
author
Oskar Widmark
committed
feat: gap size for elements
1 parent c488b1b commit d2a3a71

File tree

6 files changed

+23
-46
lines changed

6 files changed

+23
-46
lines changed

src/App.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
.drawer > div > * {
1919
border-bottom: rgb(69, 69, 69) solid 4px;
20-
padding: 8px;
20+
padding: 8px 12px;
2121

2222
}
2323

src/App.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ class App extends React.Component<Props> {
326326
if (this.state.settings.columnNbr === columnNbr) return;
327327

328328
this.sortingAlgorithms.columnNbr = columnNbr;
329-
this.canvasController.columnNbr = columnNbr;
329+
this.canvasController.context.columnNbr = columnNbr;
330330
this.setSettings({ columnNbr }, () => this.resetAndDraw());
331331
};
332332

@@ -375,10 +375,8 @@ class App extends React.Component<Props> {
375375
this.setSettings({ ...settings });
376376
this.stopSorting();
377377
entries(settings).forEach(([key, value]) => {
378-
if (key !== 'backgroundColor') {
379-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
380-
this.canvasController[key] = value as any;
381-
}
378+
// Probably problems with type intersections, but ok
379+
this.canvasController.context[key] = value as never;
382380
});
383381

384382
this.canvasController.redrawAll(this.arr);

src/ColorTab.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
} from './types';
88
import { TitledSelect } from './components/TitledSelect';
99
import { ColorField } from './components/ColorField';
10+
import { TitledSlider } from './components/TitledSlider';
1011

1112
export function ColorTab(props: {
1213
settings: ColorSettings;
@@ -90,6 +91,15 @@ export function ColorTab(props: {
9091
}
9192
options={Object.values(DisplayType)}
9293
/>
94+
<TitledSlider
95+
title="Gap size"
96+
value={props.settings.gapSize}
97+
min={0}
98+
max={10}
99+
step={1}
100+
marks
101+
onChange={(_, value) => setColorSettings({ gapSize: value as number })}
102+
/>
93103
</>
94104
);
95105
}

src/canvas-controller.ts

Lines changed: 7 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
ColorPreset,
3+
ColorSettings,
34
DisplayType,
45
DrawData,
56
SortValue,
@@ -16,16 +17,10 @@ export class CanvasController {
1617
_canvas2dCtx: CanvasRenderingContext2D | null = null;
1718

1819
constructor(
19-
private context: {
20+
public context: {
2021
canvasRef: React.RefObject<HTMLCanvasElement>;
2122
columnNbr: number;
22-
colorPreset: ColorPreset;
23-
columnColor1: string;
24-
columnColor2: string;
25-
highlightColor: string;
26-
visualizationType: VisualizationType;
27-
displayType: DisplayType;
28-
},
23+
} & ColorSettings,
2924
) {}
3025

3126
get canvasRef() {
@@ -61,34 +56,6 @@ export class CanvasController {
6156
return window.devicePixelRatio || 1;
6257
}
6358

64-
set columnNbr(value: number) {
65-
this.context.columnNbr = value;
66-
}
67-
68-
set colorPreset(value: string) {
69-
this.context.colorPreset = value as ColorPreset;
70-
}
71-
72-
set columnColor1(value: string) {
73-
this.context.columnColor1 = value;
74-
}
75-
76-
set columnColor2(value: string) {
77-
this.context.columnColor2 = value;
78-
}
79-
80-
set highlightColor(value: string) {
81-
this.context.highlightColor = value;
82-
}
83-
84-
set visualizationType(value: string) {
85-
this.context.visualizationType = value as VisualizationType;
86-
}
87-
88-
set displayType(value: string) {
89-
this.context.displayType = value as DisplayType;
90-
}
91-
9259
get height() {
9360
switch (this.context.displayType) {
9461
case DisplayType.Full:
@@ -417,10 +384,10 @@ export class CanvasController {
417384
height: number,
418385
) => {
419386
this.canvas2dCtx.fillRect(
420-
this.snap(startX),
421-
this.snap(this.height - startY - height),
422-
this.snap(width),
423-
this.snap(height),
387+
this.snap(startX + this.context.gapSize),
388+
this.snap(this.height - startY - height + this.context.gapSize),
389+
this.snap(width - this.context.gapSize),
390+
this.snap(height - this.context.gapSize),
424391
);
425392
};
426393

src/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export const INIT_SETTINGS: Settings = {
4343
highlightColor: '#ff0000',
4444
visualizationType: VisualizationType.Bars,
4545
displayType: DisplayType.Full,
46+
gapSize: 0,
4647
soundVolume: DEFAULT_SOUND_VOLUME,
4748
soundType: DEFAULT_SOUND_TYPE,
4849
frequencyRange: [200, 640],

src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export type ColorSettings = {
9898
backgroundColor: string;
9999
visualizationType: VisualizationType;
100100
displayType: DisplayType;
101+
gapSize: number;
101102
};
102103

103104
export type SoundSettings = {

0 commit comments

Comments
 (0)