Skip to content

Commit 9f829a9

Browse files
committed
docs: add triangle example & add renderer into
1 parent 0efd3df commit 9f829a9

22 files changed

+193
-117
lines changed

Diff for: README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,13 @@ component.html
105105
</canvas>
106106
```
107107
108-
Graph example:
108+
How to work renderer:
109109
110-
<img src ="https://github.com/irustm/angular-canvas/blob/master/assets/graph-example2.png?raw=true">
110+
<img src ="https://github.com/irustm/angular-canvas/blob/master/assets/renderer.png?raw=true">
111+
112+
Demo example:
113+
114+
<img src ="https://github.com/irustm/angular-canvas/blob/master/assets/graph-example3.png?raw=true">
111115
112116
Game example:
113117

Diff for: assets/graph-example3.png

303 KB
Loading

Diff for: assets/renderer.png

66.3 KB
Loading

Diff for: src/app/demos/graph-canvas/graph-canvas.component.ts renamed to src/app/demos/components/graph-canvas/graph-canvas.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { CanvasComponent } from 'angular-canvas';
33

44
@CanvasComponent
55
@Component({
6-
selector: 'app-graph-canvas-example',
6+
selector: 'app-graph-canvas',
77
templateUrl: './graph-canvas.component.html',
88
styleUrls: ['./graph-canvas.component.scss'],
99
})
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<div class="canvas-container">
2+
<canvas>
3+
<triangle
4+
[x]="mouseX"
5+
[y]="mouseY"
6+
(hovered)="hover(true)"
7+
(unhovered)="hover(false)"
8+
></triangle>
9+
</canvas>
10+
</div>
11+
12+
<div *ngIf="isHovered" class="hovered-text">Hover: true</div>
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.canvas-container {
2+
width: 250px;
3+
height: 190px;
4+
margin: 0 auto;
5+
position: relative;
6+
}
7+
8+
canvas {
9+
width: 100%;
10+
left: 0;
11+
}
12+
.hovered-text {
13+
text-align: center;
14+
}
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Component, HostListener } from '@angular/core';
2+
import { CanvasComponent } from 'angular-canvas';
3+
4+
@CanvasComponent
5+
@Component({
6+
selector: 'app-triangle',
7+
templateUrl: './triangle.component.html',
8+
styleUrls: ['./triangle.component.scss'],
9+
})
10+
export class TriangleComponent {
11+
public mouseX = 0;
12+
public mouseY = 0;
13+
14+
public isHovered = false;
15+
16+
@HostListener('mousemove', ['$event'])
17+
private onMouseMove(event: MouseEvent) {
18+
this.mouseX = event.offsetX;
19+
this.mouseY = event.offsetY;
20+
}
21+
22+
public hover(value: boolean) {
23+
this.isHovered = value;
24+
}
25+
}

Diff for: src/app/demos/container/container.component.html

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h4 class="title">Graph example</h4>
2+
<div class="description">Press Scroll < | > or zoom (Ctrl) graph</div>
3+
<app-graph-canvas></app-graph-canvas>
4+
5+
<h4 class="title">Hover Output example</h4>
6+
<div class="description">Hover to triangle</div>
7+
<app-triangle></app-triangle>

Diff for: src/app/demos/graph-container/graph-container.component.scss renamed to src/app/demos/container/container.component.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ h4.title {
1212
text-align: center;
1313
}
1414

15-
app-graph-canvas-example {
15+
app-graph-canvas, app-triangle {
1616
position: relative;
1717
display: block;
1818
width: 100%;

Diff for: src/app/demos/container/container.component.ts

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { Component } from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-demo-container',
5+
templateUrl: './container.component.html',
6+
styleUrls: ['./container.component.scss'],
7+
})
8+
export class ContainerComponent {}

Diff for: src/app/demos/demos.module.ts

+21-6
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,36 @@ import { CommonModule } from '@angular/common';
33
import { CanvasDomModule } from 'angular-canvas';
44
import { RouterModule } from '@angular/router';
55

6-
import { GraphCanvasComponent } from './graph-canvas/graph-canvas.component';
7-
import { GraphContainerComponent } from './graph-container/graph-container.component';
6+
import { GraphCanvasComponent } from './components/graph-canvas/graph-canvas.component';
87

9-
import { NgText, NgRect, NgLine, NgGraph, NgGrid } from './elements';
8+
import {
9+
NgText,
10+
NgRect,
11+
NgLine,
12+
NgGraph,
13+
NgGrid,
14+
TriangleElement,
15+
} from './elements';
16+
import { TriangleComponent } from './components/triangle/triangle.component';
17+
import { ContainerComponent } from './container/container.component';
1018

1119
// @ts-ignore
1220
@NgModule({
13-
declarations: [GraphCanvasComponent, GraphContainerComponent],
21+
declarations: [GraphCanvasComponent, ContainerComponent, TriangleComponent],
1422
imports: [
1523
CommonModule,
16-
CanvasDomModule.forRoot([NgText, NgRect, NgLine, NgGraph, NgGrid]),
24+
CanvasDomModule.forRoot([
25+
NgText,
26+
NgRect,
27+
NgLine,
28+
NgGraph,
29+
NgGrid,
30+
TriangleElement,
31+
]),
1732
RouterModule.forChild([
1833
{
1934
path: '',
20-
component: GraphContainerComponent,
35+
component: ContainerComponent,
2136
},
2237
]),
2338
],
File renamed without changes.

Diff for: src/app/demos/elements/grid.ts renamed to src/app/demos/elements/grid.element.ts

-17
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { RendererStyleFlags2 } from '@angular/core';
21
import { NgCanvas, NgCanvasElement, CanvasElement } from 'angular-canvas';
32

43
const STEP = 20;
@@ -20,20 +19,10 @@ export class NgGrid implements NgCanvasElement {
2019
// Attributes
2120
public strokeStyle = 'gray';
2221

23-
appendChild(newChild: any): void {}
24-
25-
insertBefore(newChild: any, refChild: any): void {}
26-
27-
removeAttribute(name: string, namespace?: string | null): void {}
28-
2922
removeChild(oldChild: any): void {
3023
this.parent.removeChild(oldChild);
3124
}
3225

33-
removeClass(name: string): void {}
34-
35-
removeStyle(style: string, flags?: RendererStyleFlags2): void {}
36-
3726
setNgAttribute(name: string, value: string, namespace?: string | null): void {
3827
this[name] = value;
3928
this.parent && this.parent.drawAll();
@@ -44,10 +33,6 @@ export class NgGrid implements NgCanvasElement {
4433
this.parent.drawAll();
4534
}
4635

47-
setStyle(style: string, value: any, flags?: RendererStyleFlags2): void {}
48-
49-
setValue(): void {}
50-
5136
draw(context: CanvasRenderingContext2D): void {
5237
const viewWidth = this.parent.element.width;
5338
const viewHeight = this.parent.element.height;
@@ -80,6 +65,4 @@ export class NgGrid implements NgCanvasElement {
8065
context.strokeStyle = this.strokeStyle;
8166
context.stroke();
8267
}
83-
84-
addClass(name): void {}
8568
}

Diff for: src/app/demos/elements/index.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
export {NgText} from './text';
2-
export {NgRect} from './rect';
3-
export {NgLine} from './line';
4-
export {NgGraph} from './graph';
5-
export {NgGrid} from './grid';
1+
export { NgText } from './text.element';
2+
export { NgRect } from './rect.element';
3+
export { NgLine } from './line.element';
4+
export { NgGraph } from './graph.element';
5+
export { NgGrid } from './grid.element';
6+
export { TriangleElement } from './triangle.element';

Diff for: src/app/demos/elements/line.ts renamed to src/app/demos/elements/line.element.ts

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
import {RendererStyleFlags2} from '@angular/core';
2-
import {NgCanvas, NgCanvasElement, CanvasElement} from 'angular-canvas';
1+
import { NgCanvas, NgCanvasElement, CanvasElement } from 'angular-canvas';
32

43
@CanvasElement({
5-
selector: 'line'
4+
selector: 'line',
65
})
76
export class NgLine implements NgCanvasElement {
87
public parent: NgCanvas;
@@ -16,28 +15,10 @@ export class NgLine implements NgCanvasElement {
1615
// Attributes
1716
public strokeStyle = 'black';
1817

19-
appendChild(newChild: any): void {
20-
}
21-
22-
addClass(name): void {
23-
}
24-
25-
insertBefore(newChild: any, refChild: any): void {
26-
}
27-
28-
removeAttribute(name: string, namespace?: string | null): void {
29-
}
30-
3118
removeChild(oldChild: any): void {
3219
this.parent.removeChild(oldChild);
3320
}
3421

35-
removeClass(name: string): void {
36-
}
37-
38-
removeStyle(style: string, flags?: RendererStyleFlags2): void {
39-
}
40-
4122
setNgAttribute(name: string, value: string, namespace?: string | null): void {
4223
this[name] = value;
4324
this.parent && this.parent.drawAll();
@@ -48,12 +29,6 @@ export class NgLine implements NgCanvasElement {
4829
this.parent.drawAll();
4930
}
5031

51-
setStyle(style: string, value: any, flags?: RendererStyleFlags2): void {
52-
}
53-
54-
setValue(): void {
55-
}
56-
5732
draw(context: CanvasRenderingContext2D): void {
5833
context.strokeStyle = this.strokeStyle;
5934
context.beginPath();

Diff for: src/app/demos/elements/rect.ts renamed to src/app/demos/elements/rect.element.ts

-15
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,10 @@ export class NgRect implements NgCanvasElement {
1313
public h: number;
1414
public fillStyle = 'black';
1515

16-
appendChild(newChild: any): void {}
17-
addClass(name): void {}
18-
19-
insertBefore(newChild: any, refChild: any): void {}
20-
21-
removeAttribute(name: string, namespace?: string | null): void {}
22-
2316
removeChild(oldChild: any): void {
2417
this.parent.removeChild(oldChild);
2518
}
2619

27-
removeClass(name: string): void {}
28-
29-
removeStyle(style: string, flags?: RendererStyleFlags2): void {}
30-
3120
setNgAttribute(name: string, value: string, namespace?: string | null): void {
3221
this[name] = value;
3322
this.parent && this.parent.drawAll();
@@ -38,10 +27,6 @@ export class NgRect implements NgCanvasElement {
3827
this.parent.drawAll();
3928
}
4029

41-
setStyle(style: string, value: any, flags?: RendererStyleFlags2): void {}
42-
43-
setValue(): void {}
44-
4530
draw(context: CanvasRenderingContext2D): void {
4631
context.fillRect(this.x, this.y, this.w, this.h);
4732
}

Diff for: src/app/demos/elements/text.ts renamed to src/app/demos/elements/text.element.ts

+2-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
import {NgCanvasElement} from '../../../../projects/angular-canvas-lib/src/lib/components/ng-canvas-element';
2-
import {RendererStyleFlags2} from '@angular/core';
3-
import {NgCanvas, CanvasElement} from 'angular-canvas';
1+
import { NgCanvas, CanvasElement, NgCanvasElement } from 'angular-canvas';
42

53
@CanvasElement({
6-
selector: 'text'
4+
selector: 'text',
75
})
86
export class NgText implements NgCanvasElement {
97
public parent: NgCanvas;
@@ -14,26 +12,10 @@ export class NgText implements NgCanvasElement {
1412

1513
constructor() {}
1614

17-
appendChild(newChild: any): void {
18-
}
19-
addClass(name): void {
20-
}
21-
insertBefore(newChild: any, refChild: any): void {
22-
}
23-
24-
removeAttribute(name: string, namespace?: string | null): void {
25-
}
26-
2715
removeChild(oldChild: any): void {
2816
this.parent.removeChild(oldChild);
2917
}
3018

31-
removeClass(name: string): void {
32-
}
33-
34-
removeStyle(style: string, flags?: RendererStyleFlags2): void {
35-
}
36-
3719
setNgAttribute(name: string, value: string, namespace?: string | null): void {
3820
this[name] = value;
3921
}
@@ -42,12 +24,6 @@ export class NgText implements NgCanvasElement {
4224
this[name] = value;
4325
}
4426

45-
setStyle(style: string, value: any, flags?: RendererStyleFlags2): void {
46-
}
47-
48-
setValue(value: any): void {
49-
}
50-
5127
draw(context: CanvasRenderingContext2D): void {
5228
if (this.text && this.x && this.y) {
5329
context.fillStyle = this.fillStyle;

0 commit comments

Comments
 (0)