From 1ee676ac9ae2ef1c35fe1af261d1a75240ca66be Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Thu, 26 Apr 2018 14:12:06 -0500 Subject: [PATCH 1/2] add clear_on_doubleclick prop for clearing clickData --- dash_core_components/metadata.json | 11 +++++++++++ src/components/Graph.react.js | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/dash_core_components/metadata.json b/dash_core_components/metadata.json index e2adde4bc..5f0e4c0e9 100644 --- a/dash_core_components/metadata.json +++ b/dash_core_components/metadata.json @@ -920,6 +920,17 @@ "computed": false } }, + "clear_on_doubleclick": { + "type": { + "name": "bool" + }, + "required": false, + "description": "If True, `clear_on_doubleclick` will clear the `clickData` property\nwhen the user double clicks (when dragmode='zoom').", + "defaultValue": { + "value": "false", + "computed": false + } + }, "hoverData": { "type": { "name": "object" diff --git a/src/components/Graph.react.js b/src/components/Graph.react.js index 0315567ba..7f0c6d426 100644 --- a/src/components/Graph.react.js +++ b/src/components/Graph.react.js @@ -102,7 +102,7 @@ export default class PlotlyGraph extends Component { } bindEvents() { - const {id, fireEvent, setProps, clear_on_unhover} = this.props; + const {id, fireEvent, setProps, clear_on_unhover, clear_on_doubleclick} = this.props; const gd = document.getElementById(id); @@ -144,6 +144,13 @@ export default class PlotlyGraph extends Component { if (fireEvent) fireEvent({event: 'unhover'}); } }); + gd.on('plotly_doubleclick', () => { + if (clear_on_doubleclick) { + if (setProps) setProps({clickData: null}); + if (fireEvent) fireEvent({event: 'doubleclick'}); + } + }) + } componentDidMount() { @@ -212,6 +219,12 @@ PlotlyGraph.propTypes = { */ clickData: PropTypes.object, + /** + * If True, `clear_on_doubleclick` will clear the `clickData` property + * when the user double clicks (when dragmode='zoom'). + */ + clear_on_doubleclick: PropTypes.bool, + /** * Data from latest hover event */ @@ -225,6 +238,7 @@ PlotlyGraph.propTypes = { */ clear_on_unhover: PropTypes.bool, + /** * Data from latest select event */ @@ -481,6 +495,7 @@ PlotlyGraph.defaultProps = { ease: 'cubic-in-out' } }, + clear_on_doubleclick: false, clear_on_unhover: false, config: { staticPlot: false, From d00621fab14e5b4f9db33c0bfbbbe97c4b782290 Mon Sep 17 00:00:00 2001 From: Carson Sievert Date: Mon, 30 Apr 2018 15:22:40 -0500 Subject: [PATCH 2/2] clear on deselect events as well --- dash_core_components/metadata.json | 2 +- src/components/Graph.react.js | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/dash_core_components/metadata.json b/dash_core_components/metadata.json index 5f0e4c0e9..d2533e373 100644 --- a/dash_core_components/metadata.json +++ b/dash_core_components/metadata.json @@ -925,7 +925,7 @@ "name": "bool" }, "required": false, - "description": "If True, `clear_on_doubleclick` will clear the `clickData` property\nwhen the user double clicks (when dragmode='zoom').", + "description": "If True, `clear_on_doubleclick` will clear the `clickData` property\nwhen the user double clicks.", "defaultValue": { "value": "false", "computed": false diff --git a/src/components/Graph.react.js b/src/components/Graph.react.js index 7f0c6d426..c6713cbbd 100644 --- a/src/components/Graph.react.js +++ b/src/components/Graph.react.js @@ -130,6 +130,10 @@ export default class PlotlyGraph extends Component { gd.on('plotly_deselect', () => { if (setProps) setProps({selectedData: null}); if (fireEvent) fireEvent({event: 'selected'}); + if (clear_on_doubleclick) { + if (setProps) setProps({clickData: null}); + if (fireEvent) fireEvent({event: 'unclick'}); + } }); gd.on('plotly_relayout', (eventData) => { const relayoutData = filterEventData(gd, eventData, 'relayout'); @@ -147,7 +151,7 @@ export default class PlotlyGraph extends Component { gd.on('plotly_doubleclick', () => { if (clear_on_doubleclick) { if (setProps) setProps({clickData: null}); - if (fireEvent) fireEvent({event: 'doubleclick'}); + if (fireEvent) fireEvent({event: 'unclick'}); } }) @@ -221,7 +225,7 @@ PlotlyGraph.propTypes = { /** * If True, `clear_on_doubleclick` will clear the `clickData` property - * when the user double clicks (when dragmode='zoom'). + * when the user double clicks. */ clear_on_doubleclick: PropTypes.bool,