From 47dc364a2f91e9df06bf7b2536055b0e09ade5c9 Mon Sep 17 00:00:00 2001 From: Rafal Slawik Date: Fri, 16 Aug 2019 22:17:19 +0100 Subject: [PATCH] Fix: update selection after selection event --- google-chart.js | 3 +++ test/basic-tests.html | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/google-chart.js b/google-chart.js index 6200903..2aa7b75 100644 --- a/google-chart.js +++ b/google-chart.js @@ -364,6 +364,9 @@ Polymer({ google.visualization.events.addListener(chartWrapper, 'ready', () => { this._setDrawn(true); }); + google.visualization.events.addListener(chartWrapper, 'select', () => { + this.selection = chartWrapper.getChart().getSelection(); + }); this._propagateEvents(DEFAULT_EVENTS, chartWrapper); }); }, diff --git a/test/basic-tests.html b/test/basic-tests.html index 55ee18c..f3c3928 100644 --- a/test/basic-tests.html +++ b/test/basic-tests.html @@ -79,6 +79,27 @@ return chart.$$('rect[stroke="#ffffff"]'); }, done); }); + test('updates selection', function(done) { + chart.data = [ + ['Data', 'Value'], + ['Something 1', 1], + ['Something 2', 2], + ['Something 3', 3], + ]; + chart.addEventListener('google-chart-select', () => { + assert.sameDeepMembers(chart.selection, [ {row: 2, column: 1} ]); + done(); + }, {once: true}); + chart.selection = [ {row: 0, column: 1} ]; + chart.addEventListener('google-chart-ready', () => { + // Look for something that can be clicked. Find rectangles for legend + // and each bar. + const rects = chart.$$('#chartdiv') + .querySelectorAll('rect[fill="#3366cc"]'); + // Click on the last bar ('Something 3'). + rects[3].dispatchEvent(new MouseEvent('click', {bubbles: true})); + }, {once: true}); + }); test('default options are null', function() { assert.equal(chart.options, null); });