Skip to content

Commit

Permalink
fix(core, react, angular, vue): default width & height to 100%, and c…
Browse files Browse the repository at this point in the history
…all setOptions on option change
  • Loading branch information
theiliad committed Oct 25, 2019
1 parent 7cf4db8 commit db251b4
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 14 deletions.
8 changes: 2 additions & 6 deletions packages/angular/src/base-chart.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class BaseChart implements AfterViewInit, OnInit {
this._data = newData;

if (dataExistsAlready) {
this.chart.setData(newData);
this.chart.model.setData(newData);
}
}

Expand All @@ -47,7 +47,7 @@ export class BaseChart implements AfterViewInit, OnInit {
this._options = newOptions;

if (optionsExistAlready) {
this.chart.setOptions(newOptions);
this.chart.model.setOptions(newOptions);
}
}

Expand Down Expand Up @@ -85,15 +85,11 @@ export class BaseChart implements AfterViewInit, OnInit {
// Width prop is mandatory for the wrappers
if (this.width) {
this.options.width = this.width;
} else if (!this.options.width) {
console.error("Missing `width` Input!");
}

// Height prop is mandatory for the wrappers
if (this.height) {
this.options.height = this.height;
} else if (!this.options.height) {
console.error("Missing `height` Input!");
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export const timeScale: TimeScaleOptions = {
* Base chart options common to any chart
*/
const chart: BaseChartOptions = {
width: "100%",
height: "100%",
resizable: true,
theme: ChartTheme.DEFAULT,
tooltip: baseTooltip,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/interfaces/charts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ export interface BaseChartOptions {
/**
* Optionally specify a width for the chart
*/
width?: number;
width?: number | string;
/**
* Optionally specify a height for the chart
*/
height?: number;
height?: number | string;
/**
* Optional function to generate the fill color based on datasetLabel, label, and/or value
*/
Expand Down
7 changes: 2 additions & 5 deletions packages/react/src/base-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,18 @@ export default class BaseChart extends React.Component {
// Width prop is mandatory for the wrappers
if (props.width) {
this.options.width = props.width;
} else if (!this.options.width) {
console.error("Missing `width` prop!");
}

// Height prop is mandatory for the wrappers
if (props.height) {
this.options.height = props.height;
} else if (!this.options.height) {
console.error("Missing `height` prop!");
}

Object.assign(this, this.chart);
}

componentDidUpdate() {
this.chart.setData(this.props.data);
this.chart.model.setData(this.props.data);
this.chart.model.setOptions(this.props.options);
}
}
8 changes: 7 additions & 1 deletion packages/vue/src/ccv-base-chart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ export default {
watch: {
data: {
handler: function(newData) {
this.coreChart.setData(newData);
this.coreChart.model.setData(newData);
},
deep: true,
},
options: {
handler: function(newOptions) {
this.coreChart.model.setOptions(newOptions);
},
deep: true,
}
},
};
</script>

0 comments on commit db251b4

Please sign in to comment.