Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update libary to work with angular 2.2 #51

Merged
merged 14 commits into from
Jun 6, 2017
Merged
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
node_modules
examples
coverage
build/test
app
typings
npm-debug*.log
build/test
2 changes: 2 additions & 0 deletions build/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export { NvD3Component } from './ng2-nvd3.component';
export { NvD3Module } from './ng2-nvd3.module';
6 changes: 6 additions & 0 deletions build/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
var ng2_nvd3_component_1 = require("./ng2-nvd3.component");
exports.NvD3Component = ng2_nvd3_component_1.NvD3Component;
var ng2_nvd3_module_1 = require("./ng2-nvd3.module");
exports.NvD3Module = ng2_nvd3_module_1.NvD3Module;
1 change: 1 addition & 0 deletions build/index.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"__symbolic":"module","version":3,"metadata":{},"exports":[{"from":"./ng2-nvd3.component","export":["NvD3Component"]},{"from":"./ng2-nvd3.module","export":["NvD3Module"]}]},{"__symbolic":"module","version":1,"metadata":{},"exports":[{"from":"./ng2-nvd3.component","export":["NvD3Component"]},{"from":"./ng2-nvd3.module","export":["NvD3Module"]}]}]
15 changes: 0 additions & 15 deletions build/lib/ng2-nvd3.d.ts

This file was deleted.

