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

Commit 96e54cc

Browse files
Merge pull request #219 from plotly/remove-graph-id
Set Graph id to be optional
2 parents 2fb53f3 + f90fe4c commit 96e54cc

File tree

7 files changed

+61
-9
lines changed

7 files changed

+61
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55
## [0.28.2] - 2018-09-07
66
### Changed
77
- The `Interval` component's `max_interval` prop can now be used to stop/restart the interval. Fixes [#266](https://github.com/plotly/dash-core-components/issues/266)
8+
- The `Graph` component's `id` is now not required to be set.
89
### Fixed
910
- Fixed bug where Graph would resize randomly when rerendered, for example in a dcc.Tabs component.
10-
-
1111

1212
## [0.28.2] - 2018-09-06
1313
### Fixed

dash_core_components/Graph.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ class Graph(Component):
88
99
1010
Keyword arguments:
11-
- id (string; required)
11+
- id (string; optional): The ID of this component, used to identify dash components
12+
in callbacks. The ID needs to be unique across all of the
13+
components in an app.
1214
- clickData (dict; optional): Data from latest click event
1315
- hoverData (dict; optional): Data from latest hover event
1416
- clear_on_unhover (boolean; optional): If True, `clear_on_unhover` will clear the `hoverData` property
@@ -84,7 +86,7 @@ class Graph(Component):
8486
8587
Available events: 'click', 'hover', 'selected', 'relayout', 'unhover'"""
8688
@_explicitize_args
87-
def __init__(self, id=Component.REQUIRED, clickData=Component.UNDEFINED, hoverData=Component.UNDEFINED, clear_on_unhover=Component.UNDEFINED, selectedData=Component.UNDEFINED, relayoutData=Component.UNDEFINED, figure=Component.UNDEFINED, style=Component.UNDEFINED, className=Component.UNDEFINED, animate=Component.UNDEFINED, animation_options=Component.UNDEFINED, config=Component.UNDEFINED, **kwargs):
89+
def __init__(self, id=Component.UNDEFINED, clickData=Component.UNDEFINED, hoverData=Component.UNDEFINED, clear_on_unhover=Component.UNDEFINED, selectedData=Component.UNDEFINED, relayoutData=Component.UNDEFINED, figure=Component.UNDEFINED, style=Component.UNDEFINED, className=Component.UNDEFINED, animate=Component.UNDEFINED, animation_options=Component.UNDEFINED, config=Component.UNDEFINED, **kwargs):
8890
self._prop_names = ['id', 'clickData', 'hoverData', 'clear_on_unhover', 'selectedData', 'relayoutData', 'figure', 'style', 'className', 'animate', 'animation_options', 'config']
8991
self._type = 'Graph'
9092
self._namespace = 'dash_core_components'
@@ -98,7 +100,7 @@ def __init__(self, id=Component.REQUIRED, clickData=Component.UNDEFINED, hoverDa
98100
_locals.update(kwargs) # For wildcard attrs
99101
args = {k: _locals[k] for k in _explicit_args if k != 'children'}
100102

101-
for k in ['id']:
103+
for k in []:
102104
if k not in args:
103105
raise TypeError(
104106
'Required argument `' + k + '` was not specified.')

dash_core_components/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dash_core_components/metadata.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,12 @@
11471147
"type": {
11481148
"name": "string"
11491149
},
1150-
"required": true,
1151-
"description": ""
1150+
"required": false,
1151+
"description": "The ID of this component, used to identify dash components\nin callbacks. The ID needs to be unique across all of the\ncomponents in an app.",
1152+
"defaultValue": {
1153+
"value": "'graph-' + Math.random().toString(36).substring(2,7)",
1154+
"computed": false
1155+
}
11521156
},
11531157
"clickData": {
11541158
"type": {

dash_core_components/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "dash-core-components",
3-
"version": "0.28.2",
3+
"version": "0.28.3",
44
"description": "Core component suite for Dash",
55
"repository": {
66
"type": "git",

src/components/Graph.react.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,12 @@ export default class PlotlyGraph extends Component {
193193
}
194194

195195
PlotlyGraph.propTypes = {
196-
id: PropTypes.string.isRequired,
196+
/**
197+
* The ID of this component, used to identify dash components
198+
* in callbacks. The ID needs to be unique across all of the
199+
* components in an app.
200+
*/
201+
id: PropTypes.string,
197202
/**
198203
* Data from latest click event
199204
*/
@@ -453,6 +458,9 @@ PlotlyGraph.propTypes = {
453458
}
454459

455460
PlotlyGraph.defaultProps = {
461+
/* eslint-disable no-magic-numbers */
462+
id: 'graph-' + Math.random().toString(36).substring(2,7),
463+
/* eslint-enable no-magic-numbers */
456464
clickData: null,
457465
hoverData: null,
458466
selectedData: null,

test/test_integration.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,44 @@ def update_graph(n_clicks):
854854
time.sleep(2)
855855
self.snapshot('candlestick - 2 click')
856856

857+
def test_graphs_with_different_figures(self):
858+
app = dash.Dash(__name__)
859+
app.layout = html.Div([
860+
dcc.Graph(
861+
id='example-graph',
862+
figure={
863+
'data': [
864+
{'x': [1, 2, 3], 'y': [4, 1, 2],
865+
'type': 'bar', 'name': 'SF'},
866+
{'x': [1, 2, 3], 'y': [2, 4, 5],
867+
'type': 'bar', 'name': u'Montréal'},
868+
],
869+
'layout': {
870+
'title': 'Dash Data Visualization'
871+
}
872+
}
873+
),
874+
dcc.Graph(
875+
id='example-graph-2',
876+
figure={
877+
'data': [
878+
{'x': [20, 24, 33], 'y': [5, 2, 3],
879+
'type': 'bar', 'name': 'SF'},
880+
{'x': [11, 22, 33], 'y': [22, 44, 55],
881+
'type': 'bar', 'name': u'Montréal'},
882+
],
883+
'layout': {
884+
'title': 'Dash Data Visualization'
885+
}
886+
}
887+
),
888+
889+
])
890+
891+
self.startServer(app=app)
892+
893+
self.snapshot('2 graphs with different figures')
894+
857895
def test_datepickerrange_updatemodes(self):
858896
app = dash.Dash(__name__)
859897

0 commit comments

Comments
 (0)