-
-
Notifications
You must be signed in to change notification settings - Fork 145
dcc.Graph: Improve responsiveness, expose resize status, allow wrapper extension #706
Changes from all commits
6a4a2b3
d721038
6361f5b
a02a986
2f957bf
33afc15
260c90b
ed02f5e
c2fcd2c
3badeb9
327a9e3
46aed75
c3f6fd9
0b78f42
b36919d
b784df8
dc6b4ae
de29b48
9ba52e6
41527bf
f0ba158
79d3bfa
0d81609
860d133
4555c68
c8a5679
c01eb32
28e9dd6
c6a2d4a
577cc8b
571db5a
a30abcb
71852a3
3e4de1c
c60b59c
ed1b823
cd41f75
68b9c8e
a59682e
8beae49
99b9a08
74b08fc
fb218a5
8addc80
d1a1dd5
701809b
530ef65
cb77c3b
b39406e
56d883b
6867be2
c744ae9
de59930
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,9 +34,7 @@ Locally](README.md#testing-locally) section of README.md. | |
## Updating Plotly.js | ||
|
||
1. Update the version of `plotly.js` in package.json. Always use an exact version without "^" or "~" | ||
2. Run `npm install` followed by `npm run build`, this will ensure the latest version of Plotly.js is in `node_modules` and copy | ||
that version over with the other build artifacts | ||
3. Update `dash_core_components_base/__init__.py` plotly.js `relative_package_path` and `external_url` | ||
2. Run `npm install` followed by `npm run build`, the Plotly.js artifact will be copied and bundled over as required | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plotly.js artifact is now always |
||
4. Update `CHANGELOG.md` with links to the releases and a description of the changes. The message should state (see the existing `CHANGELOG.md` for examples): | ||
* If you're only bumping the patch level, the heading is "Fixed" and the text starts "Patched plotly.js". Otherwise the heading is "Updated" and the text starts "Upgraded plotly.js" | ||
* The new plotly.js version number, and the PR in which this was done | ||
|
This file was deleted.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,12 @@ | ||
import React, {Component, PureComponent, Suspense} from 'react'; | ||
import React, {Component, memo, Suspense} from 'react'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import {asyncDecorator} from '@plotly/dash-component-plugins'; | ||
import LazyLoader from '../utils/LazyLoader'; | ||
import { | ||
privatePropTypes, | ||
privateDefaultProps, | ||
} from '../fragments/Graph.privateprops'; | ||
|
||
const EMPTY_EXTEND_DATA = []; | ||
|
||
|
@@ -76,11 +80,9 @@ class PlotlyGraph extends Component { | |
render() { | ||
return ( | ||
<ControlledPlotlyGraph | ||
{...{ | ||
...this.props, | ||
extendData: this.state.extendData, | ||
clearExtendData: this.clearExtendData, | ||
}} | ||
{...this.props} | ||
extendData={this.state.extendData} | ||
clearExtendData={this.clearExtendData} | ||
/> | ||
); | ||
} | ||
|
@@ -90,24 +92,58 @@ const RealPlotlyGraph = asyncDecorator(PlotlyGraph, () => | |
LazyLoader.plotly().then(LazyLoader.graph) | ||
); | ||
|
||
class ControlledPlotlyGraph extends PureComponent { | ||
render() { | ||
return ( | ||
<Suspense fallback={null}> | ||
<RealPlotlyGraph {...this.props} /> | ||
</Suspense> | ||
); | ||
} | ||
} | ||
const ControlledPlotlyGraph = memo(props => { | ||
const {className, id} = props; | ||
|
||
const extendedClassName = className | ||
? 'dash-graph ' + className | ||
: 'dash-graph'; | ||
|
||
return ( | ||
<Suspense | ||
fallback={ | ||
<div | ||
id={id} | ||
key={id} | ||
className={`${extendedClassName} dash-graph--pending`} | ||
/> | ||
} | ||
> | ||
<RealPlotlyGraph {...props} className={extendedClassName} /> | ||
</Suspense> | ||
); | ||
}); | ||
|
||
ControlledPlotlyGraph.propTypes = PropTypes.any; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Marc-Andre-Rivet I'm seeing a funny warning message in debug mode:
That I think is coming from here... Should this just be a copy of |
||
|
||
PlotlyGraph.propTypes = { | ||
...privatePropTypes, | ||
|
||
/** | ||
* The ID of this component, used to identify dash components | ||
* in callbacks. The ID needs to be unique across all of the | ||
* components in an app. | ||
*/ | ||
id: PropTypes.string, | ||
|
||
/** | ||
* If True, the Plotly.js plot will be fully responsive to window resize | ||
* and parent element resize event. This is achieved by overriding | ||
* `config.responsive` to True, `figure.layout.autosize` to True and unsetting | ||
* `figure.layout.height` and `figure.layout.width`. | ||
* If False, the Plotly.js plot not be responsive to window resize and | ||
* parent element resize event. This is achieved by overriding `config.responsive` | ||
* to False and `figure.layout.autosize` to False. | ||
* If 'auto' (default), the Graph will determine if the Plotly.js plot can be made fully | ||
* responsive (True) or not (False) based on the values in `config.responsive`, | ||
* `figure.layout.autosize`, `figure.layout.height`, `figure.layout.width`. | ||
* This is the legacy behavior of the Graph component. | ||
* | ||
* Needs to be combined with appropriate dimension / styling through the `style` prop | ||
* to fully take effect. | ||
*/ | ||
responsive: PropTypes.oneOf([true, false, 'auto']), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Allow users to define the behavior they want for their graph, allowing them to override the normal behavior for their |
||
|
||
/** | ||
* Data from latest click event. Read-only. | ||
*/ | ||
|
@@ -479,6 +515,8 @@ PlotlyGraph.propTypes = { | |
}; | ||
|
||
PlotlyGraph.defaultProps = { | ||
...privateDefaultProps, | ||
|
||
clickData: null, | ||
clickAnnotationData: null, | ||
hoverData: null, | ||
|
@@ -491,6 +529,7 @@ PlotlyGraph.defaultProps = { | |
layout: {}, | ||
frames: [], | ||
}, | ||
responsive: 'auto', | ||
animate: false, | ||
animation_options: { | ||
frame: { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import PropTypes from 'prop-types'; | ||
|
||
export const privatePropTypes = { | ||
_dashprivate_transformConfig: PropTypes.func, | ||
_dashprivate_transformFigure: PropTypes.func, | ||
}; | ||
|
||
export const privateDefaultProps = { | ||
_dashprivate_transformConfig: c => c, | ||
_dashprivate_transformFigure: f => f, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Plotly.js 1.51.3 with the promise fix 🎉