20 changes: 20 additions & 0 deletions build/ng2-nvd3.component.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/// <reference path="../typings/globals/d3/index.d.ts" />
/// <reference path="../typings/globals/nvd3/index.d.ts" />
import { OnChanges, ElementRef, SimpleChanges } from '@angular/core';
export declare class NvD3Component implements OnChanges {
options: any;
data: any;
el: HTMLElement;
chart: any;
chartType: string;
svg: any;
constructor(elementRef: ElementRef);
ngOnChanges(changes: SimpleChanges): void;
initChart(options: any): void;
updateWithOptions(options: any): void;
updateWithData(data: any): void;
updateSize(): void;
configure(chart: any, options: any, chartType: any): void;
configureEvents(dispatch: any, options: any): void;
clearElement(): void;
}
136 changes: 86 additions & 50 deletions build/lib/ng2-nvd3.js → build/ng2-nvd3.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,45 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var core_1 = require('@angular/core');
var nvD3 = (function () {
function nvD3(elementRef) {
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var NvD3Component = (function () {
function NvD3Component(elementRef) {
this.el = elementRef.nativeElement;
}
nvD3.prototype.ngOnChanges = function () {
this.updateWithOptions(this.options);
NvD3Component.prototype.ngOnChanges = function (changes) {
if (this.options) {
if (!this.chart || this.chartType !== this.options.chart.type) {
this.initChart(this.options);
}
else {
this.updateWithOptions(this.options);
}
}
};
nvD3.prototype.updateWithOptions = function (options) {
var self = this;
NvD3Component.prototype.initChart = function (options) {
var _this = this;
this.clearElement();
if (!options)
return;
this.chart = nv.models[options.chart.type]();
this.chartType = this.options.chart.type;
this.chart.id = Math.random().toString(36).substr(2, 15);
this.updateWithOptions(options);
nv.addGraph(function () {
if (!_this.chart)
return;
if (_this.chart.resizeHandler)
_this.chart.resizeHandler.clear();
_this.chart.resizeHandler = nv.utils.windowResize(function () {
_this.chart && _this.chart.update && _this.chart.update();
});
return _this.chart;
}, options.chart['callback']);
};
NvD3Component.prototype.updateWithOptions = function (options) {
if (!options)
return;
for (var key in this.chart) {
if (!this.chart.hasOwnProperty(key))
continue;
Expand Down Expand Up @@ -82,30 +103,37 @@ var nvD3 = (function () {
(key === 'stacked' && options.chart.type === 'stackedAreaChart')) {
this.configure(this.chart[key], options.chart[key], options.chart.type);
}
else if ((key === 'xTickFormat' || key === 'yTickFormat') && options.chart.type === 'lineWithFocusChart') { }
else if ((key === 'tooltips') && options.chart.type === 'boxPlotChart') { }
else if ((key === 'tooltipXContent' || key === 'tooltipYContent') && options.chart.type === 'scatterChart') { }
else if (options.chart[key] === undefined || options.chart[key] === null) { }
else if ((key === 'xTickFormat' || key === 'yTickFormat') && options.chart.type === 'lineWithFocusChart') {
}
else if ((key === 'tooltips') && options.chart.type === 'boxPlotChart') {
}
else if ((key === 'tooltipXContent' || key === 'tooltipYContent') && options.chart.type === 'scatterChart') {
}
else if (options.chart[key] === undefined || options.chart[key] === null) {
}
else
this.chart[key](options.chart[key]);
}
this.updateWithData(this.data);
nv.addGraph(function () {
if (!self.chart)
return;
if (self.chart.resizeHandler)
self.chart.resizeHandler.clear();
self.chart.resizeHandler = nv.utils.windowResize(function () {
self.chart && self.chart.update && self.chart.update();
});
return self.chart;
}, options.chart['callback']);
};
nvD3.prototype.updateWithData = function (data) {
NvD3Component.prototype.updateWithData = function (data) {
if (data) {
d3.select(this.el).select('svg').remove();
var h, w;
this.svg = d3.select(this.el).append('svg');
{
var svgElement = this.el.querySelector('svg');
if (!svgElement) {
this.svg = d3.select(this.el).append('svg');
}
else {
this.svg = d3.select(svgElement);
}
}
this.updateSize();
this.svg.datum(data).call(this.chart);
}
};
NvD3Component.prototype.updateSize = function () {
if (this.svg) {
var h = void 0, w = void 0;
if (h = this.options.chart.height) {
if (!isNaN(+h))
h += 'px';
Expand All @@ -119,16 +147,16 @@ var nvD3 = (function () {
else {
this.svg.attr('width', '100%').style({ width: '100%' });
}
this.svg.datum(data).call(this.chart);
}
};
nvD3.prototype.configure = function (chart, options, chartType) {
NvD3Component.prototype.configure = function (chart, options, chartType) {
if (chart && options) {
for (var key in chart) {
if (!chart.hasOwnProperty(key))
continue;
var value = chart[key];
if (key[0] === '_') { }
if (key[0] === '_') {
}
else if (key === 'dispatch')
this.configureEvents(value, options[key]);
else if (key === 'tooltip')
Expand All @@ -150,34 +178,36 @@ var nvD3 = (function () {
'open',
'close'
].indexOf(key) === -1) {
if (options[key] === undefined || options[key] === null) { }
if (options[key] === undefined || options[key] === null) {
}
else
chart[key](options[key]);
}
}
}
};
nvD3.prototype.configureEvents = function (dispatch, options) {
NvD3Component.prototype.configureEvents = function (dispatch, options) {
if (dispatch && options) {
for (var key in dispatch) {
if (!dispatch.hasOwnProperty(key))
continue;
var value = dispatch[key];
if (options[key] === undefined || options[key] === null) { }
if (options[key] === undefined || options[key] === null) {
}
else
dispatch.on(key + '._', options[key]);
}
}
};
nvD3.prototype.clearElement = function () {
NvD3Component.prototype.clearElement = function () {
this.el.innerHTML = '';
if (this.chart && this.chart.tooltip && this.chart.tooltip.id) {
d3.select('#' + this.chart.tooltip.id()).remove();
}
if (nv.graphs && this.chart) {
for (var i = nv.graphs.length - 1; i >= 0; i--) {
if (nv.graphs[i] && (nv.graphs[i].id === this.chart.id)) {
nv.graphs.splice(i, 1);
if (nv['graphs'] && this.chart) {
for (var i = nv['graphs'].length - 1; i >= 0; i--) {
if (nv['graphs'][i] && (nv['graphs'][i].id === this.chart.id)) {
nv['graphs'].splice(i, 1);
}
}
}
Expand All @@ -188,15 +218,21 @@ var nvD3 = (function () {
this.chart.resizeHandler.clear();
this.chart = null;
};
nvD3 = __decorate([
core_1.Component({
selector: 'nvd3',
inputs: ['options', 'data'],
template: ""
}),
__param(0, core_1.Inject(core_1.ElementRef)),
__metadata('design:paramtypes', [core_1.ElementRef])
], nvD3);
return nvD3;
return NvD3Component;
}());
exports.nvD3 = nvD3;
__decorate([
core_1.Input(),
__metadata("design:type", Object)
], NvD3Component.prototype, "options", void 0);
__decorate([
core_1.Input(),
__metadata("design:type", Object)
], NvD3Component.prototype, "data", void 0);
NvD3Component = __decorate([
core_1.Component({
selector: 'nvd3',
template: ""
}),
__metadata("design:paramtypes", [core_1.ElementRef])
], NvD3Component);
exports.NvD3Component = NvD3Component;
1 change: 1 addition & 0 deletions build/ng2-nvd3.component.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"__symbolic":"module","version":3,"metadata":{"NvD3Component":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"nvd3","template":""}]}],"members":{"options":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"data":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"}]}],"ngOnChanges":[{"__symbolic":"method"}],"initChart":[{"__symbolic":"method"}],"updateWithOptions":[{"__symbolic":"method"}],"updateWithData":[{"__symbolic":"method"}],"updateSize":[{"__symbolic":"method"}],"configure":[{"__symbolic":"method"}],"configureEvents":[{"__symbolic":"method"}],"clearElement":[{"__symbolic":"method"}]}}}},{"__symbolic":"module","version":1,"metadata":{"NvD3Component":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Component"},"arguments":[{"selector":"nvd3","template":""}]}],"members":{"options":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"data":[{"__symbolic":"property","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"Input"}}]}],"__ctor__":[{"__symbolic":"constructor","parameters":[{"__symbolic":"reference","module":"@angular/core","name":"ElementRef"}]}],"ngOnChanges":[{"__symbolic":"method"}],"initChart":[{"__symbolic":"method"}],"updateWithOptions":[{"__symbolic":"method"}],"updateWithData":[{"__symbolic":"method"}],"updateSize":[{"__symbolic":"method"}],"configure":[{"__symbolic":"method"}],"configureEvents":[{"__symbolic":"method"}],"clearElement":[{"__symbolic":"method"}]}}}}]
2 changes: 2 additions & 0 deletions build/ng2-nvd3.module.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export declare class NvD3Module {
}
22 changes: 22 additions & 0 deletions build/ng2-nvd3.module.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
"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;
};
Object.defineProperty(exports, "__esModule", { value: true });
var core_1 = require("@angular/core");
var ng2_nvd3_component_1 = require("./ng2-nvd3.component");
var NvD3Module = (function () {
function NvD3Module() {
}
return NvD3Module;
}());
NvD3Module = __decorate([
core_1.NgModule({
declarations: [ng2_nvd3_component_1.NvD3Component],
exports: [ng2_nvd3_component_1.NvD3Component]
})
], NvD3Module);
exports.NvD3Module = NvD3Module;
1 change: 1 addition & 0 deletions build/ng2-nvd3.module.metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"__symbolic":"module","version":3,"metadata":{"NvD3Module":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[{"__symbolic":"reference","module":"./ng2-nvd3.component","name":"NvD3Component"}],"exports":[{"__symbolic":"reference","module":"./ng2-nvd3.component","name":"NvD3Component"}]}]}]}}},{"__symbolic":"module","version":1,"metadata":{"NvD3Module":{"__symbolic":"class","decorators":[{"__symbolic":"call","expression":{"__symbolic":"reference","module":"@angular/core","name":"NgModule"},"arguments":[{"declarations":[{"__symbolic":"reference","module":"./ng2-nvd3.component","name":"NvD3Component"}],"exports":[{"__symbolic":"reference","module":"./ng2-nvd3.component","name":"NvD3Component"}]}]}]}}}]
1 change: 1 addition & 0 deletions compiled/lib/index.ngsummary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"summaries":[{"symbol":{"__symbol":0},"metadata":{"__symbol":1}},{"symbol":{"__symbol":2},"metadata":{"__symbol":3}}],"symbols":[{"__symbol":0,"name":"NvD3Component","filePath":"C:/Home/Projects/ng2-nvd3/lib/index.d.ts"},{"__symbol":1,"name":"NvD3Component","filePath":"C:/Home/Projects/ng2-nvd3/lib/ng2-nvd3.component.d.ts"},{"__symbol":2,"name":"NvD3Module","filePath":"C:/Home/Projects/ng2-nvd3/lib/index.d.ts"},{"__symbol":3,"name":"NvD3Module","filePath":"C:/Home/Projects/ng2-nvd3/lib/ng2-nvd3.module.d.ts"}]}
Loading