-
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.
Merge pull request #98 from swordensen/feature/digitalClock
Feature/digital clock
- Loading branch information
Showing
35 changed files
with
450 additions
and
125 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
1 change: 1 addition & 0 deletions
1
app/src/renderer/src/app/components/analog-clock/analog-clock.component.html
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 @@ | ||
<div #clock id="clock"></div> |
6 changes: 6 additions & 0 deletions
6
app/src/renderer/src/app/components/analog-clock/analog-clock.component.scss
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 @@ | ||
:host, | ||
div { | ||
display: block; | ||
height: 100%; | ||
width: 100%; | ||
} |
25 changes: 25 additions & 0 deletions
25
app/src/renderer/src/app/components/analog-clock/analog-clock.component.spec.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,25 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { AnalogClockComponent } from './analog-clock.component'; | ||
|
||
describe('ClockComponent', () => { | ||
let component: AnalogClockComponent; | ||
let fixture: ComponentFixture<AnalogClockComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
declarations: [ AnalogClockComponent ] | ||
}) | ||
.compileComponents(); | ||
}); | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(AnalogClockComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
102 changes: 102 additions & 0 deletions
102
app/src/renderer/src/app/components/analog-clock/analog-clock.component.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,102 @@ | ||
import { | ||
AfterViewInit, | ||
Component, | ||
ElementRef, | ||
OnInit, | ||
ViewChild, | ||
} from '@angular/core'; | ||
import { SVG, Color } from '@svgdotjs/svg.js'; | ||
|
||
@Component({ | ||
selector: 'app-analog-clock', | ||
templateUrl: './analog-clock.component.html', | ||
styleUrls: ['./analog-clock.component.scss'], | ||
}) | ||
export class AnalogClockComponent implements AfterViewInit { | ||
@ViewChild('clock') clockElem: ElementRef; | ||
|
||
constructor(private elRef: ElementRef) {} | ||
|
||
ngAfterViewInit(): void { | ||
this.renderClock(); | ||
// @ts-ignore | ||
const resizeObserver = new ResizeObserver(() => { | ||
this.rerender(); | ||
}).observe(this.clockElem.nativeElement); | ||
} | ||
|
||
rerender() { | ||
this.clockElem.nativeElement.innerHTML = ''; | ||
this.renderClock(); | ||
} | ||
|
||
/************************************ | ||
This codepen is part of the svg.js | ||
advent calendar. You can find all | ||
the pens at twitter: @svg_js | ||
*************************************/ | ||
|
||
renderClock() { | ||
const width = this.clockElem.nativeElement.clientWidth; | ||
const height = this.clockElem.nativeElement.clientHeight; | ||
|
||
if (width && height) { | ||
const backGroundColor = '#03DAC6'; | ||
const hourHandColor = '#3700B3'; | ||
const minuteHandColor = '#180edc'; | ||
const secondHandColor = '#52008d'; | ||
const realHeight = height - 20; | ||
|
||
// Create SVG and set viewbox | ||
// so that we zoom into the center | ||
const canvas = SVG() | ||
.addTo('#clock') | ||
.size(width, height) | ||
.viewbox(-width / 8, -realHeight / 8, width / 4, realHeight / 4); | ||
|
||
// Big circle | ||
canvas.circle(80).center(0, 0).fill('none').stroke({ | ||
width: 1, | ||
color: backGroundColor, | ||
}); | ||
|
||
// Hours line | ||
const hour = canvas.line(0, 0, 0, -20).stroke(hourHandColor); | ||
// .animate(new SVG.Spring(400, 20)) | ||
|
||
// Minutes line | ||
const min = canvas.line(0, 0, 0, -30).stroke(minuteHandColor); | ||
// .animate(new SVG.Spring(400, 20)) | ||
|
||
// Seconds line | ||
const sec = canvas.line(0, 0, 0, -38).stroke(secondHandColor); | ||
// .animate(new SVG.Spring(400, 20)) | ||
|
||
const update = () => { | ||
// Get time | ||
const localDate = new Date(Date.now()); | ||
let h = localDate.getHours(); | ||
let m = localDate.getMinutes(); | ||
let s = localDate.getSeconds(); | ||
|
||
// Make sure we see partial hours | ||
h += m / 60; | ||
|
||
// Calculate angle | ||
const hAngle = (h / 24) * 360; | ||
const mAngle = (m / 60) * 360; | ||
const sAngle = (s / 60) * 360; | ||
|
||
// Rotate | ||
hour.transform({ rotate: hAngle, origin: [0, 0] }); | ||
min.transform({ rotate: mAngle, origin: [0, 0] }); | ||
sec.transform({ rotate: sAngle, origin: [0, 0] }); | ||
}; | ||
|
||
setInterval(update, 1000); | ||
update(); | ||
} | ||
} | ||
|
||
// renderClock(); | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/renderer/src/app/components/analog-clock/analog-clock.module.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,14 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
import { AnalogClockComponent } from './analog-clock.component'; | ||
|
||
|
||
|
||
@NgModule({ | ||
declarations: [AnalogClockComponent], | ||
imports: [ | ||
CommonModule | ||
], | ||
exports: [AnalogClockComponent] | ||
}) | ||
export class AnalogClockModule { } |
18 changes: 17 additions & 1 deletion
18
app/src/renderer/src/app/components/clock/clock.component.html
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 |
---|---|---|
@@ -1 +1,17 @@ | ||
<div #clock id="clock"></div> | ||
<div class="clock-container"> | ||
<div class="clock-toggle"> | ||
<mat-label class="mat-slide-toggle-content" >Digital</mat-label> | ||
<mat-slide-toggle [checked]="isClockAnalog$ | async" [hideIcon]="true" (toggleChange)="toggleClock()"></mat-slide-toggle> | ||
<mat-label class="mat-slide-toggle-content">Analog</mat-label> | ||
</div> | ||
<div class="clock"> | ||
<ng-container *ngIf="isClockAnalog$ | async; else digital"> | ||
<app-analog-clock></app-analog-clock> | ||
</ng-container> | ||
|
||
<ng-template #digital> | ||
<app-digital-clock></app-digital-clock> | ||
</ng-template> | ||
</div> | ||
|
||
</div> |
32 changes: 27 additions & 5 deletions
32
app/src/renderer/src/app/components/clock/clock.component.scss
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 |
---|---|---|
@@ -1,6 +1,28 @@ | ||
:host, | ||
div { | ||
display: block; | ||
height: 100%; | ||
width: 100%; | ||
.clock-toggle{ | ||
display:flex; | ||
flex-direction: row; | ||
justify-content: flex-end; | ||
padding: 16px; | ||
display:flex; | ||
gap: 8px; | ||
} | ||
|
||
.clock-container{ | ||
display:flex; | ||
flex-direction: column; | ||
flex: 1; | ||
height: 100%; | ||
} | ||
|
||
app-digital-clock, app-analog-clock{ | ||
flex: 1; | ||
display:flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100%; | ||
} | ||
|
||
.clock{ | ||
flex: 1 1 0; | ||
width: 100%; | ||
} |
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
Oops, something went wrong.