Skip to content

Commit

Permalink
feat: Added TS definitions from Highcharts into the wrapper for types…
Browse files Browse the repository at this point in the history
… reference.
  • Loading branch information
KacperMadej committed Dec 22, 2018
1 parent acc13b2 commit 56d93fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
16 changes: 8 additions & 8 deletions highcharts-angular/src/lib/highcharts-chart.component.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
import { Component, ElementRef, EventEmitter, Input, OnDestroy, Output, NgZone } from '@angular/core';
import * as Highcharts from 'highcharts';

@Component({
selector: 'highcharts-chart',
template: ''
})
export class HighchartsChartComponent implements OnDestroy {
@Input() Highcharts: any;
@Input() Highcharts: typeof Highcharts;
@Input() constructorType: string;
@Input() callbackFunction: any;
@Input() callbackFunction: Highcharts.ChartCallbackFunction;
@Input() oneToOne: boolean; // #20
@Input() runOutsideAngular: boolean; // #75

@Input() set options(val: any) {
@Input() set options(val: Highcharts.Options) {
this.optionsValue = val;
this.wrappedUpdateOrCreateChart();
}
Expand All @@ -23,10 +24,10 @@ export class HighchartsChartComponent implements OnDestroy {
}

@Output() updateChange = new EventEmitter<boolean>(true);
@Output() chartInstance = new EventEmitter<any>(); // #26
@Output() chartInstance = new EventEmitter<Highcharts.Chart>(); // #26

private chart: any;
private optionsValue: any;
private chart: Highcharts.Chart;
private optionsValue: Highcharts.Options;

constructor(
private el: ElementRef,
Expand All @@ -47,12 +48,11 @@ export class HighchartsChartComponent implements OnDestroy {
if (this.chart && this.chart.update) {
this.chart.update(this.optionsValue, true, this.oneToOne || false);
} else {
this.chart = this.Highcharts[this.constructorType || 'chart'](
this.chart = (this.Highcharts as any)[this.constructorType || 'chart'](
this.el.nativeElement,
this.optionsValue,
this.callbackFunction || null
);
this.optionsValue.series = this.chart.userOptions.series;

// emit chart instance on init
this.chartInstance.emit(this.chart);
Expand Down
7 changes: 3 additions & 4 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ declare var require: any;

import { Component } from '@angular/core';

import * as Highcharts from 'highcharts/highcharts';
import * as Highcharts from 'highcharts';

import StockModule from 'highcharts/modules/stock';
import MapModule from 'highcharts/modules/map';
Expand Down Expand Up @@ -41,7 +41,6 @@ export class AppComponent {
{
"title": { "text": "Highcharts chart" },
"series": [{
"type": "line",
"data": [11,2,3]
}, {
"data": [5,6,7]
Expand All @@ -68,9 +67,9 @@ export class AppComponent {
spline: 'line'
};

toggleSeriesType(index = 0) {
toggleSeriesType(index: number = 0) {
this.optFromInput.series[index].type =
this.seriesTypes[this.optFromInput.series[index].type] as
this.seriesTypes[this.optFromInput.series[index].type || 'line'] as
"column" | "scatter" | "spline" | "line";
// nested change - must trigger update
this.updateFromInput = true;
Expand Down

0 comments on commit 56d93fa

Please sign in to comment.