Skip to content

Commit 902be58

Browse files
rslawikwesalvaro
authored andcommitted
Fix: update selection after selection event (#251)
1 parent ad7db2a commit 902be58

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

google-chart.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,9 @@ Polymer({
364364
google.visualization.events.addListener(chartWrapper, 'ready', () => {
365365
this._setDrawn(true);
366366
});
367+
google.visualization.events.addListener(chartWrapper, 'select', () => {
368+
this.selection = chartWrapper.getChart().getSelection();
369+
});
367370
this._propagateEvents(DEFAULT_EVENTS, chartWrapper);
368371
});
369372
},

test/basic-tests.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,27 @@
7979
return chart.$$('rect[stroke="#ffffff"]');
8080
}, done);
8181
});
82+
test('updates selection', function(done) {
83+
chart.data = [
84+
['Data', 'Value'],
85+
['Something 1', 1],
86+
['Something 2', 2],
87+
['Something 3', 3],
88+
];
89+
chart.addEventListener('google-chart-select', () => {
90+
assert.sameDeepMembers(chart.selection, [ {row: 2, column: 1} ]);
91+
done();
92+
}, {once: true});
93+
chart.selection = [ {row: 0, column: 1} ];
94+
chart.addEventListener('google-chart-ready', () => {
95+
// Look for something that can be clicked. Find rectangles for legend
96+
// and each bar.
97+
const rects = chart.$$('#chartdiv')
98+
.querySelectorAll('rect[fill="#3366cc"]');
99+
// Click on the last bar ('Something 3').
100+
rects[3].dispatchEvent(new MouseEvent('click', {bubbles: true}));
101+
}, {once: true});
102+
});
82103
test('default options are null', function() {
83104
assert.equal(chart.options, null);
84105
});

0 commit comments

Comments
 (0)