Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

dcc.Graph: Improve responsiveness, expose resize status, allow wrapper extension #706

Merged
merged 53 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
6a4a2b3
wip - responsive graph
Nov 20, 2019
d721038
render and layout strategies
Nov 21, 2019
6361f5b
unified render, overrideable responsive behavior
Nov 21, 2019
a02a986
cleanup
Nov 21, 2019
2f957bf
Merge branch 'dev' into 605-graph-resize
Marc-Andre-Rivet Nov 21, 2019
33afc15
undo webpack changes
Nov 21, 2019
260c90b
Merge branch '605-graph-resize' of github.com:plotly/dash-core-compon…
Nov 21, 2019
ed02f5e
document `responsive`
Nov 21, 2019
c2fcd2c
format
Nov 21, 2019
3badeb9
comments
Nov 21, 2019
327a9e3
format
Nov 21, 2019
46aed75
clean up overrides
Nov 21, 2019
c3f6fd9
rework
Nov 29, 2019
0b78f42
typo
Nov 29, 2019
b36919d
Merge branch 'dev' into 605-graph-resize
Marc-Andre-Rivet Nov 29, 2019
b784df8
rework layout logic
Nov 29, 2019
dc6b4ae
- all graph responsiveness combos
Nov 29, 2019
de29b48
is True/False
Nov 29, 2019
9ba52e6
- default to responsive 'auto'
Nov 29, 2019
41527bf
update prop description
Nov 29, 2019
f0ba158
resize counter
Dec 2, 2019
79d3bfa
update tests
Dec 2, 2019
0d81609
changelog
Dec 2, 2019
860d133
update responsive docs
Dec 2, 2019
4555c68
lint
Dec 2, 2019
c8a5679
responsive relation with style
Dec 3, 2019
c01eb32
- private layout/config transform methods to customize plot behavior
Dec 5, 2019
28e9dd6
update tests
Dec 5, 2019
c6a2d4a
- remove counters (requires plotly.js 4392 to fully work)
Dec 5, 2019
577cc8b
div -> fragment wrapper
Dec 6, 2019
571db5a
lint
Dec 6, 2019
a30abcb
plot on transform functions update
Dec 10, 2019
71852a3
format
Dec 10, 2019
3e4de1c
use props arg
Dec 10, 2019
c60b59c
reduce meddling to a minimum when using `auto` mode - eval responsive…
Dec 10, 2019
ed1b823
update responsiveness and tests based on plotly.js' behavior (auto) w…
Dec 10, 2019
cd41f75
Due to react-resize-detector, need to move back to the div wrapper to…
Dec 11, 2019
68b9c8e
dash-graph and 'legacy' js-plotly-plot class
Dec 11, 2019
a59682e
Update dash-graph-resizing to dash-graph--pending
Dec 11, 2019
8beae49
Remove `dash-graph--pending` from scope
Dec 12, 2019
99b9a08
add it back...
Dec 12, 2019
74b08fc
- clean up className passing
Dec 12, 2019
fb218a5
- add pending class on `Plotly.react`
Dec 12, 2019
8addc80
Merge branch 'dev' into 605-graph-resize
Marc-Andre-Rivet Dec 12, 2019
d1a1dd5
update changelog
Dec 12, 2019
701809b
Merge branch '605-graph-resize' of github.com:plotly/dash-core-compon…
Dec 12, 2019
530ef65
Merge branch 'dev' into 605-graph-resize
Marc-Andre-Rivet Dec 13, 2019
cb77c3b
- update to plotly.js 1.51.3
Dec 16, 2019
b39406e
re-remove js-plotly-plot
Dec 16, 2019
56d883b
Clean up props usage
Dec 16, 2019
6867be2
clean up the clean up
Dec 16, 2019
c744ae9
clean up the clean up of the clean up
Dec 16, 2019
de59930
remove useless gitignore entry
Dec 16, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- [#706](https://github.com/plotly/dash-core-components/pull/706)
- Added new `responsive` property that overrides the underlying Plotly.js graph responsiveness from Dash-land
- Added responsiveness on graph parent element resize (previously only worked on window.resize)
- Added new `dash-graph--pending` class to dcc.Graph, present while resizing, (re-)rendering, loading

### Updated
- [#706](https://github.com/plotly/dash-core-components/pull/706)
- Upgraded plotly.js to [1.51.3](https://github.com/plotly/plotly.js/releases/tag/v1.51.3)

Copy link
Contributor Author

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 🎉

## [1.6.0] - 2019-11-27
### Updated
- Upgraded plotly.js to 1.51.2 [#708](https://github.com/plotly/dash-core-components/pull/708)
Expand Down
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Plotly.js artifact is now always plotly.min.js, no need for weird updates

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
Expand Down
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include dash_core_components/async~*.js.map
include dash_core_components/highlight.pack.js
include dash_core_components/metadata.json
include dash_core_components/package-info.json
include dash_core_components/plotly-*.min.js
include dash_core_components/plotly.min.js
include README.md
include LICENSE.txt
include package.json
4 changes: 2 additions & 2 deletions dash_core_components_base/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@
'dynamic': True
},
{
'relative_package_path': 'plotly-1.51.2.min.js',
'relative_package_path': 'plotly.min.js',
'external_url': (
'https://unpkg.com/dash-core-components@{}'
'/dash_core_components/plotly-1.51.2.min.js'
'/dash_core_components/plotly.min.js'
).format(__version__),
'namespace': 'dash_core_components',
'async': 'eager'
Expand Down
7 changes: 0 additions & 7 deletions dash_core_components_base/plotly-1.51.2.min.js

This file was deleted.

51 changes: 45 additions & 6 deletions package-lock.json

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

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"format": "prettier --config .prettierrc --write src/**/*.js tests/unit/*.js",
"format:test": "prettier --config .prettierrc src/**/*.js tests/unit/*.js --list-different",
"uninstall-local": "pip uninstall dash-core-components -y",
"prebuild:js": "cp node_modules/plotly.js/dist/plotly.min.js dash_core_components_base/plotly.min.js",
"build:js": "webpack --mode production",
"build:py_and_r": "dash-generate-components ./src/components dash_core_components -p package-info.json && cp dash_core_components_base/** dash_core_components/ && dash-generate-components ./src/components dash_core_components -p package-info.json --r-prefix 'dcc'",
"build": "run-s build:js generator build:py_and_r",
Expand All @@ -36,7 +37,7 @@
"color": "^3.1.0",
"fast-isnumeric": "^1.1.3",
"moment": "^2.20.1",
"plotly.js": "1.51.2",
"plotly.js": "1.51.3",
"prop-types": "^15.6.0",
"ramda": "^0.26.1",
"rc-slider": "^8.6.11",
Expand Down Expand Up @@ -78,6 +79,7 @@
"prettier": "^1.14.2",
"react": "^16.8.6",
"react-dom": "^16.8.6",
"react-resize-detector": "^4.2.1",
"style-loader": "^0.23.1",
"styled-jsx": "^3.1.1",
"terser-webpack-plugin": "^2.3.0",
Expand Down
69 changes: 54 additions & 15 deletions src/components/Graph.react.js
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 = [];

Expand Down Expand Up @@ -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}
/>
);
}
Expand All @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The 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:

The prop `isRequired` is marked as required in `<<anonymous>>`,
but its value is `undefined`

That I think is coming from here... Should this just be a copy of PlotlyGraph.propTypes perhaps?


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']),
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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 config/figure values.


/**
* Data from latest click event. Read-only.
*/
Expand Down Expand Up @@ -479,6 +515,8 @@ PlotlyGraph.propTypes = {
};

PlotlyGraph.defaultProps = {
...privateDefaultProps,

clickData: null,
clickAnnotationData: null,
hoverData: null,
Expand All @@ -491,6 +529,7 @@ PlotlyGraph.defaultProps = {
layout: {},
frames: [],
},
responsive: 'auto',
animate: false,
animation_options: {
frame: {
Expand Down
11 changes: 11 additions & 0 deletions src/fragments/Graph.privateprops.js
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,
};
Loading