Skip to content

Commit

Permalink
loadable plotly
Browse files Browse the repository at this point in the history
  • Loading branch information
mihai-macaneata committed Jan 12, 2020
1 parent 19fadff commit b23bdcc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 deletions.
11 changes: 10 additions & 1 deletion src/ChartBlock/Edit.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,16 @@ class Edit extends Component {
}

render() {
const plotly = require('plotly.js/dist/plotly');
const plotly = Loadable({
loader: () => import('plotly.js/dist/plotly'),
loading() {
return <div>Loading chart editor...</div>;
},
});

const selectProviders = this.props.providers.map(el => {
return [el['@id'], el.title];
});

const chartData = this.props.data.chartData || {
layout: {},
Expand Down
7 changes: 6 additions & 1 deletion src/Widget/ModalEditor.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,13 @@ class Edit extends Component {
constructor(props) {
super(props);
this.state = {
plotly: require('plotly.js/dist/plotly'),
providerData: null,
plotly: Loadable({
loader: () => import('plotly.js/dist/plotly'),
loading() {
return <div>Loading chart editor...</div>;
},
}),
};
}

Expand Down
9 changes: 8 additions & 1 deletion src/Widget/Widget.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import ChartEditor from './ModalEditor';
import React, { Component } from 'react';
import { Button, Modal, Form, Grid, Label } from 'semantic-ui-react';
import { map } from 'lodash';
import Loadable from 'react-loadable';

class ModalChartEditor extends Component {
constructor(props) {
Expand Down Expand Up @@ -69,7 +70,13 @@ class ChartWidget extends Component {
height: this.props.value?.layout?.height || 240,
};

const LoadablePlot = require('react-plotly.js').default;
const LoadablePlot = Loadable({
loader: () => import('react-plotly.js'),
loading() {
return <div>Loading chart editor...</div>;
},
}).default;

return (
<Form.Field
inline
Expand Down
3 changes: 0 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
import plotly from 'react-plotly.js';

export default plotly;

0 comments on commit b23bdcc

Please sign in to comment.