added starting and ending points
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
<canvas appCanvas (emitConfig)="updateCanvasConfig($event)"></canvas>
|
<div class="canvas" appCanvas (emitConfig)="updateCanvasConfig($event)"></div>
|
||||||
|
|
||||||
<ul *ngIf="canvasConfig">
|
<ul *ngIf="canvasConfig">
|
||||||
<li><pre>{{canvasConfig | json}}</pre></li>
|
<li><pre>{{canvasConfig | json}}</pre></li>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
canvas {
|
.canvas {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
top: 0;
|
top: 0;
|
||||||
left: 0;
|
left: 0;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul {
|
ul {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Point } from './../models/point.model';
|
import { Point } from './../models/point.model';
|
||||||
import { Directive, ElementRef, Renderer, AfterViewInit, HostListener, Output, EventEmitter, OnInit } from '@angular/core';
|
import { Directive, ElementRef, Renderer, AfterViewInit, HostListener, Output, EventEmitter, OnInit } from '@angular/core';
|
||||||
import { Config } from './../models/config.model';
|
import { Config } from './../models/config.model';
|
||||||
import { select } from 'd3-selection';
|
import { select, selectAll } from 'd3-selection';
|
||||||
|
|
||||||
@Directive({
|
@Directive({
|
||||||
selector: '[appCanvas]'
|
selector: '[appCanvas]'
|
||||||
@@ -14,13 +14,7 @@ export class CanvasDirective implements OnInit {
|
|||||||
@Output() emitConfig: EventEmitter<Config>;
|
@Output() emitConfig: EventEmitter<Config>;
|
||||||
@HostListener('window:resize', ['$event'])
|
@HostListener('window:resize', ['$event'])
|
||||||
private onResize(event) {
|
private onResize(event) {
|
||||||
this.updateConfig();
|
this.init();
|
||||||
|
|
||||||
if (this.svg) {
|
|
||||||
this.updateSvg();
|
|
||||||
} else {
|
|
||||||
this.initSvg();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
@@ -32,13 +26,20 @@ export class CanvasDirective implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
|
this.init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private init() {
|
||||||
this.updateConfig();
|
this.updateConfig();
|
||||||
this.initSvg();
|
this.initSvg();
|
||||||
this.render();
|
this.render();
|
||||||
}
|
}
|
||||||
|
|
||||||
private initSvg() {
|
private initSvg() {
|
||||||
this.svg = select(this.canvas).append('svg')
|
if (!this.svg) {
|
||||||
|
this.svg = select(this.canvas).append('svg');
|
||||||
|
}
|
||||||
|
this.svg
|
||||||
.attr('width', this.config.width)
|
.attr('width', this.config.width)
|
||||||
.attr('height', this.config.height);
|
.attr('height', this.config.height);
|
||||||
}
|
}
|
||||||
@@ -50,17 +51,25 @@ export class CanvasDirective implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private render() {
|
private render() {
|
||||||
this.drawLine([
|
this.resetPoints();
|
||||||
|
this.drawPoints([
|
||||||
this.config.start,
|
this.config.start,
|
||||||
this.config.end
|
this.config.end
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private drawLine(points: Point[]) {
|
private resetPoints(): void {
|
||||||
// d3.line()
|
selectAll('circle').remove();
|
||||||
// .x(function(d) { return x(d.date); })
|
}
|
||||||
// .y(function(d) { return y(d.value); })
|
|
||||||
// .curve(d3.curveCatmullRom.alpha(0.5));
|
private drawPoints(points: Point[]) {
|
||||||
|
points.forEach(point => {
|
||||||
|
this.svg.append('circle')
|
||||||
|
.attr('r', 50)
|
||||||
|
.attr('cx', point.x)
|
||||||
|
.attr('cy', point.y)
|
||||||
|
.attr('fill', '#971240');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateConfig(): void {
|
private updateConfig(): void {
|
||||||
|
|||||||
Reference in New Issue
Block a user