-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WIP: rotaation widget
- Loading branch information
Showing
37 changed files
with
1,217 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
import { ChangeDetectorRef, Directive, ElementRef, EventEmitter, HostBinding, HostListener, Input, Output, inject } from "@angular/core"; | ||
import { fromEvent, merge, Observable, of } from "rxjs"; | ||
import { debounceTime, distinctUntilChanged, map, scan, switchMap, takeUntil } from "rxjs/operators"; | ||
import { MatSnackBar, MatSnackBarRef, SimpleSnackBar } from "src/sharedModule" | ||
import { DestroyDirective } from "src/util/destroy.directive"; | ||
|
||
@Directive({ | ||
selector: '[drag-drop-file]', | ||
exportAs: 'dragDropFile', | ||
hostDirectives: [ | ||
DestroyDirective | ||
] | ||
}) | ||
|
||
export class DragDropFileDirective { | ||
|
||
destroyed$ = inject(DestroyDirective).destroyed$ | ||
|
||
@Input() | ||
public snackText: string|undefined | ||
|
||
@Output('drag-drop-file') | ||
public dragDropOnDrop: EventEmitter<File[]> = new EventEmitter() | ||
|
||
@HostBinding('style.transition') | ||
public transition = `opacity 300ms ease-in` | ||
|
||
@HostBinding('style.opacity') | ||
public hostOpacity: number = 0.5 | ||
|
||
get opacity() { | ||
return this.hostOpacity | ||
} | ||
|
||
@Input('drag-drop-file-opacity') | ||
set opacity(val: number) { | ||
this.hostOpacity = val | ||
this.cdr.markForCheck() | ||
} | ||
|
||
public snackbarRef: MatSnackBarRef<SimpleSnackBar>|undefined | ||
|
||
private dragover$: Observable<boolean> | ||
|
||
@HostListener('dragover', ['$event']) | ||
public ondragover(ev: DragEvent) { | ||
ev.preventDefault() | ||
} | ||
|
||
@HostListener('drop', ['$event']) | ||
public ondrop(ev: DragEvent) { | ||
ev.preventDefault() | ||
this.reset() | ||
|
||
this.dragDropOnDrop.emit(Array.from(ev?.dataTransfer?.files || [])) | ||
} | ||
|
||
public reset() { | ||
if (this.snackbarRef) { | ||
this.snackbarRef.dismiss() | ||
} | ||
this.snackbarRef = undefined | ||
this.opacity = 0.5 | ||
} | ||
|
||
constructor(private snackBar: MatSnackBar, private el: ElementRef, private cdr: ChangeDetectorRef) { | ||
this.dragover$ = merge( | ||
of(null), | ||
fromEvent(this.el.nativeElement, 'drop'), | ||
).pipe( | ||
switchMap(() => merge( | ||
fromEvent(this.el.nativeElement, 'dragenter').pipe( | ||
map(() => 1), | ||
), | ||
fromEvent(this.el.nativeElement, 'dragleave').pipe( | ||
map(() => -1), | ||
), | ||
).pipe( | ||
scan((acc, curr) => acc + curr, 0), | ||
map(val => val > 0), | ||
)), | ||
) | ||
|
||
this.dragover$.pipe( | ||
takeUntil(this.destroyed$), | ||
debounceTime(16), | ||
distinctUntilChanged(), | ||
).subscribe(flag => { | ||
if (flag) { | ||
this.snackbarRef = this.snackBar.open( | ||
this.snackText || `Drop file(s) here.`, 'Dismiss', | ||
{ | ||
panelClass: 'sxplr-pe-none' | ||
} | ||
) | ||
|
||
/** | ||
* In buggy scenarios, user could at least dismiss by action | ||
*/ | ||
this.snackbarRef.afterDismissed().subscribe(reason => { | ||
if (reason.dismissedByAction) { | ||
this.reset() | ||
} | ||
}) | ||
this.opacity = 0.2 | ||
} else { | ||
this.reset() | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
export type SvgPath = { | ||
path: { | ||
type: 'M' | 'C' | 'z' | ||
coords: number[][] | ||
}[] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { CommonModule } from "@angular/common"; | ||
import { NO_ERRORS_SCHEMA, NgModule } from "@angular/core"; | ||
import { GetClosestFurtherestPipe } from "./pathGetClosestFarthest.pipe"; | ||
import { SvgPathToDPipe } from "./pathToD.pipe"; | ||
import { RotationWidgetCmp } from "./rotation-widget.components"; | ||
|
||
@NgModule({ | ||
imports: [ | ||
CommonModule, | ||
], | ||
declarations: [ | ||
RotationWidgetCmp, | ||
SvgPathToDPipe, | ||
GetClosestFurtherestPipe, | ||
], | ||
exports: [ | ||
RotationWidgetCmp | ||
], | ||
schemas: [ | ||
NO_ERRORS_SCHEMA, | ||
] | ||
}) | ||
|
||
export class RotationWidgetModule {} |
26 changes: 26 additions & 0 deletions
26
frontend/src/layer-tune/rotation-widget/pathGetClosestFarthest.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { Pipe, PipeTransform } from "@angular/core"; | ||
import { SvgPath } from "./consts"; | ||
|
||
@Pipe({ | ||
name: 'getClosestFurtherest', | ||
pure: true | ||
}) | ||
|
||
export class GetClosestFurtherestPipe implements PipeTransform{ | ||
transform(value: SvgPath) { | ||
const arr = value.path.map(p => p.coords).flatMap(v => v).filter(v => !!v) | ||
const sorted = arr.map((coord, idx) => { | ||
return { | ||
z: coord[2], | ||
idx, | ||
} | ||
}) | ||
sorted.sort((a, b) => a.z - b.z) | ||
const sortedIdx = sorted[0].idx | ||
|
||
return { | ||
closest: arr[sortedIdx], | ||
furthest: arr[(sortedIdx + 7) % arr.length] | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Pipe, PipeTransform } from "@angular/core"; | ||
import { SvgPath } from "./consts"; | ||
|
||
@Pipe({ | ||
name: 'pathToD', | ||
pure: true | ||
}) | ||
|
||
export class SvgPathToDPipe implements PipeTransform{ | ||
transform(value: SvgPath): string[] { | ||
return value.path.map(obj => { | ||
const coordStr = obj.coords.map(coord => coord.slice(0, 2)).join(" ") | ||
return `${obj.type}${coordStr}` | ||
}) | ||
} | ||
} |
Oops, something went wrong.