Skip to content

Commit

Permalink
Updated all code
Browse files Browse the repository at this point in the history
  • Loading branch information
hendrathings committed Jan 13, 2017
1 parent 76d8cfa commit 419d363
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 66 deletions.
10 changes: 5 additions & 5 deletions dist/angular2-nvd3/angular2-nvd3.component.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ElementRef, OnChanges, AfterViewInit } from '@angular/core';
export declare class NvD3Component implements OnChanges, AfterViewInit {
import { ElementRef, OnChanges, OnInit } from '@angular/core';
export declare class NvD3Component implements OnChanges, OnInit {
private el;
private options;
private data;
options: any;
data: any;
private ngNvD3;
constructor(el: ElementRef);
ngOnChanges(): void;
ngAfterViewInit(): void;
ngOnInit(): void;
}
8 changes: 4 additions & 4 deletions dist/angular2-nvd3/angular2-nvd3.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ var angular2_nvd3_core_1 = require("./angular2-nvd3.core");
var NvD3Component = (function () {
function NvD3Component(el) {
this.el = el;
this.ngNvD3 = angular2_nvd3_core_1.Angular2NvD3.NgNvD3.getInstance(this.el, this.data, this.options);
this.ngNvD3 = angular2_nvd3_core_1.Angular2NvD3.NgNvD3.getInstance(this.el);
}
NvD3Component.prototype.ngOnChanges = function () {
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
};
NvD3Component.prototype.ngAfterViewInit = function () {
NvD3Component.prototype.ngOnInit = function () {
this.ngNvD3.isViewInitialize(true);
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
};
return NvD3Component;
}());
Expand Down
10 changes: 4 additions & 6 deletions dist/angular2-nvd3/angular2-nvd3.core.d.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
export declare namespace Angular2NvD3 {
class NgNvD3 {
private el;
private data;
private options;
private chart;
private svg;
private viewInitialize;
private static instance;
constructor(el: any, options: any, data: any);
static getInstance(el: any, options: any, data: any): NgNvD3;
constructor(el: any);
static getInstance(el: any): NgNvD3;
isViewInitialize(value: boolean): void;
updateWithOptions(): void;
private updateWithData(data);
updateWithOptions(options: any, data: any): void;
private updateWithData(data, options);
private configure(chart, options, chartType);
private configureEvents(dispatch, options);
private clearElement();
Expand Down
19 changes: 8 additions & 11 deletions dist/angular2-nvd3/angular2-nvd3.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,20 @@ var nv = require("nvd3");
var Angular2NvD3;
(function (Angular2NvD3) {
var NgNvD3 = (function () {
function NgNvD3(el, options, data) {
function NgNvD3(el) {
this.viewInitialize = false;
this.el = el;
this.data = data;
this.options = options;
}
NgNvD3.getInstance = function (el, options, data) {
NgNvD3.getInstance = function (el) {
if (!NgNvD3.instance) {
NgNvD3.instance = new NgNvD3(el, options, data);
NgNvD3.instance = new NgNvD3(el);
}
return NgNvD3.instance;
};
NgNvD3.prototype.isViewInitialize = function (value) {
this.viewInitialize = value;
};
NgNvD3.prototype.updateWithOptions = function () {
var options = this.options;
NgNvD3.prototype.updateWithOptions = function (options, data) {
if (!this.viewInitialize || !options) {
return;
}
Expand Down Expand Up @@ -100,7 +97,7 @@ var Angular2NvD3;
this.chart[key](options.chart[key]);
}
}
this.updateWithData(this.data);
this.updateWithData(data, options);
nv.addGraph(function () {
if (!self.chart) {
return;
Expand All @@ -116,18 +113,18 @@ var Angular2NvD3;
return self.chart;
}, options.chart['callback']);
};
NgNvD3.prototype.updateWithData = function (data) {
NgNvD3.prototype.updateWithData = function (data, options) {
if (data) {
d3.select(this.el.nativeElement).select('svg').remove();
var h = void 0, w = void 0;
this.svg = d3.select(this.el.nativeElement).append('svg');
if (h = this.options.chart.height) {
if (h = options.chart.height) {
if (!isNaN(+h)) {
h += 'px';
}
this.svg.attr('height', h).style({ height: h });
}
if (w = this.options.chart.width) {
if (w = options.chart.width) {
if (!isNaN(+w)) {
w += 'px';
}
Expand Down
10 changes: 5 additions & 5 deletions dist/angular2-nvd3/angular2-nvd3.directive.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ElementRef, OnChanges, AfterViewInit } from '@angular/core';
export declare class NvD3Directive implements OnChanges, AfterViewInit {
import { ElementRef, OnChanges, OnInit } from '@angular/core';
export declare class NvD3Directive implements OnChanges, OnInit {
private el;
private options;
private data;
options: any;
data: any;
private ngNvD3;
constructor(el: ElementRef);
ngOnChanges(): void;
ngAfterViewInit(): void;
ngOnInit(): void;
}
8 changes: 4 additions & 4 deletions dist/angular2-nvd3/angular2-nvd3.directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ var angular2_nvd3_core_1 = require("./angular2-nvd3.core");
var NvD3Directive = (function () {
function NvD3Directive(el) {
this.el = el;
this.ngNvD3 = angular2_nvd3_core_1.Angular2NvD3.NgNvD3.getInstance(this.el, this.data, this.options);
this.ngNvD3 = angular2_nvd3_core_1.Angular2NvD3.NgNvD3.getInstance(this.el);
}
NvD3Directive.prototype.ngOnChanges = function () {
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
};
NvD3Directive.prototype.ngAfterViewInit = function () {
NvD3Directive.prototype.ngOnInit = function () {
this.ngNvD3.isViewInitialize(true);
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
};
return NvD3Directive;
}());
Expand Down
16 changes: 8 additions & 8 deletions src/angular2-nvd3/angular2-nvd3.component.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Component, ElementRef, Input, OnChanges, AfterViewInit } from '@angular/core';
import { Component, ElementRef, Input, OnChanges, OnInit } from '@angular/core';
import { Angular2NvD3 } from './angular2-nvd3.core';

@Component({ selector: 'app-nvd3', template: '' })
export class NvD3Component implements OnChanges, AfterViewInit {
export class NvD3Component implements OnChanges, OnInit {
@Input()
private options: any;
public options: any;

@Input()
private data: any;
public data: any;

private ngNvD3: any;

constructor(private el: ElementRef) {
this.ngNvD3 = Angular2NvD3.NgNvD3.getInstance(this.el, this.data, this.options);
this.ngNvD3 = Angular2NvD3.NgNvD3.getInstance(this.el);
}

ngOnChanges() {
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
}

ngAfterViewInit() {
ngOnInit() {
this.ngNvD3.isViewInitialize(true);
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
}
}
25 changes: 10 additions & 15 deletions src/angular2-nvd3/angular2-nvd3.core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,18 @@ export namespace Angular2NvD3 {

export class NgNvD3 {
private el: any;
private data: any;
private options: any;
private chart: any;
private svg: any;
private viewInitialize: boolean = false;
private static instance: NgNvD3;

constructor(el, options, data) {
constructor(el) {
this.el = el;
this.data = data;
this.options = options;
}

static getInstance(el, options, data) {
static getInstance(el) {
if (!NgNvD3.instance) {
NgNvD3.instance = new NgNvD3(el, options, data);
NgNvD3.instance = new NgNvD3(el);
}
return NgNvD3.instance;
}
Expand All @@ -29,8 +25,7 @@ export namespace Angular2NvD3 {
this.viewInitialize = value;
}

public updateWithOptions() {
let options = this.options;
public updateWithOptions(options: any, data: any) {
// Exit if options are not yet bound
if (!this.viewInitialize || !options) { return; };

Expand Down Expand Up @@ -108,24 +103,24 @@ export namespace Angular2NvD3 {
} else { this.chart[key](options.chart[key]); }
}

this.updateWithData(this.data);
this.updateWithData(data, options);

nv.addGraph(function() {
nv.addGraph(() => {
if (!self.chart) { return; }

// Remove resize handler. Due to async execution should be placed here, not in the clearElement
if (self.chart.resizeHandler) { self.chart.resizeHandler.clear(); }

// Update the chart when window resizes
self.chart.resizeHandler = nv.utils.windowResize(function() {
self.chart.resizeHandler = nv.utils.windowResize(() => {
if (self.chart && self.chart.update) { self.chart.update(); }
});

return self.chart;
}, options.chart['callback']);
}

private updateWithData(data) {
private updateWithData(data: any, options: any) {
if (data) {
// remove whole svg element with old data
d3.select(this.el.nativeElement).select('svg').remove();
Expand All @@ -134,11 +129,11 @@ export namespace Angular2NvD3 {

// Select the current element to add <svg> element and to render the chart in
this.svg = d3.select(this.el.nativeElement).append('svg');
if (h = this.options.chart.height) {
if (h = options.chart.height) {
if (!isNaN(+h)) { h += 'px'; }
this.svg.attr('height', h).style({height: h});
}
if (w = this.options.chart.width) {
if (w = options.chart.width) {
if (!isNaN(+w)) { w += 'px'; }
this.svg.attr('width', w).style({width: w});
} else {
Expand Down
16 changes: 8 additions & 8 deletions src/angular2-nvd3/angular2-nvd3.directive.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
import { Directive, ElementRef, Input, OnChanges, AfterViewInit } from '@angular/core';
import { Directive, ElementRef, Input, OnChanges, OnInit } from '@angular/core';
import { Angular2NvD3 } from './angular2-nvd3.core';

@Directive({ selector: '[appNvD3]' })
export class NvD3Directive implements OnChanges, AfterViewInit {
export class NvD3Directive implements OnChanges, OnInit {
@Input()
private options: any;
public options: any;

@Input()
private data: any;
public data: any;

private ngNvD3: any;

constructor(private el: ElementRef) {
this.ngNvD3 = Angular2NvD3.NgNvD3.getInstance(this.el, this.data, this.options);
this.ngNvD3 = Angular2NvD3.NgNvD3.getInstance(this.el);
}

ngOnChanges() {
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
}

ngAfterViewInit() {
ngOnInit() {
this.ngNvD3.isViewInitialize(true);
this.ngNvD3.updateWithOptions();
this.ngNvD3.updateWithOptions(this.options, this.data);
}
}

0 comments on commit 419d363

Please sign in to comment.