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

Fix #260, allow '{}' as Graph.figure #285

Merged
merged 3 commits into from
Aug 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.28.1] - 2018-08-29
### Changed
- `candlestick` and `OHLC` charts are now plotted using the `Plotly.react` method instead of the `Plotly.newPlot` method.
### Fixed
- Fix bug where front-end error was thrown when setting `Graph.figure = {}` (fixes [#260]).

## [0.28.0]
- Upgraded Plotly.js, the underlying library behind the
`dash_core_components.Graph` component, to [version 1.40.1](https://github.com/plotly/plotly.js/releases/tag/v1.40.1).
Expand Down
6 changes: 3 additions & 3 deletions dash_core_components/bundle.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dash_core_components/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2703,7 +2703,7 @@
"required": false,
"description": "Overrides the default (inline) styles when disabled",
"defaultValue": {
"value": "{\n color: '#d6d6d6',\n}",
"value": "{\n color: '#d6d6d6'\n}",
"computed": false
}
},
Expand Down Expand Up @@ -2864,7 +2864,7 @@
"required": false,
"description": "Holds the colors used by the Tabs and Tab components. If you set these, you should specify colors for all properties, so:\ncolors: {\n border: '#d6d6d6',\n primary: '#1975FA',\n background: '#f9f9f9'\n }",
"defaultValue": {
"value": "{\n border: '#d6d6d6',\n primary: '#1975FA',\n background: '#f9f9f9',\n}",
"value": "{\n border: '#d6d6d6',\n primary: '#1975FA',\n background: '#f9f9f9'\n}",
"computed": false
}
}
Expand Down
2 changes: 1 addition & 1 deletion dash_core_components/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.28.0'
__version__ = '0.28.1'
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dash-core-components",
"version": "0.28.0",
"version": "0.28.1",
"description": "Core component suite for Dash",
"repository": {
"type": "git",
Expand Down
15 changes: 2 additions & 13 deletions src/components/Graph.react.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {contains, intersection, filter, has, isNil, type, pluck} from 'ramda';
import {contains, filter, has, isNil, type} from 'ramda';
/* global Plotly:true */

const filterEventData = (gd, eventData, event) => {
Expand Down Expand Up @@ -77,18 +77,7 @@ export default class PlotlyGraph extends Component {
if (animate && this._hasPlotted && figure.data.length === gd.data.length) {
return Plotly.animate(id, figure, animation_options);
} else {

let PlotMethod;
if (intersection(
pluck('type', figure.data),
['candlestick', 'ohlc']).length
) {
PlotMethod = Plotly.newPlot;
} else {
PlotMethod = Plotly.react;
}

return PlotMethod(id, figure.data, figure.layout, config).then(
return Plotly.react(id, figure.data, figure.layout, config).then(
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you clarify this for me? Isn't Plotly.newPlot needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am not sure, I just reverted this commit: ea4e66c#diff-b2faf9645a4fcca0badb59ef2fba58a3

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For context, that change was made because there was a bug in Plotly. That bug was fixed in plotly/plotly.js#2561 but we never removed the fix from Dash.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

#170 I found this, this is why we call Plotly.react

Copy link
Member

Choose a reason for hiding this comment

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

For some more context:

  • newPlot is needed for the first plot
  • Subsequent plots can be done with Plotly.react. It was intended to the be faster way to handle updates but in reality we don't get many of the improvements because we are always providing new copies of data. Context here: Plotly.react plotly.js#2341. If users added a layout.datarevision, then they would get some performance improvements but I haven't tested this and it's not really documented.
  • So, while we don't get the main intended features of Plotly.react, we do get one very critical feature: the ability to repeatedly replot webgl plots: Repeatedly calling newPlot with scatter3d causes graphs to disappear plotly.js#2423
  • Now, there were a lot of bugs with Plotly.react when it first came out. One of the bugs was that candlestick and ohlc charts didn't work with it. So, I called newPlot just for those chart types
  • However, that bug has been fixed. So, we should standardize on all chart types using Plotly.react. It also might fix an issue that a community user was seeing in relayoutData fails with Candlestick plots  dash#355 (comment)

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, great! Thanks for clarifying!

() => {
if (!this._hasPlotted) {
this.bindEvents();
Expand Down
6 changes: 3 additions & 3 deletions src/components/Tab.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,14 @@ Tab.propTypes = {
/**
* Overrides the default (inline) styles for the Tab component when it is selected.
*/
selected_style: PropTypes.object,
selected_style: PropTypes.object
};

Tab.defaultProps = {
disabled: false,
disabled_style: {
color: '#d6d6d6',
},
color: '#d6d6d6'
}
};

export default Tab;
16 changes: 8 additions & 8 deletions src/components/Tabs.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const EnhancedTab = ({
disabled_className,
mobile_breakpoint,
amountOfTabs,
colors,
colors
}) => {
let tabStyle = style;
if (disabled) {
Expand Down Expand Up @@ -110,14 +110,14 @@ export default class Tabs extends Component {
constructor(props) {
super(props);
this.state = {
selected: this.props.value || 'tab-1',
selected: this.props.value || 'tab-1'
};

this.selectHandler = this.selectHandler.bind(this);
}
selectHandler(value) {
this.setState({
selected: value,
selected: value
});
if (this.props.setProps) {
this.props.setProps({value: value});
Expand All @@ -126,7 +126,7 @@ export default class Tabs extends Component {
componentWillReceiveProps(newProps) {
const value = newProps.value;
this.setState({
selected: value,
selected: value
});
}
render() {
Expand Down Expand Up @@ -270,8 +270,8 @@ Tabs.defaultProps = {
colors: {
border: '#d6d6d6',
primary: '#1975FA',
background: '#f9f9f9',
},
background: '#f9f9f9'
}
};

Tabs.propTypes = {
Expand Down Expand Up @@ -343,6 +343,6 @@ Tabs.propTypes = {
colors: PropTypes.shape({
border: PropTypes.string,
primary: PropTypes.string,
background: PropTypes.string,
}),
background: PropTypes.string
})
};
Empty file removed test.py
Empty file.
28 changes: 27 additions & 1 deletion test/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import dash_html_components as html
import dash_core_components as dcc
import dash_table_experiments as dt
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import InvalidElementStateException

Expand Down Expand Up @@ -851,3 +850,30 @@ def on_click(n_clicks):
time.sleep(2)

self.driver.switch_to.alert.accept()

def test_empty_graph(self):
app = dash.Dash(__name__)

app.layout = html.Div([
html.Button(id='click', children='Click me'),
dcc.Graph(
id='graph',
figure={
'data': [dict(x=[1, 2, 3], y=[1, 2, 3], type='scatter')]
}
)
])

@app.callback(dash.dependencies.Output('graph', 'figure'),
[dash.dependencies.Input('click', 'n_clicks')],
[dash.dependencies.State('graph', 'figure')])
def render_content(click, prev_graph):
if click:
return {}
return prev_graph

self.startServer(app)
button = self.wait_for_element_by_css_selector('#click')
button.click()
time.sleep(2) # Wait for graph to re-render
self.snapshot('render-empty-graph')