2
0

triggering drag event

This commit is contained in:
2018-05-12 20:16:46 +02:00
parent 94516e0512
commit 19cb4f06d2

View File

@@ -2,6 +2,7 @@ import { Directive, ElementRef, Renderer, AfterViewInit, HostListener, Output, E
import * as Selection from 'd3-selection'; import * as Selection from 'd3-selection';
import * as Shape from 'd3-shape'; import * as Shape from 'd3-shape';
import * as Random from 'd3-random'; import * as Random from 'd3-random';
import * as Drag from 'd3-drag';
import { Config } from './../models/config.model'; import { Config } from './../models/config.model';
import { Point } from './../models/point.model'; import { Point } from './../models/point.model';
@@ -16,6 +17,7 @@ export class CanvasDirective implements OnInit {
private gradient: any; private gradient: any;
private svg: any; private svg: any;
private expandedPoints: Point[]; private expandedPoints: Point[];
private drag: Point;
public config: Config; public config: Config;
@Input() param: Param; @Input() param: Param;
@@ -51,7 +53,14 @@ export class CanvasDirective implements OnInit {
} }
this.svg this.svg
.attr('width', this.config.width) .attr('width', this.config.width)
.attr('height', this.config.height); .attr('height', this.config.height)
.call(Drag.drag().on('drag', () => {
this.drag = {
x: Selection.event.x,
y: Selection.event.y
};
this.updateConfig();
}));
this.defs = this.svg.append('defs'); this.defs = this.svg.append('defs');
@@ -151,6 +160,7 @@ export class CanvasDirective implements OnInit {
y: this.canvas.clientHeight, y: this.canvas.clientHeight,
color: this.param.colors.end color: this.param.colors.end
}, },
drag: this.drag
}; };
// Emit Canvas Config to parent Component // Emit Canvas Config to parent Component
this.emitConfig.next(this.config); this.emitConfig.next(this.config);