Skip to content

Commit

Permalink
Remove unnecessary divs. Pass chart styles to dashboard. #237
Browse files Browse the repository at this point in the history
  • Loading branch information
rakannimer committed Aug 21, 2018
1 parent 19b294d commit 5133765
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 31 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-google-charts",
"version": "3.0.5",
"version": "3.0.6",
"type": "react-component",
"description": "react-google-charts React component",
"main": "dist/index.cjs.js",
Expand Down
51 changes: 23 additions & 28 deletions src/ReactGoogleCharts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,30 @@ export class Chart extends React.Component<
loader
} = this.props;
return (
<div>
<ContextProvider
value={this.props as ReactGoogleChartPropsWithDefaults}
>
{this.state.loadingStatus === "ready" &&
this.state.google !== null ? (
<GoogleChart
{...this.props as ReactGoogleChartPropsWithDefaults}
google={this.state.google}
/>
) : (
loader
)}
<GoogleChartLoader
{...{ chartLanguage, chartPackages, chartVersion, mapsApiKey }}
onLoad={google => {
this.setState({
loadingStatus: "ready",
google
});
}}
onError={() => {
this.setState({
loadingStatus: "errored"
});
}}
<ContextProvider value={this.props as ReactGoogleChartPropsWithDefaults}>
{this.state.loadingStatus === "ready" && this.state.google !== null ? (
<GoogleChart
{...this.props as ReactGoogleChartPropsWithDefaults}
google={this.state.google}
/>
</ContextProvider>
</div>
) : (
loader
)}
<GoogleChartLoader
{...{ chartLanguage, chartPackages, chartVersion, mapsApiKey }}
onLoad={google => {
this.setState({
loadingStatus: "ready",
google
});
}}
onError={() => {
this.setState({
loadingStatus: "errored"
});
}}
/>
</ContextProvider>
);
}
}
Expand Down
11 changes: 9 additions & 2 deletions src/components/GoogleChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,16 @@ export class GoogleChart extends React.Component<Props, State> {
return <div ref={this.toolbar_ref} />;
};
render() {
const { width, height, options, style } = this.props;

const divStyle = {
height: height || (options && options.height),
width: width || (options && options.width),
...style
};
if (this.props.render !== null) {
return (
<div ref={this.dashboard_ref}>
<div ref={this.dashboard_ref} style={divStyle}>
<div ref={this.toolbar_ref} id="toolbar" />
{this.props.render({
renderChart: this.renderChart,
Expand All @@ -279,7 +286,7 @@ export class GoogleChart extends React.Component<Props, State> {
);
} else {
return (
<div ref={this.dashboard_ref}>
<div ref={this.dashboard_ref} style={divStyle}>
{this.renderControl(({ controlProp }) => {
return controlProp.controlPosition !== "bottom";
})}
Expand Down

0 comments on commit 5133765

Please sign in to comment.