mcourteix-ngx-vis
Version:
Angular x components for using vis.js
124 lines (123 loc) • 5.07 kB
JavaScript
"use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var vis_network_service_1 = require("./vis-network.service");
/**
* Use this directive with a div container to show network data.
*
* @export
* @class VisNetworkDirective
* @implements {OnInit}
* @implements {OnDestroy}
* @implements {OnChanges}
*/
var VisNetworkDirective = /** @class */ (function () {
/**
* Creates an instance of VisNetworkDirective.
*
* @param {ElementRef} elementRef The HTML element reference.
* @param {VisNetworkService} visNetworkService The VisNetworkService.
*
* @memberOf VisNetworkDirective
*/
function VisNetworkDirective(elementRef, visNetworkService) {
this.elementRef = elementRef;
this.visNetworkService = visNetworkService;
/**
* This event will be raised when the network is initialized.
* At this point of time the network is successfully registered
* with the VisNetworkService and you can register to events.
* The event data is the name of the network as a string.
*
* @type {EventEmitter<any>}
* @memberOf VisNetworkDirective
*/
this.initialized = new core_1.EventEmitter();
this.isInitialized = false;
this.visNetworkContainer = elementRef.nativeElement;
}
/**
* Create the network when at least visNetwork and visNetworkData
* are defined.
*
* @memberOf VisNetworkDirective
*/
VisNetworkDirective.prototype.ngOnInit = function () {
if (!this.isInitialized && this.visNetwork && this.visNetworkData) {
this.createNetwork();
}
};
/**
* Update the network data or options on reference changes to
* the visNetworkData or visNetworkOptions properties.
*
* @param {{[propName: string]: SimpleChange}} changes
*
* @memberOf VisNetworkDirective
*/
VisNetworkDirective.prototype.ngOnChanges = function (changes) {
if (!this.isInitialized && this.visNetwork && this.visNetworkData) {
this.createNetwork();
}
for (var propertyName in changes) {
if (changes.hasOwnProperty(propertyName)) {
var change = changes[propertyName];
if (!change.isFirstChange()) {
if (propertyName === 'visNetworkData') {
this.visNetworkService.setData(this.visNetwork, changes[propertyName].currentValue);
}
if (propertyName === 'visNetworkOptions') {
this.visNetworkService.setOptions(this.visNetwork, changes[propertyName].currentValue);
}
}
}
}
};
/**
* Calls the destroy function for this network instance.
*
* @memberOf VisNetworkDirective
*/
VisNetworkDirective.prototype.ngOnDestroy = function () {
this.isInitialized = false;
this.visNetworkService.destroy(this.visNetwork);
};
VisNetworkDirective.prototype.createNetwork = function () {
this.visNetworkService.create(this.visNetwork, this.visNetworkContainer, this.visNetworkData, this.visNetworkOptions);
this.isInitialized = true;
this.initialized.emit(this.visNetwork);
};
__decorate([
core_1.Input('visNetwork'),
__metadata("design:type", String)
], VisNetworkDirective.prototype, "visNetwork", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", Object)
], VisNetworkDirective.prototype, "visNetworkData", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", Object)
], VisNetworkDirective.prototype, "visNetworkOptions", void 0);
__decorate([
core_1.Output(),
__metadata("design:type", core_1.EventEmitter)
], VisNetworkDirective.prototype, "initialized", void 0);
VisNetworkDirective = __decorate([
core_1.Directive({
selector: '[visNetwork]',
}),
__metadata("design:paramtypes", [core_1.ElementRef, vis_network_service_1.VisNetworkService])
], VisNetworkDirective);
return VisNetworkDirective;
}());
exports.VisNetworkDirective = VisNetworkDirective;