Skip to content

Commit

Permalink
feat: Watch options/series for changes
Browse files Browse the repository at this point in the history
  • Loading branch information
mikaelkaron committed Feb 28, 2019
1 parent ba3cbaa commit 7637278
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 25 additions & 9 deletions src/components/apex-chart/apex-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, Prop, State } from '@stencil/core';
import { Component, Prop, State, Watch } from '@stencil/core';
import ApexCharts from 'apexcharts';
import { ApexOptions } from 'apexcharts';
import {
Expand Down Expand Up @@ -46,29 +46,45 @@ export class chart {
*/
@Prop() type: ApexChartType;

/**
* ApexChart height
* @see https://apexcharts.com/docs/options/chart/height/
*/
@Prop() height: ApexChartHeight;

/**
* ApexChart width
* @see https://apexcharts.com/docs/options/chart/width/
*/
@Prop() width: ApexChartWidth;

/**
* ApexChart height
* @see https://apexcharts.com/docs/options/chart/height/
*/
@Prop() height: ApexChartHeight;

/**
* ApexCharts options
* @see https://apexcharts.com/docs/options/
*/
@Prop() options: ApexOptions;
@Prop({ mutable: true }) options: ApexOptions;

@Watch('options')
optionsChanged(options) {
if (this.chartObj !== null) {
return this.chartObj.updateOptions(
config(options, this.type, this.width, options, this.series)
);
}
}

/**
* ApexCharts series
* @see https://apexcharts.com/docs/options/series/
*/
@Prop() series: ApexOptionsSeries;
@Prop({ mutable: true }) series: ApexOptionsSeries;

@Watch('series')
seriesChanged(series) {
if (this.chartObj !== null) {
this.chartObj.updateSeries(series, true);
}
}

componentDidLoad() {
if (this.chartObj === null) {
Expand Down

0 comments on commit 7637278

Please sign in to comment.