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

add clear_on_doubleclick prop for clearing clickData #193

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 11 additions & 0 deletions dash_core_components/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 16 additions & 1 deletion src/components/Graph.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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').
Copy link
Member

Choose a reason for hiding this comment

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

Only on dragmode='zoom'? Also, could we be more specific about dragmode, like figure['layout']['dragmode'] = 'zoom' or config['dragmode'] = 'zoom'

*/
clear_on_doubleclick: PropTypes.bool,

/**
* Data from latest hover event
*/
Expand All @@ -225,6 +238,7 @@ PlotlyGraph.propTypes = {
*/
clear_on_unhover: PropTypes.bool,


/**
* Data from latest select event
*/
Expand Down Expand Up @@ -481,6 +495,7 @@ PlotlyGraph.defaultProps = {
ease: 'cubic-in-out'
}
},
clear_on_doubleclick: false,
clear_on_unhover: false,
config: {
staticPlot: false,
Expand Down