From 0812a01cbf7193bacbdc95769be3b946ed46df6c Mon Sep 17 00:00:00 2001 From: Martin Krey Date: Fri, 6 Apr 2018 21:04:41 +0200 Subject: [PATCH 1/2] added clickannotation event --- src/components/Graph.react.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/components/Graph.react.js b/src/components/Graph.react.js index 20b4da617..be074f51a 100644 --- a/src/components/Graph.react.js +++ b/src/components/Graph.react.js @@ -98,6 +98,11 @@ export default class PlotlyGraph extends Component { if (fireEvent) fireEvent({event: 'click'}); } }); + gd.on('plotly_clickannotation', (eventData) => { + const clickAnnotationData = eventData; + if (setProps) setProps({clickAnnotationData}); + if (fireEvent) fireEvent({event: 'clickannotation'}); + }); gd.on('plotly_hover', (eventData) => { const hoverData = filterEventData(gd, eventData, 'hover'); if (!isNil(hoverData)) { @@ -196,6 +201,11 @@ PlotlyGraph.propTypes = { * Data from latest click event */ clickData: PropTypes.object, + + /** + * Data from latest click annotation event + */ + clickAnnotationData: PropTypes.object, /** * Data from latest hover event @@ -433,6 +443,7 @@ PlotlyGraph.propTypes = { */ dashEvents: PropTypes.oneOf([ 'click', + 'clickannotation', 'hover', 'selected', 'relayout', @@ -452,6 +463,7 @@ PlotlyGraph.propTypes = { PlotlyGraph.defaultProps = { clickData: null, + clickAnnotationData: null, hoverData: null, selectedData: null, relayoutData: null, From 0fe41d1518e402cda9dcda476359ef7cd6be2994 Mon Sep 17 00:00:00 2001 From: Martin Krey Date: Tue, 1 May 2018 12:22:45 +0200 Subject: [PATCH 2/2] Added `clickannotation` event to `dcc.Graph` with filtering of `fullAnnotation` and `event` data. --- CHANGELOG.md | 5 +++++ dash_core_components/version.py | 2 +- src/components/Graph.react.js | 4 ++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b2a2d7413..c3d37b956 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.22.2] - 2018-05-01 +### Added +- Added `clickannotation` event to `dcc.Graph`. +See https://github.com/plotly/dash-core-components/pull/182. + ## [0.22.1] - 2018-04-09 ### Fixed - Various bugs with the `ohlc` and `candlestick` chart type in the `dcc.Graph` diff --git a/dash_core_components/version.py b/dash_core_components/version.py index 66d9d1e39..cc3736414 100644 --- a/dash_core_components/version.py +++ b/dash_core_components/version.py @@ -1 +1 @@ -__version__ = '0.22.1' +__version__ = '0.22.2' diff --git a/src/components/Graph.react.js b/src/components/Graph.react.js index 0c2cff045..924768c50 100644 --- a/src/components/Graph.react.js +++ b/src/components/Graph.react.js @@ -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, intersection, filter, has, isNil, type, pluck, omit} from 'ramda'; /* global Plotly:true */ const filterEventData = (gd, eventData, event) => { @@ -114,7 +114,7 @@ export default class PlotlyGraph extends Component { } }); gd.on('plotly_clickannotation', (eventData) => { - const clickAnnotationData = eventData; + const clickAnnotationData = omit(['event', 'fullAnnotation'], eventData); if (setProps) setProps({clickAnnotationData}); if (fireEvent) fireEvent({event: 'clickannotation'}); });